Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ fn build_binding() {
.generate_cstr(true)
.rustified_enum(".*UseCounterFeature")
.rustified_enum(".*ModuleImportPhase")
.bitfield_enum(".*GCType")
.bitfield_enum(".*GCCallbackFlags")
.allowlist_item("v8__.*")
.allowlist_item("cppgc__.*")
.allowlist_item("RustObj")
Expand Down
52 changes: 22 additions & 30 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,34 @@ void v8__Isolate__RemoveGCPrologueCallback(
isolate->RemoveGCPrologueCallback(callback, data);
}

void v8__Isolate__AddGCEpilogueCallback(
v8::Isolate* isolate, v8::Isolate::GCCallbackWithData callback, void* data,
v8::GCType gc_type_filter) {
isolate->AddGCEpilogueCallback(callback, data, gc_type_filter);
}

void v8__Isolate__RemoveGCEpilogueCallback(
v8::Isolate* isolate, v8::Isolate::GCCallbackWithData callback,
void* data) {
isolate->RemoveGCEpilogueCallback(callback, data);
}

void v8__Isolate__AddNearHeapLimitCallback(v8::Isolate* isolate,
v8::NearHeapLimitCallback callback,
void* data) {
isolate->AddNearHeapLimitCallback(callback, data);
}

size_t v8__Isolate__NumberOfHeapSpaces(v8::Isolate* isolate) {
return isolate->NumberOfHeapSpaces();
}

bool v8__Isolate__GetHeapSpaceStatistics(
v8::Isolate* isolate, v8::HeapSpaceStatistics* space_statistics,
size_t index) {
return isolate->GetHeapSpaceStatistics(space_statistics, index);
}

void v8__Isolate__RemoveNearHeapLimitCallback(
v8::Isolate* isolate, v8::NearHeapLimitCallback callback,
size_t heap_limit) {
Expand Down Expand Up @@ -3395,36 +3417,6 @@ void v8__HeapProfiler__TakeHeapSnapshot(v8::Isolate* isolate,
const_cast<v8::HeapSnapshot*>(snapshot)->Delete();
}

void v8__HeapStatistics__CONSTRUCT(uninit_t<v8::HeapStatistics>* buf) {
// Should be <= than its counterpart in src/isolate.rs
static_assert(sizeof(v8::HeapStatistics) <= sizeof(uintptr_t[16]),
"HeapStatistics mismatch");
construct_in_place<v8::HeapStatistics>(buf);
}

// The const_cast doesn't violate const correctness, the methods
// are simple getters that don't mutate the object or global state.
#define V(name) \
size_t v8__HeapStatistics__##name(const v8::HeapStatistics* s) { \
return const_cast<v8::HeapStatistics*>(s)->name(); \
}

V(total_heap_size)
V(total_heap_size_executable)
V(total_physical_size)
V(total_available_size)
V(total_global_handles_size)
V(used_global_handles_size)
V(used_heap_size)
V(heap_size_limit)
V(malloced_memory)
V(external_memory)
V(peak_malloced_memory)
V(number_of_native_contexts)
V(number_of_detached_contexts)
V(does_zap_garbage) // Returns size_t, not bool like you'd expect.

#undef V
} // extern "C"

// v8::ValueSerializer::Delegate
Expand Down
4 changes: 4 additions & 0 deletions src/binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ using v8__FastOneByteString = v8::FastOneByteString;
using v8__Isolate__UseCounterFeature = v8::Isolate::UseCounterFeature;
using v8__String__WriteFlags = v8::String::WriteFlags;
using v8__ModuleImportPhase = v8::ModuleImportPhase;
using v8__HeapStatistics = v8::HeapStatistics;
using v8__HeapSpaceStatistics = v8::HeapSpaceStatistics;
using v8__GCType = v8::GCType;
using v8__GCCallbackFlags = v8::GCCallbackFlags;

static uint32_t v8__MAJOR_VERSION = V8_MAJOR_VERSION;
static uint32_t v8__MINOR_VERSION = V8_MINOR_VERSION;
Expand Down
74 changes: 2 additions & 72 deletions src/gc.rs
Original file line number Diff line number Diff line change
@@ -1,72 +1,2 @@
/// Applications can register callback functions which will be called before and
/// after certain garbage collection operations. Allocations are not allowed in
/// the callback functions, you therefore cannot manipulate objects (set or
/// delete properties for example) since it is possible such operations will
/// result in the allocation of objects.
#[repr(C)]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub struct GCType(u32);

impl GCType {
pub const SCAVENGE: Self = Self(1 << 0);

pub const MINOR_MARK_COMPACT: Self = Self(1 << 1);

pub const MARK_SWEEP_COMPACT: Self = Self(1 << 2);

pub const INCREMENTAL_MARKING: Self = Self(1 << 3);

pub const PROCESS_WEAK_CALLBACKS: Self = Self(1 << 4);

pub const ALL: Self = Self(31);
}

impl std::ops::BitOr for GCType {
type Output = Self;

fn bitor(self, Self(rhs): Self) -> Self {
let Self(lhs) = self;
Self(lhs | rhs)
}
}

/// GCCallbackFlags is used to notify additional information about the GC
/// callback.
/// - GCCallbackFlagConstructRetainedObjectInfos: The GC callback is for
/// constructing retained object infos.
/// - GCCallbackFlagForced: The GC callback is for a forced GC for testing.
/// - GCCallbackFlagSynchronousPhantomCallbackProcessing: The GC callback
/// is called synchronously without getting posted to an idle task.
/// - GCCallbackFlagCollectAllAvailableGarbage: The GC callback is called
/// in a phase where V8 is trying to collect all available garbage
/// (e.g., handling a low memory notification).
/// - GCCallbackScheduleIdleGarbageCollection: The GC callback is called to
/// trigger an idle garbage collection.
#[repr(C)]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub struct GCCallbackFlags(u32);

impl GCCallbackFlags {
pub const NONE: Self = Self(0);

pub const CONSTRUCT_RETAINED_OBJECT_INFOS: Self = Self(1 << 1);

pub const FORCED: Self = Self(1 << 2);

pub const SYNCHRONOUS_PHANTOM_CALLBACK_PROCESSING: Self = Self(1 << 3);

pub const COLLECT_ALL_AVAILABLE_GARBAGE: Self = Self(1 << 4);

pub const COLLECT_ALL_EXTERNAL_MEMORY: Self = Self(1 << 5);

pub const SCHEDULE_IDLE_GARBAGE_COLLECTION: Self = Self(1 << 6);
}

impl std::ops::BitOr for GCCallbackFlags {
type Output = Self;

fn bitor(self, Self(rhs): Self) -> Self {
let Self(lhs) = self;
Self(lhs | rhs)
}
}
pub use crate::binding::v8__GCCallbackFlags as GCCallbackFlags;
pub use crate::binding::v8__GCType as GCType;
Loading
Loading