diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-02 16:35:55 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-02 16:39:28 +0200 |
commit | 6a1b82df2b9c176c46be3fd89ad78184a5a4f55c (patch) | |
tree | 288ff50f216094ba6d393d7001dee036a92a2df3 /Userland/Libraries | |
parent | f290c59dd82b3ae59bdb7c10bd7026788b879b8d (diff) | |
download | serenity-6a1b82df2b9c176c46be3fd89ad78184a5a4f55c.zip |
LibJS: Put zombie cell tracking code behind a compile-time flag
Since this is a debug-only feature, let's not have it impact GC marking
performance when you don't need it.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Cell.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Heap.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Heap.h | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Shape.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Shape.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakMap.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakRef.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakSet.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibTest/JavaScriptTestRunner.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/Wrapper.h | 7 |
12 files changed, 69 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Cell.h b/Userland/Libraries/LibJS/Heap/Cell.h index 6e3e107988..85bc0e5675 100644 --- a/Userland/Libraries/LibJS/Heap/Cell.h +++ b/Userland/Libraries/LibJS/Heap/Cell.h @@ -24,12 +24,18 @@ public: bool is_marked() const { return m_mark; } void set_marked(bool b) { m_mark = b; } - virtual void did_become_zombie() { } +#ifdef JS_TRACK_ZOMBIE_CELLS + virtual void did_become_zombie() + { + } +#endif enum class State { Live, Dead, +#ifdef JS_TRACK_ZOMBIE_CELLS Zombie, +#endif }; State state() const { return m_state; } diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp index 5db59c29b4..43a8d41b87 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.cpp +++ b/Userland/Libraries/LibJS/Heap/Heap.cpp @@ -184,11 +184,13 @@ public: return; dbgln_if(HEAP_DEBUG, " ! {}", &cell); +#ifdef JS_TRACK_ZOMBIE_CELLS if (cell.state() == Cell::State::Zombie) { dbgln("BUG! Marking a zombie cell, {} @ {:p}", cell.class_name(), &cell); cell.vm().dump_backtrace(); VERIFY_NOT_REACHED(); } +#endif cell.set_marked(true); cell.visit_edges(*this); @@ -230,12 +232,16 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure dbgln_if(HEAP_DEBUG, " ~ {}", cell); if (should_store_swept_cells) swept_cells.append(cell); +#ifdef JS_TRACK_ZOMBIE_CELLS if (m_zombify_dead_cells) { cell->set_state(Cell::State::Zombie); cell->did_become_zombie(); } else { +#endif block.deallocate(cell); +#ifdef JS_TRACK_ZOMBIE_CELLS } +#endif ++collected_cells; collected_cell_bytes += block.cell_size(); } else { diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index 2e44f27e59..a68e3ffc5b 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -62,7 +62,12 @@ public: bool should_collect_on_every_allocation() const { return m_should_collect_on_every_allocation; } void set_should_collect_on_every_allocation(bool b) { m_should_collect_on_every_allocation = b; } - void set_zombify_dead_cells(bool b) { m_zombify_dead_cells = b; } +#ifdef JS_TRACK_ZOMBIE_CELLS + void set_zombify_dead_cells(bool b) + { + m_zombify_dead_cells = b; + } +#endif void did_create_handle(Badge<HandleImpl>, HandleImpl&); void did_destroy_handle(Badge<HandleImpl>, HandleImpl&); @@ -122,7 +127,10 @@ private: bool m_should_gc_when_deferral_ends { false }; bool m_collecting_garbage { false }; + +#ifdef JS_TRACK_ZOMBIE_CELLS bool m_zombify_dead_cells { false }; +#endif }; } diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h index 6affdcd6a3..681df05c3b 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h @@ -34,7 +34,13 @@ public: private: virtual void visit_edges(Visitor& visitor) override; - virtual void did_become_zombie() override { deregister(); } + +#ifdef JS_TRACK_ZOMBIE_CELLS + virtual void did_become_zombie() override + { + deregister(); + } +#endif FunctionObject* m_cleanup_callback { nullptr }; diff --git a/Userland/Libraries/LibJS/Runtime/Shape.cpp b/Userland/Libraries/LibJS/Runtime/Shape.cpp index a8f41db40f..e937d540b0 100644 --- a/Userland/Libraries/LibJS/Runtime/Shape.cpp +++ b/Userland/Libraries/LibJS/Runtime/Shape.cpp @@ -238,9 +238,11 @@ FLATTEN void Shape::add_property_without_transition(PropertyName const& property add_property_without_transition(property_name.to_string_or_symbol(), attributes); } +#ifdef JS_TRACK_ZOMBIE_CELLS void Shape::did_become_zombie() { revoke_weak_ptrs(); } +#endif } diff --git a/Userland/Libraries/LibJS/Runtime/Shape.h b/Userland/Libraries/LibJS/Runtime/Shape.h index 89d29394f9..bfec255572 100644 --- a/Userland/Libraries/LibJS/Runtime/Shape.h +++ b/Userland/Libraries/LibJS/Runtime/Shape.h @@ -88,7 +88,10 @@ public: private: virtual const char* class_name() const override { return "Shape"; } virtual void visit_edges(Visitor&) override; + +#ifdef JS_TRACK_ZOMBIE_CELLS virtual void did_become_zombie() override; +#endif Shape* get_or_prune_cached_forward_transition(TransitionKey const&); Shape* get_or_prune_cached_prototype_transition(Object* prototype); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.h b/Userland/Libraries/LibJS/Runtime/WeakMap.h index d946c5241f..9e15860c68 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMap.h +++ b/Userland/Libraries/LibJS/Runtime/WeakMap.h @@ -30,7 +30,13 @@ public: virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override; private: - virtual void did_become_zombie() override { deregister(); } +#ifdef JS_TRACK_ZOMBIE_CELLS + virtual void did_become_zombie() override + { + deregister(); + } +#endif + void visit_edges(Visitor&) override; HashMap<Cell*, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.h b/Userland/Libraries/LibJS/Runtime/WeakRef.h index 40a370105e..5aa3ed1ee7 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRef.h +++ b/Userland/Libraries/LibJS/Runtime/WeakRef.h @@ -31,7 +31,13 @@ public: private: virtual void visit_edges(Visitor&) override; - virtual void did_become_zombie() override { deregister(); } + +#ifdef JS_TRACK_ZOMBIE_CELLS + virtual void did_become_zombie() override + { + deregister(); + } +#endif Object* m_value { nullptr }; u32 m_last_execution_generation { 0 }; diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.h b/Userland/Libraries/LibJS/Runtime/WeakSet.h index 2206037c70..645dd476d9 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.h +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.h @@ -30,7 +30,12 @@ public: virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override; private: - virtual void did_become_zombie() override { deregister(); } +#ifdef JS_TRACK_ZOMBIE_CELLS + virtual void did_become_zombie() override + { + deregister(); + } +#endif HashTable<Cell*> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping }; diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 641b4e8a3d..da826093d2 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -113,7 +113,9 @@ static consteval size_t __testjs_last() { return (AK::Detail::IntegralConstant<s static constexpr auto TOP_LEVEL_TEST_NAME = "__$$TOP_LEVEL$$__"; extern RefPtr<JS::VM> g_vm; extern bool g_collect_on_every_allocation; +#ifdef JS_TRACK_ZOMBIE_CELLS extern bool g_zombify_dead_cells; +#endif extern bool g_run_bytecode; extern bool g_dump_bytecode; extern String g_currently_running_test; @@ -284,7 +286,10 @@ inline JSFileResult TestRunner::run_file_test(const String& test_path) JS::VM::InterpreterExecutionScope scope(*interpreter); interpreter->heap().set_should_collect_on_every_allocation(g_collect_on_every_allocation); + +#ifdef JS_TRACK_ZOMBIE_CELLS interpreter->heap().set_zombify_dead_cells(g_zombify_dead_cells); +#endif if (g_run_file) { auto result = g_run_file(test_path, *interpreter); diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp index 2a7355b41c..7fb9dbe8b1 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp +++ b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp @@ -18,7 +18,9 @@ namespace JS { RefPtr<::JS::VM> g_vm; bool g_collect_on_every_allocation = false; +#ifdef JS_TRACK_ZOMBIE_CELLS bool g_zombify_dead_cells = false; +#endif bool g_run_bytecode = false; bool g_dump_bytecode = false; String g_currently_running_test; @@ -110,7 +112,9 @@ int main(int argc, char** argv) }); args_parser.add_option(print_json, "Show results as JSON", "json", 'j'); args_parser.add_option(g_collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g'); +#ifdef JS_TRACK_ZOMBIE_CELLS args_parser.add_option(g_zombify_dead_cells, "Zombify dead cells (to catch missing GC marks)", "zombify-dead-cells", 'z'); +#endif args_parser.add_option(g_run_bytecode, "Use the bytecode interpreter", "run-bytecode", 'b'); args_parser.add_option(g_dump_bytecode, "Dump the bytecode", "dump-bytecode", 'd'); args_parser.add_option(test_glob, "Only run tests matching the given glob", "filter", 'f', "glob"); diff --git a/Userland/Libraries/LibWeb/Bindings/Wrapper.h b/Userland/Libraries/LibWeb/Bindings/Wrapper.h index 092510b1bb..11da182ea6 100644 --- a/Userland/Libraries/LibWeb/Bindings/Wrapper.h +++ b/Userland/Libraries/LibWeb/Bindings/Wrapper.h @@ -25,7 +25,12 @@ protected: { } - virtual void did_become_zombie() override { revoke_weak_ptrs(); } +#ifdef JS_TRACK_ZOMBIE_CELLS + virtual void did_become_zombie() override + { + revoke_weak_ptrs(); + } +#endif }; } |