From 560f8f9b2f39aad387eac577af469828cfeae3dd Mon Sep 17 00:00:00 2001 From: valtermiari Date: Mon, 8 May 2023 12:03:55 +0200 Subject: [PATCH] Hash table lookup for marking --- src/GC/lib/heap.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 91f1e02..3213a67 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -234,6 +234,7 @@ namespace GC // create_table(); // mark_hash(stack_bottom, stack_top); + create_table(); vector roots; // cout << "\nb4 find_roots\n"; find_roots(stack_bottom, roots); @@ -299,7 +300,26 @@ namespace GC void Heap::find_chunks(uintptr_t *stack_addr, std::queue> &chunk_spaces) { - auto iter = m_allocated_chunks.begin(); + Heap &heap = Heap::the(); + + auto it = heap.m_chunk_table.find(*stack_addr); + if (it != heap.m_chunk_table.end()) + { + auto chunk = it->second; + + if (!chunk->m_marked) + { + auto c_start = reinterpret_cast(chunk->m_start); + auto c_size = reinterpret_cast(chunk->m_size); + auto c_end = reinterpret_cast(c_start + c_size); + + chunk->m_marked = true; + chunk_spaces.push(std::make_pair(c_start, c_end)); + } + + } + +/* auto iter = m_allocated_chunks.begin(); auto end = m_allocated_chunks.end(); while (iter != end) @@ -318,7 +338,8 @@ namespace GC chunk->m_marked = true; chunk_spaces.push(std::make_pair(c_start, c_end)); } - } + } */ + } void Heap::create_table()