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;