summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Heap
diff options
context:
space:
mode:
authordavidot <david.tuin@gmail.com>2021-09-07 17:14:05 +0200
committerLinus Groh <mail@linusgroh.de>2021-09-08 08:53:02 +0100
commit43b17f27a31f160eb2c92ed51bcc78b1efd93042 (patch)
tree23b68a2e2a686e85d590a58e28c55d59d1a163e9 /Userland/Libraries/LibJS/Heap
parent33730909939ecb742ff7815a7f4525443c1b8636 (diff)
downloadserenity-43b17f27a31f160eb2c92ed51bcc78b1efd93042.zip
test-js: Add a mark_as_garbage method to force GC to collect that object
This should fix the flaky tests of test-js. It also fixes the tests when running with the -g flag since the values will not be garbage collected too soon.
Diffstat (limited to 'Userland/Libraries/LibJS/Heap')
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.cpp11
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.h4
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp
index 3329489e0e..d0bc3ba289 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.cpp
+++ b/Userland/Libraries/LibJS/Heap/Heap.cpp
@@ -191,9 +191,15 @@ public:
void Heap::mark_live_cells(const HashTable<Cell*>& roots)
{
dbgln_if(HEAP_DEBUG, "mark_live_cells:");
+
MarkingVisitor visitor;
for (auto* root : roots)
visitor.visit(root);
+
+ for (auto& inverse_root : m_uprooted_cells)
+ inverse_root->set_marked(false);
+
+ m_uprooted_cells.clear();
}
void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measurement_timer)
@@ -327,4 +333,9 @@ void Heap::undefer_gc(Badge<DeferGC>)
}
}
+void Heap::uproot_cell(Cell* cell)
+{
+ m_uprooted_cells.append(cell);
+}
+
}
diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h
index 157eff0f3a..8f7ac0d39e 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.h
+++ b/Userland/Libraries/LibJS/Heap/Heap.h
@@ -83,6 +83,8 @@ public:
BlockAllocator& block_allocator() { return m_block_allocator; }
+ void uproot_cell(Cell* cell);
+
private:
Cell* allocate_cell(size_t);
@@ -117,6 +119,8 @@ private:
WeakContainer::List m_weak_containers;
+ Vector<Cell*> m_uprooted_cells;
+
BlockAllocator m_block_allocator;
size_t m_gc_deferrals { 0 };