From 30c3de1ffb2daa8b2b8281bcece806793c4d4803 Mon Sep 17 00:00:00 2001 From: Jeff Sturm Date: Mon, 28 Jul 2003 04:18:23 +0000 Subject: Import GC 6.3alpha1. * BCC_MAKEFILE: Merge with GC 6.3alpha1 release. * ChangeLog: Likewise. * Makefile.am: Likewise. * Makefile.direct: Likewise. * Makefile.dj: Likewise. * allchblk.c: Likewise. * alloc.c: Likewise. * backgraph.c: Likewise. * configure.host: Likewise. * configure.in: Likewise. * dbg_mlc.c: Likewise. * dyn_load.c: Likewise. * finalize.c: Likewise. * gc_cpp.cc: Likewise. * gc_dlopen.c: Likewise. * gcj_mlc.c: Likewise. * if_mach.c: Likewise. * mach_dep.c: Likewise. * malloc.c: Likewise. * mallocx.c: Likewise. * mark.c: Likewise. * mark_rts.c: Likewise. * misc.c: Likewise. * os_dep.c: Likewise. * ptr_chck.c: Likewise. * reclaim.c: Likewise. * solaris_pthreads.c: Likewise. * solaris_threads.c: Likewise. * sparc_mach_dep.S: Likewise. * threadlibs.c: Likewise. * typd_mlc.c: Likewise. * version.h: Likewise. * win32_threads.c: Likewise. * Mac_files/MacOS_Test_config.h: Likewise. * Mac_files/MacOS_config.h: Likewise. * cord/cordbscs.c: Likewise. * cord/cordprnt.c: Likewise. * cord/de_win.c: Likewise. * doc/README: Likewise. * doc/README.MacOSX: Likewise. * doc/README.changes: Likewise. * doc/README.environment: Likewise. * doc/README.ews4800: Likewise. * doc/README.linux: Likewise. * doc/README.macros: Likewise. * doc/README.win32: Likewise. * doc/debugging.html: Likewise. * doc/gcdescr.html: Likewise. * doc/tree.html: Likewise. * include/Makefile.in: Likewise. * include/gc.h: Likewise. * include/gc_cpp.h: Likewise. * include/gc_local_alloc.h: Likewise. * include/gc_mark.h: Likewise. * include/gc_pthread_redirects.h: Likewise. * include/gc_typed.h: Likewise. * include/new_gc_alloc.h: Likewise. * include/private/dbg_mlc.h: Likewise. * include/private/gc_hdrs.h: Likewise. * include/private/gc_locks.h: Likewise. * include/private/gc_pmark.h: Likewise. * include/private/gc_priv.h: Likewise. * include/private/gcconfig.h: Likewise. * include/private/solaris_threads.h: Likewise. * include/private/specific.h: Likewise. * tests/test.c: Likewise. * tests/test_cpp.cc: Likewise. * configure: Rebuild. * Makefile.in: Rebuild. * mips_sgi_mach_dep.s: Add. * alpha_mach_dep.s: Remove. * irix_threads.c: Remove. * linux_threads.c: Remove. * mips_sgi_mach_dep.S: Remove. * missing: Remove. * powerpc_macosx_mach_dep.s: Remove. * doc/Makefile.am: Remove. * doc/Makefile.in: Remove. From-SVN: r69880 --- boehm-gc/tests/test.c | 332 +++++++++++++++++++++++++++++++++++---------- boehm-gc/tests/test_cpp.cc | 33 +++-- 2 files changed, 280 insertions(+), 85 deletions(-) (limited to 'boehm-gc/tests') diff --git a/boehm-gc/tests/test.c b/boehm-gc/tests/test.c index 7cb4d0c..cfe23c0 100644 --- a/boehm-gc/tests/test.c +++ b/boehm-gc/tests/test.c @@ -43,7 +43,7 @@ # include "gc_local_alloc.h" # endif # include "private/gc_priv.h" /* For output, locking, MIN_WORDS, */ - /* and some statistics. */ + /* and some statistics. */ # include "private/gcconfig.h" # if defined(MSWIN32) || defined(MSWINCE) @@ -68,14 +68,14 @@ # include # endif -# ifdef GC_WIN32_THREADS -# ifndef MSWINCE -# include -# define GC_CreateThread(a,b,c,d,e,f) ((HANDLE) _beginthreadex(a,b,c,d,e,f)) -# endif +# if defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS) static CRITICAL_SECTION incr_cs; # endif +#ifdef __STDC__ +# include +#endif + /* Allocation Statistics */ int stubborn_count = 0; @@ -205,40 +205,6 @@ sexpr y; } # endif -sexpr small_cons (x, y) -sexpr x; -sexpr y; -{ - register sexpr r; - - collectable_count++; - r = (sexpr) GC_MALLOC(sizeof(struct SEXPR)); - if (r == 0) { - (void)GC_printf0("Out of memory\n"); - exit(1); - } - r -> sexpr_car = x; - r -> sexpr_cdr = y; - return(r); -} - -sexpr small_cons_uncollectable (x, y) -sexpr x; -sexpr y; -{ - register sexpr r; - - uncollectable_count++; - r = (sexpr) GC_MALLOC_UNCOLLECTABLE(sizeof(struct SEXPR)); - if (r == 0) { - (void)GC_printf0("Out of memory\n"); - exit(1); - } - r -> sexpr_car = x; - r -> sexpr_cdr = (sexpr)(~(unsigned long)y); - return(r); -} - #ifdef GC_GCJ_SUPPORT #include "gc_mark.h" @@ -279,6 +245,93 @@ struct GC_ms_entry * fake_gcj_mark_proc(word * addr, return(mark_stack_ptr); } +#endif /* GC_GCJ_SUPPORT */ + +#ifdef THREAD_LOCAL_ALLOC + +#undef GC_REDIRECT_TO_LOCAL +#include "gc_local_alloc.h" + +sexpr local_cons (x, y) +sexpr x; +sexpr y; +{ + register sexpr r; + register int *p; + register int my_extra = extra_count; + static int my_random = 0; + + collectable_count++; + r = (sexpr) GC_LOCAL_MALLOC(sizeof(struct SEXPR) + my_extra); +# ifdef GC_GCJ_SUPPORT + if (collectable_count % 2 == 0) { + r = (sexpr) GC_LOCAL_GCJ_MALLOC(sizeof(struct SEXPR) + sizeof(GC_word) + my_extra, + &gcj_class_struct1); + r = (sexpr) ((GC_word *)r + 1); + } +# endif + if (r == 0) { + (void)GC_printf0("Out of memory\n"); + exit(1); + } + for (p = (int *)r; + ((char *)p) < ((char *)r) + my_extra + sizeof(struct SEXPR); p++) { + if (*p) { + (void)GC_printf1("Found nonzero at 0x%lx (local) - allocator is broken\n", + (unsigned long)p); + FAIL; + } + *p = 13; + } + r -> sexpr_car = x; + r -> sexpr_cdr = y; + my_extra++; + if ( my_extra >= 5000 || my_extra == 200 && ++my_random % 37 != 0) { + extra_count = 0; + } else { + extra_count = my_extra; + } + return(r); +} +#endif /* THREAD_LOCAL_ALLOC */ + +sexpr small_cons (x, y) +sexpr x; +sexpr y; +{ + register sexpr r; + + collectable_count++; + r = (sexpr) GC_MALLOC(sizeof(struct SEXPR)); + if (r == 0) { + (void)GC_printf0("Out of memory\n"); + exit(1); + } + r -> sexpr_car = x; + r -> sexpr_cdr = y; + return(r); +} + +sexpr small_cons_uncollectable (x, y) +sexpr x; +sexpr y; +{ + register sexpr r; + + uncollectable_count++; + r = (sexpr) GC_MALLOC_UNCOLLECTABLE(sizeof(struct SEXPR)); + if (r == 0) { + (void)GC_printf0("Out of memory\n"); + exit(1); + } + r -> sexpr_car = x; + r -> sexpr_cdr = (sexpr)(~(unsigned long)y); + return(r); +} + +#ifdef GC_GCJ_SUPPORT + + sexpr gcj_cons(x, y) sexpr x; sexpr y; @@ -323,6 +376,9 @@ sexpr x, y; sexpr reverse(x) sexpr x; { +# ifdef TEST_WITH_SYSTEM_MALLOC + malloc(100000); +# endif return( reverse1(x, nil) ); } @@ -365,6 +421,35 @@ int low, up; } #endif /* GC_GCJ_SUPPORT */ +#ifdef THREAD_LOCAL_ALLOC +/* Return reverse(x) concatenated with y */ +sexpr local_reverse1(x, y) +sexpr x, y; +{ + if (is_nil(x)) { + return(y); + } else { + return( local_reverse1(cdr(x), local_cons(car(x), y)) ); + } +} + +sexpr local_reverse(x) +sexpr x; +{ + return( local_reverse1(x, nil) ); +} + +sexpr local_ints(low, up) +int low, up; +{ + if (low > up) { + return(nil); + } else { + return(local_cons(local_cons(INT_TO_SEXPR(low), nil), local_ints(low+1, up))); + } +} +#endif /* THREAD_LOCAL_ALLOC */ + /* To check uncollectable allocation we build lists with disguised cdr */ /* pointers, and make sure they don't go away. */ sexpr uncollectable_ints(low, up) @@ -435,25 +520,24 @@ sexpr x; } } -/* Try to force a to be strangely aligned */ -struct { - char dummy; - sexpr aa; -} A; -#define a A.aa - /* * A tiny list reversal test to check thread creation. */ #ifdef THREADS -# ifdef GC_WIN32_THREADS - unsigned __stdcall tiny_reverse_test(void * arg) +# if defined(GC_WIN32_THREADS) && !defined(CYGWIN32) + DWORD __stdcall tiny_reverse_test(void * arg) # else void * tiny_reverse_test(void * arg) # endif { - check_ints(reverse(reverse(ints(1,10))), 1, 10); + int i; + for (i = 0; i < 5; ++i) { + check_ints(reverse(reverse(ints(1,10))), 1, 10); +# ifdef THREAD_LOCAL_ALLOC + check_ints(local_reverse(local_reverse(local_ints(1,10))), 1, 10); +# endif + } return 0; } @@ -477,7 +561,7 @@ struct { # elif defined(GC_WIN32_THREADS) void fork_a_thread() { - unsigned thread_id; + DWORD thread_id; HANDLE h; h = GC_CreateThread(NULL, 0, tiny_reverse_test, 0, 0, &thread_id); if (h == (HANDLE)NULL) { @@ -506,6 +590,13 @@ struct { #endif +/* Try to force a to be strangely aligned */ +struct { + char dummy; + sexpr aa; +} A; +#define a A.aa + /* * Repeatedly reverse lists built out of very different sized cons cells. * Check that we didn't lose anything. @@ -563,7 +654,9 @@ void reverse_test() h = (sexpr *)GC_REALLOC((GC_PTR)h, 2000 * sizeof(sexpr)); # ifdef GC_GCJ_SUPPORT h[1999] = gcj_ints(1,200); - h[1999] = gcj_reverse(h[1999]); + for (i = 0; i < 51; ++i) + h[1999] = gcj_reverse(h[1999]); + /* Leave it as the reveresed list for now. */ # else h[1999] = ints(1,200); # endif @@ -594,6 +687,9 @@ void reverse_test() /* 49 integers. Thus this is thread safe without locks, */ /* assuming atomic pointer assignments. */ a = reverse(reverse(a)); +# ifdef THREAD_LOCAL_ALLOC + a = local_reverse(local_reverse(a)); +# endif # if !defined(AT_END) && !defined(THREADS) /* This is not thread safe, since realloc explicitly deallocates */ if (i & 1) { @@ -621,6 +717,8 @@ void reverse_test() b = c = 0; } +#undef a + /* * The rest of this builds balanced binary trees, checks that they don't * disappear, and tests finalization. @@ -655,15 +753,17 @@ VOLATILE int dropped_something = 0; # if defined(GC_PTHREADS) static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&incr_lock); -# endif -# ifdef GC_WIN32_THREADS - EnterCriticalSection(&incr_cs); +# else +# ifdef GC_WIN32_THREADS + EnterCriticalSection(&incr_cs); +# endif # endif if ((int)(GC_word)client_data != t -> level) { (void)GC_printf0("Wrong finalization data - collector is broken\n"); FAIL; } finalized_count++; + t -> level = -1; /* detect duplicate finalization immediately */ # ifdef PCR PCR_ThCrSec_ExitSys(); # endif @@ -672,9 +772,10 @@ VOLATILE int dropped_something = 0; # endif # if defined(GC_PTHREADS) pthread_mutex_unlock(&incr_lock); -# endif -# ifdef GC_WIN32_THREADS - LeaveCriticalSection(&incr_cs); +# else +# ifdef GC_WIN32_THREADS + LeaveCriticalSection(&incr_cs); +# endif # endif } @@ -746,9 +847,10 @@ int n; # if defined(GC_PTHREADS) static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&incr_lock); -# endif -# ifdef GC_WIN32_THREADS - EnterCriticalSection(&incr_cs); +# else +# ifdef GC_WIN32_THREADS + EnterCriticalSection(&incr_cs); +# endif # endif /* Losing a count here causes erroneous report of failure. */ finalizable_count++; @@ -761,9 +863,10 @@ int n; # endif # if defined(GC_PTHREADS) pthread_mutex_unlock(&incr_lock); -# endif -# ifdef GC_WIN32_THREADS - LeaveCriticalSection(&incr_cs); +# else +# ifdef GC_WIN32_THREADS + LeaveCriticalSection(&incr_cs); +# endif # endif } @@ -1068,6 +1171,25 @@ void fail_proc1(GC_PTR x) fail_count++; } +static void uniq(void *p, ...) { + va_list a; + void *q[100]; + int n = 0, i, j; + q[n++] = p; + va_start(a,p); + for (;(q[n] = va_arg(a,void *));n++) ; + va_end(a); + for (i=0; i 4) { - max_heap_sz = 15000000; + max_heap_sz = 19000000; } else { max_heap_sz = 11000000; } @@ -1212,7 +1371,7 @@ void check_heap_stats() # ifdef SAVE_CALL_CHAIN max_heap_sz *= 3; # ifdef SAVE_CALL_COUNT - max_heap_sz *= SAVE_CALL_COUNT/4; + max_heap_sz += max_heap_sz * SAVE_CALL_COUNT/4; # endif # endif # endif @@ -1327,6 +1486,10 @@ void SetMinimumStack(long minSize) # endif n_tests = 0; +#if defined(__APPLE__) && defined(__MACH__) + GC_INIT(); +#endif + # if defined(DJGPP) /* No good way to determine stack base from library; do it */ /* manually on this platform. */ @@ -1340,13 +1503,18 @@ void SetMinimumStack(long minSize) # endif GC_INIT(); /* Only needed if gc is dynamic library. */ (void) GC_set_warn_proc(warn_proc); -# if (defined(MPROTECT_VDB) || defined(PROC_VDB)) && !defined(MAKE_BACK_GRAPH) +# if (defined(MPROTECT_VDB) || defined(PROC_VDB)) \ + && !defined(MAKE_BACK_GRAPH) GC_enable_incremental(); (void) GC_printf0("Switched to incremental mode\n"); # if defined(MPROTECT_VDB) (void)GC_printf0("Emulating dirty bits with mprotect/signals\n"); # else +# ifdef PROC_VDB (void)GC_printf0("Reading dirty bits from /proc\n"); +# else + (void)GC_printf0("Using DEFAULT_VDB dirty bit implementation\n"); +# endif # endif # endif run_one_test(); @@ -1378,9 +1546,9 @@ void SetMinimumStack(long minSize) } # endif -#ifdef GC_WIN32_THREADS +#if defined(GC_WIN32_THREADS) && !defined(CYGWIN32) -unsigned __stdcall thr_run_one_test(void *arg) +DWORD __stdcall thr_run_one_test(void *arg) { run_one_test(); return 0; @@ -1412,7 +1580,7 @@ LRESULT CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return ret; } -unsigned __stdcall thr_window(void *arg) +DWORD __stdcall thr_window(void *arg) { WNDCLASS win_class = { CS_NOCLOSE, @@ -1474,10 +1642,11 @@ int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev, LPSTR cmd, int n) # ifdef MSWINCE HANDLE win_thr_h; # endif - unsigned thread_id; + DWORD thread_id; # if 0 GC_enable_incremental(); # endif + GC_init(); InitializeCriticalSection(&incr_cs); (void) GC_set_warn_proc(warn_proc); # ifdef MSWINCE @@ -1625,15 +1794,30 @@ main() (void)GC_printf0("pthread_default_stacksize_np failed.\n"); } # endif /* GC_HPUX_THREADS */ +# if defined(__APPLE__) && defined(__MACH__) + GC_INIT(); +# endif + pthread_attr_init(&attr); -# if defined(GC_IRIX_THREADS) || defined(GC_FREEBSD_THREADS) +# if defined(GC_IRIX_THREADS) || defined(GC_FREEBSD_THREADS) \ + || defined(GC_DARWIN_THREADS) || defined(GC_AIX_THREADS) pthread_attr_setstacksize(&attr, 1000000); # endif n_tests = 0; -# if defined(MPROTECT_VDB) && !defined(PARALLEL_MARK) &&!defined(REDIRECT_MALLOC) && !defined(MAKE_BACK_GRAPH) +# if (defined(MPROTECT_VDB)) \ + && !defined(PARALLEL_MARK) &&!defined(REDIRECT_MALLOC) \ + && !defined(MAKE_BACK_GRAPH) GC_enable_incremental(); (void) GC_printf0("Switched to incremental mode\n"); - (void) GC_printf0("Emulating dirty bits with mprotect/signals\n"); +# if defined(MPROTECT_VDB) + (void)GC_printf0("Emulating dirty bits with mprotect/signals\n"); +# else +# ifdef PROC_VDB + (void)GC_printf0("Reading dirty bits from /proc\n"); +# else + (void)GC_printf0("Using DEFAULT_VDB dirty bit implementation\n"); +# endif +# endif # endif (void) GC_set_warn_proc(warn_proc); if ((code = pthread_key_create(&fl_key, 0)) != 0) { diff --git a/boehm-gc/tests/test_cpp.cc b/boehm-gc/tests/test_cpp.cc index 75fd366..7e50e8a 100644 --- a/boehm-gc/tests/test_cpp.cc +++ b/boehm-gc/tests/test_cpp.cc @@ -28,7 +28,10 @@ few minutes to complete. #include #include #include -#ifdef __GNUC__ +#define USE_STD_ALLOCATOR +#ifdef USE_STD_ALLOCATOR +# include "gc_allocator.h" +#elif __GNUC__ # include "new_gc_alloc.h" #else # include "gc_alloc.h" @@ -189,25 +192,32 @@ int APIENTRY WinMain( # endif #endif + GC_init(); + # if defined(MACOS) // MacOS char* argv_[] = {"test_cpp", "10"}; // doesn't argv = argv_; // have a argc = sizeof(argv_)/sizeof(argv_[0]); // commandline # endif int i, iters, n; -# if !defined(MACOS) +# ifdef USE_STD_ALLOCATOR + int *x = gc_allocator().allocate(1); + int **xptr = traceable_allocator().allocate(1); +# else # ifdef __GNUC__ - int *x = (int *)gc_alloc::allocate(sizeof(int)); + int *x = (int *)gc_alloc::allocate(sizeof(int)); # else - int *x = (int *)alloc::allocate(sizeof(int)); + int *x = (int *)alloc::allocate(sizeof(int)); # endif - - *x = 29; - x -= 3; +# endif + *x = 29; +# ifdef USE_STD_ALLOCATOR + *xptr = x; + x = 0; # endif if (argc != 2 || (0 >= (n = atoi( argv[ 1 ] )))) { - GC_printf0( "usage: test_cpp number-of-iterations\n" ); - exit( 1 );} + GC_printf0( "usage: test_cpp number-of-iterations\nAssuming 10 iters\n" ); + n = 10;} for (iters = 1; iters <= n; iters++) { GC_printf1( "Starting iteration %d\n", iters ); @@ -268,9 +278,10 @@ int APIENTRY WinMain( D::Test(); F::Test();} -# if !defined(__GNUC__) && !defined(MACOS) - my_assert (29 == x[3]); +# ifdef USE_STD_ALLOCATOR + x = *xptr; # endif + my_assert (29 == x[0]); GC_printf0( "The test appears to have succeeded.\n" ); return( 0 );} -- cgit v1.1