mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:57:35 +00:00
LibJS: Only consider VM-accessible execution contexts as strong roots
Partially reverts 3dc5f467a8
to fix
GC memory leak that happens because we treated all execution contexts
as strong roots.
This commit is contained in:
parent
cbb660c756
commit
b108d51c5b
9 changed files with 32 additions and 18 deletions
|
@ -192,6 +192,8 @@ void AsyncFunctionDriverWrapper::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_top_level_promise);
|
||||
if (m_current_promise)
|
||||
visitor.visit(m_current_promise);
|
||||
if (m_suspended_execution_context)
|
||||
m_suspended_execution_context->visit_edges(visitor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ void AsyncGenerator::visit_edges(Cell::Visitor& visitor)
|
|||
if (m_frame)
|
||||
m_frame->visit_edges(visitor);
|
||||
visitor.visit(m_current_promise);
|
||||
m_async_generator_context->visit_edges(visitor);
|
||||
}
|
||||
|
||||
// 27.6.3.4 AsyncGeneratorEnqueue ( generator, completion, promiseCapability ), https://tc39.es/ecma262/#sec-asyncgeneratorenqueue
|
||||
|
|
|
@ -21,12 +21,10 @@ NonnullOwnPtr<ExecutionContext> ExecutionContext::create(Heap& heap)
|
|||
ExecutionContext::ExecutionContext(Heap& heap)
|
||||
: m_heap(heap)
|
||||
{
|
||||
m_heap.did_create_execution_context({}, *this);
|
||||
}
|
||||
|
||||
ExecutionContext::~ExecutionContext()
|
||||
{
|
||||
m_heap.did_destroy_execution_context({}, *this);
|
||||
}
|
||||
|
||||
NonnullOwnPtr<ExecutionContext> ExecutionContext::copy() const
|
||||
|
|
|
@ -51,6 +51,7 @@ void GeneratorObject::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_previous_value);
|
||||
if (m_frame)
|
||||
m_frame->visit_edges(visitor);
|
||||
m_execution_context->visit_edges(visitor);
|
||||
}
|
||||
|
||||
// 27.5.3.2 GeneratorValidate ( generator, generatorBrand ), https://tc39.es/ecma262/#sec-generatorvalidate
|
||||
|
|
|
@ -153,6 +153,20 @@ Bytecode::Interpreter& VM::bytecode_interpreter()
|
|||
return *m_bytecode_interpreter;
|
||||
}
|
||||
|
||||
struct ExecutionContextRootsCollector : public Cell::Visitor {
|
||||
virtual void visit_impl(Cell& cell) override
|
||||
{
|
||||
roots.set(&cell);
|
||||
}
|
||||
|
||||
virtual void visit_possible_values(ReadonlyBytes) override
|
||||
{
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
HashTable<Cell*> roots;
|
||||
};
|
||||
|
||||
void VM::gather_roots(HashMap<Cell*, HeapRoot>& roots)
|
||||
{
|
||||
roots.set(m_empty_string, HeapRoot { .type = HeapRoot::Type::VM });
|
||||
|
@ -169,6 +183,18 @@ void VM::gather_roots(HashMap<Cell*, HeapRoot>& roots)
|
|||
|
||||
for (auto finalization_registry : m_finalization_registry_cleanup_jobs)
|
||||
roots.set(finalization_registry, HeapRoot { .type = HeapRoot::Type::VM });
|
||||
|
||||
auto gather_roots_from_execution_context_stack = [&roots](Vector<ExecutionContext*> const& stack) {
|
||||
for (auto const& execution_context : stack) {
|
||||
ExecutionContextRootsCollector visitor;
|
||||
execution_context->visit_edges(visitor);
|
||||
for (auto* cell : visitor.roots)
|
||||
roots.set(cell, HeapRoot { .type = HeapRoot::Type::VM });
|
||||
}
|
||||
};
|
||||
gather_roots_from_execution_context_stack(m_execution_context_stack);
|
||||
for (auto& saved_stack : m_saved_execution_context_stacks)
|
||||
gather_roots_from_execution_context_stack(saved_stack);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Value> VM::named_evaluation_if_anonymous_function(ASTNode const& expression, DeprecatedFlyString const& name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue