This commit is contained in:
Victor Olin 2023-05-06 10:23:09 +02:00
parent 7975b6cbe2
commit 3f42a8f16d

View file

@ -242,7 +242,7 @@ namespace GC
Profiler::record(CollectStart); Profiler::record(CollectStart);
// get current stack frame // get current stack frame
// auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(2)); stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
if (heap.m_stack_top == nullptr) if (heap.m_stack_top == nullptr)
throw std::runtime_error(std::string("Error: Heap is not initialized, read the docs!")); throw std::runtime_error(std::string("Error: Heap is not initialized, read the docs!"));
@ -276,12 +276,10 @@ namespace GC
void Heap::find_roots(uintptr_t *stack_bottom, vector<uintptr_t *> &roots) void Heap::find_roots(uintptr_t *stack_bottom, vector<uintptr_t *> &roots)
{ {
Heap &heap = Heap::the(); auto heap_bottom = reinterpret_cast<const uintptr_t>(m_heap);
auto stack_top = heap.m_stack_top; auto heap_top = reinterpret_cast<const uintptr_t>(m_heap + HEAP_SIZE);
auto heap_bottom = reinterpret_cast<const uintptr_t>(heap.m_heap);
auto heap_top = reinterpret_cast<const uintptr_t>(heap.m_heap + HEAP_SIZE);
while (stack_bottom < stack_top) while (stack_bottom < m_stack_top)
{ {
if (heap_bottom < *stack_bottom && *stack_bottom < heap_top) if (heap_bottom < *stack_bottom && *stack_bottom < heap_top)
{ {
@ -314,25 +312,26 @@ namespace GC
Profiler::record(MarkStart); Profiler::record(MarkStart);
auto iter = roots.begin(), end = roots.end(); auto iter = roots.begin(), end = roots.end();
// vector<std::pair<uintptr_t, uintptr_t>> chunk_spaces;
std::queue<std::pair<uintptr_t, uintptr_t>> chunk_spaces; std::queue<std::pair<uintptr_t, uintptr_t>> chunk_spaces;
// std::set<uintptr_t> visited_addresses;
// cout << "b4 find_chunks of roots\n";
while (iter != end) while (iter != end)
{ {
find_chunks(*iter++, chunk_spaces); find_chunks(*iter++, chunk_spaces);
} }
// cout << "b4 find_chunks of chunks\n";
while (!chunk_spaces.empty()) while (!chunk_spaces.empty())
{ {
auto range = chunk_spaces.front(); auto range = chunk_spaces.front();
chunk_spaces.pop(); chunk_spaces.pop();
auto stack_addr = reinterpret_cast<uintptr_t *>(range.first); auto addr_bottom = reinterpret_cast<uintptr_t *>(range.first);
auto addr_top = reinterpret_cast<uintptr_t *>(range.second);
find_chunks(stack_addr, chunk_spaces); while (addr_bottom < addr_top)
{
find_chunks(addr_bottom, chunk_spaces);
addr_bottom++;
}
} }
} }
@ -355,12 +354,12 @@ namespace GC
if (c_start < *stack_addr && *stack_addr < c_end) if (c_start < *stack_addr && *stack_addr < c_end)
{ {
chunk->m_marked = true; 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)); chunk_spaces.push(std::make_pair(c_start, c_end));
} }
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
void Heap::mark_range(vector<AddrRange *> &ranges, vector<Chunk *> &worklist) void Heap::mark_range(vector<AddrRange *> &ranges, vector<Chunk *> &worklist)
{ {
@ -445,6 +444,8 @@ namespace GC
>>>>>>> 74e0282 (Added Hash map marking) >>>>>>> 74e0282 (Added Hash map marking)
=======
>>>>>>> 830d863 (bugfix)
void Heap::create_table() void Heap::create_table()
{ {
Heap &heap = Heap::the(); Heap &heap = Heap::the();