Verified Commit 95e8c887 authored by Camil Staps's avatar Camil Staps 🚀

Fix after 99471786: keep the end of the current heap semispace, and use that...

Fix after 99471786: keep the end of the current heap semispace, and use that to compute the number of free words; otherwise we risk overwriting the end of the heap (this only matters for interworking, when interpret is called multiple times and the number of free words needs to be recomputed)
parent 1c66ecc7
......@@ -477,12 +477,12 @@ static void add_shared_nodes(struct interpretation_environment *ie, BC_WORD *nod
int copy_to_interpreter_or_garbage_collect(struct interpretation_environment *ie,
BC_WORD **target, BC_WORD *node) {
BC_WORD_S heap_free=ie->heap + ie->heap_size/(ie->options.in_first_semispace ? 2 : 1) - ie->hp;
BC_WORD_S heap_free=ie->hp_end-ie->hp;
int words_needed=copied_node_size (ie->program,node);
if (heap_free<words_needed) {
ie->hp=garbage_collect(ie->stack, ie->asp, ie->heap, ie->heap_size/2, &heap_free, ie->caf_list
, &ie->options, &ie->host->clean_ie->__ie_2->__ie_shared_nodes[3]
, &ie->options, ie, &ie->host->clean_ie->__ie_2->__ie_shared_nodes[3]
#ifdef DEBUG_GARBAGE_COLLECTOR
, ie->program->code, ie->program->data
#endif
......
......@@ -65,6 +65,7 @@ struct interpretation_environment *build_interpretation_environment(
ie->bsp = bsp;
ie->csp = csp;
ie->hp = hp;
ie->hp_end = hp+heap_size;
ie->caf_list[0] = 0;
ie->caf_list[1] = &ie->caf_list[1];
ie->options.in_first_semispace=1;
......
......@@ -226,7 +226,7 @@ BC_WORD *garbage_collect(BC_WORD *stack, BC_WORD *asp,
BC_WORD *heap, size_t heap_size, BC_WORD_S *heap_free,
void **cafs, struct interpretation_options *options
#ifdef LINK_CLEAN_RUNTIME
, BC_WORD **shared_nodes_of_host
, struct interpretation_environment *ie, BC_WORD **shared_nodes_of_host
#endif
#ifdef DEBUG_GARBAGE_COLLECTOR
, BC_WORD *code, BC_WORD *data
......@@ -372,6 +372,8 @@ BC_WORD *garbage_collect(BC_WORD *stack, BC_WORD *asp,
else
shared_nodes_of_host[host_nodeid]=&__Nil-1;
}
ie->hp_end=new.end;
#endif
*heap_free=new.end-new.new;
......
......@@ -7,7 +7,7 @@ BC_WORD *garbage_collect(BC_WORD *stack, BC_WORD *asp,
BC_WORD *heap, size_t heap_size, BC_WORD_S *heap_free,
void **cafs, struct interpretation_options *options
#ifdef LINK_CLEAN_RUNTIME
, BC_WORD **shared_nodes_of_host
, struct interpretation_environment *ie, BC_WORD **shared_nodes_of_host
#endif
#ifdef DEBUG_GARBAGE_COLLECTOR
, BC_WORD *code, BC_WORD *data
......
......@@ -439,7 +439,7 @@ int interpret(
#endif
heap_size /= 2; /* copying garbage collector */
#ifdef LINK_CLEAN_RUNTIME
BC_WORD_S heap_free=heap + heap_size/(ie->options.in_first_semispace ? 2 : 1) - hp;
BC_WORD_S heap_free=ie->hp_end-hp;
#else
BC_WORD_S heap_free = heap + heap_size - hp;
#endif
......@@ -545,7 +545,7 @@ eval_to_hnf_return_failure:
int old_heap_free = heap_free;
hp = garbage_collect(stack, asp, heap, heap_size, &heap_free, caf_list
#ifdef LINK_CLEAN_RUNTIME
, &ie->options, &ie->host->clean_ie->__ie_2->__ie_shared_nodes[3]
, &ie->options, ie, &ie->host->clean_ie->__ie_2->__ie_shared_nodes[3]
#else
, &options
#endif
......
......@@ -47,6 +47,7 @@ struct interpretation_environment {
BC_WORD *bsp;
BC_WORD *csp;
BC_WORD *hp;
BC_WORD *hp_end;
void *caf_list[2];
struct interpretation_options options;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment