From 746b310061e8ba90aa0de40070c38fc97adde4cd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Jul 2021 19:45:21 +0200 Subject: LibJS: Use IntrusiveList for keeping track of HandleImpls This allows us to remove a HashTable from heap and cuts down on some of the malloc traffic when creating handles. --- Userland/Libraries/LibJS/Heap/Handle.h | 6 ++++++ Userland/Libraries/LibJS/Heap/Heap.cpp | 12 ++++++------ Userland/Libraries/LibJS/Heap/Heap.h | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibJS/Heap/Handle.h b/Userland/Libraries/LibJS/Heap/Handle.h index ace0257ade..b9eab8a225 100644 --- a/Userland/Libraries/LibJS/Heap/Handle.h +++ b/Userland/Libraries/LibJS/Heap/Handle.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -30,6 +31,11 @@ private: explicit HandleImpl(Cell*); Cell* m_cell { nullptr }; + + IntrusiveListNode m_list_node; + +public: + using List = IntrusiveList, &HandleImpl::m_list_node>; }; template diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp index c1ee023ecb..16555b0a2d 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.cpp +++ b/Userland/Libraries/LibJS/Heap/Heap.cpp @@ -91,8 +91,8 @@ void Heap::gather_roots(HashTable& roots) vm().gather_roots(roots); gather_conservative_roots(roots); - for (auto* handle : m_handles) - roots.set(handle->cell()); + for (auto& handle : m_handles) + roots.set(handle.cell()); for (auto* list : m_marked_value_lists) { for (auto& value : list->values()) { @@ -258,14 +258,14 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure void Heap::did_create_handle(Badge, HandleImpl& impl) { - VERIFY(!m_handles.contains(&impl)); - m_handles.set(&impl); + VERIFY(!m_handles.contains(impl)); + m_handles.append(impl); } void Heap::did_destroy_handle(Badge, HandleImpl& impl) { - VERIFY(m_handles.contains(&impl)); - m_handles.remove(&impl); + VERIFY(m_handles.contains(impl)); + m_handles.remove(impl); } void Heap::did_create_marked_value_list(Badge, MarkedValueList& list) diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index 57cf1a40cc..362639d96f 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -105,7 +106,8 @@ private: VM& m_vm; Vector> m_allocators; - HashTable m_handles; + + HandleImpl::List m_handles; HashTable m_marked_value_lists; -- cgit v1.2.3