Skip to content

Commit

Permalink
When growing the heap, verify before swapping in new space
Browse files Browse the repository at this point in the history
  • Loading branch information
tekknolagi committed Jul 26, 2024
1 parent 2505cfc commit ff63e6a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ static NEVER_INLINE void heap_verify(struct gc_heap* heap) {
}
}

void collect(struct gc_heap* heap) {
#ifndef NDEBUG
heap_verify(heap);
#endif
void collect_no_verify(struct gc_heap* heap) {
flip(heap);
uintptr_t scan = heap->hp;
trace_roots(heap, visit_field);
Expand All @@ -255,12 +252,21 @@ void collect(struct gc_heap* heap) {
}
// TODO(max): If we have < 25% heap utilization, shrink the heap
#ifndef NDEBUG
heap_verify(heap);
// Zero out the rest of the heap for debugging
memset((void*)scan, 0, heap->limit - scan);
#endif
}

void collect(struct gc_heap* heap) {
#ifndef NDEBUG
heap_verify(heap);
#endif
collect_no_verify(heap);
#ifndef NDEBUG
heap_verify(heap);
#endif
}

#if defined(__builtin_expect)
#define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
Expand All @@ -274,8 +280,14 @@ void collect(struct gc_heap* heap) {
static NEVER_INLINE void heap_grow(struct gc_heap* heap) {
struct space old_space = heap->space;
struct space new_space = make_space(old_space.size * 2);
#ifndef NDEBUG
heap_verify(heap);
#endif
init_heap(heap, new_space);
collect(heap);
collect_no_verify(heap);
#ifndef NDEBUG
heap_verify(heap);
#endif
destroy_space(old_space);
}
#endif
Expand Down

0 comments on commit ff63e6a

Please sign in to comment.