1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

LibJS: Add source location for Handle nodes in GC graph dumper output

With this change JS::Handle root nodes will contain source location
where they were constructed like:
```
    "94675029575744": {
        "root": "Handle activate_event_handler \
           serenity/Userland/Libraries/LibWeb/DOM/EventTarget.cpp:564",
        "class_name": "HTMLButtonElement",
        "edges": [
            "94675025955904",
            "94675026899520",
            "94675030831168",
```
This commit is contained in:
Aliaksandr Kalenik 2023-09-22 02:04:16 +02:00 committed by Andreas Kling
parent 4b06cef93a
commit 719a00df3a
9 changed files with 129 additions and 121 deletions

View file

@ -192,29 +192,29 @@ Bytecode::Interpreter& VM::bytecode_interpreter()
return *m_bytecode_interpreter;
}
void VM::gather_roots(HashMap<Cell*, HeapRootTypeOrLocation>& roots)
void VM::gather_roots(HashMap<Cell*, HeapRoot>& roots)
{
roots.set(m_empty_string, HeapRootType::VM);
roots.set(m_empty_string, HeapRoot { .type = HeapRoot::Type::VM });
for (auto string : m_single_ascii_character_strings)
roots.set(string, HeapRootType::VM);
roots.set(string, HeapRoot { .type = HeapRoot::Type::VM });
auto gather_roots_from_execution_context_stack = [&roots](Vector<ExecutionContext*> const& stack) {
for (auto& execution_context : stack) {
if (execution_context->this_value.is_cell())
roots.set(&execution_context->this_value.as_cell(), HeapRootType::VM);
roots.set(&execution_context->this_value.as_cell(), { .type = HeapRoot::Type::VM });
for (auto& argument : execution_context->arguments) {
if (argument.is_cell())
roots.set(&argument.as_cell(), HeapRootType::VM);
roots.set(&argument.as_cell(), HeapRoot { .type = HeapRoot::Type::VM });
}
roots.set(execution_context->lexical_environment, HeapRootType::VM);
roots.set(execution_context->variable_environment, HeapRootType::VM);
roots.set(execution_context->private_environment, HeapRootType::VM);
roots.set(execution_context->lexical_environment, HeapRoot { .type = HeapRoot::Type::VM });
roots.set(execution_context->variable_environment, HeapRoot { .type = HeapRoot::Type::VM });
roots.set(execution_context->private_environment, HeapRoot { .type = HeapRoot::Type::VM });
if (auto context_owner = execution_context->context_owner)
roots.set(context_owner, HeapRootType::VM);
roots.set(context_owner, HeapRoot { .type = HeapRoot::Type::VM });
execution_context->script_or_module.visit(
[](Empty) {},
[&](auto& script_or_module) {
roots.set(script_or_module.ptr(), HeapRootType::VM);
roots.set(script_or_module.ptr(), HeapRoot { .type = HeapRoot::Type::VM });
});
}
};
@ -224,15 +224,15 @@ void VM::gather_roots(HashMap<Cell*, HeapRootTypeOrLocation>& roots)
gather_roots_from_execution_context_stack(saved_stack);
#define __JS_ENUMERATE(SymbolName, snake_name) \
roots.set(m_well_known_symbols.snake_name, HeapRootType::VM);
roots.set(m_well_known_symbols.snake_name, HeapRoot { .type = HeapRoot::Type::VM });
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE
for (auto& symbol : m_global_symbol_registry)
roots.set(symbol.value, HeapRootType::VM);
roots.set(symbol.value, HeapRoot { .type = HeapRoot::Type::VM });
for (auto finalization_registry : m_finalization_registry_cleanup_jobs)
roots.set(finalization_registry, HeapRootType::VM);
roots.set(finalization_registry, HeapRoot { .type = HeapRoot::Type::VM });
}
ThrowCompletionOr<Value> VM::named_evaluation_if_anonymous_function(ASTNode const& expression, DeprecatedFlyString const& name)