From: Björn Lindqvist Date: Thu, 20 Nov 2014 22:30:43 +0000 (+0100) Subject: VM: each_object() can't iterate the nursery so instead we assume it's empty X-Git-Tag: unmaintained~3288 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=2a5e1e06f3f0c7527ad290db6a63f4559e7fcc8c VM: each_object() can't iterate the nursery so instead we assume it's empty --- diff --git a/core/memory/memory-tests.factor b/core/memory/memory-tests.factor index 74e002faa9..c7ec6ee8d6 100644 --- a/core/memory/memory-tests.factor +++ b/core/memory/memory-tests.factor @@ -13,6 +13,25 @@ IN: memory.tests ! Tests for 'become' [ ] [ { } { } become ] unit-test +! Become something when it's on the data stack. +{ "replacer" } [ + "original" dup 1array { "replacer" } become +] unit-test + +! Nested in aging +{ "replacer" } [ + "original" [ 5 [ 1array ] times ] [ 1array ] bi + minor-gc + { "replacer" } become 5 [ first ] times +] unit-test + +! Also when it is nested in nursery +{ "replacer" } [ + minor-gc + "original" [ 5 [ 1array ] times ] [ 1array ] bi { "replacer" } become + 5 [ first ] times +] unit-test + ! Bug found on Windows build box, having too many words in the ! image breaks 'become' [ ] [ 100000 [ f ] replicate { } { } become drop ] unit-test @@ -45,12 +64,12 @@ SYMBOL: foo gc data-room tenured>> size>> - + 10 [ 4 [ 120 1024 * f ] replicate foo set-global 100 [ 256 1024 * f drop ] times ] times - + data-room tenured>> size>> assert= ] unit-test diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 89d1c4c8d0..fe49761011 100644 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -149,6 +149,7 @@ struct object_accumulator { /* Allocates memory */ cell factor_vm::instances(cell type) { + primitive_full_gc(); object_accumulator accum(type); each_object(accum); return std_vector_to_array(accum.objects); @@ -156,7 +157,6 @@ cell factor_vm::instances(cell type) { /* Allocates memory */ void factor_vm::primitive_all_instances() { - primitive_full_gc(); ctx->push(instances(TYPE_COUNT)); } diff --git a/vm/objects.cpp b/vm/objects.cpp index 587f4592cb..6d97ab7199 100644 --- a/vm/objects.cpp +++ b/vm/objects.cpp @@ -122,6 +122,7 @@ struct code_block_write_barrier_visitor { /* classes.tuple uses this to reshape tuples; tools.deploy.shaker uses this to coalesce equal but distinct quotations and wrappers. */ void factor_vm::primitive_become() { + primitive_minor_gc(); array* new_objects = untag_check(ctx->pop()); array* old_objects = untag_check(ctx->pop()); diff --git a/vm/vm.hpp b/vm/vm.hpp index 87a8c878e2..d17a0e9bad 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -327,12 +327,15 @@ struct factor_vm { } template inline void each_object(Iterator& iterator) { - gc_off = true; + /* The nursery can't be iterated because there may be gaps between + the objects (see factor_vm::reallot_array) so we require it to + be empty first. */ + FACTOR_ASSERT(nursery.occupied_space() == 0); + + gc_off = true; each_object(data->tenured, iterator); each_object(data->aging, iterator); - each_object(data->nursery, iterator); - gc_off = false; }