30c3de1ffb
* 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
306 lines
9.5 KiB
C
306 lines
9.5 KiB
C
/*
|
|
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
|
|
* Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
|
|
*
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
*
|
|
* Permission is hereby granted to use or copy this program
|
|
* for any purpose, provided the above notices are retained on all copies.
|
|
* Permission to modify the code and to distribute modified code is granted,
|
|
* provided the above notices are retained, and a notice that the code was
|
|
* modified is included with the above copyright notice.
|
|
*
|
|
*/
|
|
/* Boehm, July 31, 1995 5:02 pm PDT */
|
|
|
|
#ifdef GC_GCJ_SUPPORT
|
|
|
|
/*
|
|
* This is an allocator interface tuned for gcj (the GNU static
|
|
* java compiler).
|
|
*
|
|
* Each allocated object has a pointer in its first word to a vtable,
|
|
* which for our purposes is simply a structure describing the type of
|
|
* the object.
|
|
* This descriptor structure contains a GC marking descriptor at offset
|
|
* MARK_DESCR_OFFSET.
|
|
*
|
|
* It is hoped that this interface may also be useful for other systems,
|
|
* possibly with some tuning of the constants. But the immediate goal
|
|
* is to get better gcj performance.
|
|
*
|
|
* We assume:
|
|
* 1) We have an ANSI conforming C compiler.
|
|
* 2) Counting on explicit initialization of this interface is OK.
|
|
* 3) FASTLOCK is not a significant win.
|
|
*/
|
|
|
|
#include "private/gc_pmark.h"
|
|
#include "gc_gcj.h"
|
|
#include "private/dbg_mlc.h"
|
|
|
|
GC_bool GC_gcj_malloc_initialized = FALSE;
|
|
|
|
int GC_gcj_kind; /* Object kind for objects with descriptors */
|
|
/* in "vtable". */
|
|
int GC_gcj_debug_kind; /* The kind of objects that is always marked */
|
|
/* with a mark proc call. */
|
|
|
|
ptr_t * GC_gcjobjfreelist;
|
|
ptr_t * GC_gcjdebugobjfreelist;
|
|
|
|
/* Caller does not hold allocation lock. */
|
|
void GC_init_gcj_malloc(int mp_index, void * /* really GC_mark_proc */mp)
|
|
{
|
|
register int i;
|
|
GC_bool ignore_gcj_info;
|
|
DCL_LOCK_STATE;
|
|
|
|
GC_init(); /* In case it's not already done. */
|
|
DISABLE_SIGNALS();
|
|
LOCK();
|
|
if (GC_gcj_malloc_initialized) {
|
|
UNLOCK();
|
|
ENABLE_SIGNALS();
|
|
return;
|
|
}
|
|
GC_gcj_malloc_initialized = TRUE;
|
|
ignore_gcj_info = (0 != GETENV("GC_IGNORE_GCJ_INFO"));
|
|
# ifdef CONDPRINT
|
|
if (GC_print_stats && ignore_gcj_info) {
|
|
GC_printf0("Gcj-style type information is disabled!\n");
|
|
}
|
|
# endif
|
|
GC_mark_procs[mp_index] = (GC_mark_proc)mp;
|
|
if (mp_index >= GC_n_mark_procs) ABORT("GC_init_gcj_malloc: bad index");
|
|
/* Set up object kind gcj-style indirect descriptor. */
|
|
GC_gcjobjfreelist = (ptr_t *)
|
|
GC_INTERNAL_MALLOC((MAXOBJSZ+1)*sizeof(ptr_t), PTRFREE);
|
|
if (GC_gcjobjfreelist == 0) ABORT("Couldn't allocate GC_gcjobjfreelist");
|
|
BZERO(GC_gcjobjfreelist, (MAXOBJSZ+1)*sizeof(ptr_t));
|
|
GC_gcj_kind = GC_n_kinds++;
|
|
GC_obj_kinds[GC_gcj_kind].ok_freelist = GC_gcjobjfreelist;
|
|
GC_obj_kinds[GC_gcj_kind].ok_reclaim_list = 0;
|
|
if (ignore_gcj_info) {
|
|
/* Use a simple length-based descriptor, thus forcing a fully */
|
|
/* conservative scan. */
|
|
GC_obj_kinds[GC_gcj_kind].ok_descriptor = (0 | GC_DS_LENGTH);
|
|
GC_obj_kinds[GC_gcj_kind].ok_relocate_descr = TRUE;
|
|
} else {
|
|
GC_obj_kinds[GC_gcj_kind].ok_descriptor =
|
|
(((word)(-MARK_DESCR_OFFSET - GC_INDIR_PER_OBJ_BIAS))
|
|
| GC_DS_PER_OBJECT);
|
|
GC_obj_kinds[GC_gcj_kind].ok_relocate_descr = FALSE;
|
|
}
|
|
GC_obj_kinds[GC_gcj_kind].ok_init = TRUE;
|
|
/* Set up object kind for objects that require mark proc call. */
|
|
GC_gcjdebugobjfreelist = (ptr_t *)
|
|
GC_INTERNAL_MALLOC((MAXOBJSZ+1)*sizeof(ptr_t), PTRFREE);
|
|
if (GC_gcjdebugobjfreelist == 0)
|
|
ABORT("Couldn't allocate GC_gcjdebugobjfreelist");
|
|
BZERO(GC_gcjdebugobjfreelist, (MAXOBJSZ+1)*sizeof(ptr_t));
|
|
GC_gcj_debug_kind = GC_n_kinds++;
|
|
GC_obj_kinds[GC_gcj_debug_kind].ok_freelist = GC_gcjdebugobjfreelist;
|
|
GC_obj_kinds[GC_gcj_debug_kind].ok_reclaim_list = 0;
|
|
if (ignore_gcj_info) {
|
|
GC_obj_kinds[GC_gcj_kind].ok_descriptor = (0 | GC_DS_LENGTH);
|
|
GC_obj_kinds[GC_gcj_kind].ok_relocate_descr = TRUE;
|
|
} else {
|
|
GC_obj_kinds[GC_gcj_debug_kind].ok_descriptor =
|
|
GC_MAKE_PROC(mp_index, 1 /* allocated with debug info */);
|
|
GC_obj_kinds[GC_gcj_debug_kind].ok_relocate_descr = FALSE;
|
|
}
|
|
GC_obj_kinds[GC_gcj_debug_kind].ok_init = TRUE;
|
|
UNLOCK();
|
|
ENABLE_SIGNALS();
|
|
}
|
|
|
|
ptr_t GC_clear_stack();
|
|
|
|
#define GENERAL_MALLOC(lb,k) \
|
|
(GC_PTR)GC_clear_stack(GC_generic_malloc_inner((word)lb, k))
|
|
|
|
#define GENERAL_MALLOC_IOP(lb,k) \
|
|
(GC_PTR)GC_clear_stack(GC_generic_malloc_inner_ignore_off_page(lb, k))
|
|
|
|
/* Allocate an object, clear it, and store the pointer to the */
|
|
/* type structure (vtable in gcj). */
|
|
/* This adds a byte at the end of the object if GC_malloc would.*/
|
|
void * GC_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr)
|
|
{
|
|
register ptr_t op;
|
|
register ptr_t * opp;
|
|
register word lw;
|
|
DCL_LOCK_STATE;
|
|
|
|
if( EXPECT(SMALL_OBJ(lb), 1) ) {
|
|
# ifdef MERGE_SIZES
|
|
lw = GC_size_map[lb];
|
|
# else
|
|
lw = ALIGNED_WORDS(lb);
|
|
# endif
|
|
opp = &(GC_gcjobjfreelist[lw]);
|
|
LOCK();
|
|
op = *opp;
|
|
if( EXPECT(op == 0, 0)) {
|
|
op = (ptr_t)GENERAL_MALLOC((word)lb, GC_gcj_kind);
|
|
if (0 == op) {
|
|
UNLOCK();
|
|
return(GC_oom_fn(lb));
|
|
}
|
|
# ifdef MERGE_SIZES
|
|
lw = GC_size_map[lb]; /* May have been uninitialized. */
|
|
# endif
|
|
} else {
|
|
*opp = obj_link(op);
|
|
GC_words_allocd += lw;
|
|
}
|
|
*(void **)op = ptr_to_struct_containing_descr;
|
|
GC_ASSERT(((void **)op)[1] == 0);
|
|
UNLOCK();
|
|
} else {
|
|
LOCK();
|
|
op = (ptr_t)GENERAL_MALLOC((word)lb, GC_gcj_kind);
|
|
if (0 == op) {
|
|
UNLOCK();
|
|
return(GC_oom_fn(lb));
|
|
}
|
|
*(void **)op = ptr_to_struct_containing_descr;
|
|
UNLOCK();
|
|
}
|
|
return((GC_PTR) op);
|
|
}
|
|
|
|
/* Similar to GC_gcj_malloc, but add debug info. This is allocated */
|
|
/* with GC_gcj_debug_kind. */
|
|
GC_PTR GC_debug_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr,
|
|
GC_EXTRA_PARAMS)
|
|
{
|
|
GC_PTR result;
|
|
|
|
/* We clone the code from GC_debug_gcj_malloc, so that we */
|
|
/* dont end up with extra frames on the stack, which could */
|
|
/* confuse the backtrace. */
|
|
LOCK();
|
|
result = GC_generic_malloc_inner(lb + DEBUG_BYTES, GC_gcj_debug_kind);
|
|
if (result == 0) {
|
|
UNLOCK();
|
|
GC_err_printf2("GC_debug_gcj_malloc(%ld, 0x%lx) returning NIL (",
|
|
(unsigned long) lb,
|
|
(unsigned long) ptr_to_struct_containing_descr);
|
|
GC_err_puts(s);
|
|
GC_err_printf1(":%ld)\n", (unsigned long)i);
|
|
return(GC_oom_fn(lb));
|
|
}
|
|
*((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
|
|
UNLOCK();
|
|
if (!GC_debugging_started) {
|
|
GC_start_debugging();
|
|
}
|
|
ADD_CALL_CHAIN(result, ra);
|
|
return (GC_store_debug_info(result, (word)lb, s, (word)i));
|
|
}
|
|
|
|
/* Similar to GC_gcj_malloc, but the size is in words, and we don't */
|
|
/* adjust it. The size is assumed to be such that it can be */
|
|
/* allocated as a small object. */
|
|
void * GC_gcj_fast_malloc(size_t lw, void * ptr_to_struct_containing_descr)
|
|
{
|
|
ptr_t op;
|
|
ptr_t * opp;
|
|
DCL_LOCK_STATE;
|
|
|
|
opp = &(GC_gcjobjfreelist[lw]);
|
|
LOCK();
|
|
op = *opp;
|
|
if( EXPECT(op == 0, 0) ) {
|
|
op = (ptr_t)GC_clear_stack(
|
|
GC_generic_malloc_words_small_inner(lw, GC_gcj_kind));
|
|
if (0 == op) {
|
|
UNLOCK();
|
|
return GC_oom_fn(WORDS_TO_BYTES(lw));
|
|
}
|
|
} else {
|
|
*opp = obj_link(op);
|
|
GC_words_allocd += lw;
|
|
}
|
|
*(void **)op = ptr_to_struct_containing_descr;
|
|
UNLOCK();
|
|
return((GC_PTR) op);
|
|
}
|
|
|
|
/* And a debugging version of the above: */
|
|
void * GC_debug_gcj_fast_malloc(size_t lw,
|
|
void * ptr_to_struct_containing_descr,
|
|
GC_EXTRA_PARAMS)
|
|
{
|
|
GC_PTR result;
|
|
size_t lb = WORDS_TO_BYTES(lw);
|
|
|
|
/* We clone the code from GC_debug_gcj_malloc, so that we */
|
|
/* dont end up with extra frames on the stack, which could */
|
|
/* confuse the backtrace. */
|
|
LOCK();
|
|
result = GC_generic_malloc_inner(lb + DEBUG_BYTES, GC_gcj_debug_kind);
|
|
if (result == 0) {
|
|
UNLOCK();
|
|
GC_err_printf2("GC_debug_gcj_fast_malloc(%ld, 0x%lx) returning NIL (",
|
|
(unsigned long) lw,
|
|
(unsigned long) ptr_to_struct_containing_descr);
|
|
GC_err_puts(s);
|
|
GC_err_printf1(":%ld)\n", (unsigned long)i);
|
|
return GC_oom_fn(WORDS_TO_BYTES(lw));
|
|
}
|
|
*((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
|
|
UNLOCK();
|
|
if (!GC_debugging_started) {
|
|
GC_start_debugging();
|
|
}
|
|
ADD_CALL_CHAIN(result, ra);
|
|
return (GC_store_debug_info(result, (word)lb, s, (word)i));
|
|
}
|
|
|
|
void * GC_gcj_malloc_ignore_off_page(size_t lb,
|
|
void * ptr_to_struct_containing_descr)
|
|
{
|
|
register ptr_t op;
|
|
register ptr_t * opp;
|
|
register word lw;
|
|
DCL_LOCK_STATE;
|
|
|
|
if( SMALL_OBJ(lb) ) {
|
|
# ifdef MERGE_SIZES
|
|
lw = GC_size_map[lb];
|
|
# else
|
|
lw = ALIGNED_WORDS(lb);
|
|
# endif
|
|
opp = &(GC_gcjobjfreelist[lw]);
|
|
LOCK();
|
|
if( (op = *opp) == 0 ) {
|
|
op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_gcj_kind);
|
|
# ifdef MERGE_SIZES
|
|
lw = GC_size_map[lb]; /* May have been uninitialized. */
|
|
# endif
|
|
} else {
|
|
*opp = obj_link(op);
|
|
GC_words_allocd += lw;
|
|
}
|
|
*(void **)op = ptr_to_struct_containing_descr;
|
|
UNLOCK();
|
|
} else {
|
|
op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_gcj_kind);
|
|
if (0 != op) {
|
|
*(void **)op = ptr_to_struct_containing_descr;
|
|
}
|
|
UNLOCK();
|
|
}
|
|
return((GC_PTR) op);
|
|
}
|
|
|
|
#else
|
|
|
|
char GC_no_gcj_support;
|
|
|
|
#endif /* GC_GCJ_SUPPORT */
|