From 830d863c70d124ea3bb37624aa6bdba33da12cf4 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Sat, 6 May 2023 10:23:09 +0200 Subject: [PATCH] bugfix --- src/GC/lib/heap.cpp | 75 +++++++-------------------------------------- 1 file changed, 11 insertions(+), 64 deletions(-) diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 960e724..352c94b 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -220,7 +220,7 @@ namespace GC Profiler::record(CollectStart); // get current stack frame - // auto stack_bottom = reinterpret_cast(__builtin_frame_address(2)); + stack_bottom = reinterpret_cast(__builtin_frame_address(0)); if (heap.m_stack_top == nullptr) throw std::runtime_error(std::string("Error: Heap is not initialized, read the docs!")); @@ -254,12 +254,10 @@ namespace GC void Heap::find_roots(uintptr_t *stack_bottom, vector &roots) { - Heap &heap = Heap::the(); - auto stack_top = heap.m_stack_top; - auto heap_bottom = reinterpret_cast(heap.m_heap); - auto heap_top = reinterpret_cast(heap.m_heap + HEAP_SIZE); + auto heap_bottom = reinterpret_cast(m_heap); + auto heap_top = reinterpret_cast(m_heap + HEAP_SIZE); - while (stack_bottom < stack_top) + while (stack_bottom < m_stack_top) { if (heap_bottom < *stack_bottom && *stack_bottom < heap_top) { @@ -292,25 +290,26 @@ namespace GC Profiler::record(MarkStart); auto iter = roots.begin(), end = roots.end(); - // vector> chunk_spaces; std::queue> chunk_spaces; - // std::set visited_addresses; - // cout << "b4 find_chunks of roots\n"; while (iter != end) { find_chunks(*iter++, chunk_spaces); } - // cout << "b4 find_chunks of chunks\n"; while (!chunk_spaces.empty()) { auto range = chunk_spaces.front(); chunk_spaces.pop(); - auto stack_addr = reinterpret_cast(range.first); + auto addr_bottom = reinterpret_cast(range.first); + auto addr_top = reinterpret_cast(range.second); - find_chunks(stack_addr, chunk_spaces); + while (addr_bottom < addr_top) + { + find_chunks(addr_bottom, chunk_spaces); + addr_bottom++; + } } } @@ -333,63 +332,11 @@ namespace GC if (c_start < *stack_addr && *stack_addr < c_end) { chunk->m_marked = true; - // chunk_spaces.push_back(std::make_pair(c_start, c_end)); chunk_spaces.push(std::make_pair(c_start, c_end)); } } } - void Heap::mark_range(vector &ranges, vector &worklist) - { - Heap &heap = Heap::the(); - bool profiler_enabled = heap.m_profiler_enable; - if (profiler_enabled) - Profiler::record(MarkStart); - - auto iter = ranges.begin(); - auto stop = ranges.end(); - - while (iter != stop) - { - auto range = *iter++; - uintptr_t *start = (uintptr_t *)range->start; - const uintptr_t *end = range->end; - if (start == nullptr) - cout << "\nstart is null\n"; - for (; start <= end; start++) - { - auto wliter = worklist.begin(); - auto wlstop = worklist.end(); - while (wliter != wlstop) - { - Chunk *chunk = *wliter; - 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); - - if (c_start <= *start && *start < c_end) - { - if (!chunk->m_marked) - { - chunk->m_marked = true; - wliter = worklist.erase(wliter); - ranges.push_back(new AddrRange((uintptr_t *)c_start, (uintptr_t *)c_end)); - stop = ranges.end(); - } - else - { - wliter++; - } - } - else - { - wliter++; - } - } - } - } - } - void Heap::create_table() { Heap &heap = Heap::the();