static void mark() { for (int i = 0; i < num_roots; i++) { if (DEBUG) printf("root[%d]=%p\n", i, _roots[i]); heap_object *p = *_roots[i]; if (p != NULL) { if (ptr_is_in_heap(p)) { mark_object(p); } } else if ( DEBUG ) { if (DEBUG) printf("root[%d]=%p -> %p INVALID\n", i, _roots[i], p); } } }
/* Walk all roots and traverse object graph. Mark all p->mark=true for reachable p. */ void gc_mark() { if (DEBUG) printf("MARK\n"); for (int i = 0; i < num_roots; i++) { heap_object *p = *_roots[i]; if ( p != NULL ) { if ( ptr_is_in_heap(p) ) { if (DEBUG) printf("root[%d]=%p -> %s@%p (0x%x bytes)\n", i, _roots[i], p->metadata->name, p, p->size); mark_object(p); } else if ( DEBUG ) { if (DEBUG) printf("root[%d]=%p -> %p INVALID\n", i, _roots[i], p); } } } }