Skip to main content

Heap

Struct Heap 

Source
pub struct Heap { /* private fields */ }

Implementations§

Source§

impl Heap

Source

pub fn collect(&mut self)

A full collection.

Source

pub fn set_gc_manual(&mut self, manual: bool)

Turns the growth trigger off (manual) or back on, with the budget of the live bytes the last collection left.

Source

pub fn verify(&mut self)

Post-collection verification: every live record is reachable and every reachable record is live; no free slot is marked and every arena’s free count agrees with its bitmap; every value-heap slot has exactly one owner, a live range or the free space.

Source§

impl Heap

Source

pub fn new(limits: HeapLimits) -> Self

Source

pub fn roots(&mut self) -> &mut RootStack

Source

pub fn handles(&mut self) -> &mut Handles

Source

pub fn handles_ref(&self) -> &Handles

Source

pub fn add_fixed_root(&mut self, value: Value) -> usize

Adds a runtime root; returns its slot.

Source

pub fn set_fixed_root(&mut self, slot: usize, value: Value)

Source

pub fn fixed_root(&self, slot: usize) -> Value

Source

pub fn gc(&self) -> &GcState

Source

pub fn gc_mut(&mut self) -> &mut GcState

Source

pub fn bytes(&self) -> usize

Bytes reserved by every arena, the value heap and the tables beside them (the ropes’ halves, the atom table, the inline caches): what the cap limits and the budget bounds.

Source

pub fn table_bytes(&self) -> usize

Bytes of the tables beside the arenas: the ropes’ halves, the atom table and the inline caches.

Source

pub fn used_bytes(&self) -> usize

Bytes held by live records and live value ranges.

Source

pub fn ics(&self) -> &IcStore

Source

pub fn ics_mut(&mut self) -> &mut IcStore

Source

pub fn global_generation(&self) -> u32

Source

pub fn value_heap(&self) -> &ValueHeap

Source

pub fn regexps(&self) -> &RegExpStore

The regular-expression programs.

Source

pub fn atom_table(&self) -> &AtomTable

Source

pub fn live_objects(&self) -> usize

Source

pub fn live_shapes(&self) -> usize

Source

pub fn live_strings(&self) -> usize

Source

pub fn live_cells(&self) -> usize

Source

pub fn is_live(&self, value: Value) -> bool

Source

pub fn alloc_object( &mut self, kind: ObjectKind, prototype: Option<ObjectId>, slot_capacity: u32, ) -> Result<ObjectId, HeapError>

A new object with room for slot_capacity named properties (rounded up to a size class) before its first growth. The global object kind is created in dictionary mode.

Source

pub fn alloc_internal( &mut self, kind: ObjectKind, tag: InternalTag, prototype: Option<ObjectId>, slot_capacity: u32, slots: &[Value], data: InternalData, extra_flags: u8, ) -> Result<ObjectId, HeapError>

An object of a kind with internal slots: an Internal record holding slots (rooted for the call) and data, with room for slot_capacity named properties. extra_flags adds CALLABLE and CONSTRUCTOR for the callable kinds.

Source

pub fn internal(&self, object: ObjectId) -> &Internal

The internal record of an object of a kind with internal slots.

Source

pub fn internal_mut(&mut self, object: ObjectId) -> &mut Internal

Source

pub fn internal_tag(&self, object: ObjectId) -> InternalTag

The tag of a ObjectKind::Builtin object, or None for any other.

Source

pub fn internal_slot(&self, object: ObjectId, slot: usize) -> Value

Source

pub fn set_internal_slot(&mut self, object: ObjectId, slot: usize, value: Value)

Source

pub fn push_internal_slot( &mut self, object: ObjectId, value: Value, ) -> Result<(), HeapError>

Appends value to the internal slots of object (a collection’s entries, a promise’s reactions), charging the growth to the trigger.

Source

pub fn object_kind(&self, object: ObjectId) -> ObjectKind

Source

pub fn header(&self, object: ObjectId) -> &ObjectHeader

Source

pub fn alloc_object_with_elements( &mut self, kind: ObjectKind, prototype: Option<ObjectId>, slot_capacity: u32, element_capacity: u32, ) -> Result<ObjectId, HeapError>

An object with room for slot_capacity named properties and element_capacity elements, for the kinds without a side record.

Source

pub fn alloc_array( &mut self, prototype: Option<ObjectId>, capacity: u32, ) -> Result<ObjectId, HeapError>

A dense array with room for capacity elements; length 0.

Source

pub fn array_length(&self, array: ObjectId) -> u32

Source

pub fn get_element(&self, object: ObjectId, index: u32) -> Value

The element at index: Value::EMPTY for a hole or past the end.

Source

pub fn set_element( &mut self, object: ObjectId, index: u32, value: Value, ) -> Result<(), HeapError>

Stores an element, growing the dense range; indices skipped over become holes. An array’s length follows. There is no sparse fallback here: the heap cap bounds a far index, and an object goes sparse only through Heap::make_sparse.

Source

pub fn make_sparse(&mut self, object: ObjectId) -> Result<(), HeapError>

Moves every element of object into a named property with an index key and marks it flags::SPARSE, so element attributes and extensibility follow the ordinary rules. The element range is freed.

Source

pub fn holes_writable(&self) -> bool

Whether a write into an element hole may skip the prototype chain.

Source

pub fn push_element( &mut self, array: ObjectId, value: Value, ) -> Result<(), HeapError>

Source

pub fn set_array_length(&mut self, array: ObjectId, length: u32)

Sets an array’s length. Shrinking clears the cut elements; growing adds holes without allocating.

Source

pub fn alloc_scope( &mut self, parent: Option<ScopeId>, slots: u32, ) -> Result<ScopeId, HeapError>

A scope with slots variables (initialized to Value::EMPTY, the TDZ marker) whose parent is parent.

Source

pub fn scope_parent(&self, scope: ScopeId) -> Option<ScopeId>

Source

pub fn scope_get(&self, scope: ScopeId, depth: u32, index: u32) -> Value

LoadScope(depth, index): depth parent hops and one load.

Source

pub fn scope_set( &mut self, scope: ScopeId, depth: u32, index: u32, value: Value, )

Source

pub fn alloc_function( &mut self, prototype: Option<ObjectId>, scope: Option<ScopeId>, ) -> Result<ObjectId, HeapError>

A function object capturing scope.

Source

pub fn alloc_function_with( &mut self, prototype: Option<ObjectId>, scope: Option<ScopeId>, slot_capacity: u32, ) -> Result<ObjectId, HeapError>

Heap::alloc_function with room for slot_capacity properties (length, name and a constructor’s prototype).

Source

pub fn function_scope(&self, function: ObjectId) -> Option<ScopeId>

Source

pub fn alloc_bytecode_function( &mut self, prototype: Option<ObjectId>, scope: Option<ScopeId>, tree: &[BytecodeTemplate<'_>], ) -> Result<ObjectId, HeapError>

A function object over the root of a published code-unit tree, with one bytecode record per unit (the constant tables and the child links). tree[0] is the root; children index into tree. The constants are rooted for the call.

Source

pub fn alloc_closure( &mut self, prototype: Option<ObjectId>, scope: Option<ScopeId>, bytecode: BytecodeId, ) -> Result<ObjectId, HeapError>

A closure over bytecode, for MakeClosure. The record must be reachable through a rooted function (it is a child of the running function’s record), since a record is not a value the root stack can hold.

Source

pub fn alloc_native_function( &mut self, prototype: Option<ObjectId>, native: u32, ) -> Result<ObjectId, HeapError>

A host function object: native indexes the runtime’s native table.

Source

pub fn alloc_native_closure( &mut self, prototype: Option<ObjectId>, native: u32, data: Option<ObjectId>, ) -> Result<ObjectId, HeapError>

A host function object with captured state: data (an object whose internal slots the native reads, rooted by the function) is held in the function record’s scope.

Source

pub fn function_record(&self, function: ObjectId) -> FunctionRecord

The function record of a Function object.

Source

pub fn function_bytecode(&self, function: ObjectId) -> Option<BytecodeId>

Source

pub fn bytecode_unit(&self, bytecode: BytecodeId) -> CodeUnitId

Source

pub fn bytecode_constants(&self, bytecode: BytecodeId) -> &[Value]

Source

pub fn bytecode_constant(&self, bytecode: BytecodeId, index: u32) -> Value

Source

pub fn bytecode_child(&self, bytecode: BytecodeId, index: u32) -> BytecodeId

The record of child index of bytecode’s unit.

Source

pub fn live_bytecodes(&self) -> usize

Source

pub fn alloc_string_repr( &mut self, repr: StringRepr, ) -> Result<StringId, HeapError>

A string with a representation the caller made canonical.

Source

pub fn alloc_string(&mut self, text: &str) -> Result<StringId, HeapError>

A string that is not an atom.

Source

pub fn alloc_string_units( &mut self, units: &[u16], ) -> Result<StringId, HeapError>

Source

pub fn string(&self, id: StringId) -> &StringRecord

The record of id, flattened if it was a rope.

Source

pub fn string_len(&self, id: StringId) -> usize

The length of id without flattening it.

Source

pub fn string_is_one_byte(&self, id: StringId) -> bool

Whether every unit of id fits in a byte, without flattening it.

Source

pub fn alloc_rope( &mut self, left: StringId, right: StringId, ) -> Result<StringId, HeapError>

The concatenation of left and right as a rope (len units).

Source

pub fn string_text(&self, id: StringId) -> String

Source

pub fn pin_atom(&mut self, id: StringId)

Keeps atom id for the heap’s lifetime.

Source

pub fn set_atom_mode(&mut self, mode: AtomMode) -> AtomMode

Sets how Heap::intern keeps its atoms; returns the mode before.

Source

pub fn atom_mode(&self) -> AtomMode

Source

pub fn intern_pinned(&mut self, text: &str) -> Result<StringId, HeapError>

The atom with this content, kept for the heap’s lifetime: a name the natives spell as a literal and hold across allocations.

Source

pub fn property_key_pinned( &mut self, text: &str, ) -> Result<PropertyKey, HeapError>

Heap::property_key kept for the heap’s lifetime, as Heap::intern_pinned.

Source

pub fn intern(&mut self, text: &str) -> Result<StringId, HeapError>

The atom with this content.

Source

pub fn intern_units(&mut self, units: &[u16]) -> Result<StringId, HeapError>

Source

pub fn intern_latin1(&mut self, bytes: &[u8]) -> Result<StringId, HeapError>

The atom of the Latin-1 string bytes; it allocates only when the atom is new.

Source

pub fn intern_string(&mut self, string: StringId) -> Result<StringId, HeapError>

The atom with the content of string (itself, if it is one).

Source

pub fn property_key(&mut self, text: &str) -> Result<PropertyKey, HeapError>

The property key spelled by text: an immediate index for a canonical array index below 2^31 (which never enters the atom table), otherwise an atom.

Source

pub fn property_key_units( &mut self, units: &[u16], ) -> Result<PropertyKey, HeapError>

Source

pub fn property_key_latin1( &mut self, bytes: &[u8], ) -> Result<PropertyKey, HeapError>

Self::property_key for the Latin-1 string bytes.

Source

pub fn alloc_symbol( &mut self, description: Option<StringId>, private: bool, ) -> Result<SymbolId, HeapError>

Source

pub fn symbol(&self, id: SymbolId) -> &SymbolRecord

Source

pub fn symbol_description(&self, id: SymbolId) -> Option<StringId>

Source

pub fn alloc_bigint( &mut self, negative: bool, limbs: &[u64], ) -> Result<BigIntId, HeapError>

Source

pub fn bigint(&self, id: BigIntId) -> &BigIntRecord

Source§

impl Heap

Source

pub fn shape_lookup( &self, shape: ShapeId, key: PropertyKey, ) -> Option<(u32, PropertyFlags)>

Looks key up in one shape.

Source

pub fn shape_entries( &self, shape: ShapeId, ) -> Vec<(PropertyKey, PropertyFlags, u32)>

(key, flags, slot) of every property in insertion order.

Source

pub fn shape(&self, shape: ShapeId) -> &Shape

Source

pub fn shape_of(&self, object: ObjectId) -> ShapeId

Source

pub fn is_dictionary(&self, object: ObjectId) -> bool

Source

pub fn prototype_of(&self, object: ObjectId) -> Option<ObjectId>

Source

pub fn lookup_own( &self, object: ObjectId, key: PropertyKey, ) -> Option<(u32, PropertyFlags)>

The slot and flags of an own named property.

Source

pub fn get_slot(&self, object: ObjectId, slot: u32) -> Value

values[start + slot]: one header load, one value load.

Source

pub fn set_slot(&mut self, object: ObjectId, slot: u32, value: Value)

Source

pub fn get_property(&self, object: ObjectId, key: PropertyKey) -> Option<Value>

The value of a named property, following the prototype chain.

Source

pub fn add_property( &mut self, object: ObjectId, key: PropertyKey, flags: PropertyFlags, value: Value, ) -> Result<(), HeapError>

Adds a new own data property. DuplicateKey if it already exists.

Source

pub fn add_accessor( &mut self, object: ObjectId, key: PropertyKey, flags: PropertyFlags, getter: Value, setter: Value, ) -> Result<(), HeapError>

Adds a new own accessor property: getter and setter take two consecutive slots, undefined for an absent half. lookup_own reports the getter’s slot.

Source

pub fn reorder_dictionary(&mut self, object: ObjectId, front: &[PropertyKey])

Moves the own properties front names to the start of a dictionary object’s key order, in that order (realm setup: the global object’s order is QuickJS’s, not the install order). Values keep their slots.

Source

pub fn delete_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, HeapError>

Deletes an own property; returns whether it existed. The object enters dictionary mode.

Source

pub fn set_property_flags( &mut self, object: ObjectId, key: PropertyKey, flags: PropertyFlags, ) -> Result<bool, HeapError>

Changes the flags of an own property, keeping its slot. Returns whether the property exists.

Source

pub fn reshape_property( &mut self, object: ObjectId, key: PropertyKey, flags: PropertyFlags, values: [Value; 2], ) -> Result<(), HeapError>

Replaces an own property’s flags and values, keeping its place in the key order. A change between data and accessor moves the object to dictionary mode. values are rooted for the call.

Source

pub fn set_prototype( &mut self, object: ObjectId, prototype: Option<ObjectId>, ) -> Result<(), HeapError>

Sets [[Prototype]]. PrototypeCycle if prototype inherits from object.

Source

pub fn own_keys(&self, object: ObjectId) -> Vec<PropertyKey>

Own keys in [[OwnPropertyKeys]] order: array indices ascending (elements and named), then strings, then symbols, each in insertion order. Private names are hidden.

Source

pub fn validity_cell( &mut self, object: ObjectId, ) -> Result<ValidityCellId, HeapError>

The cell guarding object’s prototype chain: valid until any object on that chain changes. Allocates a fresh cell after an invalidation.

Source

pub fn chain_cell( &mut self, prototype: ObjectId, ) -> Result<ValidityCellId, HeapError>

The cell guarding the chain that starts at prototype: valid until prototype or any object above it changes. It is the cell Heap::validity_cell gives an object whose prototype is prototype; the string-receiver cache uses it for %String.prototype%, which no object inherits from.

Source

pub fn cell_is_valid(&self, cell: ValidityCellId) -> bool

Trait Implementations§

Source§

impl Default for Heap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Heap

§

impl !RefUnwindSafe for Heap

§

impl !Send for Heap

§

impl !Sync for Heap

§

impl !UnwindSafe for Heap

§

impl Unpin for Heap

§

impl UnsafeUnpin for Heap

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.