From 3399023e3e025c0a7532364ae6f5f019e590ec3d Mon Sep 17 00:00:00 2001 From: valtermiari Date: Mon, 8 May 2023 11:55:56 +0200 Subject: [PATCH] Testing 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 352c94b..073a6eb 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); @@ -315,7 +316,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) @@ -334,7 +354,8 @@ namespace GC chunk->m_marked = true; chunk_spaces.push(std::make_pair(c_start, c_end)); } - } + } */ + } void Heap::create_table()