diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-21 13:47:33 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-21 14:34:40 +0200 |
commit | fbe290751067b52770ead18ff6f06bccc55e2c98 (patch) | |
tree | 73a256c8de5df3e01c87fb9b048a6029d9f64fa1 | |
parent | 31bb107922f8c869bfecb348288a7e4dc74d8937 (diff) | |
download | serenity-fbe290751067b52770ead18ff6f06bccc55e2c98.zip |
LibJS: GC should gather roots from all active interpreters
If we are in a nested execution context, we shouldn't only mark things
used by the active interpreter.
-rw-r--r-- | Libraries/LibJS/Heap/Heap.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibJS/Interpreter.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Interpreter.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/VM.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/VM.h | 2 |
5 files changed, 11 insertions, 5 deletions
diff --git a/Libraries/LibJS/Heap/Heap.cpp b/Libraries/LibJS/Heap/Heap.cpp index 9f9cb02c15..a4a131fe5c 100644 --- a/Libraries/LibJS/Heap/Heap.cpp +++ b/Libraries/LibJS/Heap/Heap.cpp @@ -105,9 +105,7 @@ void Heap::collect_garbage(CollectionType collection_type, bool print_report) void Heap::gather_roots(HashTable<Cell*>& roots) { - if (auto* interpreter = vm().interpreter_if_exists()) - interpreter->gather_roots({}, roots); - + vm().gather_roots(roots); gather_conservative_roots(roots); for (auto* handle : m_handles) diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index 3165c8dd47..56386e9ea5 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -223,7 +223,7 @@ Symbol* Interpreter::get_global_symbol(const String& description) return new_global_symbol; } -void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots) +void Interpreter::gather_roots(HashTable<Cell*>& roots) { roots.set(m_exception); diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index b356adfbed..86a90bdc51 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -135,7 +135,7 @@ public: Symbol* get_global_symbol(const String& description); - void gather_roots(Badge<Heap>, HashTable<Cell*>&); + void gather_roots(HashTable<Cell*>&); void enter_scope(const ScopeNode&, ArgumentVector, ScopeType, GlobalObject&); void exit_scope(const ScopeNode&); diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cpp index 41b1e46ec4..3a221d9862 100644 --- a/Libraries/LibJS/Runtime/VM.cpp +++ b/Libraries/LibJS/Runtime/VM.cpp @@ -82,4 +82,10 @@ VM::InterpreterScope::~InterpreterScope() m_interpreter.vm().pop_interpreter(m_interpreter); } +void VM::gather_roots(HashTable<Cell*>& roots) +{ + for (auto* interpreter : m_interpreters) + interpreter->gather_roots(roots); +} + } diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.h index d262398219..dd1b333cc0 100644 --- a/Libraries/LibJS/Runtime/VM.h +++ b/Libraries/LibJS/Runtime/VM.h @@ -53,6 +53,8 @@ public: Interpreter& m_interpreter; }; + void gather_roots(HashTable<Cell*>&); + private: VM(); |