From 9c9c29cfd07b3d1e0d858dcd8d118f1f685126f6 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sat, 3 Sep 2016 18:32:37 +0200 Subject: [PATCH 2/3] Make weak symbol GC the default. Because symbol GC is now nothing special, we can do this. The overhead of the symbol table fixup in update_symbol_tables() is neglible, and in many cases offset by the gains of not needlessly copying symbol data. This removes the -:w option, and the SYMBOLGC compile-time option no longer does anything. --- Makefile.aix | 3 -- Makefile.android | 3 -- Makefile.bsd | 3 -- Makefile.cross-linux-mingw | 3 -- Makefile.cygwin | 3 -- Makefile.haiku | 3 -- Makefile.hurd | 3 -- Makefile.ios | 3 -- Makefile.linux | 3 -- Makefile.macosx | 3 -- Makefile.mingw | 3 -- Makefile.mingw-msys | 3 -- Makefile.solaris | 3 -- NEWS | 1 + README | 9 ------ chicken.h | 6 ++-- config.make | 3 -- runtime.c | 79 ++++++++++++++++------------------------------ tests/runtests.bat | 2 +- tests/runtests.sh | 2 +- tests/symbolgc-tests.scm | 4 --- 21 files changed, 32 insertions(+), 113 deletions(-) diff --git a/Makefile.aix b/Makefile.aix index 3884dce..977e3b2 100644 --- a/Makefile.aix +++ b/Makefile.aix @@ -97,9 +97,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.android b/Makefile.android index c48b4f7..fb1edeb 100644 --- a/Makefile.android +++ b/Makefile.android @@ -91,9 +91,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.bsd b/Makefile.bsd index bf64a15..ceb0b72 100644 --- a/Makefile.bsd +++ b/Makefile.bsd @@ -97,9 +97,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.cross-linux-mingw b/Makefile.cross-linux-mingw index 6bb28be..721bea4 100644 --- a/Makefile.cross-linux-mingw +++ b/Makefile.cross-linux-mingw @@ -114,9 +114,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)rules.make diff --git a/Makefile.cygwin b/Makefile.cygwin index b4587f5..94bb814 100644 --- a/Makefile.cygwin +++ b/Makefile.cygwin @@ -111,9 +111,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.haiku b/Makefile.haiku index 11787e0..94466b4 100644 --- a/Makefile.haiku +++ b/Makefile.haiku @@ -91,9 +91,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.hurd b/Makefile.hurd index 1feb580..3d11c77 100644 --- a/Makefile.hurd +++ b/Makefile.hurd @@ -92,9 +92,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.ios b/Makefile.ios index 70a5f27..9f46064 100644 --- a/Makefile.ios +++ b/Makefile.ios @@ -95,9 +95,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.linux b/Makefile.linux index 276f9ff..2917d0d 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -99,9 +99,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.macosx b/Makefile.macosx index 13792bd..949428a 100644 --- a/Makefile.macosx +++ b/Makefile.macosx @@ -120,9 +120,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.mingw b/Makefile.mingw index f9cda73..b791f99 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -101,9 +101,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo #define C_GC_HOOKS >>$@ endif -ifdef SYMBOLGC - echo #define C_COLLECT_ALL_SYMBOLS >>$@ -endif type chicken-defaults.h >>$@ include $(SRCDIR)rules.make diff --git a/Makefile.mingw-msys b/Makefile.mingw-msys index 981b8d5..207f2bd 100644 --- a/Makefile.mingw-msys +++ b/Makefile.mingw-msys @@ -106,9 +106,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/Makefile.solaris b/Makefile.solaris index c290665..0efd46f 100644 --- a/Makefile.solaris +++ b/Makefile.solaris @@ -121,9 +121,6 @@ chicken-config.h: chicken-defaults.h ifdef GCHOOKS echo "#define C_GC_HOOKS" >>$@ endif -ifdef SYMBOLGC - echo "#define C_COLLECT_ALL_SYMBOLS" >>$@ -endif cat chicken-defaults.h >>$@ include $(SRCDIR)/rules.make diff --git a/NEWS b/NEWS index 34ec4bc..7587d59 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ flag to a bitmap, to allow for multidirectional ports. - Weak symbol GC is faster, simpler, and can now collect all unreferenced symbols instead of a maximum of 997 per major GC. + - The -:w option has been removed; symbols are now always collected. - Compiler - Fixed an off by one allocation problem in generated C code for (list ...). diff --git a/README b/README index eaf9f93..4dcaa0e 100644 --- a/README +++ b/README @@ -164,15 +164,6 @@ `chicken-status' will not be generated, as it is mostly useless unless compiled code can be loaded. - SYMBOLGC=1 - Always enable garbage collection for unused symbols in the - symbol table by default. This will result in slightly slower - garbage collection, but minimizes the amount of garbage - retained at runtime (which might be important for long - running server applications). If you don't specify this - option you can still enable symbol GC at runtime by passing - the `-:w' runtime option when running the program. - EXTRA_CHICKEN_OPTIONS=... Additional options that should be passed to `chicken' when building the system. diff --git a/chicken.h b/chicken.h index 2cd705b..a94de73 100644 --- a/chicken.h +++ b/chicken.h @@ -1765,7 +1765,6 @@ C_varextern C_TLS int C_abort_on_thread_exceptions, C_interrupts_enabled, C_disable_overflow_check, - C_enable_gcweak, C_heap_size_is_fixed, C_max_pending_finalizers, C_trace_buffer_size, @@ -2781,8 +2780,7 @@ C_inline int C_persistable_symbol(C_word x) { C_word val = C_symbol_value(x); /* Symbol is bound (and not a keyword), or has a non-empty plist */ - return (!C_enable_gcweak || /* Overrides to always true */ - (val != C_SCHEME_UNBOUND && val != x) || + return ((val != C_SCHEME_UNBOUND && val != x) || C_symbol_plist(x) != C_SCHEME_END_OF_LIST); } @@ -3422,7 +3420,7 @@ C_inline C_word C_fcall C_a_bucket(C_word **ptr, C_word head, C_word tail) { C_word *p = *ptr, *p0 = p; - *(p++) = C_enable_gcweak ? C_WEAK_BUCKET_TAG : C_BUCKET_TAG; + *(p++) = C_WEAK_BUCKET_TAG; /* Changes to strong if sym is persisted */ *(p++) = head; *(p++) = tail; *ptr = p; diff --git a/config.make b/config.make index 04d7cf1..0cfe765 100644 --- a/config.make +++ b/config.make @@ -20,9 +20,6 @@ # Build static runtime library only: #STATICBUILD=1 -# Enable GC of symbols: -#SYMBOLGC=1 - # Use alternative C compiler #C_COMPILER= diff --git a/runtime.c b/runtime.c index 14732bf..f2662d2 100644 --- a/runtime.c +++ b/runtime.c @@ -370,11 +370,6 @@ C_TLS int C_enable_repl, C_interrupts_enabled, C_disable_overflow_check, -#ifdef C_COLLECT_ALL_SYMBOLS - C_enable_gcweak = 1, -#else - C_enable_gcweak = 0, -#endif C_heap_size_is_fixed, C_trace_buffer_size = DEFAULT_TRACE_BUFFER_SIZE, C_max_pending_finalizers = C_DEFAULT_MAX_PENDING_FINALIZERS, @@ -1459,10 +1454,6 @@ void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *st gc_report_flag = 2; break; - case 'w': - C_enable_gcweak = 1; - break; - case 'P': profiling = 1; profile_frequency = arg_val(ptr); @@ -4132,59 +4123,43 @@ C_regparm void C_fcall update_symbol_tables(int mode) C_SYMBOL_TABLE *stp; assert(mode != GC_MINOR); /* Call only in major or realloc mode */ - if(C_enable_gcweak) { - /* Update symbol locations through fptrs or drop if unreferenced */ - for(stp = symbol_table_list; stp != NULL; stp = stp->next) { - for(i = 0; i < stp->size; ++i) { - last = 0; + /* Update symbol locations through fptrs or drop if unreferenced */ + for(stp = symbol_table_list; stp != NULL; stp = stp->next) { + for(i = 0; i < stp->size; ++i) { + last = 0; - for(bucket = stp->table[ i ]; bucket != C_SCHEME_END_OF_LIST; bucket = C_block_item(bucket,1)) { + for(bucket = stp->table[ i ]; bucket != C_SCHEME_END_OF_LIST; bucket = C_block_item(bucket,1)) { - sym = C_block_item(bucket, 0); - h = C_block_header(sym); + sym = C_block_item(bucket, 0); + h = C_block_header(sym); - /* Resolve any forwarding pointers */ - while(is_fptr(h)) { - sym = fptr_to_ptr(h); - h = C_block_header(sym); - } + /* Resolve any forwarding pointers */ + while(is_fptr(h)) { + sym = fptr_to_ptr(h); + h = C_block_header(sym); + } - assert((h & C_HEADER_TYPE_BITS) == C_SYMBOL_TYPE); + assert((h & C_HEADER_TYPE_BITS) == C_SYMBOL_TYPE); - /* If the symbol is unreferenced, drop it: */ - if(!C_truep(C_permanentp(sym)) && (mode == GC_REALLOC ? - !C_in_new_heapp(sym) : - !C_in_fromspacep(sym))) { + /* If the symbol is unreferenced, drop it: */ + if(!C_truep(C_permanentp(sym)) && (mode == GC_REALLOC ? + !C_in_new_heapp(sym) : + !C_in_fromspacep(sym))) { - if(last) C_set_block_item(last, 1, C_block_item(bucket,1)); - else stp->table[ i ] = C_block_item(bucket,1); + if(last) C_set_block_item(last, 1, C_block_item(bucket,1)); + else stp->table[ i ] = C_block_item(bucket,1); - assert(!C_persistable_symbol(sym)); - ++weakn; - } else { - C_set_block_item(bucket,0,sym); /* Might have moved */ - last = bucket; - } + assert(!C_persistable_symbol(sym)); + ++weakn; + } else { + C_set_block_item(bucket,0,sym); /* Might have moved */ + last = bucket; } } } - if(gc_report_flag && weakn) - C_dbg("GC", C_text("%d recoverable weakly held items found\n"), weakn); - } else { -#ifdef DEBUGBUILD - /* Sanity check: all symbols should've been marked */ - for(stp = symbol_table_list; stp != NULL; stp = stp->next) - for(i = 0; i < stp->size; ++i) - for(bucket = stp->table[ i ]; bucket != C_SCHEME_END_OF_LIST; bucket = C_block_item(bucket,1)) { - sym = C_block_item(bucket, 0); - assert(!is_fptr(C_block_header(sym)) && - (C_truep(C_permanentp(sym)) || - (mode == GC_REALLOC ? - C_in_new_heapp(sym) : - C_in_fromspacep(sym)))); - } -#endif } + if(gc_report_flag && weakn) + C_dbg("GC", C_text("%d recoverable weakly held items found\n"), weakn); } @@ -4901,7 +4876,7 @@ C_regparm C_word C_fcall C_fudge(C_word fudge_factor) return C_mk_bool(C_interrupts_enabled); case C_fix(15): /* symbol-gc enabled? */ - return C_mk_bool(C_enable_gcweak); + return C_SCHEME_TRUE; case C_fix(16): /* milliseconds (wall clock) */ panic(C_text("(##sys#fudge 16) [current wall clock milliseconds] not implemented")); diff --git a/tests/runtests.bat b/tests/runtests.bat index 00f7687..a05f206 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -480,7 +480,7 @@ for %%s in (100000 120000 200000 250000 300000 350000 400000 450000 500000) do ( echo ======================================== symbol-GC tests ... %compile% symbolgc-tests.scm if errorlevel 1 exit /b 1 -a.out -:w +a.out if errorlevel 1 exit /b 1 echo ======================================== finalizer tests ... diff --git a/tests/runtests.sh b/tests/runtests.sh index 13f4405..4f447ee 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -415,7 +415,7 @@ done echo "======================================== symbol-GC tests ..." $compile symbolgc-tests.scm -./a.out -:w +./a.out echo "======================================== finalizer tests ..." $interpret -s test-finalizers.scm diff --git a/tests/symbolgc-tests.scm b/tests/symbolgc-tests.scm index 0b45859..923ee71 100644 --- a/tests/symbolgc-tests.scm +++ b/tests/symbolgc-tests.scm @@ -1,11 +1,7 @@ ;;;; symbolgc-tests.scm -; -; - run this with the "-:w" option (use gc (chicken format)) -(assert (##sys#fudge 15) "please run this test with the `-:w' runtime option") - ;; Ensure counts are defined before creating the disposable symbols. ;; This way, this program can also be run in interpreted mode. (define *count-before* #f) -- 2.1.4