pub struct Heap { /* private fields */ }Implementations§
Source§impl Heap
impl Heap
Sourcepub fn set_gc_manual(&mut self, manual: bool)
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§impl Heap
impl Heap
pub fn new(limits: HeapLimits) -> Self
pub fn roots(&mut self) -> &mut RootStack
pub fn handles(&mut self) -> &mut Handles
pub fn handles_ref(&self) -> &Handles
Sourcepub fn add_fixed_root(&mut self, value: Value) -> usize
pub fn add_fixed_root(&mut self, value: Value) -> usize
Adds a runtime root; returns its slot.
pub fn set_fixed_root(&mut self, slot: usize, value: Value)
pub fn fixed_root(&self, slot: usize) -> Value
pub fn gc(&self) -> &GcState
pub fn gc_mut(&mut self) -> &mut GcState
Sourcepub fn bytes(&self) -> usize
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.
Sourcepub fn table_bytes(&self) -> usize
pub fn table_bytes(&self) -> usize
Bytes of the tables beside the arenas: the ropes’ halves, the atom table and the inline caches.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Bytes held by live records and live value ranges.
pub fn ics(&self) -> &IcStore
pub fn ics_mut(&mut self) -> &mut IcStore
pub fn global_generation(&self) -> u32
pub fn value_heap(&self) -> &ValueHeap
Sourcepub fn regexps(&self) -> &RegExpStore
pub fn regexps(&self) -> &RegExpStore
The regular-expression programs.
pub fn atom_table(&self) -> &AtomTable
pub fn live_objects(&self) -> usize
pub fn live_shapes(&self) -> usize
pub fn live_strings(&self) -> usize
pub fn live_cells(&self) -> usize
pub fn is_live(&self, value: Value) -> bool
Sourcepub fn alloc_object(
&mut self,
kind: ObjectKind,
prototype: Option<ObjectId>,
slot_capacity: u32,
) -> Result<ObjectId, HeapError>
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.
Sourcepub 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>
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.
Sourcepub fn internal(&self, object: ObjectId) -> &Internal
pub fn internal(&self, object: ObjectId) -> &Internal
The internal record of an object of a kind with internal slots.
pub fn internal_mut(&mut self, object: ObjectId) -> &mut Internal
Sourcepub fn internal_tag(&self, object: ObjectId) -> InternalTag
pub fn internal_tag(&self, object: ObjectId) -> InternalTag
The tag of a ObjectKind::Builtin object, or None for any other.
pub fn internal_slot(&self, object: ObjectId, slot: usize) -> Value
pub fn set_internal_slot(&mut self, object: ObjectId, slot: usize, value: Value)
Sourcepub fn push_internal_slot(
&mut self,
object: ObjectId,
value: Value,
) -> Result<(), HeapError>
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.
pub fn object_kind(&self, object: ObjectId) -> ObjectKind
pub fn header(&self, object: ObjectId) -> &ObjectHeader
Sourcepub fn alloc_object_with_elements(
&mut self,
kind: ObjectKind,
prototype: Option<ObjectId>,
slot_capacity: u32,
element_capacity: u32,
) -> Result<ObjectId, HeapError>
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.
Sourcepub fn alloc_array(
&mut self,
prototype: Option<ObjectId>,
capacity: u32,
) -> Result<ObjectId, HeapError>
pub fn alloc_array( &mut self, prototype: Option<ObjectId>, capacity: u32, ) -> Result<ObjectId, HeapError>
A dense array with room for capacity elements; length 0.
pub fn array_length(&self, array: ObjectId) -> u32
Sourcepub fn get_element(&self, object: ObjectId, index: u32) -> Value
pub fn get_element(&self, object: ObjectId, index: u32) -> Value
The element at index: Value::EMPTY for a hole or past the end.
Sourcepub fn set_element(
&mut self,
object: ObjectId,
index: u32,
value: Value,
) -> Result<(), HeapError>
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.
Sourcepub fn make_sparse(&mut self, object: ObjectId) -> Result<(), HeapError>
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.
Sourcepub fn holes_writable(&self) -> bool
pub fn holes_writable(&self) -> bool
Whether a write into an element hole may skip the prototype chain.
pub fn push_element( &mut self, array: ObjectId, value: Value, ) -> Result<(), HeapError>
Sourcepub fn set_array_length(&mut self, array: ObjectId, length: u32)
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.
Sourcepub fn alloc_scope(
&mut self,
parent: Option<ScopeId>,
slots: u32,
) -> Result<ScopeId, HeapError>
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.
pub fn scope_parent(&self, scope: ScopeId) -> Option<ScopeId>
Sourcepub fn scope_get(&self, scope: ScopeId, depth: u32, index: u32) -> Value
pub fn scope_get(&self, scope: ScopeId, depth: u32, index: u32) -> Value
LoadScope(depth, index): depth parent hops and one load.
pub fn scope_set( &mut self, scope: ScopeId, depth: u32, index: u32, value: Value, )
Sourcepub fn alloc_function(
&mut self,
prototype: Option<ObjectId>,
scope: Option<ScopeId>,
) -> Result<ObjectId, HeapError>
pub fn alloc_function( &mut self, prototype: Option<ObjectId>, scope: Option<ScopeId>, ) -> Result<ObjectId, HeapError>
A function object capturing scope.
Sourcepub fn alloc_function_with(
&mut self,
prototype: Option<ObjectId>,
scope: Option<ScopeId>,
slot_capacity: u32,
) -> Result<ObjectId, HeapError>
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).
pub fn function_scope(&self, function: ObjectId) -> Option<ScopeId>
Sourcepub fn alloc_bytecode_function(
&mut self,
prototype: Option<ObjectId>,
scope: Option<ScopeId>,
tree: &[BytecodeTemplate<'_>],
) -> Result<ObjectId, HeapError>
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.
Sourcepub fn alloc_closure(
&mut self,
prototype: Option<ObjectId>,
scope: Option<ScopeId>,
bytecode: BytecodeId,
) -> Result<ObjectId, HeapError>
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.
Sourcepub fn alloc_native_function(
&mut self,
prototype: Option<ObjectId>,
native: u32,
) -> Result<ObjectId, HeapError>
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.
Sourcepub fn alloc_native_closure(
&mut self,
prototype: Option<ObjectId>,
native: u32,
data: Option<ObjectId>,
) -> Result<ObjectId, HeapError>
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.
Sourcepub fn function_record(&self, function: ObjectId) -> FunctionRecord
pub fn function_record(&self, function: ObjectId) -> FunctionRecord
The function record of a Function object.
pub fn function_bytecode(&self, function: ObjectId) -> Option<BytecodeId>
pub fn bytecode_unit(&self, bytecode: BytecodeId) -> CodeUnitId
pub fn bytecode_constants(&self, bytecode: BytecodeId) -> &[Value]
pub fn bytecode_constant(&self, bytecode: BytecodeId, index: u32) -> Value
Sourcepub fn bytecode_child(&self, bytecode: BytecodeId, index: u32) -> BytecodeId
pub fn bytecode_child(&self, bytecode: BytecodeId, index: u32) -> BytecodeId
The record of child index of bytecode’s unit.
pub fn live_bytecodes(&self) -> usize
Sourcepub fn alloc_string_repr(
&mut self,
repr: StringRepr,
) -> Result<StringId, HeapError>
pub fn alloc_string_repr( &mut self, repr: StringRepr, ) -> Result<StringId, HeapError>
A string with a representation the caller made canonical.
Sourcepub fn alloc_string(&mut self, text: &str) -> Result<StringId, HeapError>
pub fn alloc_string(&mut self, text: &str) -> Result<StringId, HeapError>
A string that is not an atom.
pub fn alloc_string_units( &mut self, units: &[u16], ) -> Result<StringId, HeapError>
Sourcepub fn string(&self, id: StringId) -> &StringRecord
pub fn string(&self, id: StringId) -> &StringRecord
The record of id, flattened if it was a rope.
Sourcepub fn string_len(&self, id: StringId) -> usize
pub fn string_len(&self, id: StringId) -> usize
The length of id without flattening it.
Sourcepub fn string_is_one_byte(&self, id: StringId) -> bool
pub fn string_is_one_byte(&self, id: StringId) -> bool
Whether every unit of id fits in a byte, without flattening it.
Sourcepub fn alloc_rope(
&mut self,
left: StringId,
right: StringId,
) -> Result<StringId, HeapError>
pub fn alloc_rope( &mut self, left: StringId, right: StringId, ) -> Result<StringId, HeapError>
The concatenation of left and right as a rope (len units).
pub fn string_text(&self, id: StringId) -> String
Sourcepub fn set_atom_mode(&mut self, mode: AtomMode) -> AtomMode
pub fn set_atom_mode(&mut self, mode: AtomMode) -> AtomMode
Sets how Heap::intern keeps its atoms; returns the mode before.
pub fn atom_mode(&self) -> AtomMode
Sourcepub fn intern_pinned(&mut self, text: &str) -> Result<StringId, HeapError>
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.
Sourcepub fn property_key_pinned(
&mut self,
text: &str,
) -> Result<PropertyKey, HeapError>
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.
Sourcepub fn intern(&mut self, text: &str) -> Result<StringId, HeapError>
pub fn intern(&mut self, text: &str) -> Result<StringId, HeapError>
The atom with this content.
pub fn intern_units(&mut self, units: &[u16]) -> Result<StringId, HeapError>
Sourcepub fn intern_latin1(&mut self, bytes: &[u8]) -> Result<StringId, HeapError>
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.
Sourcepub fn intern_string(&mut self, string: StringId) -> Result<StringId, HeapError>
pub fn intern_string(&mut self, string: StringId) -> Result<StringId, HeapError>
The atom with the content of string (itself, if it is one).
Sourcepub fn property_key(&mut self, text: &str) -> Result<PropertyKey, HeapError>
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.
pub fn property_key_units( &mut self, units: &[u16], ) -> Result<PropertyKey, HeapError>
Sourcepub fn property_key_latin1(
&mut self,
bytes: &[u8],
) -> Result<PropertyKey, HeapError>
pub fn property_key_latin1( &mut self, bytes: &[u8], ) -> Result<PropertyKey, HeapError>
Self::property_key for the Latin-1 string bytes.
pub fn alloc_symbol( &mut self, description: Option<StringId>, private: bool, ) -> Result<SymbolId, HeapError>
pub fn symbol(&self, id: SymbolId) -> &SymbolRecord
pub fn symbol_description(&self, id: SymbolId) -> Option<StringId>
pub fn alloc_bigint( &mut self, negative: bool, limbs: &[u64], ) -> Result<BigIntId, HeapError>
pub fn bigint(&self, id: BigIntId) -> &BigIntRecord
Source§impl Heap
impl Heap
Sourcepub fn shape_lookup(
&self,
shape: ShapeId,
key: PropertyKey,
) -> Option<(u32, PropertyFlags)>
pub fn shape_lookup( &self, shape: ShapeId, key: PropertyKey, ) -> Option<(u32, PropertyFlags)>
Looks key up in one shape.
Sourcepub fn shape_entries(
&self,
shape: ShapeId,
) -> Vec<(PropertyKey, PropertyFlags, u32)>
pub fn shape_entries( &self, shape: ShapeId, ) -> Vec<(PropertyKey, PropertyFlags, u32)>
(key, flags, slot) of every property in insertion order.
pub fn shape(&self, shape: ShapeId) -> &Shape
pub fn shape_of(&self, object: ObjectId) -> ShapeId
pub fn is_dictionary(&self, object: ObjectId) -> bool
pub fn prototype_of(&self, object: ObjectId) -> Option<ObjectId>
Sourcepub fn lookup_own(
&self,
object: ObjectId,
key: PropertyKey,
) -> Option<(u32, PropertyFlags)>
pub fn lookup_own( &self, object: ObjectId, key: PropertyKey, ) -> Option<(u32, PropertyFlags)>
The slot and flags of an own named property.
Sourcepub fn get_slot(&self, object: ObjectId, slot: u32) -> Value
pub fn get_slot(&self, object: ObjectId, slot: u32) -> Value
values[start + slot]: one header load, one value load.
pub fn set_slot(&mut self, object: ObjectId, slot: u32, value: Value)
Sourcepub fn get_property(&self, object: ObjectId, key: PropertyKey) -> Option<Value>
pub fn get_property(&self, object: ObjectId, key: PropertyKey) -> Option<Value>
The value of a named property, following the prototype chain.
Sourcepub fn add_property(
&mut self,
object: ObjectId,
key: PropertyKey,
flags: PropertyFlags,
value: Value,
) -> Result<(), HeapError>
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.
Sourcepub fn add_accessor(
&mut self,
object: ObjectId,
key: PropertyKey,
flags: PropertyFlags,
getter: Value,
setter: Value,
) -> Result<(), HeapError>
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.
Sourcepub fn reorder_dictionary(&mut self, object: ObjectId, front: &[PropertyKey])
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.
Sourcepub fn delete_property(
&mut self,
object: ObjectId,
key: PropertyKey,
) -> Result<bool, HeapError>
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.
Sourcepub fn set_property_flags(
&mut self,
object: ObjectId,
key: PropertyKey,
flags: PropertyFlags,
) -> Result<bool, HeapError>
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.
Sourcepub fn reshape_property(
&mut self,
object: ObjectId,
key: PropertyKey,
flags: PropertyFlags,
values: [Value; 2],
) -> Result<(), HeapError>
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.
Sourcepub fn set_prototype(
&mut self,
object: ObjectId,
prototype: Option<ObjectId>,
) -> Result<(), HeapError>
pub fn set_prototype( &mut self, object: ObjectId, prototype: Option<ObjectId>, ) -> Result<(), HeapError>
Sets [[Prototype]]. PrototypeCycle if prototype inherits from
object.
Sourcepub fn own_keys(&self, object: ObjectId) -> Vec<PropertyKey>
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.
Sourcepub fn validity_cell(
&mut self,
object: ObjectId,
) -> Result<ValidityCellId, HeapError>
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.
Sourcepub fn chain_cell(
&mut self,
prototype: ObjectId,
) -> Result<ValidityCellId, HeapError>
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.