Fixed bug in sweep and updated tests

This commit is contained in:
valtermiari 2023-03-17 11:45:32 +01:00
parent ce714db3f1
commit 78ccade17d
6 changed files with 56 additions and 32 deletions

View file

@ -185,7 +185,7 @@ namespace GC
auto it = worklist.begin();
auto stop = worklist.end();
// for (auto it = worklist.begin(); it != worklist.end();) {
while (it != stop)
while (it != stop) // while (it != stop)
{
Chunk *chunk = *it;
@ -193,10 +193,10 @@ namespace GC
auto c_size = reinterpret_cast<uintptr_t>(chunk->size);
auto c_end = reinterpret_cast<uintptr_t>(c_start + c_size);
cout << "Value of Start:\t\t" << start << endl;
/* cout << "Value of Start:\t\t" << start << endl;
cout << "Start points to:\t" << hex << *start << endl;
cout << "Chunk start:\t\t" << hex << c_start << endl;
cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl;
cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl; */
// Check if the stack pointer aligns with the chunk
if (c_start <= *start && *start < c_end)
@ -212,6 +212,7 @@ namespace GC
it = worklist.erase(it);
// Recursively call mark, to see if the reachable chunk further points to another chunk
mark((uintptr_t *)c_start, (uintptr_t *)c_end, worklist);
//mark_step(c_start, c_end, worklist);
}
else
@ -283,10 +284,11 @@ namespace GC
*/
void Heap::sweep(Heap *heap)
{
cout << "--- sweep() was called ---" << endl;
auto iter = heap->m_allocated_chunks.begin();
auto stop = heap->m_allocated_chunks.end();
// for (auto it = heap->m_allocated_chunks.begin(); it != heap->m_allocated_chunks.end();) {
while (iter != stop)
// This cannot "iter != stop", results in seg fault, since the end gets updated, I think.
while (iter != heap->m_allocated_chunks.end())
{
Chunk *chunk = *iter;
@ -318,12 +320,14 @@ namespace GC
*/
void Heap::free(Heap *heap)
{
cout << "--- free() was called ---" << endl;
if (heap->m_freed_chunks.size() > FREE_THRESH)
{
while (heap->m_freed_chunks.size())
{
auto chunk = heap->m_freed_chunks.back();
heap->m_freed_chunks.pop_back();
cout << "Freed chunk was deleted" << endl;
delete chunk;
}
}
@ -392,6 +396,8 @@ namespace GC
*/
void Heap::collect(CollectOption flags)
{
set_profiler(true);
if (getProfilerMode())
Profiler::record(CollectStart);
@ -504,4 +510,11 @@ namespace GC
auto heap = Heap::the();
heap->m_profiler_enable = mode;
}
void Heap::print_allocated_chunks(Heap *heap) {
cout << "--- Allocated Chunks ---\n" << endl;
for (auto chunk : heap->m_allocated_chunks) {
print_line(chunk);
}
}
}

View file

@ -32,7 +32,7 @@ namespace GC
auto start = profiler->m_events.begin();
auto end = profiler->m_events.end();
std::ofstream fstr = profiler->createFileStream(); // this is now found
std::ofstream fstr = profiler->createFileStream();
char buffer[22];
std::tm *btm;
std::time_t tt;
@ -42,15 +42,15 @@ namespace GC
{
auto event = *start++;
tt = event->getTimeStamp(); // this is found
tt = event->getTimeStamp();
btm = std::localtime(&tt);
std::strftime(buffer, 22, "%a %T", btm);
fstr << "--------------------------------\n"
<< buffer
<< "\nEvent:\t" << event->TypeToString(); // this is not found
<< "\nEvent:\t" << event->TypeToString();
chunk = event->getChunk(); // this is found
chunk = event->getChunk();
if (chunk) {
fstr << "\nChunk:\t" << chunk->start
@ -69,7 +69,8 @@ namespace GC
std::strftime(buffer, 32, "/profiler/log_%a_%H_%M_%S.txt", ptm);
std::string filename(buffer);
const std::string ABS_PATH = "/home/virre/dev/systemF/org/language/src/GC/";
//const std::string ABS_PATH = "/home/virre/dev/systemF/org/language/src/GC/";
const std::string ABS_PATH = "/Users/valtermiari/Desktop/DV/Bachelors/code/language/src/GC";
std::string fullpath = ABS_PATH + filename;
std::ofstream fstr(fullpath);