From 2c76171c8a7b6fb4a502b7a8573bff4250f7d813 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 5 Apr 2008 08:27:07 -0500 Subject: [PATCH] Fix profiler crash with large heap --- vm/data_gc.c | 21 +++++++++++++++++++++ vm/data_gc.h | 2 ++ vm/factor.c | 15 +-------------- vm/profiler.c | 16 +++++++++------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/vm/data_gc.c b/vm/data_gc.c index b7bba4997e..86552d6401 100755 --- a/vm/data_gc.c +++ b/vm/data_gc.c @@ -821,3 +821,24 @@ DEFINE_PRIMITIVE(become) gc(); } + +CELL find_all_words(void) +{ + GROWABLE_ARRAY(words); + + begin_scan(); + + CELL obj; + while((obj = next_object()) != F) + { + if(type_of(obj) == WORD_TYPE) + GROWABLE_ADD(words,obj); + } + + /* End heap scan */ + gc_off = false; + + GROWABLE_TRIM(words); + + return words; +} diff --git a/vm/data_gc.h b/vm/data_gc.h index acbc38a6cb..0adcf0ca39 100755 --- a/vm/data_gc.h +++ b/vm/data_gc.h @@ -365,3 +365,5 @@ DLLEXPORT void simple_gc(void); DECLARE_PRIMITIVE(gc); DECLARE_PRIMITIVE(gc_time); DECLARE_PRIMITIVE(become); + +CELL find_all_words(void); diff --git a/vm/factor.c b/vm/factor.c index c3d85eff5e..073b3e2e34 100755 --- a/vm/factor.c +++ b/vm/factor.c @@ -38,21 +38,8 @@ void do_stage1_init(void) fprintf(stderr,"*** Stage 2 early init... "); fflush(stderr); - GROWABLE_ARRAY(words); + CELL words = find_all_words(); - begin_scan(); - - CELL obj; - while((obj = next_object()) != F) - { - if(type_of(obj) == WORD_TYPE) - GROWABLE_ADD(words,obj); - } - - /* End heap scan */ - gc_off = false; - - GROWABLE_TRIM(words); REGISTER_ROOT(words); CELL i; diff --git a/vm/profiler.c b/vm/profiler.c index 407fefaace..08bb846c85 100755 --- a/vm/profiler.c +++ b/vm/profiler.c @@ -61,17 +61,19 @@ void set_profiling(bool profiling) and allocate profiling blocks if necessary */ gc(); - /* Update word XTs and saved callstack objects */ - begin_scan(); + CELL words = find_all_words(); - CELL obj; - while((obj = next_object()) != F) + REGISTER_ROOT(words); + + CELL i; + CELL length = array_capacity(untag_object(words)); + for(i = 0; i < length; i++) { - if(type_of(obj) == WORD_TYPE) - update_word_xt(untag_object(obj)); + F_WORD *word = untag_word(array_nth(untag_array(words),i)); + update_word_xt(word); } - gc_off = false; /* end heap scan */ + UNREGISTER_ROOT(words); /* Update XTs in code heap */ iterate_code_heap(relocate_code_block);