From e9f848d4453d39dcd1fda67573ce46db473454de Mon Sep 17 00:00:00 2001 From: Reece Date: Sat, 25 Mar 2023 23:49:14 +0000 Subject: [PATCH] [+] v8::DisableHeapGC [+] v8::EnableHeapGC (high level heap gc request filters, not safepoint assertions) Last aurora commit: 65aae12e *amended to include commit link* --- src/api/api.cc | 10 ++++++++++ src/heap/heap.cc | 16 ++++++++++++++++ src/heap/heap.h | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/src/api/api.cc b/src/api/api.cc index 14eedff223..3b07a86a2b 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -1164,6 +1164,16 @@ V8_EXPORT void SafepointUnparkIsolate(v8::Isolate* pIsolate) { reinterpret_cast(pIsolate)->heap()->safepoint()->NotifyUnpark(); } +// Reece: +V8_EXPORT void DisableHeapGC(v8::Isolate* pIsolate) { + reinterpret_cast(pIsolate)->heap()->is_forcing_no_gc = true; +} + +// Reece: +V8_EXPORT void EnableHeapGC(v8::Isolate* pIsolate) { + reinterpret_cast(pIsolate)->heap()->is_forcing_no_gc = false; +} + void Context::Enter() { i::DisallowGarbageCollection no_gc; i::Context env = *Utils::OpenHandle(this); diff --git a/src/heap/heap.cc b/src/heap/heap.cc index d8c6006f4d..f58fde9e8d 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -1652,6 +1652,22 @@ void Heap::CollectGarbage(AllocationSpace space, FatalProcessOutOfMemory("GC during deserialization"); } + if (V8_UNLIKELY(is_forcing_no_gc)) { + if (!(((int)gc_callback_flags & + ((int)v8::GCCallbackFlags::kGCCallbackFlagForced) | + 0))) { + if (gc_reason != GarbageCollectionReason::kLastResort && + gc_reason != GarbageCollectionReason::kFinalizeMarkingViaTask && + gc_reason != GarbageCollectionReason::kFinalizeMarkingViaStackGuard && + gc_reason != GarbageCollectionReason::kFinalizeMinorMC && + gc_reason != GarbageCollectionReason::kExternalFinalize && + gc_reason != GarbageCollectionReason::kAllocationFailure && + gc_reason != GarbageCollectionReason::kAllocationLimit) { + return; + } + } + } + // CollectGarbage consists of three parts: // 1. The prologue part which may execute callbacks. These callbacks may // allocate and trigger another garbage collection. diff --git a/src/heap/heap.h b/src/heap/heap.h index bc8926a733..ed8d6bdba8 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -2413,6 +2413,11 @@ class Heap { // This field is used only when not running with MinorMC. ResizeNewSpaceMode resize_new_space_mode_ = ResizeNewSpaceMode::kNone; + // Reece: (another hack) + public: + bool is_forcing_no_gc = false; + private: + // Classes in "heap" can be friends. friend class AlwaysAllocateScope; friend class ArrayBufferCollector;