diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 299fe85..3016159 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -67,7 +67,7 @@ namespace GC { // get the frame adress, whwere local variables and saved registers are located auto stack_start = reinterpret_cast(__builtin_frame_address(0)); // looking at 10 stack frames back - const uintptr_t *stack_end = (uintptr_t *)0; + const uintptr_t *stack_end = (uintptr_t *)0; // temporary // denna segfaultar om arg för __b_f_a är > 2 // reinterpret_cast(__builtin_frame_address(10)); @@ -93,8 +93,9 @@ namespace GC { cout << "DEBUG COLLECT\nFLAGS: " << flags << endl; // get the frame adress, whwere local variables and saved registers are located auto stack_start = reinterpret_cast(__builtin_frame_address(0)); + cout << "Stack start:\t" << stack_start << endl; - const uintptr_t *stack_end = (uintptr_t *)0; // dummy value + const uintptr_t *stack_end = (uintptr_t *) stack_start - 40; // dummy value // denna segfaultar om arg för __b_f_a är > 2 // reinterpret_cast(__builtin_frame_address(10)); @@ -136,9 +137,12 @@ namespace GC { // TODO: return the worklist filtered on mark = true void Heap::mark(uintptr_t *start, const uintptr_t *end, vector work_list) { - for (; start < end; start++) { // to find adresses thats in the worklist + for (; start > end; start--) { // to find adresses thats in the worklist + cout << "Value of start pointer:\t" << start << endl; for (size_t i = 0; i < work_list.size(); i++) { // fix this auto chunk = work_list.at(i); + cout << "Chunk value:\t" << chunk->start << endl; + cout << "Chunk pointer value:\t" << &chunk << endl; if (chunk->start <= start && start < chunk->start + chunk->size) { if (!chunk->marked) { chunk->marked = true; @@ -150,7 +154,30 @@ namespace GC { } } } - + +/* void mark_test(vector worklist) { + while (worklist.size() > 0) { + Chunk *ref = worklist.pop_back(); + Chunk *child = (Chunk*) *ref; + if (child != NULL && !child->marked) { + child->marked = true; + worklist.push_back(child); + mark_test(worklist); + } + } + } + + void mark_from_roots(uintptr_t *start, const uintptr_t *end) { + vector worklist; + for (;start > end; start--) { + Chunk *ref = *start; + if (ref != NULL && !ref->marked) { + ref->marked = true; + worklist.push_back(ref); + mark_test(worklist); + } + } + } */ /* Alternative marking, pseudocode mark_from_roots(): diff --git a/src/GC/tests/h_test.cpp b/src/GC/tests/h_test.cpp index f26ed55..2f605ca 100644 --- a/src/GC/tests/h_test.cpp +++ b/src/GC/tests/h_test.cpp @@ -1,27 +1,31 @@ -#include "heap.hpp" +#include "../include/heap.hpp" GC::Heap *gc = GC::Heap::the2(); void init() { - std::vector live_int_vec{1, 2, 3, 4, 5}; - std::vector dead_int_vec(1000000, 1); - int *arr = static_cast(gc->alloc(sizeof(int) * 300)); - int *a_ptr; - int a = 10; - a_ptr = &a; - auto temp1 = gc->alloc(sizeof(a_ptr)); - auto temp2 = gc->alloc(sizeof(live_int_vec)); - auto temp3 = gc->alloc(sizeof(dead_int_vec)); - // *arr, *temp1, *temp2 and *temp3 should all be on the stack - //a_ptr = nullptr; + auto stack_start = reinterpret_cast(__builtin_frame_address(0)); + auto stack_end = stack_start - 160; + std::cout << "Stack start from init:\t" << stack_start << std::endl; + std::cout << "Imaginary stack end:\t" << stack_end << std::endl; + int *arr = static_cast(gc->alloc(sizeof(int) * 300)); + for (int i = 0; i < (sizeof(int) * 300); i++) { + arr[i] = i; + } + std::cout << "First stack pointer:\t" << &arr << std::endl; + long *l = static_cast(gc->alloc(sizeof(long))); + *l = 20; + // This doesn't get allocated on our heap, but how is it viewed on valgr? + int *arr2 = new int[1000]; + for (int i = 0; i < 1000; i++) { + arr2[i] = i; + } } int main() { - //init(); - for (int i = 1; i < 10; i++) { - gc->alloc(sizeof(i)); - } + auto stack_start = reinterpret_cast(__builtin_frame_address(0)); + std::cout << "Stack start from main:\t" << stack_start << std::endl; + init(); gc->collect(MARK | SWEEP); gc->print_contents(); //delete gc; diff --git a/src/GC/tests/h_test.out.dSYM/Contents/Resources/DWARF/h_test.out b/src/GC/tests/h_test.out.dSYM/Contents/Resources/DWARF/h_test.out index af32e37..d3ad3e7 100644 Binary files a/src/GC/tests/h_test.out.dSYM/Contents/Resources/DWARF/h_test.out and b/src/GC/tests/h_test.out.dSYM/Contents/Resources/DWARF/h_test.out differ