Tweaked sweeping, test with detached pointers
This commit is contained in:
parent
6cd6edb594
commit
3860d0ec4f
3 changed files with 42 additions and 33 deletions
|
|
@ -9,36 +9,42 @@ GC::Heap *gc = GC::Heap::the();
|
|||
*dst = local;
|
||||
} */
|
||||
|
||||
void create_array(size_t size) {
|
||||
int *arr = static_cast<int *>(gc->alloc(sizeof(int) * size));
|
||||
}
|
||||
|
||||
void detach_pointer(long **ptr) {
|
||||
long dummy = 10; // dummy value
|
||||
long *dummy_ptr = &dummy;
|
||||
*ptr = dummy_ptr;
|
||||
std::cout << "Dummy pointer: \t" << dummy_ptr << std::endl;
|
||||
std::cout << "Detach pointer result:\t" << ptr << std::endl;
|
||||
}
|
||||
|
||||
void init() {
|
||||
|
||||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
//auto stack_end = stack_start - 40;
|
||||
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<int *>(gc->alloc(sizeof(int) * 100));
|
||||
create_array(100);
|
||||
//arr = create_array(100);
|
||||
//std::cout << "Arr_ptr" << std::hex << arr << "\n\n\n" << std::endl;
|
||||
for (int i = 0; i < (sizeof(int) * 100); i++) {
|
||||
arr[i] = i;
|
||||
}
|
||||
for (int i = 0; i < (sizeof(int) * 20); i++) {
|
||||
gc->alloc(sizeof(int));
|
||||
}
|
||||
std::cout << "Pointer for arr:\t" << &arr << std::endl;
|
||||
long a = 20;
|
||||
long *l = static_cast<long *>(gc->alloc(sizeof(long)));
|
||||
std::cout << "Pointer for l:\t\t" << &l << std::endl;
|
||||
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
||||
std::cout << "Pointer for i:\t\t" << &i << std::endl;
|
||||
//l = &a;
|
||||
//*l = 20;
|
||||
std::cout << "l points to:\t\t" << l << std::endl;
|
||||
detach_pointer(&l);
|
||||
std::cout << "l points to:\t\t" << l << std::endl;
|
||||
// l still gets marked, which is not supposed to happen
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from main:\t" << stack_start << std::endl;
|
||||
init();
|
||||
gc->collect(MARK | SWEEP); // some bug in free (vector out of range)
|
||||
gc->collect(MARK); // some bug in free (vector out of range)
|
||||
gc->print_contents();
|
||||
//delete gc;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue