bugfix
This commit is contained in:
parent
b3ed111099
commit
830d863c70
1 changed files with 11 additions and 64 deletions
|
|
@ -220,7 +220,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!"));
|
||||||
|
|
@ -254,12 +254,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)
|
||||||
{
|
{
|
||||||
|
|
@ -292,25 +290,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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,63 +332,11 @@ 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Heap::mark_range(vector<AddrRange *> &ranges, vector<Chunk *> &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<uintptr_t>(chunk->m_start);
|
|
||||||
auto c_size = reinterpret_cast<uintptr_t>(chunk->m_size);
|
|
||||||
auto c_end = reinterpret_cast<uintptr_t>(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()
|
void Heap::create_table()
|
||||||
{
|
{
|
||||||
Heap &heap = Heap::the();
|
Heap &heap = Heap::the();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue