Some tweaks in mark. Testing of chain references
This commit is contained in:
parent
12a460ae4c
commit
6fff6ef2d1
2 changed files with 76 additions and 44 deletions
|
|
@ -2,48 +2,70 @@
|
|||
|
||||
GC::Heap *gc = GC::Heap::the();
|
||||
|
||||
/* void assign(int *dst) {
|
||||
int *local = static_cast<int *>(gc->alloc(sizeof(int)));
|
||||
*local = 10;
|
||||
dst = reinterpret_cast<int **>(dst);
|
||||
*dst = local;
|
||||
} */
|
||||
struct Node {
|
||||
int id;
|
||||
Node *child;
|
||||
};
|
||||
|
||||
Node *create_chain(int depth) {
|
||||
Node* nodes[depth];
|
||||
if (depth > 0) {
|
||||
Node *last_node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||
last_node->id = depth;
|
||||
last_node->child = nullptr;
|
||||
nodes[0] = last_node;
|
||||
for (int i = 1; i < depth; i++) {
|
||||
Node *node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||
node->id = depth-i;
|
||||
node->child = nodes[i-1];
|
||||
nodes[i] = node;
|
||||
}
|
||||
return nodes[depth];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
long *dummy_ptr = nullptr;
|
||||
*ptr = dummy_ptr;
|
||||
std::cout << "Dummy pointer: \t" << dummy_ptr << std::endl;
|
||||
std::cout << "Detach pointer result:\t" << ptr << std::endl;
|
||||
}
|
||||
|
||||
void init() {
|
||||
|
||||
void test_chain(int depth, bool detach) {
|
||||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from init:\t" << stack_start << 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;
|
||||
}
|
||||
std::cout << "Pointer for arr:\t" << &arr << std::endl;
|
||||
std::cout << "Stack start from test_chain:\t" << stack_start << std::endl;
|
||||
|
||||
Node *node_chain = create_chain(depth);
|
||||
// This generates a segmentation fault (should be investigated further)
|
||||
if (detach)
|
||||
node_chain->child = nullptr;
|
||||
|
||||
}
|
||||
|
||||
void test_some_types() {
|
||||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from test_some_types:\t" << stack_start << std::endl;
|
||||
|
||||
long *l = static_cast<long *>(gc->alloc(sizeof(long)));
|
||||
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
|
||||
|
||||
// Some more dummy values of different sizes, to test stack pointer alignment
|
||||
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
||||
char *c = static_cast<char *>(gc->alloc(sizeof(int)));
|
||||
short *s = static_cast<short *>(gc->alloc(sizeof(short)));
|
||||
}
|
||||
|
||||
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();
|
||||
test_chain(10, false);
|
||||
gc->collect(MARK); // some bug in free (vector out of range)
|
||||
gc->print_contents();
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue