소스 검색

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.
Andreas Kling 4 년 전
부모
커밋
746b310061
3개의 변경된 파일15개의 추가작업 그리고 7개의 파일을 삭제
  1. 6 0
      Userland/Libraries/LibJS/Heap/Handle.h
  2. 6 6
      Userland/Libraries/LibJS/Heap/Heap.cpp
  3. 3 1
      Userland/Libraries/LibJS/Heap/Heap.h

+ 6 - 0
Userland/Libraries/LibJS/Heap/Handle.h

@@ -7,6 +7,7 @@
 #pragma once
 
 #include <AK/Badge.h>
+#include <AK/IntrusiveList.h>
 #include <AK/Noncopyable.h>
 #include <AK/RefCounted.h>
 #include <AK/RefPtr.h>
@@ -30,6 +31,11 @@ private:
 
     explicit HandleImpl(Cell*);
     Cell* m_cell { nullptr };
+
+    IntrusiveListNode<HandleImpl> m_list_node;
+
+public:
+    using List = IntrusiveList<HandleImpl, RawPtr<HandleImpl>, &HandleImpl::m_list_node>;
 };
 
 template<class T>

+ 6 - 6
Userland/Libraries/LibJS/Heap/Heap.cpp

@@ -91,8 +91,8 @@ void Heap::gather_roots(HashTable<Cell*>& 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>, 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>, 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>, MarkedValueList& list)

+ 3 - 1
Userland/Libraries/LibJS/Heap/Heap.h

@@ -7,6 +7,7 @@
 #pragma once
 
 #include <AK/HashTable.h>
+#include <AK/IntrusiveList.h>
 #include <AK/Noncopyable.h>
 #include <AK/NonnullOwnPtr.h>
 #include <AK/Types.h>
@@ -105,7 +106,8 @@ private:
     VM& m_vm;
 
     Vector<NonnullOwnPtr<CellAllocator>> m_allocators;
-    HashTable<HandleImpl*> m_handles;
+
+    HandleImpl::List m_handles;
 
     HashTable<MarkedValueList*> m_marked_value_lists;