Skip to content

Commit

Permalink
fix(GC): breaking gc stuff with arraybuffer and regexp disabled (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 authored Dec 7, 2024
1 parent 81314f7 commit 4c910a0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
6 changes: 4 additions & 2 deletions nova_vm/src/ecmascript/types/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub use symbol::{Symbol, SymbolHeapData};
pub use value::Value;
#[cfg(feature = "date")]
pub(crate) use value::DATE_DISCRIMINANT;
#[cfg(feature = "regexp")]
pub(crate) use value::REGEXP_DISCRIMINANT;
#[cfg(feature = "shared-array-buffer")]
pub(crate) use value::SHARED_ARRAY_BUFFER_DISCRIMINANT;
pub(crate) use value::{
Expand All @@ -52,8 +54,8 @@ pub(crate) use value::{
FINALIZATION_REGISTRY_DISCRIMINANT, FLOAT_DISCRIMINANT, GENERATOR_DISCRIMINANT,
INTEGER_DISCRIMINANT, ITERATOR_DISCRIMINANT, MAP_DISCRIMINANT, MAP_ITERATOR_DISCRIMINANT,
MODULE_DISCRIMINANT, NUMBER_DISCRIMINANT, OBJECT_DISCRIMINANT, PROMISE_DISCRIMINANT,
PROXY_DISCRIMINANT, REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT,
SMALL_BIGINT_DISCRIMINANT, SMALL_STRING_DISCRIMINANT, STRING_DISCRIMINANT, SYMBOL_DISCRIMINANT,
PROXY_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, SMALL_BIGINT_DISCRIMINANT,
SMALL_STRING_DISCRIMINANT, STRING_DISCRIMINANT, SYMBOL_DISCRIMINANT,
};
#[cfg(feature = "array-buffer")]
pub(crate) use value::{
Expand Down
6 changes: 4 additions & 2 deletions nova_vm/src/ecmascript/types/language/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ use crate::ecmascript::builtins::regexp::RegExp;
use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer;
#[cfg(feature = "weak-refs")]
use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet};
use crate::engine::context::NoGcScope;
#[cfg(feature = "array-buffer")]
use crate::engine::context::GcScope;
use crate::{
ecmascript::builtins::{data_view::DataView, typed_array::TypedArray, ArrayBuffer},
engine::context::NoGcScope,
heap::indexes::TypedArrayIndex,
};
use crate::{
Expand Down Expand Up @@ -85,6 +84,7 @@ use crate::{
execution::{Agent, JsResult},
types::PropertyDescriptor,
},
engine::context::GcScope,
engine::rootable::{HeapRootData, HeapRootRef, Rootable},
heap::{
indexes::{ArrayIndex, ObjectIndex},
Expand Down Expand Up @@ -2440,6 +2440,7 @@ impl Rootable for Object {
Self::Map(map) => Err(HeapRootData::Map(map)),
Self::Promise(promise) => Err(HeapRootData::Promise(promise)),
Self::Proxy(proxy) => Err(HeapRootData::Proxy(proxy)),
#[cfg(feature = "regexp")]
Self::RegExp(reg_exp) => Err(HeapRootData::RegExp(reg_exp)),
Self::Set(set) => Err(HeapRootData::Set(set)),
#[cfg(feature = "shared-array-buffer")]
Expand Down Expand Up @@ -2545,6 +2546,7 @@ impl Rootable for Object {
HeapRootData::Map(map) => Some(Self::Map(map)),
HeapRootData::Promise(promise) => Some(Self::Promise(promise)),
HeapRootData::Proxy(proxy) => Some(Self::Proxy(proxy)),
#[cfg(feature = "regexp")]
HeapRootData::RegExp(reg_exp) => Some(Self::RegExp(reg_exp)),
HeapRootData::Set(set) => Some(Self::Set(set)),
#[cfg(feature = "shared-array-buffer")]
Expand Down
2 changes: 2 additions & 0 deletions nova_vm/src/ecmascript/types/language/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ impl Rootable for Value {
Self::Map(map) => Err(HeapRootData::Map(map)),
Self::Promise(promise) => Err(HeapRootData::Promise(promise)),
Self::Proxy(proxy) => Err(HeapRootData::Proxy(proxy)),
#[cfg(feature = "regexp")]
Self::RegExp(reg_exp) => Err(HeapRootData::RegExp(reg_exp)),
Self::Set(set) => Err(HeapRootData::Set(set)),
#[cfg(feature = "shared-array-buffer")]
Expand Down Expand Up @@ -1282,6 +1283,7 @@ impl Rootable for Value {
HeapRootData::Map(map) => Some(Self::Map(map)),
HeapRootData::Promise(promise) => Some(Self::Promise(promise)),
HeapRootData::Proxy(proxy) => Some(Self::Proxy(proxy)),
#[cfg(feature = "regexp")]
HeapRootData::RegExp(reg_exp) => Some(Self::RegExp(reg_exp)),
HeapRootData::Set(set) => Some(Self::Set(set)),
#[cfg(feature = "shared-array-buffer")]
Expand Down
18 changes: 17 additions & 1 deletion nova_vm/src/ecmascript/types/spec/data_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ use crate::{
to_int8_number, to_uint16_number, to_uint32_number, to_uint8_clamp_number,
to_uint8_number,
},
execution::{agent::ExceptionType, Agent, JsResult, ProtoIntrinsics},
execution::{agent::ExceptionType, Agent, JsResult},
types::{BigInt, IntoNumeric, Number, Numeric},
},
engine::context::NoGcScope,
};

#[cfg(feature = "array-buffer")]
use crate::ecmascript::execution::ProtoIntrinsics;

/// Sentinel pointer for a detached data block.
///
/// We allocate at 8 byte alignment so this is never a valid DataBlock pointer normally.
Expand Down Expand Up @@ -84,6 +87,8 @@ pub trait Viewable: private::Sealed + Copy {
/// as a marker for data views. Used to determine that the viewable type is
/// a BigInt.
const IS_BIGINT: bool = false;

#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics;

fn into_be_value<'a>(self, agent: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a>;
Expand All @@ -93,6 +98,7 @@ pub trait Viewable: private::Sealed + Copy {
}

impl Viewable for u8 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Uint8Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -118,6 +124,7 @@ impl Viewable for u8 {
}
}
impl Viewable for U8Clamped {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Uint8ClampedArray;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -143,6 +150,7 @@ impl Viewable for U8Clamped {
}
}
impl Viewable for i8 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Int8Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -168,6 +176,7 @@ impl Viewable for i8 {
}
}
impl Viewable for u16 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Uint16Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -193,6 +202,7 @@ impl Viewable for u16 {
}
}
impl Viewable for i16 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Int16Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -218,6 +228,7 @@ impl Viewable for i16 {
}
}
impl Viewable for u32 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Uint32Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -243,6 +254,7 @@ impl Viewable for u32 {
}
}
impl Viewable for i32 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Int32Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -269,6 +281,7 @@ impl Viewable for i32 {
}
impl Viewable for u64 {
const IS_BIGINT: bool = true;
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::BigUint64Array;

fn into_be_value<'a>(self, agent: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -295,6 +308,7 @@ impl Viewable for u64 {
}
impl Viewable for i64 {
const IS_BIGINT: bool = true;
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::BigInt64Array;

fn into_be_value<'a>(self, agent: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -320,6 +334,7 @@ impl Viewable for i64 {
}
}
impl Viewable for f32 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Float32Array;

fn into_be_value<'a>(self, _: &mut Agent, _: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand All @@ -345,6 +360,7 @@ impl Viewable for f32 {
}
}
impl Viewable for f64 {
#[cfg(feature = "array-buffer")]
const PROTO: ProtoIntrinsics = ProtoIntrinsics::Float64Array;

fn into_be_value<'a>(self, agent: &mut Agent, gc: NoGcScope<'a, '_>) -> Numeric<'a> {
Expand Down
16 changes: 12 additions & 4 deletions nova_vm/src/engine/rootable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use private::RootableSealed;

#[cfg(feature = "date")]
use crate::ecmascript::builtins::date::Date;
#[cfg(feature = "regexp")]
use crate::ecmascript::builtins::regexp::RegExp;
#[cfg(feature = "shared-array-buffer")]
use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer;
#[cfg(feature = "array-buffer")]
Expand All @@ -17,6 +19,8 @@ use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer};
use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet};
#[cfg(feature = "date")]
use crate::ecmascript::types::DATE_DISCRIMINANT;
#[cfg(feature = "regexp")]
use crate::ecmascript::types::REGEXP_DISCRIMINANT;
#[cfg(feature = "shared-array-buffer")]
use crate::ecmascript::types::SHARED_ARRAY_BUFFER_DISCRIMINANT;
#[cfg(feature = "array-buffer")]
Expand Down Expand Up @@ -52,7 +56,6 @@ use crate::{
promise::Promise,
promise_objects::promise_abstract_operations::promise_resolving_functions::BuiltinPromiseResolvingFunction,
proxy::Proxy,
regexp::RegExp,
set::Set,
Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction,
},
Expand All @@ -68,8 +71,8 @@ use crate::{
ECMASCRIPT_FUNCTION_DISCRIMINANT, EMBEDDER_OBJECT_DISCRIMINANT, ERROR_DISCRIMINANT,
FINALIZATION_REGISTRY_DISCRIMINANT, GENERATOR_DISCRIMINANT, ITERATOR_DISCRIMINANT,
MAP_DISCRIMINANT, MAP_ITERATOR_DISCRIMINANT, MODULE_DISCRIMINANT, NUMBER_DISCRIMINANT,
OBJECT_DISCRIMINANT, PROMISE_DISCRIMINANT, PROXY_DISCRIMINANT, REGEXP_DISCRIMINANT,
SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, STRING_DISCRIMINANT, SYMBOL_DISCRIMINANT,
OBJECT_DISCRIMINANT, PROMISE_DISCRIMINANT, PROXY_DISCRIMINANT, SET_DISCRIMINANT,
SET_ITERATOR_DISCRIMINANT, STRING_DISCRIMINANT, SYMBOL_DISCRIMINANT,
},
},
heap::HeapMarkAndSweep,
Expand All @@ -78,6 +81,8 @@ use crate::{
mod private {
#[cfg(feature = "date")]
use crate::ecmascript::builtins::date::Date;
#[cfg(feature = "regexp")]
use crate::ecmascript::builtins::regexp::RegExp;
#[cfg(feature = "shared-array-buffer")]
use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer;
#[cfg(feature = "array-buffer")]
Expand All @@ -102,7 +107,6 @@ mod private {
promise::Promise,
promise_objects::promise_abstract_operations::promise_resolving_functions::BuiltinPromiseResolvingFunction,
proxy::Proxy,
regexp::RegExp,
set::Set,
Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction,
},
Expand Down Expand Up @@ -144,6 +148,7 @@ mod private {
impl RootableSealed for PrimitiveObject {}
impl RootableSealed for Promise {}
impl RootableSealed for Proxy {}
#[cfg(feature = "regexp")]
impl RootableSealed for RegExp {}
impl RootableSealed for Set {}
impl RootableSealed for SetIterator {}
Expand Down Expand Up @@ -233,6 +238,7 @@ pub enum HeapRootData {
Map(Map) = MAP_DISCRIMINANT,
Promise(Promise) = PROMISE_DISCRIMINANT,
Proxy(Proxy) = PROXY_DISCRIMINANT,
#[cfg(feature = "regexp")]
RegExp(RegExp) = REGEXP_DISCRIMINANT,
Set(Set) = SET_DISCRIMINANT,
#[cfg(feature = "shared-array-buffer")]
Expand Down Expand Up @@ -358,6 +364,7 @@ impl HeapMarkAndSweep for HeapRootData {
HeapRootData::Map(map) => map.mark_values(queues),
HeapRootData::Promise(promise) => promise.mark_values(queues),
HeapRootData::Proxy(proxy) => proxy.mark_values(queues),
#[cfg(feature = "regexp")]
HeapRootData::RegExp(reg_exp) => reg_exp.mark_values(queues),
HeapRootData::Set(set) => set.mark_values(queues),
#[cfg(feature = "shared-array-buffer")]
Expand Down Expand Up @@ -445,6 +452,7 @@ impl HeapMarkAndSweep for HeapRootData {
HeapRootData::Map(map) => map.sweep_values(compactions),
HeapRootData::Promise(promise) => promise.sweep_values(compactions),
HeapRootData::Proxy(proxy) => proxy.sweep_values(compactions),
#[cfg(feature = "regexp")]
HeapRootData::RegExp(reg_exp) => reg_exp.sweep_values(compactions),
HeapRootData::Set(set) => set.sweep_values(compactions),
#[cfg(feature = "shared-array-buffer")]
Expand Down
6 changes: 3 additions & 3 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ use crate::ecmascript::builtins::regexp::RegExpHeapData;
use crate::ecmascript::builtins::shared_array_buffer::data::SharedArrayBufferHeapData;
#[cfg(feature = "array-buffer")]
use crate::ecmascript::builtins::{
data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData,
data_view::{data::DataViewHeapData, DataView},
typed_array::{data::TypedArrayHeapData, TypedArray},
ArrayBufferHeapData,
};
#[cfg(feature = "weak-refs")]
use crate::ecmascript::builtins::{
Expand All @@ -54,7 +56,6 @@ use crate::{
promise_resolving_functions::PromiseResolvingFunctionHeapData,
},
},
data_view::DataView,
embedder_object::data::EmbedderObjectHeapData,
error::ErrorHeapData,
finalization_registry::data::FinalizationRegistryHeapData,
Expand All @@ -69,7 +70,6 @@ use crate::{
promise::data::PromiseHeapData,
proxy::data::ProxyHeapData,
set::data::SetHeapData,
typed_array::TypedArray,
ArrayHeapData,
},
execution::{Environments, Realm, RealmIdentifier},
Expand Down
8 changes: 4 additions & 4 deletions nova_vm/src/heap/heap_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

use std::thread;

#[cfg(feature = "array-buffer")]
use super::indexes::TypedArrayIndex;
use super::{
element_array::ElementArrays,
heap_bits::{
mark_array_with_u32_length, mark_descriptors, sweep_heap_elements_vector_descriptors,
sweep_heap_u16_elements_vector_values, sweep_heap_u32_elements_vector_values,
sweep_heap_u8_elements_vector_values, sweep_heap_vector_values, sweep_side_table_values,
CompactionLists, HeapBits, HeapMarkAndSweep, WorkQueues,
sweep_heap_u8_elements_vector_values, sweep_heap_vector_values, CompactionLists, HeapBits,
HeapMarkAndSweep, WorkQueues,
},
indexes::{ElementIndex, StringIndex},
Heap, WellKnownSymbolIndexes,
};
#[cfg(feature = "array-buffer")]
use super::{heap_bits::sweep_side_table_values, indexes::TypedArrayIndex};
#[cfg(feature = "date")]
use crate::ecmascript::builtins::date::Date;
#[cfg(feature = "regexp")]
Expand Down

0 comments on commit 4c910a0

Please sign in to comment.