X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libjava%2Fboehm.cc;h=be2855aef72b9b410054bb608c6d1a76682fedcc;hb=aa92b578d78c555a5574638d154fcb90b5e57123;hp=bec0b6fc91f725dae260d51ca0687d7c9144bfc3;hpb=f4673084b9af89fead20326078f04dfb24521dab;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/boehm.cc b/libjava/boehm.cc index bec0b6fc91f..be2855aef72 100644 --- a/libjava/boehm.cc +++ b/libjava/boehm.cc @@ -1,6 +1,6 @@ // boehm.cc - interface between libjava and Boehm GC. -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation This file is part of libgcj. @@ -26,41 +26,22 @@ details. */ extern "C" { -#include #include #include +#ifdef THREAD_LOCAL_ALLOC +# define GC_REDIRECT_TO_LOCAL +# include +#endif + // These aren't declared in any Boehm GC header. void GC_finalize_all (void); ptr_t GC_debug_generic_malloc (size_t size, int k, GC_EXTRA_PARAMS); }; -// FIXME: this should probably be defined in some GC header. -#ifdef GC_DEBUG -# define GC_GENERIC_MALLOC(Size, Type) \ - GC_debug_generic_malloc (Size, Type, GC_EXTRAS) -#else -# define GC_GENERIC_MALLOC(Size, Type) GC_generic_malloc (Size, Type) -#endif - // We must check for plausibility ourselves. #define MAYBE_MARK(Obj, Top, Limit, Source, Exit) \ - if ((ptr_t) (Obj) >= GC_least_plausible_heap_addr \ - && (ptr_t) (Obj) <= GC_greatest_plausible_heap_addr) \ - PUSH_CONTENTS (Obj, Top, Limit, Source, Exit) - - - -// Nonzero if this module has been initialized. -static int initialized = 0; - -#if 0 -// `kind' index used when allocating Java objects. -static int obj_kind_x; - -// Freelist used for Java objects. -static ptr_t *obj_free_list; -#endif /* 0 */ + Top=GC_MARK_AND_PUSH((GC_PTR)Obj, Top, Limit, (GC_PTR *)Source) // `kind' index used when allocating Java arrays. static int array_kind_x; @@ -97,10 +78,13 @@ _Jv_MarkObj (void *addr, void *msp, void *msl, void * /* env */) if (__builtin_expect (! dt || !(dt -> get_finalizer()), false)) return mark_stack_ptr; jclass klass = dt->clas; + ptr_t p; - // Every object has a sync_info pointer. - ptr_t p = (ptr_t) obj->sync_info; - MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj, o1label); +# ifndef JV_HASH_SYNCHRONIZATION + // Every object has a sync_info pointer. + p = (ptr_t) obj->sync_info; + MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj, o1label); +# endif // Mark the object's class. p = (ptr_t) klass; MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj, o2label); @@ -300,13 +284,16 @@ _Jv_MarkArray (void *addr, void *msp, void *msl, void * /*env*/) if (__builtin_expect (! dt || !(dt -> get_finalizer()), false)) return mark_stack_ptr; jclass klass = dt->clas; + ptr_t p; - // Every object has a sync_info pointer. - ptr_t p = (ptr_t) array->sync_info; - MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, array, e1label); +# ifndef JV_HASH_SYNCHRONIZATION + // Every object has a sync_info pointer. + p = (ptr_t) array->sync_info; + MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, array, e1label); +# endif // Mark the object's class. p = (ptr_t) klass; - MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, obj, o2label); + MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, &(dt -> clas), o2label); for (int i = 0; i < JvGetArrayLength (array); ++i) { @@ -318,26 +305,30 @@ _Jv_MarkArray (void *addr, void *msp, void *msl, void * /*env*/) return mark_stack_ptr; } -// Return GC descriptor for interpreted class -#ifdef INTERPRETER - +// Generate a GC marking descriptor for a class. +// // We assume that the gcj mark proc has index 0. This is a dubious assumption, // since another one could be registered first. But the compiler also // knows this, so in that case everything else will break, too. #define GCJ_DEFAULT_DESCR GC_MAKE_PROC(GC_GCJ_RESERVED_MARK_PROC_INDEX,0) void * -_Jv_BuildGCDescr(jclass klass) +_Jv_BuildGCDescr(jclass) { /* FIXME: We should really look at the class and build the descriptor. */ return (void *)(GCJ_DEFAULT_DESCR); } -#endif -// Allocate space for a new Java object. +// Allocate some space that is known to be pointer-free. void * -_Jv_AllocObj (jsize size, jclass klass) +_Jv_AllocBytes (jsize size) { - return GC_GCJ_MALLOC (size, klass->vtable); + void *r = GC_MALLOC_ATOMIC (size); + // We have to explicitly zero memory here, as the GC doesn't + // guarantee that PTRFREE allocations are zeroed. Note that we + // don't have to do this for other allocation types because we set + // the `ok_init' flag in the type descriptor. + memset (r, 0, size); + return r; } // Allocate space for a new Java array. @@ -362,24 +353,18 @@ _Jv_AllocArray (jsize size, jclass klass) if (size < min_heap_addr) obj = GC_MALLOC(size); else - obj = GC_GENERIC_MALLOC (size, array_kind_x); + obj = GC_generic_malloc (size, array_kind_x); #endif *((_Jv_VTable **) obj) = klass->vtable; return obj; } -// Allocate some space that is known to be pointer-free. +/* Allocate space for a new non-Java object, which does not have the usual + Java object header but may contain pointers to other GC'ed objects. */ void * -_Jv_AllocBytes (jsize size) +_Jv_AllocRawObj (jsize size) { - void *r = GC_MALLOC_ATOMIC (size); - // We have to explicitly zero memory here, as the GC doesn't - // guarantee that PTRFREE allocations are zeroed. Note that we - // don't have to do this for other allocation types because we set - // the `ok_init' flag in the type descriptor. - if (__builtin_expect (r != NULL, !NULL)) - memset (r, 0, size); - return r; + return (void *) GC_MALLOC (size); } static void @@ -462,29 +447,27 @@ _Jv_EnableGC (void) _Jv_MutexUnlock (&disable_gc_mutex); } +static void * handle_out_of_memory(size_t) +{ + _Jv_ThrowNoMemory(); +} + void _Jv_InitGC (void) { int proc; - DCL_LOCK_STATE; - DISABLE_SIGNALS (); - LOCK (); - - if (initialized) - { - UNLOCK (); - ENABLE_SIGNALS (); - return; - } - initialized = 1; - UNLOCK (); + // Ignore pointers that do not point to the start of an object. + GC_all_interior_pointers = 0; // Configure the collector to use the bitmap marking descriptors that we // stash in the class vtable. GC_init_gcj_malloc (0, (void *) _Jv_MarkObj); - LOCK (); + // Cause an out of memory error to be thrown from the allocators, + // instead of returning 0. This is cheaper than checking on allocation. + GC_oom_fn = handle_out_of_memory; + GC_java_finalization = 1; // We use a different mark procedure for object arrays. This code @@ -506,67 +489,64 @@ _Jv_InitGC (void) GC_obj_kinds[array_kind_x].ok_init = TRUE; _Jv_MutexInit (&disable_gc_mutex); - - UNLOCK (); - ENABLE_SIGNALS (); } -#if 0 -void -_Jv_InitGC (void) -{ - int proc; - DCL_LOCK_STATE; - - DISABLE_SIGNALS (); - LOCK (); - - if (initialized) - { - UNLOCK (); - ENABLE_SIGNALS (); - return; - } - initialized = 1; - - GC_java_finalization = 1; +#ifdef JV_HASH_SYNCHRONIZATION +// Allocate an object with a fake vtable pointer, which causes only +// the first field (beyond the fake vtable pointer) to be traced. +// Eventually this should probably be generalized. + +static _Jv_VTable trace_one_vtable = { + 0, // class pointer + (void *)(2 * sizeof(void *)), + // descriptor; scan 2 words incl. vtable ptr. + // Least significant bits must be zero to + // identify this as a length descriptor + {0} // First method +}; - // Set up state for marking and allocation of Java objects. - obj_free_list = (ptr_t *) GC_generic_malloc_inner ((MAXOBJSZ + 1) - * sizeof (ptr_t), - PTRFREE); - memset (obj_free_list, 0, (MAXOBJSZ + 1) * sizeof (ptr_t)); +void * +_Jv_AllocTraceOne (jsize size /* includes vtable slot */) +{ + return GC_GCJ_MALLOC (size, &trace_one_vtable); +} - proc = GC_n_mark_procs++; - GC_mark_procs[proc] = (GC_mark_proc) _Jv_MarkObj; +// Ditto for two words. +// the first field (beyond the fake vtable pointer) to be traced. +// Eventually this should probably be generalized. - obj_kind_x = GC_n_kinds++; - GC_obj_kinds[obj_kind_x].ok_freelist = obj_free_list; - GC_obj_kinds[obj_kind_x].ok_reclaim_list = 0; - GC_obj_kinds[obj_kind_x].ok_descriptor = GC_MAKE_PROC (proc, 0); - GC_obj_kinds[obj_kind_x].ok_relocate_descr = FALSE; - GC_obj_kinds[obj_kind_x].ok_init = TRUE; +static _Jv_VTable trace_two_vtable = +{ + 0, // class pointer + (void *)(3 * sizeof(void *)), + // descriptor; scan 3 words incl. vtable ptr. + {0} // First method +}; - // Set up state for marking and allocation of arrays of Java - // objects. - array_free_list = (ptr_t *) GC_generic_malloc_inner ((MAXOBJSZ + 1) - * sizeof (ptr_t), - PTRFREE); - memset (array_free_list, 0, (MAXOBJSZ + 1) * sizeof (ptr_t)); +void * +_Jv_AllocTraceTwo (jsize size /* includes vtable slot */) +{ + return GC_GCJ_MALLOC (size, &trace_two_vtable); +} - proc = GC_n_mark_procs++; - GC_mark_procs[proc] = (GC_mark_proc) _Jv_MarkArray; +#endif /* JV_HASH_SYNCHRONIZATION */ - array_kind_x = GC_n_kinds++; - GC_obj_kinds[array_kind_x].ok_freelist = array_free_list; - GC_obj_kinds[array_kind_x].ok_reclaim_list = 0; - GC_obj_kinds[array_kind_x].ok_descriptor = GC_MAKE_PROC (proc, 0); - GC_obj_kinds[array_kind_x].ok_relocate_descr = FALSE; - GC_obj_kinds[array_kind_x].ok_init = TRUE; +void +_Jv_GCInitializeFinalizers (void (*notifier) (void)) +{ + GC_finalize_on_demand = 1; + GC_finalizer_notifier = notifier; +} - _Jv_MutexInit (&disable_gc_mutex); +void +_Jv_GCRegisterDisappearingLink (jobject *objp) +{ + GC_general_register_disappearing_link ((GC_PTR *) objp, (GC_PTR) *objp); +} - UNLOCK (); - ENABLE_SIGNALS (); +jboolean +_Jv_GCCanReclaimSoftReference (jobject) +{ + // For now, always reclaim soft references. FIXME. + return true; } -#endif /* 0 */