From 8081bc5d676cab6d6f4ab75dcd10b59e72bbd2b9 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Tue, 21 Mar 2023 14:31:40 +0100 Subject: [PATCH] Minor changes Co-authored-by: ValterMiari --- src/Accurate_GC/gc.cpp | 4 +-- src/Accurate_GC/gc_printer.cpp | 4 +-- src/Accurate_GC/shadow_stack.cpp | 4 +-- src/GC/Makefile | 12 +++---- src/GC/include/event.hpp | 3 +- src/GC/include/heap.hpp | 4 ++- src/GC/lib/event.cpp | 7 +++- src/GC/lib/heap.cpp | 56 +------------------------------- src/GC/lib/profiler.cpp | 4 ++- src/GC/tests/h_test.cpp | 3 ++ src/GC/todo.md | 19 ++++++----- 11 files changed, 39 insertions(+), 81 deletions(-) diff --git a/src/Accurate_GC/gc.cpp b/src/Accurate_GC/gc.cpp index f4a8ca8..ddf8bc0 100644 --- a/src/Accurate_GC/gc.cpp +++ b/src/Accurate_GC/gc.cpp @@ -1,4 +1,4 @@ -/* // TODO: include these properly +// TODO: include these properly #include "llvm/CodeGen/GCStrategy.h" #include "llvm/CodeGen/GCMetadata.h" #include "llvm/Support/Compiler.h" @@ -13,4 +13,4 @@ namespace { GCRegistry::Add X("gc", "The bespoken garbage collector."); -} */ \ No newline at end of file +} \ No newline at end of file diff --git a/src/Accurate_GC/gc_printer.cpp b/src/Accurate_GC/gc_printer.cpp index 361244f..f392c4b 100644 --- a/src/Accurate_GC/gc_printer.cpp +++ b/src/Accurate_GC/gc_printer.cpp @@ -1,4 +1,4 @@ -/* #include "llvm/CodeGen/GCMetadataPrinter.h" +#include "llvm/CodeGen/GCMetadataPrinter.h" #include "llvm/Support/Compiler.h" using namespace llvm; @@ -13,4 +13,4 @@ namespace { GCMetadataPrinterRegistry::Add X("gc", "The bespoken garbage collector."); -} */ \ No newline at end of file +} \ No newline at end of file diff --git a/src/Accurate_GC/shadow_stack.cpp b/src/Accurate_GC/shadow_stack.cpp index 40cd4c3..2c75629 100644 --- a/src/Accurate_GC/shadow_stack.cpp +++ b/src/Accurate_GC/shadow_stack.cpp @@ -1,4 +1,4 @@ -/* /// The map for a single function's stack frame. One of these is +/// The map for a single function's stack frame. One of these is /// compiled as constant data into the executable for each function. /// /// Storage of metadata values is elided if the %metadata parameter to @@ -60,4 +60,4 @@ void traverseStackMap() { Constant *RootMetadata = RI->Metadata; } } -} */ \ No newline at end of file +} \ No newline at end of file diff --git a/src/GC/Makefile b/src/GC/Makefile index 1c82023..001d2d6 100644 --- a/src/GC/Makefile +++ b/src/GC/Makefile @@ -20,22 +20,20 @@ heap: h_test: rm -f tests/h_test.out - $(CC) $(WFLAGS) $(STDFLAGS) $(LIB_INCL) tests/h_test.cpp lib/heap.cpp lib/profiler.cpp lib/event.cpp -o tests/h_test.out +# $(CC) $(WFLAGS) $(STDFLAGS) $(LIB_INCL) tests/h_test.cpp lib/heap.cpp lib/profiler.cpp lib/event.cpp -o tests/h_test.out + $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/h_test.out tests/h_test.cpp lib/gcoll.a -h_test_vg: - make h_test +h_test_vg: h_test valgrind $(VGFLAGS) tests/h_test.out -h_test_dbg: - make h_test +h_test_dbg: h_test lldb tests/h_test.out launch linker: rm -f tests/linker.out $(CC) $(WFLAGS) $(STDFLAGS) $(LIB_INCL) tests/linker.cpp lib/heap.cpp -o tests/linker.out -linker_vg: - make linker +linker_vg: linker valgrind $(VGFLAGS) tests/linker.out game: diff --git a/src/GC/include/event.hpp b/src/GC/include/event.hpp index 89139c9..7e29c51 100644 --- a/src/GC/include/event.hpp +++ b/src/GC/include/event.hpp @@ -60,6 +60,7 @@ namespace GC GCEventType get_type(); std::time_t get_time_stamp(); Chunk *get_chunk(); - const char *const type_to_string(); + size_t get_size(); + const char *type_to_string(); }; } \ No newline at end of file diff --git a/src/GC/include/heap.hpp b/src/GC/include/heap.hpp index 1a1175d..158f756 100644 --- a/src/GC/include/heap.hpp +++ b/src/GC/include/heap.hpp @@ -11,6 +11,7 @@ #define HEAP_SIZE 65536 #define FREE_THRESH (uint)20 +#define DEBUG namespace GC { @@ -93,7 +94,7 @@ namespace GC static void dispose(); static void *alloc(size_t size); - // DEBUG ONLY +#ifdef DEBUG static inline Heap *debug_the() { if (m_instance) // if m_instance is not a nullptr @@ -106,5 +107,6 @@ namespace GC void print_contents(); // print dummy things void print_allocated_chunks(Heap *heap); // print the contents in m_allocated_chunks void set_profiler(bool mode); +#endif }; } \ No newline at end of file diff --git a/src/GC/lib/event.cpp b/src/GC/lib/event.cpp index 9fd01d7..b4a1e81 100644 --- a/src/GC/lib/event.cpp +++ b/src/GC/lib/event.cpp @@ -22,8 +22,13 @@ namespace GC { return m_chunk; } + + size_t GCEvent::get_size() + { + return m_size; + } - const char *const GCEvent::type_to_string() + const char *GCEvent::type_to_string() { switch (m_type) { diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index b37ebe8..54726be 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -27,6 +27,7 @@ namespace GC Heap *heap = Heap::the(); if (heap->profiler_enabled()) Profiler::record(HeapInit); +#pragma clang diagnostic ignored "-Wframe-address" // clang complains because arg for __b_f_a is not 0 heap->m_stack_top = static_cast(__builtin_frame_address(1)); } @@ -194,7 +195,6 @@ namespace GC { Heap *heap = Heap::the(); bool profiler_enabled = heap->profiler_enabled(); - cout << "--- mark() was called ---\n" << endl; if (profiler_enabled) Profiler::record(MarkStart); // To find adresses thats in the worklist @@ -224,7 +224,6 @@ namespace GC if (profiler_enabled) Profiler::record(ChunkMarked, chunk); chunk->marked = true; - cout << "Marked this chunk ^\n" << endl; // Remove the marked chunk from the worklist it = worklist.erase(it); // Recursively call mark, to see if the reachable chunk further points to another chunk @@ -245,55 +244,6 @@ namespace GC } } - // Testing a strategy where if a pointer on the stack is pointing to a chunk, nested chunks, - // that are not located on the stack frame, will possibly be adjecent to the found chunk, - // allowing for a different, more efficient strategy, that doesn't have to scan the stack frame - void Heap::mark_step(uintptr_t start, uintptr_t end, vector &worklist) { - - // Should loop through the chunk size, such that if the object holds a pointer, - // wherever that pointer is located in the object, that pointer, to another chunk, - // gets detected - - cout << "--- mark_step() was called ---\n" << endl; - for (; start <= end; start += sizeof(uintptr_t)) - { - auto it = worklist.begin(); - auto end = worklist.end(); - - while (it != end) - { - Chunk *chunk = *it; - auto c_start = reinterpret_cast(chunk->start); - auto c_size = reinterpret_cast(chunk->size); - auto c_end = reinterpret_cast(c_start + c_size); - - cout << "Value of Start:\t\t" << start << endl; - cout << "Chunk start:\t\t" << hex << c_start << endl; - cout << "Chunk end:\t\t" << hex << c_end << "\n" << endl; - - if (c_start <= start && start < c_end) - { - if (!chunk->marked) { - // Mark the chunk and erase it from the worklist - chunk->marked = true; - it = worklist.erase(it); - cout << "Marked this chunk ^\n" << endl; - // Update the memory location we want to look at - //memory_location = c_end; - mark_step(c_start, c_end, worklist); - } - else - { - it++; - } - } - else - { - it++; - } - } - } - } /** * Sweeps the heap, unmarks the marked chunks for the next cycle, @@ -303,9 +253,7 @@ 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(); bool profiler_enabled = heap->profiler_enabled(); // This cannot "iter != stop", results in seg fault, since the end gets updated, I think. while (iter != heap->m_allocated_chunks.end()) @@ -341,7 +289,6 @@ namespace GC */ void Heap::free(Heap *heap) { - cout << "--- free() was called ---" << endl; if (heap->m_freed_chunks.size() > FREE_THRESH) { bool profiler_enabled = heap->profiler_enabled(); @@ -352,7 +299,6 @@ namespace GC if (profiler_enabled) Profiler::record(ChunkFreed, chunk); delete chunk; - cout << "Freed chunk was deleted" << endl; } } // if there are chunks but not more than FREE_THRESH diff --git a/src/GC/lib/profiler.cpp b/src/GC/lib/profiler.cpp index 6af632d..bc19455 100644 --- a/src/GC/lib/profiler.cpp +++ b/src/GC/lib/profiler.cpp @@ -68,8 +68,10 @@ namespace GC << "\n Size: " << chunk->size << "\n Mark: " << chunk->marked; } - fstr << "\n--------------------------------" << std::endl; + // else if (event->get) + fstr << "\n"; } + fstr << "--------------------------------" << std::endl; } void Profiler::dispose() { diff --git a/src/GC/tests/h_test.cpp b/src/GC/tests/h_test.cpp index 7358bfe..28f6387 100644 --- a/src/GC/tests/h_test.cpp +++ b/src/GC/tests/h_test.cpp @@ -68,6 +68,7 @@ void test_some_types() { int main() { GC::Heap::init(); GC::Heap *gc = GC::Heap::debug_the(); + gc->set_profiler(true); gc->check_init(); auto stack_start = reinterpret_cast(__builtin_frame_address(0)); std::cout << "Stack start from main:\t" << stack_start << std::endl; @@ -96,5 +97,7 @@ int main() { gc->collect(GC::COLLECT_ALL); gc->print_contents(); + + gc->dispose(); return 0; } \ No newline at end of file diff --git a/src/GC/todo.md b/src/GC/todo.md index 30e439b..6b75170 100644 --- a/src/GC/todo.md +++ b/src/GC/todo.md @@ -1,16 +1,17 @@ # Garbage collection ## Project - -Goal for next week (24/2): -- Write more complex tests +Deliver to samuel ## GC TODO: -- Kolla linking med Valter/Victor -- Fixa en a-fil/static lib till Samuel -- Kolla vektor vs list complexity -- Se om det är bättre att lagra Chunk och inte Chunk* i data strukturerna, -då är alla efter varandra i minnet. +- Code cleanup +- Dokumentera + - Dokumentera alla filer och funktioner + - Skriva reference guide för Samuel +- PR till master ## Tests TODO -- Write complex datastructures for tests with larger programs \ No newline at end of file +- Write complex datastructures for tests with larger programs + +## Profiler grejer +- Fixa användning av `Profiler::record(GCEventType type, size_t size)` i både alloc och dump_trace \ No newline at end of file