1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +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

@ -10,8 +10,9 @@
namespace JS { namespace JS {
HandleImpl::HandleImpl(Cell* cell) HandleImpl::HandleImpl(Cell* cell, SourceLocation location)
: m_cell(cell) : m_cell(cell)
, m_location(location)
{ {
m_cell->heap().did_create_handle({}, *this); m_cell->heap().did_create_handle({}, *this);
} }

View file

@ -11,6 +11,7 @@
#include <AK/Noncopyable.h> #include <AK/Noncopyable.h>
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/SourceLocation.h>
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
@ -26,12 +27,15 @@ public:
Cell* cell() { return m_cell; } Cell* cell() { return m_cell; }
Cell const* cell() const { return m_cell; } Cell const* cell() const { return m_cell; }
SourceLocation const& source_location() const { return m_location; }
private: private:
template<class T> template<class T>
friend class Handle; friend class Handle;
explicit HandleImpl(Cell*); explicit HandleImpl(Cell*, SourceLocation location);
GCPtr<Cell> m_cell; GCPtr<Cell> m_cell;
SourceLocation m_location;
IntrusiveListNode<HandleImpl> m_list_node; IntrusiveListNode<HandleImpl> m_list_node;
@ -44,29 +48,29 @@ class Handle {
public: public:
Handle() = default; Handle() = default;
static Handle create(T* cell) static Handle create(T* cell, SourceLocation location = SourceLocation::current())
{ {
return Handle(adopt_ref(*new HandleImpl(const_cast<RemoveConst<T>*>(cell)))); return Handle(adopt_ref(*new HandleImpl(const_cast<RemoveConst<T>*>(cell), location)));
} }
Handle(T* cell) Handle(T* cell, SourceLocation location = SourceLocation::current())
{ {
if (cell) if (cell)
m_impl = adopt_ref(*new HandleImpl(cell)); m_impl = adopt_ref(*new HandleImpl(cell, location));
} }
Handle(T& cell) Handle(T& cell, SourceLocation location = SourceLocation::current())
: m_impl(adopt_ref(*new HandleImpl(&cell))) : m_impl(adopt_ref(*new HandleImpl(&cell, location)))
{ {
} }
Handle(GCPtr<T> cell) Handle(GCPtr<T> cell, SourceLocation location = SourceLocation::current())
: Handle(cell.ptr()) : Handle(cell.ptr(), location)
{ {
} }
Handle(NonnullGCPtr<T> cell) Handle(NonnullGCPtr<T> cell, SourceLocation location = SourceLocation::current())
: Handle(*cell) : Handle(*cell, location)
{ {
} }
@ -118,31 +122,31 @@ private:
}; };
template<class T> template<class T>
inline Handle<T> make_handle(T* cell) inline Handle<T> make_handle(T* cell, SourceLocation location = SourceLocation::current())
{ {
if (!cell) if (!cell)
return Handle<T> {}; return Handle<T> {};
return Handle<T>::create(cell); return Handle<T>::create(cell, location);
} }
template<class T> template<class T>
inline Handle<T> make_handle(T& cell) inline Handle<T> make_handle(T& cell, SourceLocation location = SourceLocation::current())
{ {
return Handle<T>::create(&cell); return Handle<T>::create(&cell, location);
} }
template<class T> template<class T>
inline Handle<T> make_handle(GCPtr<T> cell) inline Handle<T> make_handle(GCPtr<T> cell, SourceLocation location = SourceLocation::current())
{ {
if (!cell) if (!cell)
return Handle<T> {}; return Handle<T> {};
return Handle<T>::create(cell.ptr()); return Handle<T>::create(cell.ptr(), location);
} }
template<class T> template<class T>
inline Handle<T> make_handle(NonnullGCPtr<T> cell) inline Handle<T> make_handle(NonnullGCPtr<T> cell, SourceLocation location = SourceLocation::current())
{ {
return Handle<T>::create(cell.ptr()); return Handle<T>::create(cell.ptr(), location);
} }
template<> template<>
@ -150,10 +154,10 @@ class Handle<Value> {
public: public:
Handle() = default; Handle() = default;
static Handle create(Value value) static Handle create(Value value, SourceLocation location)
{ {
if (value.is_cell()) if (value.is_cell())
return Handle(value, &value.as_cell()); return Handle(value, &value.as_cell(), location);
return Handle(value); return Handle(value);
} }
@ -171,9 +175,9 @@ private:
{ {
} }
explicit Handle(Value value, Cell* cell) explicit Handle(Value value, Cell* cell, SourceLocation location)
: m_value(value) : m_value(value)
, m_handle(Handle<Cell>::create(cell)) , m_handle(Handle<Cell>::create(cell, location))
{ {
} }
@ -181,9 +185,9 @@ private:
Handle<Cell> m_handle; Handle<Cell> m_handle;
}; };
inline Handle<Value> make_handle(Value value) inline Handle<Value> make_handle(Value value, SourceLocation location = SourceLocation::current())
{ {
return Handle<Value>::create(value); return Handle<Value>::create(value, location);
} }
} }

View file

@ -95,7 +95,7 @@ Cell* Heap::allocate_cell(size_t size)
return allocator.allocate_cell(*this); return allocator.allocate_cell(*this);
} }
static void add_possible_value(HashMap<FlatPtr, HeapRootTypeOrLocation>& possible_pointers, FlatPtr data, HeapRootTypeOrLocation origin) static void add_possible_value(HashMap<FlatPtr, HeapRoot>& possible_pointers, FlatPtr data, HeapRoot origin)
{ {
if constexpr (sizeof(FlatPtr*) == sizeof(Value)) { if constexpr (sizeof(FlatPtr*) == sizeof(Value)) {
// Because Value stores pointers in non-canonical form we have to check if the top bytes // Because Value stores pointers in non-canonical form we have to check if the top bytes
@ -114,7 +114,7 @@ static void add_possible_value(HashMap<FlatPtr, HeapRootTypeOrLocation>& possibl
} }
template<typename Callback> template<typename Callback>
static void for_each_cell_among_possible_pointers(HashTable<HeapBlock*> const& all_live_heap_blocks, HashMap<FlatPtr, HeapRootTypeOrLocation>& possible_pointers, Callback callback) static void for_each_cell_among_possible_pointers(HashTable<HeapBlock*> const& all_live_heap_blocks, HashMap<FlatPtr, HeapRoot>& possible_pointers, Callback callback)
{ {
for (auto possible_pointer : possible_pointers.keys()) { for (auto possible_pointer : possible_pointers.keys()) {
if (!possible_pointer) if (!possible_pointer)
@ -130,7 +130,7 @@ static void for_each_cell_among_possible_pointers(HashTable<HeapBlock*> const& a
class GraphConstructorVisitor final : public Cell::Visitor { class GraphConstructorVisitor final : public Cell::Visitor {
public: public:
explicit GraphConstructorVisitor(Heap& heap, HashMap<Cell*, HeapRootTypeOrLocation> const& roots) explicit GraphConstructorVisitor(Heap& heap, HashMap<Cell*, HeapRoot> const& roots)
: m_heap(heap) : m_heap(heap)
{ {
m_heap.for_each_block([&](auto& block) { m_heap.for_each_block([&](auto& block) {
@ -159,11 +159,11 @@ public:
virtual void visit_possible_values(ReadonlyBytes bytes) override virtual void visit_possible_values(ReadonlyBytes bytes) override
{ {
HashMap<FlatPtr, HeapRootTypeOrLocation> possible_pointers; HashMap<FlatPtr, HeapRoot> possible_pointers;
auto* raw_pointer_sized_values = reinterpret_cast<FlatPtr const*>(bytes.data()); auto* raw_pointer_sized_values = reinterpret_cast<FlatPtr const*>(bytes.data());
for (size_t i = 0; i < (bytes.size() / sizeof(FlatPtr)); ++i) for (size_t i = 0; i < (bytes.size() / sizeof(FlatPtr)); ++i)
add_possible_value(possible_pointers, raw_pointer_sized_values[i], HeapRootType::HeapFunctionCapturedPointer); add_possible_value(possible_pointers, raw_pointer_sized_values[i], HeapRoot { .type = HeapRoot::Type::HeapFunctionCapturedPointer });
for_each_cell_among_possible_pointers(m_all_live_heap_blocks, possible_pointers, [&](Cell* cell, FlatPtr) { for_each_cell_among_possible_pointers(m_all_live_heap_blocks, possible_pointers, [&](Cell* cell, FlatPtr) {
if (m_node_being_visited) if (m_node_being_visited)
@ -197,31 +197,30 @@ public:
auto node = AK::JsonObject(); auto node = AK::JsonObject();
if (it.value.root_origin.has_value()) { if (it.value.root_origin.has_value()) {
it.value.root_origin->visit( auto type = it.value.root_origin->type;
[&](HeapRootType location) { auto location = it.value.root_origin->location;
switch (location) { switch (type) {
case HeapRootType::Handle: case HeapRoot::Type::Handle:
node.set("root"sv, "Handle"sv); node.set("root"sv, DeprecatedString::formatted("Handle {} {}:{}", location->function_name(), location->filename(), location->line_number()));
return; break;
case HeapRootType::MarkedVector: case HeapRoot::Type::MarkedVector:
node.set("root"sv, "MarkedVector"); node.set("root"sv, "MarkedVector");
return; break;
case HeapRootType::RegisterPointer: case HeapRoot::Type::RegisterPointer:
node.set("root"sv, "RegisterPointer"); node.set("root"sv, "RegisterPointer");
return; break;
case HeapRootType::StackPointer: case HeapRoot::Type::StackPointer:
node.set("root"sv, "StackPointer"); node.set("root"sv, "StackPointer");
return; break;
case HeapRootType::VM: case HeapRoot::Type::VM:
node.set("root"sv, "VM"); node.set("root"sv, "VM");
return; break;
case HeapRoot::Type::SafeFunction:
node.set("root"sv, DeprecatedString::formatted("SafeFunction {} {}:{}", location->function_name(), location->filename(), location->line_number()));
break;
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
},
[&](SourceLocation* location) {
node.set("root", DeprecatedString::formatted("SafeFunction {} {}:{}", location->function_name(), location->filename(), location->line_number()));
});
} }
node.set("class_name"sv, it.value.class_name); node.set("class_name"sv, it.value.class_name);
node.set("edges"sv, edges); node.set("edges"sv, edges);
@ -233,7 +232,7 @@ public:
private: private:
struct GraphNode { struct GraphNode {
Optional<HeapRootTypeOrLocation> root_origin; Optional<HeapRoot> root_origin;
StringView class_name; StringView class_name;
HashTable<FlatPtr> edges {}; HashTable<FlatPtr> edges {};
}; };
@ -248,7 +247,7 @@ private:
void Heap::dump_graph() void Heap::dump_graph()
{ {
HashMap<Cell*, HeapRootTypeOrLocation> roots; HashMap<Cell*, HeapRoot> roots;
gather_roots(roots); gather_roots(roots);
GraphConstructorVisitor visitor(*this, roots); GraphConstructorVisitor visitor(*this, roots);
vm().bytecode_interpreter().visit_edges(visitor); vm().bytecode_interpreter().visit_edges(visitor);
@ -275,7 +274,7 @@ void Heap::collect_garbage(CollectionType collection_type, bool print_report)
m_should_gc_when_deferral_ends = true; m_should_gc_when_deferral_ends = true;
return; return;
} }
HashMap<Cell*, HeapRootTypeOrLocation> roots; HashMap<Cell*, HeapRoot> roots;
gather_roots(roots); gather_roots(roots);
mark_live_cells(roots); mark_live_cells(roots);
} }
@ -283,13 +282,13 @@ void Heap::collect_garbage(CollectionType collection_type, bool print_report)
sweep_dead_cells(print_report, collection_measurement_timer); sweep_dead_cells(print_report, collection_measurement_timer);
} }
void Heap::gather_roots(HashMap<Cell*, HeapRootTypeOrLocation>& roots) void Heap::gather_roots(HashMap<Cell*, HeapRoot>& roots)
{ {
vm().gather_roots(roots); vm().gather_roots(roots);
gather_conservative_roots(roots); gather_conservative_roots(roots);
for (auto& handle : m_handles) for (auto& handle : m_handles)
roots.set(handle.cell(), HeapRootType::Handle); roots.set(handle.cell(), HeapRoot { .type = HeapRoot::Type::Handle, .location = &handle.source_location() });
for (auto& vector : m_marked_vectors) for (auto& vector : m_marked_vectors)
vector.gather_roots(roots); vector.gather_roots(roots);
@ -302,7 +301,7 @@ void Heap::gather_roots(HashMap<Cell*, HeapRootTypeOrLocation>& roots)
} }
#ifdef HAS_ADDRESS_SANITIZER #ifdef HAS_ADDRESS_SANITIZER
__attribute__((no_sanitize("address"))) void Heap::gather_asan_fake_stack_roots(HashMap<FlatPtr, HeapRootTypeOrLocation>& possible_pointers, FlatPtr addr) __attribute__((no_sanitize("address"))) void Heap::gather_asan_fake_stack_roots(HashMap<FlatPtr, HeapRoot>& possible_pointers, FlatPtr addr)
{ {
void* begin = nullptr; void* begin = nullptr;
void* end = nullptr; void* end = nullptr;
@ -313,17 +312,17 @@ __attribute__((no_sanitize("address"))) void Heap::gather_asan_fake_stack_roots(
void const* real_address = *real_stack_addr; void const* real_address = *real_stack_addr;
if (real_address == nullptr) if (real_address == nullptr)
continue; continue;
add_possible_value(possible_pointers, reinterpret_cast<FlatPtr>(real_address), HeapRootType::StackPointer); add_possible_value(possible_pointers, reinterpret_cast<FlatPtr>(real_address), HeapRoot { .type = HeapRoot::Type::StackPointer });
} }
} }
} }
#else #else
void Heap::gather_asan_fake_stack_roots(HashMap<FlatPtr, HeapRootTypeOrLocation>&, FlatPtr) void Heap::gather_asan_fake_stack_roots(HashMap<FlatPtr, HeapRoot>&, FlatPtr)
{ {
} }
#endif #endif
__attribute__((no_sanitize("address"))) void Heap::gather_conservative_roots(HashMap<Cell*, HeapRootTypeOrLocation>& roots) __attribute__((no_sanitize("address"))) void Heap::gather_conservative_roots(HashMap<Cell*, HeapRoot>& roots)
{ {
FlatPtr dummy; FlatPtr dummy;
@ -332,19 +331,19 @@ __attribute__((no_sanitize("address"))) void Heap::gather_conservative_roots(Has
jmp_buf buf; jmp_buf buf;
setjmp(buf); setjmp(buf);
HashMap<FlatPtr, HeapRootTypeOrLocation> possible_pointers; HashMap<FlatPtr, HeapRoot> possible_pointers;
auto* raw_jmp_buf = reinterpret_cast<FlatPtr const*>(buf); auto* raw_jmp_buf = reinterpret_cast<FlatPtr const*>(buf);
for (size_t i = 0; i < ((size_t)sizeof(buf)) / sizeof(FlatPtr); ++i) for (size_t i = 0; i < ((size_t)sizeof(buf)) / sizeof(FlatPtr); ++i)
add_possible_value(possible_pointers, raw_jmp_buf[i], HeapRootType::RegisterPointer); add_possible_value(possible_pointers, raw_jmp_buf[i], HeapRoot { .type = HeapRoot::Type::RegisterPointer });
auto stack_reference = bit_cast<FlatPtr>(&dummy); auto stack_reference = bit_cast<FlatPtr>(&dummy);
auto& stack_info = m_vm.stack_info(); auto& stack_info = m_vm.stack_info();
for (FlatPtr stack_address = stack_reference; stack_address < stack_info.top(); stack_address += sizeof(FlatPtr)) { for (FlatPtr stack_address = stack_reference; stack_address < stack_info.top(); stack_address += sizeof(FlatPtr)) {
auto data = *reinterpret_cast<FlatPtr*>(stack_address); auto data = *reinterpret_cast<FlatPtr*>(stack_address);
add_possible_value(possible_pointers, data, HeapRootType::StackPointer); add_possible_value(possible_pointers, data, HeapRoot { .type = HeapRoot::Type::StackPointer });
gather_asan_fake_stack_roots(possible_pointers, data); gather_asan_fake_stack_roots(possible_pointers, data);
} }
@ -354,7 +353,7 @@ __attribute__((no_sanitize("address"))) void Heap::gather_conservative_roots(Has
for (auto& custom_range : *s_custom_ranges_for_conservative_scan) { for (auto& custom_range : *s_custom_ranges_for_conservative_scan) {
for (size_t i = 0; i < (custom_range.value / sizeof(FlatPtr)); ++i) { for (size_t i = 0; i < (custom_range.value / sizeof(FlatPtr)); ++i) {
auto safe_function_location = s_safe_function_locations->get(custom_range.key); auto safe_function_location = s_safe_function_locations->get(custom_range.key);
add_possible_value(possible_pointers, custom_range.key[i], *safe_function_location); add_possible_value(possible_pointers, custom_range.key[i], HeapRoot { .type = HeapRoot::Type::SafeFunction, .location = *safe_function_location });
} }
} }
} }
@ -377,7 +376,7 @@ __attribute__((no_sanitize("address"))) void Heap::gather_conservative_roots(Has
class MarkingVisitor final : public Cell::Visitor { class MarkingVisitor final : public Cell::Visitor {
public: public:
explicit MarkingVisitor(Heap& heap, HashMap<Cell*, HeapRootTypeOrLocation> const& roots) explicit MarkingVisitor(Heap& heap, HashMap<Cell*, HeapRoot> const& roots)
: m_heap(heap) : m_heap(heap)
{ {
m_heap.for_each_block([&](auto& block) { m_heap.for_each_block([&](auto& block) {
@ -402,11 +401,11 @@ public:
virtual void visit_possible_values(ReadonlyBytes bytes) override virtual void visit_possible_values(ReadonlyBytes bytes) override
{ {
HashMap<FlatPtr, HeapRootTypeOrLocation> possible_pointers; HashMap<FlatPtr, HeapRoot> possible_pointers;
auto* raw_pointer_sized_values = reinterpret_cast<FlatPtr const*>(bytes.data()); auto* raw_pointer_sized_values = reinterpret_cast<FlatPtr const*>(bytes.data());
for (size_t i = 0; i < (bytes.size() / sizeof(FlatPtr)); ++i) for (size_t i = 0; i < (bytes.size() / sizeof(FlatPtr)); ++i)
add_possible_value(possible_pointers, raw_pointer_sized_values[i], HeapRootType::HeapFunctionCapturedPointer); add_possible_value(possible_pointers, raw_pointer_sized_values[i], HeapRoot { .type = HeapRoot::Type::HeapFunctionCapturedPointer });
for_each_cell_among_possible_pointers(m_all_live_heap_blocks, possible_pointers, [&](Cell* cell, FlatPtr) { for_each_cell_among_possible_pointers(m_all_live_heap_blocks, possible_pointers, [&](Cell* cell, FlatPtr) {
if (cell->is_marked()) if (cell->is_marked())
@ -431,7 +430,7 @@ private:
HashTable<HeapBlock*> m_all_live_heap_blocks; HashTable<HeapBlock*> m_all_live_heap_blocks;
}; };
void Heap::mark_live_cells(HashMap<Cell*, HeapRootTypeOrLocation> const& roots) void Heap::mark_live_cells(HashMap<Cell*, HeapRoot> const& roots)
{ {
dbgln_if(HEAP_DEBUG, "mark_live_cells:"); dbgln_if(HEAP_DEBUG, "mark_live_cells:");

View file

@ -19,7 +19,7 @@
#include <LibJS/Heap/Cell.h> #include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/CellAllocator.h> #include <LibJS/Heap/CellAllocator.h>
#include <LibJS/Heap/Handle.h> #include <LibJS/Heap/Handle.h>
#include <LibJS/Heap/HeapRootTypeOrLocation.h> #include <LibJS/Heap/HeapRoot.h>
#include <LibJS/Heap/Internals.h> #include <LibJS/Heap/Internals.h>
#include <LibJS/Heap/MarkedVector.h> #include <LibJS/Heap/MarkedVector.h>
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
@ -88,10 +88,10 @@ private:
Cell* allocate_cell(size_t); Cell* allocate_cell(size_t);
void gather_roots(HashMap<Cell*, HeapRootTypeOrLocation>&); void gather_roots(HashMap<Cell*, HeapRoot>&);
void gather_conservative_roots(HashMap<Cell*, HeapRootTypeOrLocation>&); void gather_conservative_roots(HashMap<Cell*, HeapRoot>&);
void gather_asan_fake_stack_roots(HashMap<FlatPtr, HeapRootTypeOrLocation>&, FlatPtr); void gather_asan_fake_stack_roots(HashMap<FlatPtr, HeapRoot>&, FlatPtr);
void mark_live_cells(HashMap<Cell*, HeapRootTypeOrLocation> const& live_cells); void mark_live_cells(HashMap<Cell*, HeapRoot> const& live_cells);
void finalize_unmarked_cells(); void finalize_unmarked_cells();
void sweep_dead_cells(bool print_report, Core::ElapsedTimer const&); void sweep_dead_cells(bool print_report, Core::ElapsedTimer const&);

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/SourceLocation.h>
namespace JS {
struct HeapRoot {
enum class Type {
HeapFunctionCapturedPointer,
Handle,
MarkedVector,
RegisterPointer,
SafeFunction,
StackPointer,
VM,
};
Type type;
SourceLocation const* location { nullptr };
};
}

View file

@ -1,24 +0,0 @@
/*
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/SourceLocation.h>
namespace JS {
enum class HeapRootType {
HeapFunctionCapturedPointer,
Handle,
MarkedVector,
RegisterPointer,
StackPointer,
VM,
};
using HeapRootTypeOrLocation = Variant<HeapRootType, SourceLocation*>;
}

View file

@ -12,13 +12,13 @@
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
#include <LibJS/Heap/Cell.h> #include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/HeapRootTypeOrLocation.h> #include <LibJS/Heap/HeapRoot.h>
namespace JS { namespace JS {
class MarkedVectorBase { class MarkedVectorBase {
public: public:
virtual void gather_roots(HashMap<Cell*, JS::HeapRootTypeOrLocation>&) const = 0; virtual void gather_roots(HashMap<Cell*, JS::HeapRoot>&) const = 0;
protected: protected:
explicit MarkedVectorBase(Heap&); explicit MarkedVectorBase(Heap&);
@ -65,14 +65,14 @@ public:
return *this; return *this;
} }
virtual void gather_roots(HashMap<Cell*, JS::HeapRootTypeOrLocation>& roots) const override virtual void gather_roots(HashMap<Cell*, JS::HeapRoot>& roots) const override
{ {
for (auto& value : *this) { for (auto& value : *this) {
if constexpr (IsSame<Value, T>) { if constexpr (IsSame<Value, T>) {
if (value.is_cell()) if (value.is_cell())
roots.set(&const_cast<T&>(value).as_cell(), HeapRootType::MarkedVector); roots.set(&const_cast<T&>(value).as_cell(), HeapRoot { .type = HeapRoot::Type::MarkedVector });
} else { } else {
roots.set(value, HeapRootType::MarkedVector); roots.set(value, HeapRoot { .type = HeapRoot::Type::MarkedVector });
} }
} }
} }

View file

@ -192,29 +192,29 @@ Bytecode::Interpreter& VM::bytecode_interpreter()
return *m_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) 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) { auto gather_roots_from_execution_context_stack = [&roots](Vector<ExecutionContext*> const& stack) {
for (auto& execution_context : stack) { for (auto& execution_context : stack) {
if (execution_context->this_value.is_cell()) 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) { for (auto& argument : execution_context->arguments) {
if (argument.is_cell()) 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->lexical_environment, HeapRoot { .type = HeapRoot::Type::VM });
roots.set(execution_context->variable_environment, HeapRootType::VM); roots.set(execution_context->variable_environment, HeapRoot { .type = HeapRoot::Type::VM });
roots.set(execution_context->private_environment, HeapRootType::VM); roots.set(execution_context->private_environment, HeapRoot { .type = HeapRoot::Type::VM });
if (auto context_owner = execution_context->context_owner) 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( execution_context->script_or_module.visit(
[](Empty) {}, [](Empty) {},
[&](auto& script_or_module) { [&](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); gather_roots_from_execution_context_stack(saved_stack);
#define __JS_ENUMERATE(SymbolName, snake_name) \ #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 JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE #undef __JS_ENUMERATE
for (auto& symbol : m_global_symbol_registry) 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) 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) ThrowCompletionOr<Value> VM::named_evaluation_if_anonymous_function(ASTNode const& expression, DeprecatedFlyString const& name)

View file

@ -47,7 +47,7 @@ public:
void dump_backtrace() const; void dump_backtrace() const;
void gather_roots(HashMap<Cell*, HeapRootTypeOrLocation>&); void gather_roots(HashMap<Cell*, HeapRoot>&);
#define __JS_ENUMERATE(SymbolName, snake_name) \ #define __JS_ENUMERATE(SymbolName, snake_name) \
NonnullGCPtr<Symbol> well_known_symbol_##snake_name() const \ NonnullGCPtr<Symbol> well_known_symbol_##snake_name() const \