Testing recursive marking with chain references.
This commit is contained in:
parent
c6463efd51
commit
bbd2650445
2 changed files with 13 additions and 11 deletions
|
|
@ -182,6 +182,7 @@ namespace GC {
|
||||||
if (!chunk->marked) {
|
if (!chunk->marked) {
|
||||||
chunk->marked = true;
|
chunk->marked = true;
|
||||||
it = worklist.erase(it);
|
it = worklist.erase(it);
|
||||||
|
mark((uintptr_t*) c_start, (uintptr_t*) c_end, worklist);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
++it;
|
++it;
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,20 @@ struct Node {
|
||||||
};
|
};
|
||||||
|
|
||||||
Node *create_chain(int depth) {
|
Node *create_chain(int depth) {
|
||||||
Node* nodes[depth];
|
std::vector<Node*> nodes;
|
||||||
if (depth > 0) {
|
if (depth > 0) {
|
||||||
Node *last_node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
Node *last_node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||||
last_node->id = depth;
|
last_node->id = depth;
|
||||||
last_node->child = nullptr;
|
last_node->child = nullptr;
|
||||||
nodes[0] = last_node;
|
nodes.push_back(last_node);
|
||||||
for (int i = 1; i < depth; i++) {
|
for (int i = 0; i < depth; i++) {
|
||||||
Node *node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
Node *node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||||
node->id = depth-i;
|
node->id = depth-i;
|
||||||
node->child = nodes[i-1];
|
node->child = nodes[i-1];
|
||||||
nodes[i] = node;
|
nodes.push_back(node);
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < nodes.size(); i++) {
|
||||||
|
std::cout << "Element at " << i << ":\t" << nodes.at(i) << std::endl;
|
||||||
}
|
}
|
||||||
return nodes[depth];
|
return nodes[depth];
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +58,6 @@ void test_some_types() {
|
||||||
std::cout << "l points to:\t\t" << l << std::endl;
|
std::cout << "l points to:\t\t" << l << std::endl;
|
||||||
detach_pointer(&l);
|
detach_pointer(&l);
|
||||||
std::cout << "l points to:\t\t" << l << std::endl;
|
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
|
// Some more dummy values of different sizes, to test stack pointer alignment
|
||||||
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
||||||
|
|
@ -80,15 +82,14 @@ int main() {
|
||||||
for (int i = 0; i < 21; i++) {
|
for (int i = 0; i < 21; i++) {
|
||||||
longs[i] = static_cast<long *>(gc->alloc(sizeof(long)));
|
longs[i] = static_cast<long *>(gc->alloc(sizeof(long)));
|
||||||
} */
|
} */
|
||||||
//Node *root;
|
|
||||||
Node *root = test_chain(3, false);
|
Node *root = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||||
|
root = test_chain(3, false);
|
||||||
std::cout << "Adress of root:\t" << &root << std::endl;
|
std::cout << "Adress of root:\t" << &root << std::endl;
|
||||||
std::cout << "Root points to:\t" << root << std::endl;
|
std::cout << "Root points to:\t" << root << std::endl;
|
||||||
// 0x7ffdd7556bd8
|
std::cout << "Root child:\t" << root->child << std::endl;
|
||||||
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
|
||||||
std::cout << "Adress of i:\t" << &i << std::endl;
|
|
||||||
|
|
||||||
gc->collect(MARK); // free misses some chunks
|
gc->collect(MARK);
|
||||||
gc->print_contents();
|
gc->print_contents();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue