Skip to content

Truly independent web browser

LibGC: Tell whether a collection is marking the live cells

Andreas Klingcf8a48af8561
diff --git a/Libraries/LibGC/CAPI.cpp b/Libraries/LibGC/CAPI.cpp
index 191506fb305..0c49833c4d9 100644
--- a/Libraries/LibGC/CAPI.cpp
+++ b/Libraries/LibGC/CAPI.cpp
@@ -233,6 +233,11 @@ bool gc_heap_is_collecting_everything(GCHeap const* heap)
return as_heap(heap).is_collecting_everything();
}
+bool gc_heap_is_marking_for_collection(GCHeap const* heap)
+{
+ return as_heap(heap).is_marking_for_collection();
+}
+
void gc_heap_defer_gc(GCHeap* heap)
{
CAPI::defer_gc(as_heap(heap));
diff --git a/Libraries/LibGC/CAPI.h b/Libraries/LibGC/CAPI.h
index 6386e705b85..df70a69270f 100644
--- a/Libraries/LibGC/CAPI.h
+++ b/Libraries/LibGC/CAPI.h
@@ -115,6 +115,8 @@ GC_API GCHeap* gc_heap_create(GCGatherRootsCallback, void* context, bool become_
GC_API void gc_heap_destroy(GCHeap*);
GC_API void gc_heap_collect_garbage(GCHeap*, int collection_type, bool print_report);
GC_API bool gc_heap_is_collecting_everything(GCHeap const*);
+// Whether the heap gathers its roots and marks the live cells for a collection now, rather than for a graph dump.
+GC_API bool gc_heap_is_marking_for_collection(GCHeap const*);
GC_API void gc_heap_defer_gc(GCHeap*);
GC_API void gc_heap_undefer_gc(GCHeap*);
GC_API void gc_heap_deferral_state(GCHeap*, size_t** deferrals, bool** collect_when_deferrals_end);
diff --git a/Libraries/LibGC/Heap.h b/Libraries/LibGC/Heap.h
index 198686ccb1b..fb2cd594e7b 100644
--- a/Libraries/LibGC/Heap.h
+++ b/Libraries/LibGC/Heap.h
@@ -108,6 +108,8 @@ public:
bool should_collect_on_every_allocation() const { return m_should_collect_on_every_allocation; }
// This is true for any CollectEverything cycle, not only heap teardown.
bool is_collecting_everything() const { return m_collecting_garbage && m_current_collection_type == CollectionType::CollectEverything; }
+ // Whether a collection that marks the live cells runs, as opposed to one that only sweeps or a graph dump.
+ bool is_marking_for_collection() const { return m_collecting_garbage && m_current_collection_type == CollectionType::CollectGarbage; }
void set_incremental_sweep_enabled(bool enabled) { m_incremental_sweep_enabled = enabled; }
void set_should_collect_on_every_allocation(bool);