diff --git a/native/gc.c b/native/gc.c index f7c079c703..c166cd934a 100644 --- a/native/gc.c +++ b/native/gc.c @@ -10,6 +10,14 @@ CELL init_zone(ZONE *z, CELL size, CELL base) return z->limit; } +/* update this global variable. since it is stored in a non-volatile register, +we need to save its contents and re-initialize it when entering a callback, +and restore its contents when leaving the callback. see stack.c */ +void update_cards_offset(void) +{ + cards_offset = (CELL)cards - (heap_start >> CARD_BITS); +} + /* input parameters must be 8 byte aligned */ /* the heap layout is important: - two semispaces: tenured and prior @@ -35,7 +43,7 @@ void init_arena(CELL gens, CELL young_size, CELL aging_size) cards = safe_malloc(cards_size); cards_end = cards + cards_size; - cards_offset = (CELL)cards - (heap_start >> CARD_BITS); + update_cards_offset(); alloter = heap_start; diff --git a/native/gc.h b/native/gc.h index a7295fc458..07482fcbdb 100644 --- a/native/gc.h +++ b/native/gc.h @@ -118,6 +118,7 @@ INLINE void* allot_object(CELL type, CELL length) return object; } +void update_cards_offset(void); CELL collect_next(CELL scan); void garbage_collection(CELL gen); void primitive_gc(void); diff --git a/native/stack.c b/native/stack.c index c453fa532e..ca3f925cad 100644 --- a/native/stack.c +++ b/native/stack.c @@ -56,9 +56,11 @@ void nest_stacks(void) new_stacks->call_region = alloc_bounded_block(cs_size); new_stacks->next = stack_chain; stack_chain = new_stacks; + callframe = F; reset_datastack(); reset_callstack(); + update_cards_offset(); } /* called when leaving a compiled callback */