From c8baf29d82ca4db83f32a54015a3c5e92e20930e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 21 Sep 2020 14:35:19 +0200 Subject: [PATCH] LibJS: Assert if garbage collection is restarted while ongoing We can't GC while we're already in GC. Assert if this happens. --- Libraries/LibJS/Heap/Heap.cpp | 3 +++ Libraries/LibJS/Heap/Heap.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Libraries/LibJS/Heap/Heap.cpp b/Libraries/LibJS/Heap/Heap.cpp index a4a131fe5c..1bfa91e54e 100644 --- a/Libraries/LibJS/Heap/Heap.cpp +++ b/Libraries/LibJS/Heap/Heap.cpp @@ -89,6 +89,9 @@ Cell* Heap::allocate_cell(size_t size) void Heap::collect_garbage(CollectionType collection_type, bool print_report) { + ASSERT(!m_collecting_garbage); + TemporaryChange change(m_collecting_garbage, true); + Core::ElapsedTimer collection_measurement_timer; collection_measurement_timer.start(); if (collection_type == CollectionType::CollectGarbage) { diff --git a/Libraries/LibJS/Heap/Heap.h b/Libraries/LibJS/Heap/Heap.h index b1381a8dae..0d727210a4 100644 --- a/Libraries/LibJS/Heap/Heap.h +++ b/Libraries/LibJS/Heap/Heap.h @@ -109,6 +109,8 @@ private: size_t m_gc_deferrals { 0 }; bool m_should_gc_when_deferral_ends { false }; + + bool m_collecting_garbage { false }; }; }