Updates from 0.2.1 into 0.2.1-inu-1.5

This commit is contained in:
Akinori Ito
2001-11-09 04:59:17 +00:00
parent 68a07bf03b
commit 6c63633545
246 changed files with 32763 additions and 21814 deletions
+1 -1
View File
@@ -41,7 +41,7 @@
* This interface is fairly big, largely for performance reasons.
* The most basic constants and functions:
*
* CORD - the type fo a cord;
* CORD - the type of a cord;
* CORD_EMPTY - empty cord;
* CORD_len(cord) - length of a cord;
* CORD_cat(cord1,cord2) - concatenation of two cords;
+236 -78
View File
@@ -1,7 +1,8 @@
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright 1996 by Silicon Graphics. All rights reserved.
* Copyright 1996-1999 by Silicon Graphics. All rights reserved.
* Copyright 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.
@@ -28,14 +29,58 @@
#ifndef _GC_H
# define _GC_H
# define __GC
# include <stddef.h>
#if defined(__CYGWIN32__) && defined(GC_USE_DLL)
#include "libgc_globals.h"
#if defined(_SOLARIS_PTHREADS) && !defined(SOLARIS_THREADS)
# define SOLARIS_THREADS
#endif
#if defined(_MSC_VER) && defined(_DLL)
/*
* Some tests for old macros. These violate our namespace rules and will
* disappear shortly.
*/
#if defined(SOLARIS_THREADS) || defined(_SOLARIS_THREADS)
# define GC_SOLARIS_THREADS
#endif
#if defined(_SOLARIS_PTHREADS)
# define GC_SOLARIS_PTHREADS
#endif
#if defined(IRIX_THREADS)
# define GC_IRIX_THREADS
#endif
#if defined(HPUX_THREADS)
# define GC_HPUX_THREADS
#endif
#if defined(OSF1_THREADS)
# define GC_OSF1_THREADS
#endif
#if defined(LINUX_THREADS)
# define GC_LINUX_THREADS
#endif
#if defined(WIN32_THREADS)
# define GC_WIN32_THREADS
#endif
#if defined(USE_LD_WRAP)
# define GC_USE_LD_WRAP
#endif
#if !defined(_REENTRANT) && (defined(GC_SOLARIS_THREADS) \
|| defined(GC_SOLARIS_PTHREADS) \
|| defined(GC_HPUX_THREADS) \
|| defined(GC_LINUX_THREADS))
# define _REENTRANT
/* Better late than never. This fails if system headers that */
/* depend on this were previously included. */
#endif
# define __GC
# include <stddef.h>
# ifdef _WIN32_WCE
/* Yet more kluges for WinCE */
# include <stdlib.h> /* size_t is defined here */
typedef long ptrdiff_t; /* ptrdiff_t is not defined */
# endif
#if defined(__MINGW32__) && defined(WIN32_THREADS)
# ifdef GC_BUILD
# define GC_API __declspec(dllexport)
# else
@@ -43,6 +88,16 @@
# endif
#endif
#if (defined(__DMC__) || defined(_MSC_VER)) \
&& (defined(_DLL) && !defined(GC_NOT_DLL) \
|| defined(GC_DLL))
# ifdef GC_BUILD
# define GC_API extern __declspec(dllexport)
# else
# define GC_API __declspec(dllimport)
# endif
#endif
#if defined(__WATCOMC__) && defined(GC_DLL)
# ifdef GC_BUILD
# define GC_API extern __declspec(dllexport)
@@ -58,9 +113,11 @@
# if defined(__STDC__) || defined(__cplusplus)
# define GC_PROTO(args) args
typedef void * GC_PTR;
# define GC_CONST const
# else
# define GC_PROTO(args) ()
typedef char * GC_PTR;
# define GC_CONST
# endif
# ifdef __cplusplus
@@ -83,6 +140,16 @@ typedef long GC_signed_word;
GC_API GC_word GC_gc_no;/* Counter incremented per collection. */
/* Includes empty GCs at startup. */
GC_API int GC_parallel; /* GC is parallelized for performance on */
/* multiprocessors. Currently set only */
/* implicitly if collector is built with */
/* -DPARALLEL_MARK and if either: */
/* Env variable GC_NPROC is set to > 1, or */
/* GC_NPROC is not set and this is an MP. */
/* If GC_parallel is set, incremental */
/* collection is aonly partially functional, */
/* and may not be desirable. */
/* Public R/W variables */
@@ -102,6 +169,18 @@ GC_API int GC_find_leak;
/* deallocated with GC_free. Initial value */
/* is determined by FIND_LEAK macro. */
GC_API int GC_all_interior_pointers;
/* Arrange for pointers to object interiors to */
/* be recognized as valid. May not be changed */
/* after GC initialization. */
/* Initial value is determined by */
/* -DALL_INTERIOR_POINTERS. */
/* Unless DONT_ADD_BYTE_AT_END is defined, this */
/* also affects whether sizes are increased by */
/* at least a byte to allow "off the end" */
/* pointer recognition. */
/* MUST BE 0 or 1. */
GC_API int GC_quiet; /* Disable statistics output. Only matters if */
/* collector has been compiled with statistics */
/* enabled. This involves a performance cost, */
@@ -109,7 +188,7 @@ GC_API int GC_quiet; /* Disable statistics output. Only matters if */
GC_API int GC_finalize_on_demand;
/* If nonzero, finalizers will only be run in */
/* response to an eplit GC_invoke_finalizers */
/* response to an explicit GC_invoke_finalizers */
/* call. The default is determined by whether */
/* the FINALIZE_ON_DEMAND macro is defined */
/* when the collector is built. */
@@ -121,6 +200,15 @@ GC_API int GC_java_finalization;
/* ordered finalization. Default value is */
/* determined by JAVA_FINALIZATION macro. */
GC_API void (* GC_finalizer_notifier)();
/* Invoked by the collector when there are */
/* objects to be finalized. Invoked at most */
/* once per GC cycle. Never invoked unless */
/* GC_finalize_on_demand is set. */
/* Typically this will notify a finalization */
/* thread, which will call GC_invoke_finalizers */
/* in response. */
GC_API int GC_dont_gc; /* Dont collect unless explicitly requested, e.g. */
/* because it's not safe. */
@@ -128,13 +216,40 @@ GC_API int GC_dont_expand;
/* Dont expand heap unless explicitly requested */
/* or forced to. */
GC_API int GC_use_entire_heap;
/* Causes the nonincremental collector to use the */
/* entire heap before collecting. This was the only */
/* option for GC versions < 5.0. This sometimes */
/* results in more large block fragmentation, since */
/* very larg blocks will tend to get broken up */
/* during each GC cycle. It is likely to result in a */
/* larger working set, but lower collection */
/* frequencies, and hence fewer instructions executed */
/* in the collector. */
GC_API int GC_full_freq; /* Number of partial collections between */
/* full collections. Matters only if */
/* GC_incremental is set. */
/* Full collections are also triggered if */
/* the collector detects a substantial */
/* increase in the number of in-use heap */
/* blocks. Values in the tens are now */
/* perfectly reasonable, unlike for */
/* earlier GC versions. */
GC_API GC_word GC_non_gc_bytes;
/* Bytes not considered candidates for collection. */
/* Used only to control scheduling of collections. */
/* Updated by GC_malloc_uncollectable and GC_free. */
/* Wizards only. */
GC_API int GC_no_dls;
/* Don't register dynamic library data segments. */
/* Wizards only. Should be used only if the */
/* application explicitly registers all roots. */
/* In Microsoft Windows environments, this will */
/* usually also prevent registration of the */
/* main data segment as part of the root set. */
GC_API GC_word GC_free_space_divisor;
/* We try to make sure that we allocate at */
@@ -165,8 +280,16 @@ GC_API char *GC_stackbottom; /* Cool end of user stack. */
/* automatically. */
/* For multithreaded code, this is the */
/* cold end of the stack for the */
/* primordial thread. */
/* primordial thread. */
GC_API int GC_dont_precollect; /* Don't collect as part of */
/* initialization. Should be set only */
/* if the client wants a chance to */
/* manually initialize the root set */
/* before the first collection. */
/* Interferes with blacklisting. */
/* Wizards only. */
/* Public procedures */
/*
* general purpose allocation routines, with roughly malloc calling conv.
@@ -176,8 +299,13 @@ GC_API char *GC_stackbottom; /* Cool end of user stack. */
* will occur after GC_end_stubborn_change has been called on the
* result of GC_malloc_stubborn. GC_malloc_uncollectable allocates an object
* that is scanned for pointers to collectable objects, but is not itself
* collectable. GC_malloc_uncollectable and GC_free called on the resulting
* collectable. The object is scanned even if it does not appear to
* be reachable. GC_malloc_uncollectable and GC_free called on the resulting
* object implicitly update GC_non_gc_bytes appropriately.
*
* Note that the GC_malloc_stubborn support is stubbed out by default
* starting in 6.0. GC_malloc_stubborn is an alias for GC_malloc unless
* the collector is built with STUBBORN_ALLOC defined.
*/
GC_API GC_PTR GC_malloc GC_PROTO((size_t size_in_bytes));
GC_API GC_PTR GC_malloc_atomic GC_PROTO((size_t size_in_bytes));
@@ -216,6 +344,10 @@ GC_API void GC_end_stubborn_change GC_PROTO((GC_PTR));
/* Return a pointer to the base (lowest address) of an object given */
/* a pointer to a location within the object. */
/* I.e. map an interior pointer to the corresponding bas pointer. */
/* Note that with debugging allocation, this returns a pointer to the */
/* actual base of the object, i.e. the debug information, not to */
/* the base of the user object. */
/* Return 0 if displaced_pointer doesn't point to within a valid */
/* object. */
GC_API GC_PTR GC_base GC_PROTO((GC_PTR displaced_pointer));
@@ -297,15 +429,24 @@ GC_API int GC_try_to_collect GC_PROTO((GC_stop_func stop_func));
/* Includes some pages that were allocated but never written. */
GC_API size_t GC_get_heap_size GC_PROTO((void));
/* Return a lower bound on the number of free bytes in the heap. */
GC_API size_t GC_get_free_bytes GC_PROTO((void));
/* Return the number of bytes allocated since the last collection. */
GC_API size_t GC_get_bytes_since_gc GC_PROTO((void));
/* Return the total number of bytes allocated in this process. */
/* Never decreases. */
GC_API size_t GC_get_total_bytes GC_PROTO((void));
/* Enable incremental/generational collection. */
/* Not advisable unless dirty bits are */
/* available or most heap objects are */
/* pointerfree(atomic) or immutable. */
/* Don't use in leak finding mode. */
/* Ignored if GC_dont_gc is true. */
/* Only the generational piece of this is */
/* functional if GC_parallel is TRUE. */
GC_API void GC_enable_incremental GC_PROTO((void));
/* Perform some garbage collection work, if appropriate. */
@@ -341,10 +482,10 @@ GC_API GC_PTR GC_malloc_atomic_ignore_off_page GC_PROTO((size_t lb));
#ifdef GC_ADD_CALLER
# define GC_EXTRAS GC_RETURN_ADDR, __FILE__, __LINE__
# define GC_EXTRA_PARAMS GC_word ra, char * descr_string, int descr_int
# define GC_EXTRA_PARAMS GC_word ra, GC_CONST char * s, int i
#else
# define GC_EXTRAS __FILE__, __LINE__
# define GC_EXTRA_PARAMS char * descr_string, int descr_int
# define GC_EXTRA_PARAMS GC_CONST char * s, int i
#endif
/* Debugging (annotated) allocation. GC_gcollect will check */
@@ -375,6 +516,8 @@ GC_API void GC_debug_end_stubborn_change GC_PROTO((GC_PTR));
GC_debug_register_finalizer(p, f, d, of, od)
# define GC_REGISTER_FINALIZER_IGNORE_SELF(p, f, d, of, od) \
GC_debug_register_finalizer_ignore_self(p, f, d, of, od)
# define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) \
GC_debug_register_finalizer_no_order(p, f, d, of, od)
# define GC_MALLOC_STUBBORN(sz) GC_debug_malloc_stubborn(sz, GC_EXTRAS);
# define GC_CHANGE_STUBBORN(p) GC_debug_change_stubborn(p)
# define GC_END_STUBBORN_CHANGE(p) GC_debug_end_stubborn_change(p)
@@ -391,6 +534,8 @@ GC_API void GC_debug_end_stubborn_change GC_PROTO((GC_PTR));
GC_register_finalizer(p, f, d, of, od)
# define GC_REGISTER_FINALIZER_IGNORE_SELF(p, f, d, of, od) \
GC_register_finalizer_ignore_self(p, f, d, of, od)
# define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) \
GC_register_finalizer_no_order(p, f, d, of, od)
# define GC_MALLOC_STUBBORN(sz) GC_malloc_stubborn(sz)
# define GC_CHANGE_STUBBORN(p) GC_change_stubborn(p)
# define GC_END_STUBBORN_CHANGE(p) GC_end_stubborn_change(p)
@@ -462,6 +607,8 @@ GC_API void GC_debug_register_finalizer
/* but it's unavoidable for C++, since the compiler may */
/* silently introduce these. It's also benign in that specific */
/* case. */
/* Note that cd will still be viewed as accessible, even if it */
/* refers to the object itself. */
GC_API void GC_register_finalizer_ignore_self
GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
GC_finalization_proc *ofn, GC_PTR *ocd));
@@ -469,6 +616,18 @@ GC_API void GC_debug_register_finalizer_ignore_self
GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
GC_finalization_proc *ofn, GC_PTR *ocd));
/* Another version of the above. It ignores all cycles. */
/* It should probably only be used by Java implementations. */
/* Note that cd will still be viewed as accessible, even if it */
/* refers to the object itself. */
GC_API void GC_register_finalizer_no_order
GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
GC_finalization_proc *ofn, GC_PTR *ocd));
GC_API void GC_debug_register_finalizer_no_order
GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
GC_finalization_proc *ofn, GC_PTR *ocd));
/* The following routine may be used to break cycles between */
/* finalizable objects, thus causing cyclic finalizable */
/* objects to be finalized in the correct order. Standard */
@@ -525,6 +684,9 @@ GC_API int GC_unregister_disappearing_link GC_PROTO((GC_PTR * /* link */));
GC_API GC_PTR GC_make_closure GC_PROTO((GC_finalization_proc fn, GC_PTR data));
GC_API void GC_debug_invoke_finalizer GC_PROTO((GC_PTR obj, GC_PTR data));
/* Returns !=0 if GC_invoke_finalizers has something to do. */
GC_API int GC_should_invoke_finalizers GC_PROTO((void));
GC_API int GC_invoke_finalizers GC_PROTO((void));
/* Run finalizers for all objects that are ready to */
/* be finalized. Return the number of finalizers */
@@ -540,7 +702,7 @@ GC_API GC_warn_proc GC_set_warn_proc GC_PROTO((GC_warn_proc p));
/* Returns old warning procedure. */
/* The following is intended to be used by a higher level */
/* (e.g. cedar-like) finalization facility. It is expected */
/* (e.g. Java-like) finalization facility. It is expected */
/* that finalization code will arrange for hidden pointers to */
/* disappear. Otherwise objects can be accessed after they */
/* have been collected. */
@@ -560,6 +722,9 @@ typedef GC_PTR (*GC_fn_type) GC_PROTO((GC_PTR client_data));
GC_API GC_PTR GC_call_with_alloc_lock
GC_PROTO((GC_fn_type fn, GC_PTR client_data));
/* The following routines are primarily intended for use with a */
/* preprocessor which inserts calls to check C pointer arithmetic. */
/* Check that p and q point to the same object. */
/* Fail conspicuously if they don't. */
/* Returns the first argument. */
@@ -587,7 +752,7 @@ GC_API GC_PTR GC_is_visible GC_PROTO((GC_PTR p));
/* Check that if p is a pointer to a heap page, then it points to */
/* a valid displacement within a heap object. */
/* Fail conspicuously if this property does not hold. */
/* Uninteresting with ALL_INTERIOR_POINTERS. */
/* Uninteresting with GC_all_interior_pointers. */
/* Always returns its argument. */
GC_API GC_PTR GC_is_valid_displacement GC_PROTO((GC_PTR p));
@@ -603,9 +768,9 @@ GC_API GC_PTR GC_is_valid_displacement GC_PROTO((GC_PTR p));
# ifdef __GNUC__
# define GC_PTR_ADD(x, n) \
GC_PTR_ADD3(x, n, typeof(x))
# define GC_PRE_INCR(x, n) \
# define GC_PRE_INCR(x, n) \
GC_PRE_INCR3(x, n, typeof(x))
# define GC_POST_INCR(x, n) \
# define GC_POST_INCR(x, n) \
GC_POST_INCR3(x, typeof(x))
# else
/* We can't do this right without typeof, which ANSI */
@@ -645,74 +810,28 @@ GC_API void (*GC_is_valid_displacement_print_proc)
GC_API void (*GC_is_visible_print_proc)
GC_PROTO((GC_PTR p));
#if defined(_SOLARIS_PTHREADS) && !defined(SOLARIS_THREADS)
# define SOLARIS_THREADS
/* For pthread support, we generally need to intercept a number of */
/* thread library calls. We do that here by macro defining them. */
#if !defined(GC_USE_LD_WRAP) && \
(defined(GC_LINUX_THREADS) || defined(GC_HPUX_THREADS) || \
defined(GC_IRIX_THREADS) || defined(GC_SOLARIS_PTHREADS) || \
defined(GC_SOLARIS_THREADS) || defined(GC_OSF1_THREADS))
# include "gc_pthread_redirects.h"
#endif
#ifdef SOLARIS_THREADS
/* We need to intercept calls to many of the threads primitives, so */
/* that we can locate thread stacks and stop the world. */
/* Note also that the collector cannot see thread specific data. */
/* Thread specific data should generally consist of pointers to */
/* uncollectable objects, which are deallocated using the destructor */
/* facility in thr_keycreate. */
# include <thread.h>
# include <signal.h>
int GC_thr_create(void *stack_base, size_t stack_size,
void *(*start_routine)(void *), void *arg, long flags,
thread_t *new_thread);
int GC_thr_join(thread_t wait_for, thread_t *departed, void **status);
int GC_thr_suspend(thread_t target_thread);
int GC_thr_continue(thread_t target_thread);
void * GC_dlopen(const char *path, int mode);
# ifdef _SOLARIS_PTHREADS
# include <pthread.h>
extern int GC_pthread_create(pthread_t *new_thread,
const pthread_attr_t *attr,
void * (*thread_execp)(void *), void *arg);
extern int GC_pthread_join(pthread_t wait_for, void **status);
# undef thread_t
# define pthread_join GC_pthread_join
# define pthread_create GC_pthread_create
#endif
# define thr_create GC_thr_create
# define thr_join GC_thr_join
# define thr_suspend GC_thr_suspend
# define thr_continue GC_thr_continue
# define dlopen GC_dlopen
# endif /* SOLARIS_THREADS */
#if defined(IRIX_THREADS) || defined(LINUX_THREADS)
/* We treat these similarly. */
# include <pthread.h>
# include <signal.h>
int GC_pthread_create(pthread_t *new_thread,
const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
int GC_pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
int GC_pthread_join(pthread_t thread, void **retval);
# define pthread_create GC_pthread_create
# define pthread_sigmask GC_pthread_sigmask
# define pthread_join GC_pthread_join
#endif /* IRIX_THREADS || LINUX_THREADS */
# if defined(PCR) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || \
defined(IRIX_THREADS) || defined(LINUX_THREADS) || \
defined(IRIX_JDK_THREADS)
# if defined(PCR) || defined(GC_SOLARIS_THREADS) || \
defined(GC_SOLARIS_PTHREADS) || defined(GC_WIN32_THREADS) || \
defined(GC_IRIX_THREADS) || defined(GC_LINUX_THREADS) || \
defined(GC_HPUX_THREADS)
/* Any flavor of threads except SRC_M3. */
/* This returns a list of objects, linked through their first */
/* word. Its use can greatly reduce lock contention problems, since */
/* the allocation lock can be acquired and released many fewer times. */
/* lb must be large enough to hold the pointer field. */
/* It is used internally by gc_local_alloc.h, which provides a simpler */
/* programming interface on Linux. */
GC_PTR GC_malloc_many(size_t lb);
#define GC_NEXT(p) (*(GC_PTR *)(p)) /* Retrieve the next element */
/* in returned list. */
@@ -720,6 +839,35 @@ extern void GC_thr_init(); /* Needed for Solaris/X86 */
#endif /* THREADS && !SRC_M3 */
#if defined(WIN32_THREADS) && defined(_WIN32_WCE)
# include <windows.h>
/*
* win32_threads.c implements the real WinMain, which will start a new thread
* to call GC_WinMain after initializing the garbage collector.
*/
int WINAPI GC_WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow );
/*
* All threads must be created using GC_CreateThread, so that they will be
* recorded in the thread table.
*/
HANDLE WINAPI GC_CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
# ifndef GC_BUILD
# define WinMain GC_WinMain
# define CreateThread GC_CreateThread
# endif
#endif
/*
* If you are planning on putting
* the collector in a SunOS 5 dynamic library, you need to call GC_INIT()
@@ -740,13 +888,23 @@ extern void GC_thr_init(); /* Needed for Solaris/X86 */
# endif
#endif
#if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
|| defined(_WIN32)
#if !defined(_WIN32_WCE) \
&& ((defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
|| defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__))
/* win32S may not free all resources on process exit. */
/* This explicitly deallocates the heap. */
GC_API void GC_win32_free_heap ();
#endif
#if ( defined(_AMIGA) && !defined(GC_AMIGA_MAKINGLIB) )
/* Allocation really goes through GC_amiga_allocwrapper_do */
# include "gc_amiga_redirects.h"
#endif
#if defined(GC_REDIRECT_TO_LOCAL) && !defined(GC_LOCAL_ALLOC_H)
# include "gc_local_alloc.h"
#endif
#ifdef __cplusplus
} /* end of extern "C" */
#endif
+3
View File
@@ -25,6 +25,9 @@
// This uses template classes with static members, and hence does not work
// with g++ 2.7.2 and earlier.
//
// This code assumes that the collector itself has been compiled with a
// compiler that defines __STDC__ .
//
#include "gc.h"
+30
View File
@@ -0,0 +1,30 @@
#ifndef GC_AMIGA_REDIRECTS_H
# define GC_AMIGA_REDIRECTS_H
# if ( defined(_AMIGA) && !defined(GC_AMIGA_MAKINGLIB) )
extern void *GC_amiga_realloc(void *old_object,size_t new_size_in_bytes);
# define GC_realloc(a,b) GC_amiga_realloc(a,b)
extern void GC_amiga_set_toany(void (*func)(void));
extern int GC_amiga_free_space_divisor_inc;
extern void *(*GC_amiga_allocwrapper_do) \
(size_t size,void *(*AllocFunction)(size_t size2));
# define GC_malloc(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc)
# define GC_malloc_atomic(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic)
# define GC_malloc_uncollectable(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc_uncollectable)
# define GC_malloc_stubborn(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc_stubborn)
# define GC_malloc_atomic_uncollectable(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_uncollectable)
# define GC_malloc_ignore_off_page(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc_ignore_off_page)
# define GC_malloc_atomic_ignore_off_page(a) \
(*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_ignore_off_page)
# endif /* _AMIGA && !GC_AMIGA_MAKINGLIB */
#endif /* GC_AMIGA_REDIRECTS_H */
@@ -20,6 +20,8 @@
* The implementation idea is due to A. Demers.
*/
#ifndef GC_BACKPTR_H
#define GC_BACKPTR_H
/* Store information about the object referencing dest in *base_p */
/* and *offset_p. */
/* If multiple objects or roots point to dest, the one reported */
@@ -29,9 +31,11 @@
/* source is heap object ==> *base_p != 0, *offset_p = offset */
/* Returns 1 on success, 0 if source couldn't be determined. */
/* Dest can be any address within a heap object. */
typedef enum { GC_UNREFERENCED, /* No refence info available. */
typedef enum { GC_UNREFERENCED, /* No reference info available. */
GC_NO_SPACE, /* Dest not allocated with debug alloc */
GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p */
GC_REFD_FROM_REG, /* Referenced from a register, i.e. */
/* a root without an address. */
GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */
GC_FINALIZER_REFD /* Finalizable and hence accessible. */
} GC_ref_kind;
@@ -53,4 +57,9 @@ void * GC_generate_random_valid_address(void);
/* source in dbg_mlc.c also serves as a sample client. */
void GC_generate_random_backtrace(void);
/* Print a backtrace from a specific address. Used by the */
/* above. The client should call GC_gcollect() immediately */
/* before invocation. */
void GC_print_backtrace(void *);
#endif /* GC_BACKPTR_H */
+90 -24
View File
@@ -16,12 +16,11 @@ the code was modified is included with the above copyright notice.
C++ Interface to the Boehm Collector
John R. Ellis and Jesse Hull
Last modified on Mon Jul 24 15:43:42 PDT 1995 by ellis
This interface provides access to the Boehm collector. It provides
basic facilities similar to those described in "Safe, Efficient
Garbage Collection for C++", by John R. Elis and David L. Detlefs
(ftp.parc.xerox.com:/pub/ellis/gc).
(ftp://ftp.parc.xerox.com/pub/ellis/gc).
All heap-allocated objects are either "collectable" or
"uncollectable". Programs must explicitly delete uncollectable
@@ -38,7 +37,7 @@ Objects derived from class "gc" are collectable. For example:
A* a = new A; // a is collectable.
Collectable instances of non-class types can be allocated using the GC
placement:
(or UseGC) placement:
typedef int A[ 10 ];
A* a = new (GC) A;
@@ -84,7 +83,7 @@ Cautions:
1. Be sure the collector has been augmented with "make c++".
2. If your compiler supports the new "operator new[]" syntax, then
add -DOPERATOR_NEW_ARRAY to the Makefile.
add -DGC_OPERATOR_NEW_ARRAY to the Makefile.
If your compiler doesn't support "operator new[]", beware that an
array of type T, where T is derived from "gc", may or may not be
@@ -124,6 +123,12 @@ invoked using the ANSI-conforming syntax t->~T(). If you're using
cfront 3.0, you'll have to comment out the class gc_cleanup, which
uses explicit invocation.
5. GC name conflicts:
Many other systems seem to use the identifier "GC" as an abbreviation
for "Graphics Context". Since version 5.0, GC placement has been replaced
by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
****************************************************************************/
#include "gc.h"
@@ -132,24 +137,35 @@ uses explicit invocation.
#define _cdecl
#endif
#if ! defined( OPERATOR_NEW_ARRAY ) \
&& (__BORLANDC__ >= 0x450 || (__GNUC__ >= 2 && __GNUC_MINOR__ >= 6) \
|| __WATCOMC__ >= 1050)
# define OPERATOR_NEW_ARRAY
#if ! defined( GC_NO_OPERATOR_NEW_ARRAY ) \
&& !defined(_ENABLE_ARRAYNEW) /* Digimars */ \
&& (defined(__BORLANDC__) && (__BORLANDC__ < 0x450) \
|| (defined(__GNUC__) && \
(__GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 6)) \
|| (defined(__WATCOMC__) && __WATCOMC__ < 1050))
# define GC_NO_OPERATOR_NEW_ARRAY
#endif
enum GCPlacement {GC, NoGC, PointerFreeGC};
#if !defined(GC_NO_OPERATOR_NEW_ARRAY) && !defined(GC_OPERATOR_NEW_ARRAY)
# define GC_OPERATOR_NEW_ARRAY
#endif
enum GCPlacement {UseGC,
#ifndef GC_NAME_CONFLICT
GC=UseGC,
#endif
NoGC, PointerFreeGC};
class gc {public:
inline void* operator new( size_t size );
inline void* operator new( size_t size, GCPlacement gcp );
inline void operator delete( void* obj );
#ifdef OPERATOR_NEW_ARRAY
#ifdef GC_OPERATOR_NEW_ARRAY
inline void* operator new[]( size_t size );
inline void* operator new[]( size_t size, GCPlacement gcp );
inline void operator delete[]( void* obj );
#endif /* OPERATOR_NEW_ARRAY */
#endif /* GC_OPERATOR_NEW_ARRAY */
};
/*
Instances of classes derived from "gc" will be allocated in the
@@ -170,6 +186,12 @@ private:
extern "C" {typedef void (*GCCleanUpFunc)( void* obj, void* clientData );}
#ifdef _MSC_VER
// Disable warning that "no matching operator delete found; memory will
// not be freed if initialization throws an exception"
# pragma warning(disable:4291)
#endif
inline void* operator new(
size_t size,
GCPlacement gcp,
@@ -189,7 +211,50 @@ inline void* operator new(
classes derived from "gc_cleanup" or containing members derived
from "gc_cleanup". */
#ifdef OPERATOR_NEW_ARRAY
#ifdef GC_OPERATOR_NEW_ARRAY
#ifdef _MSC_VER
/** This ensures that the system default operator new[] doesn't get
* undefined, which is what seems to happen on VC++ 6 for some reason
* if we define a multi-argument operator new[].
* There seems to be really redirect new in this environment without
* including this everywhere.
*/
inline void *operator new[]( size_t size )
{
return GC_MALLOC_UNCOLLECTABLE( size );
}
inline void operator delete[](void* obj)
{
GC_FREE(obj);
};
inline void* operator new( size_t size)
{
return GC_MALLOC_UNCOLLECTABLE( size);
};
inline void operator delete(void* obj)
{
GC_FREE(obj);
};
// This new operator is used by VC++ in case of Debug builds !
inline void* operator new( size_t size,
int ,//nBlockUse,
const char * szFileName,
int nLine
) {
# ifndef GC_DEBUG
return GC_malloc_uncollectable( size );
# else
return GC_debug_malloc_uncollectable(size, szFileName, nLine);
# endif
}
#endif /* _MSC_VER */
inline void* operator new[](
size_t size,
@@ -199,7 +264,7 @@ inline void* operator new[](
/*
The operator new for arrays, identical to the above. */
#endif /* OPERATOR_NEW_ARRAY */
#endif /* GC_OPERATOR_NEW_ARRAY */
/****************************************************************************
@@ -211,7 +276,7 @@ inline void* gc::operator new( size_t size ) {
return GC_MALLOC( size );}
inline void* gc::operator new( size_t size, GCPlacement gcp ) {
if (gcp == GC)
if (gcp == UseGC)
return GC_MALLOC( size );
else if (gcp == PointerFreeGC)
return GC_MALLOC_ATOMIC( size );
@@ -222,7 +287,7 @@ inline void gc::operator delete( void* obj ) {
GC_FREE( obj );}
#ifdef OPERATOR_NEW_ARRAY
#ifdef GC_OPERATOR_NEW_ARRAY
inline void* gc::operator new[]( size_t size ) {
return gc::operator new( size );}
@@ -233,7 +298,7 @@ inline void* gc::operator new[]( size_t size, GCPlacement gcp ) {
inline void gc::operator delete[]( void* obj ) {
gc::operator delete( obj );}
#endif /* OPERATOR_NEW_ARRAY */
#endif /* GC_OPERATOR_NEW_ARRAY */
inline gc_cleanup::~gc_cleanup() {
@@ -246,12 +311,13 @@ inline gc_cleanup::gc_cleanup() {
GC_finalization_proc oldProc;
void* oldData;
void* base = GC_base( (void *) this );
if (0 == base) return;
GC_REGISTER_FINALIZER_IGNORE_SELF(
base, cleanup, (void*) ((char*) this - (char*) base),
if (0 != base) {
// Don't call the debug version, since this is a real base address.
GC_register_finalizer_ignore_self(
base, (GC_finalization_proc)cleanup, (void*) ((char*) this - (char*) base),
&oldProc, &oldData );
if (0 != oldProc) {
GC_REGISTER_FINALIZER_IGNORE_SELF( base, oldProc, oldData, 0, 0 );}}
if (0 != oldProc) {
GC_register_finalizer_ignore_self( base, oldProc, oldData, 0, 0 );}}}
inline void* operator new(
size_t size,
@@ -261,7 +327,7 @@ inline void* operator new(
{
void* obj;
if (gcp == GC) {
if (gcp == UseGC) {
obj = GC_MALLOC( size );
if (cleanup != 0)
GC_REGISTER_FINALIZER_IGNORE_SELF(
@@ -273,7 +339,7 @@ inline void* operator new(
return obj;}
#ifdef OPERATOR_NEW_ARRAY
#ifdef GC_OPERATOR_NEW_ARRAY
inline void* operator new[](
size_t size,
@@ -283,7 +349,7 @@ inline void* operator new[](
{
return ::operator new( size, gcp, cleanup, clientData );}
#endif /* OPERATOR_NEW_ARRAY */
#endif /* GC_OPERATOR_NEW_ARRAY */
#endif /* GC_CPP_H */
+104
View File
@@ -0,0 +1,104 @@
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright 1996-1999 by Silicon Graphics. All rights reserved.
* Copyright 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.
*/
/* This file assumes the collector has been compiled with GC_GCJ_SUPPORT */
/* and that an ANSI C compiler is available. */
/*
* We allocate objects whose first word contains a pointer to a struct
* describing the object type. This struct contains a garbage collector mark
* descriptor at offset MARK_DESCR_OFFSET. Alternatively, the objects
* may be marked by the mark procedure passed to GC_init_gcj_malloc.
*/
#ifndef GC_GCJ_H
#define GC_GCJ_H
#ifndef MARK_DESCR_OFFSET
# define MARK_DESCR_OFFSET sizeof(word)
#endif
/* Gcj keeps GC descriptor as second word of vtable. This */
/* probably needs to be adjusted for other clients. */
/* We currently assume that this offset is such that: */
/* - all objects of this kind are large enough to have */
/* a value at that offset, and */
/* - it is not zero. */
/* These assumptions allow objects on the free list to be */
/* marked normally. */
#ifndef _GC_H
# include "gc.h"
#endif
/* The following allocators signal an out of memory condition with */
/* return GC_oom_fn(bytes); */
extern void * (*GC_oom_action)(void);
/* The following function must be called before the gcj allocators */
/* can be invoked. */
/* mp_index and mp are the index and mark_proc (see gc_mark.h) */
/* respectively for the allocated objects. Mark_proc will be */
/* used to build the descriptor for objects allocated through the */
/* debugging interface. The mark_proc will be invoked on all such */
/* objects with an "environment" value of 1. The client may chose */
/* to use the same mark_proc for some of its generated mark descriptors.*/
/* In that case, it should use a different "environment" value to */
/* detect the presence or absence of the debug header. */
/* Mp is really of type mark_proc, as defined in gc_mark.h. We don't */
/* want to include that here for namespace pollution reasons. */
extern void GC_init_gcj_malloc(int mp_index, void * /* really mark_proc */mp);
/* 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.*/
extern void * GC_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr);
/* The debug versions allocate such that the specified mark_proc */
/* is always invoked. */
extern void * GC_debug_gcj_malloc(size_t lb,
void * ptr_to_struct_containing_descr,
GC_EXTRA_PARAMS);
/* Similar to the above, 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. */
/* Unless it is known that the collector is not configured */
/* with USE_MARK_BYTES and unless it is known that the object */
/* has weak alignment requirements, lw must be even. */
extern void * GC_gcj_fast_malloc(size_t lw,
void * ptr_to_struct_containing_descr);
extern void * GC_debug_gcj_fast_malloc(size_t lw,
void * ptr_to_struct_containing_descr,
GC_EXTRA_PARAMS);
/* Similar to GC_gcj_malloc, but assumes that a pointer to near the */
/* beginning of the resulting object is always maintained. */
extern void * GC_gcj_malloc_ignore_off_page(size_t lb,
void * ptr_to_struct_containing_descr);
# ifdef GC_DEBUG
# define GC_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
# define GC_GCJ_FAST_MALLOC(s,d) GC_debug_gcj_fast_malloc(s,d,GC_EXTRAS)
# define GC_GCJ_MALLOC_IGNORE_OFF_PAGE(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
# else
# define GC_GCJ_MALLOC(s,d) GC_gcj_malloc(s,d)
# define GC_GCJ_FAST_MALLOC(s,d) GC_gcj_fast_malloc(s,d)
# define GC_GCJ_MALLOC_IGNORE_OFF_PAGE(s,d) \
GC_gcj_malloc_ignore_off_page(s,d)
# endif
#endif /* GC_GCJ_H */
+8 -4
View File
@@ -17,18 +17,22 @@
# include "private/gc_priv.h"
# endif
/* USE OF THIS FILE IS NOT RECOMMENDED unless the collector has been */
/* compiled without -DALL_INTERIOR_POINTERS or with */
/* USE OF THIS FILE IS NOT RECOMMENDED unless GC_all_interior_pointers */
/* is always set, or the collector has been built with */
/* -DDONT_ADD_BYTE_AT_END, or the specified size includes a pointerfree */
/* word at the end. In the standard collector configuration, */
/* the final word of each object may not be scanned. */
/* This is most useful for compilers that generate C. */
/* This iinterface is most useful for compilers that generate C. */
/* Manual use is hereby discouraged. */
/* Allocate n words (NOT BYTES). X is made to point to the result. */
/* It is assumed that n < MAXOBJSZ, and */
/* that n > 0. On machines requiring double word alignment of some */
/* data, we also assume that n is 1 or even. This bypasses the */
/* data, we also assume that n is 1 or even. */
/* If the collector is built with -DUSE_MARK_BYTES or -DPARALLEL_MARK, */
/* the n = 1 case is also disallowed. */
/* Effectively this means that portable code should make sure n is even.*/
/* This bypasses the */
/* MERGE_SIZES mechanism. In order to minimize the number of distinct */
/* free lists that are maintained, the caller should ensure that a */
/* small number of distinct values of n are used. (The MERGE_SIZES */
+85
View File
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2000 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.
*/
/*
* Interface for thread local allocation. Memory obtained
* this way can be used by all threads, as though it were obtained
* from an allocator like GC_malloc. The difference is that GC_local_malloc
* counts the number of allocations of a given size from the current thread,
* and uses GC_malloc_many to perform the allocations once a threashold
* is exceeded. Thus far less synchronization may be needed.
* Allocation of known large objects should not use this interface.
* This interface is designed primarily for fast allocation of small
* objects on multiprocessors, e.g. for a JVM running on an MP server.
*
* If this file is included with GC_GCJ_SUPPORT defined, GCJ-style
* bitmap allocation primitives will also be included.
*
* If this file is included with GC_REDIRECT_TO_LOCAL defined, then
* GC_MALLOC, GC_MALLOC_ATOMIC, and possibly GC_GCJ_MALLOC will
* be redefined to use the thread local allocatoor.
*
* The interface is available only if the collector is built with
* -DTHREAD_LOCAL_ALLOC, which is currently supported only on Linux.
*
* The debugging allocators use standard, not thread-local allocation.
*/
#ifndef GC_LOCAL_ALLOC_H
#define GC_LOCAL_ALLOC_H
#ifndef _GC_H
# include "gc.h"
#endif
#if defined(GC_GCJ_SUPPORT) && !defined(GC_GCJ_H)
# include "gc_gcj.h"
#endif
/* We assume ANSI C for this interface. */
GC_PTR GC_local_malloc(size_t bytes);
GC_PTR GC_local_malloc_atomic(size_t bytes);
#if defined(GC_GCJ_SUPPORT)
GC_PTR GC_local_gcj_malloc(size_t bytes,
void * ptr_to_struct_containing_descr);
#endif
# ifdef GC_DEBUG
# define GC_LOCAL_MALLOC(s) GC_debug_malloc(s,GC_EXTRAS)
# define GC_LOCAL_MALLOC_ATOMIC(s) GC_debug_malloc_atomic(s,GC_EXTRAS)
# ifdef GC_GCJ_SUPPORT
# define GC_LOCAL_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
# endif
# else
# define GC_LOCAL_MALLOC(s) GC_local_malloc(s)
# define GC_LOCAL_MALLOC_ATOMIC(s) GC_local_malloc_atomic(s)
# ifdef GC_GCJ_SUPPORT
# define GC_LOCAL_GCJ_MALLOC(s,d) GC_local_gcj_malloc(s,d)
# endif
# endif
# ifdef GC_REDIRECT_TO_LOCAL
# undef GC_MALLOC
# define GC_MALLOC(s) GC_LOCAL_MALLOC(s)
# undef GC_MALLOC_ATOMIC
# define GC_MALLOC_ATOMIC(s) GC_LOCAL_MALLOC_ATOMIC(s)
# ifdef GC_GCJ_SUPPORT
# undef GC_GCJ_MALLOC
# define GC_GCJ_MALLOC(s,d) GC_LOCAL_GCJ_MALLOC(s,d)
# endif
# endif
#endif /* GC_LOCAL_ALLOC_H */
+145
View File
@@ -0,0 +1,145 @@
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 2001 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.
*
*/
/*
* This contains interfaces to the GC marker that are likely to be useful to
* clients that provide detailed heap layout information to the collector.
* This interface should not be used by normal C or C++ clients.
* It will be useful to runtimes for other languages.
*
* Note that this file is not "namespace-clean", i.e. it introduces names
* not prefixed with GC_, which may collide with the client's names. It
* should be included only in those few places that directly provide
* information to the collector.
*/
#ifndef GC_MARK_H
# define GC_MARK_H
# ifndef GC_H
# include "gc.h"
# endif
/* A client supplied mark procedure. Returns new mark stack pointer. */
/* Primary effect should be to push new entries on the mark stack. */
/* Mark stack pointer values are passed and returned explicitly. */
/* Global variables decribing mark stack are not necessarily valid. */
/* (This usually saves a few cycles by keeping things in registers.) */
/* Assumed to scan about GC_PROC_BYTES on average. If it needs to do */
/* much more work than that, it should do it in smaller pieces by */
/* pushing itself back on the mark stack. */
/* Note that it should always do some work (defined as marking some */
/* objects) before pushing more than one entry on the mark stack. */
/* This is required to ensure termination in the event of mark stack */
/* overflows. */
/* This procedure is always called with at least one empty entry on the */
/* mark stack. */
/* Currently we require that mark procedures look for pointers in a */
/* subset of the places the conservative marker would. It must be safe */
/* to invoke the normal mark procedure instead. */
/* WARNING: Such a mark procedure may be invoked on an unused object */
/* residing on a free list. Such objects are cleared, except for a */
/* free list link field in the first word. Thus mark procedures may */
/* not count on the presence of a type descriptor, and must handle this */
/* case correctly somehow. */
# define GC_PROC_BYTES 100
struct GC_ms_entry;
typedef struct GC_ms_entry * (*GC_mark_proc) GC_PROTO((
GC_word * addr, struct GC_ms_entry * mark_stack_ptr,
struct GC_ms_entry * mark_stack_limit, GC_word env));
# define GC_LOG_MAX_MARK_PROCS 6
# define GC_MAX_MARK_PROCS (1 << GC_LOG_MAX_MARK_PROCS)
/* In a few cases it's necessary to assign statically known indices to */
/* certain mark procs. Thus we reserve a few for well known clients. */
/* (This is necessary if mark descriptors are compiler generated.) */
#define GC_RESERVED_MARK_PROCS 8
# define GC_GCJ_RESERVED_MARK_PROC_INDEX 0
/* Object descriptors on mark stack or in objects. Low order two */
/* bits are tags distinguishing among the following 4 possibilities */
/* for the high order 30 bits. */
#define GC_DS_TAG_BITS 2
#define GC_DS_TAGS ((1 << GC_DS_TAG_BITS) - 1)
#define GC_DS_LENGTH 0 /* The entire word is a length in bytes that */
/* must be a multiple of 4. */
#define GC_DS_BITMAP 1 /* 30 (62) bits are a bitmap describing pointer */
/* fields. The msb is 1 iff the first word */
/* is a pointer. */
/* (This unconventional ordering sometimes */
/* makes the marker slightly faster.) */
/* Zeroes indicate definite nonpointers. Ones */
/* indicate possible pointers. */
/* Only usable if pointers are word aligned. */
#define GC_DS_PROC 2
/* The objects referenced by this object can be */
/* pushed on the mark stack by invoking */
/* PROC(descr). ENV(descr) is passed as the */
/* last argument. */
# define GC_MAKE_PROC(proc_index, env) \
(((((env) << GC_LOG_MAX_MARK_PROCS) \
| (proc_index)) << GC_DS_TAG_BITS) | GC_DS_PROC)
#define GC_DS_PER_OBJECT 3 /* The real descriptor is at the */
/* byte displacement from the beginning of the */
/* object given by descr & ~DS_TAGS */
/* If the descriptor is negative, the real */
/* descriptor is at (*<object_start>) - */
/* (descr & ~DS_TAGS) - GC_INDIR_PER_OBJ_BIAS */
/* The latter alternative can be used if each */
/* object contains a type descriptor in the */
/* first word. */
/* Note that in multithreaded environments */
/* per object descriptors maust be located in */
/* either the first two or last two words of */
/* the object, since only those are guaranteed */
/* to be cleared while the allocation lock is */
/* held. */
#define GC_INDIR_PER_OBJ_BIAS 0x10
extern GC_PTR GC_least_plausible_heap_addr;
extern GC_PTR GC_greatest_plausible_heap_addr;
/* Bounds on the heap. Guaranteed valid */
/* Likely to include future heap expansion. */
/* Handle nested references in a custom mark procedure. */
/* Check if obj is a valid object. If so, ensure that it is marked. */
/* If it was not previously marked, push its contents onto the mark */
/* stack for future scanning. The object will then be scanned using */
/* its mark descriptor. */
/* Returns the new mark stack pointer. */
/* Handles mark stack overflows correctly. */
/* Since this marks first, it makes progress even if there are mark */
/* stack overflows. */
/* Src is the address of the pointer to obj, which is used only */
/* for back pointer-based heap debugging. */
/* It is strongly recommended that most objects be handled without mark */
/* procedures, e.g. with bitmap descriptors, and that mark procedures */
/* be reserved for exceptional cases. That will ensure that */
/* performance of this call is not extremely performance critical. */
/* (Otherwise we would need to inline GC_mark_and_push completely, */
/* which would tie the client code to a fixed colllector version.) */
struct GC_ms_entry *GC_mark_and_push
GC_PROTO((GC_PTR obj,
struct GC_ms_entry * mark_stack_ptr,
struct GC_ms_entry * mark_stack_limit, GC_PTR *src));
#define GC_MARK_AND_PUSH(obj, msp, lim, src) \
(((GC_word)obj >= (GC_word)GC_least_plausible_heap_addr && \
(GC_word)obj <= (GC_word)GC_greatest_plausible_heap_addr)? \
GC_mark_and_push(obj, msp, lim, src) : \
msp)
#endif /* GC_MARK_H */
+69
View File
@@ -0,0 +1,69 @@
/* Our pthread support normally needs to intercept a number of thread */
/* calls. We arrange to do that here, if appropriate. */
#ifndef GC_PTHREAD_REDIRECTS_H
#define GC_PTHREAD_REDIRECTS_H
#if defined(GC_SOLARIS_THREADS)
/* We need to intercept calls to many of the threads primitives, so */
/* that we can locate thread stacks and stop the world. */
/* Note also that the collector cannot see thread specific data. */
/* Thread specific data should generally consist of pointers to */
/* uncollectable objects (allocated with GC_malloc_uncollectable, */
/* not the system malloc), which are deallocated using the destructor */
/* facility in thr_keycreate. Alternatively, keep a redundant pointer */
/* to thread specific data on the thread stack. */
# include <thread.h>
int GC_thr_create(void *stack_base, size_t stack_size,
void *(*start_routine)(void *), void *arg, long flags,
thread_t *new_thread);
int GC_thr_join(thread_t wait_for, thread_t *departed, void **status);
int GC_thr_suspend(thread_t target_thread);
int GC_thr_continue(thread_t target_thread);
void * GC_dlopen(const char *path, int mode);
# define thr_create GC_thr_create
# define thr_join GC_thr_join
# define thr_suspend GC_thr_suspend
# define thr_continue GC_thr_continue
#endif /* GC_SOLARIS_THREADS */
#if defined(GC_SOLARIS_PTHREADS)
# include <pthread.h>
# include <signal.h>
extern int GC_pthread_create(pthread_t *new_thread,
const pthread_attr_t *attr,
void * (*thread_execp)(void *), void *arg);
extern int GC_pthread_join(pthread_t wait_for, void **status);
# define pthread_join GC_pthread_join
# define pthread_create GC_pthread_create
#endif
#if defined(GC_SOLARIS_PTHREADS) || defined(GC_SOLARIS_THREADS)
# define dlopen GC_dlopen
#endif /* SOLARIS_THREADS || SOLARIS_PTHREADS */
#if !defined(GC_USE_LD_WRAP) && \
(defined(GC_IRIX_THREADS) || defined(GC_LINUX_THREADS) \
|| defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS))
/* We treat these similarly. */
# include <pthread.h>
# include <signal.h>
int GC_pthread_create(pthread_t *new_thread,
const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
int GC_pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
int GC_pthread_join(pthread_t thread, void **retval);
int GC_pthread_detach(pthread_t thread);
# define pthread_create GC_pthread_create
# define pthread_sigmask GC_pthread_sigmask
# define pthread_join GC_pthread_join
# define pthread_detach GC_pthread_detach
# define dlopen GC_dlopen
#endif /* GC_xxxxx_THREADS */
#endif /* GC_PTHREAD_REDIRECTS_H */
+2
View File
@@ -61,6 +61,7 @@ GC_API GC_PTR GC_malloc_explicitly_typed
GC_PROTO((size_t size_in_bytes, GC_descr d));
/* Allocate an object whose layout is described by d. */
/* The resulting object MAY NOT BE PASSED TO REALLOC. */
/* The returned object is cleared. */
GC_API GC_PTR GC_malloc_explicitly_typed_ignore_off_page
GC_PROTO((size_t size_in_bytes, GC_descr d));
@@ -75,6 +76,7 @@ GC_API GC_PTR GC_calloc_explicitly_typed
/* alignment required for pointers. E.g. on a 32-bit */
/* machine with 16-bit aligned pointers, size_in_bytes */
/* must be a multiple of 2. */
/* Returned object is cleared. */
#ifdef GC_DEBUG
# define GC_MALLOC_EXPLICTLY_TYPED(bytes, d) GC_MALLOC(bytes)
+12 -9
View File
@@ -20,9 +20,9 @@
// It also doesn't yet understand the new header file names or
// namespaces.
//
// This assumes the collector has been compiled with -DATOMIC_UNCOLLECTABLE
// and -DALL_INTERIOR_POINTERS. We also recommend
// -DREDIRECT_MALLOC=GC_uncollectable_malloc.
// This assumes the collector has been compiled with -DATOMIC_UNCOLLECTABLE.
// The user should also consider -DREDIRECT_MALLOC=GC_uncollectable_malloc,
// to ensure that object allocated through malloc are traced.
//
// Some of this could be faster in the explicit deallocation case.
// In particular, we spend too much time clearing objects on the
@@ -43,11 +43,14 @@
// problems. The argument for changing it is that the usual default
// allocator is usually a very bad choice for a garbage collected environment.)
//
// This code assumes that the collector itself has been compiled with a
// compiler that defines __STDC__ .
//
#ifndef GC_ALLOC_H
#include "gc.h"
#include <alloc.h>
#include <stack> // A more portable way to get stl_alloc.h .
#define GC_ALLOC_H
@@ -318,12 +321,10 @@ class traceable_alloc_template {
typedef traceable_alloc_template < 0 > traceable_alloc;
#ifdef _SGI_SOURCE
// We want to specialize simple_alloc so that it does the right thing
// for all pointerfree types. At the moment there is no portable way to
// even approximate that. The following approximation should work for
// SGI compilers, and perhaps some others.
// SGI compilers, and recent versions of g++.
# define __GC_SPECIALIZE(T,alloc) \
class simple_alloc<T, alloc> { \
@@ -339,6 +340,8 @@ public: \
{ alloc::ptr_free_deallocate(p, sizeof (T)); } \
};
__STL_BEGIN_NAMESPACE
__GC_SPECIALIZE(char, gc_alloc)
__GC_SPECIALIZE(int, gc_alloc)
__GC_SPECIALIZE(unsigned, gc_alloc)
@@ -363,6 +366,8 @@ __GC_SPECIALIZE(unsigned, single_client_traceable_alloc)
__GC_SPECIALIZE(float, single_client_traceable_alloc)
__GC_SPECIALIZE(double, single_client_traceable_alloc)
__STL_END_NAMESPACE
#ifdef __STL_USE_STD_ALLOCATORS
__STL_BEGIN_NAMESPACE
@@ -451,6 +456,4 @@ __STL_END_NAMESPACE
#endif /* __STL_USE_STD_ALLOCATORS */
#endif /* _SGI_SOURCE */
#endif /* GC_ALLOC_H */
+153
View File
@@ -0,0 +1,153 @@
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright (c) 1997 by Silicon Graphics. 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.
*/
/*
* This is mostly an internal header file. Typical clients should
* not use it. Clients that define their own object kinds with
* debugging allocators will probably want to include this, however.
* No attempt is made to keep the namespace clean. This should not be
* included from header files that are frequently included by clients.
*/
#ifndef _DBG_MLC_H
#define _DBG_MLC_H
# define I_HIDE_POINTERS
# include "gc_priv.h"
# ifdef KEEP_BACK_PTRS
# include "gc_backptr.h"
# endif
#ifndef HIDE_POINTER
/* Gc.h was previously included, and hence the I_HIDE_POINTERS */
/* definition had no effect. Repeat the gc.h definitions here to */
/* get them anyway. */
typedef GC_word GC_hidden_pointer;
# define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
# define REVEAL_POINTER(p) ((GC_PTR)(HIDE_POINTER(p)))
#endif /* HIDE_POINTER */
# define START_FLAG ((word)0xfedcedcb)
# define END_FLAG ((word)0xbcdecdef)
/* Stored both one past the end of user object, and one before */
/* the end of the object as seen by the allocator. */
# if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST)
/* Pointer "source"s that aren't real locations. */
/* Used in oh_back_ptr fields and as "source" */
/* argument to some marking functions. */
# define NOT_MARKED (ptr_t)(0)
# define MARKED_FOR_FINALIZATION (ptr_t)(2)
/* Object was marked because it is finalizable. */
# define MARKED_FROM_REGISTER (ptr_t)(4)
/* Object was marked from a rgister. Hence the */
/* source of the reference doesn't have an address. */
# endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
/* Object header */
typedef struct {
# ifdef KEEP_BACK_PTRS
GC_hidden_pointer oh_back_ptr;
/* We make sure that we only store even valued */
/* pointers here, so that the hidden version has */
/* the least significant bit set. We never */
/* overwrite a value with the least significant */
/* bit clear, thus ensuring that we never overwrite */
/* a free list link field. */
/* Note that blocks dropped by black-listing will */
/* also have the lsb clear once debugging has */
/* started. */
/* The following are special back pointer values. */
/* Note that the "hidden" (i.e. bitwise */
/* complemented version) of these is actually */
/* stored. */
# if ALIGNMENT == 1
/* Fudge back pointer to be even. */
# define HIDE_BACK_PTR(p) HIDE_POINTER(~1 & (GC_word)(p))
# else
# define HIDE_BACK_PTR(p) HIDE_POINTER(p)
# endif
# ifdef ALIGN_DOUBLE
word oh_dummy;
# endif
# endif
GC_CONST char * oh_string; /* object descriptor string */
word oh_int; /* object descriptor integers */
# ifdef NEED_CALLINFO
struct callinfo oh_ci[NFRAMES];
# endif
# ifndef SHORT_DBG_HDRS
word oh_sz; /* Original malloc arg. */
word oh_sf; /* start flag */
# endif /* SHORT_DBG_HDRS */
} oh;
/* The size of the above structure is assumed not to dealign things, */
/* and to be a multiple of the word length. */
#ifdef SHORT_DBG_HDRS
# define DEBUG_BYTES (sizeof (oh))
#else
/* Add space for END_FLAG, but use any extra space that was already */
/* added to catch off-the-end pointers. */
# define DEBUG_BYTES (sizeof (oh) + sizeof (word) - EXTRA_BYTES)
#endif
#define USR_PTR_FROM_BASE(p) ((ptr_t)(p) + sizeof(oh))
/* Round bytes to words without adding extra byte at end. */
#define SIMPLE_ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
#ifdef SAVE_CALL_CHAIN
# define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
# define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
#else
# ifdef GC_ADD_CALLER
# define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
# define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
# else
# define ADD_CALL_CHAIN(base, ra)
# define PRINT_CALL_CHAIN(base)
# endif
#endif
# ifdef GC_ADD_CALLER
# define OPT_RA ra,
# else
# define OPT_RA
# endif
/* Check whether object with base pointer p has debugging info */
/* p is assumed to point to a legitimate object in our part */
/* of the heap. */
#ifdef SHORT_DBG_HDRS
# define GC_has_other_debug_info(p) TRUE
#else
GC_bool GC_has_other_debug_info(/* p */);
#endif
#ifdef KEEP_BACK_PTRS
# define GC_HAS_DEBUG_INFO(p) \
((((oh *)p)->oh_back_ptr & 1) && GC_has_other_debug_info(p))
#else
# define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
#endif
/* Store debugging info into p. Return displaced pointer. */
/* Assumes we don't hold allocation lock. */
ptr_t GC_store_debug_info(/* p, sz, string, integer */);
#endif /* _DBG_MLC_H */
+98
View File
@@ -24,6 +24,15 @@ typedef struct hblkhdr hdr;
* The 2 level tree data structure that is used to find block headers.
* If there are more than 32 bits in a pointer, the top level is a hash
* table.
*
* This defines HDR, GET_HDR, and SET_HDR, the main macros used to
* retrieve and set object headers.
*
* Since 5.0 alpha 5, we can also take advantage of a header lookup
* cache. This is a locally declared direct mapped cache, used inside
* the marker. The HC_GET_HDR macro uses and maintains this
* cache. Assuming we get reasonable hit rates, this shaves a few
* memory references from each pointer validation.
*/
# if CPP_WORDSZ > 32
@@ -45,6 +54,95 @@ typedef struct hblkhdr hdr;
# define TOP_SZ (1 << LOG_TOP_SZ)
# define BOTTOM_SZ (1 << LOG_BOTTOM_SZ)
#ifndef SMALL_CONFIG
# define USE_HDR_CACHE
#endif
/* #define COUNT_HDR_CACHE_HITS */
extern hdr * GC_invalid_header; /* header for an imaginary block */
/* containing no objects. */
/* Check whether p and corresponding hhdr point to long or invalid */
/* object. If so, advance hhdr to */
/* beginning of block, or set hhdr to GC_invalid_header. */
#define ADVANCE(p, hhdr, source) \
{ \
hdr * new_hdr = GC_invalid_header; \
p = GC_FIND_START(p, hhdr, &new_hdr, (word)source); \
hhdr = new_hdr; \
}
#ifdef USE_HDR_CACHE
# ifdef COUNT_HDR_CACHE_HITS
extern word GC_hdr_cache_hits;
extern word GC_hdr_cache_misses;
# define HC_HIT() ++GC_hdr_cache_hits
# define HC_MISS() ++GC_hdr_cache_misses
# else
# define HC_HIT()
# define HC_MISS()
# endif
typedef struct hce {
word block_addr; /* right shifted by LOG_HBLKSIZE */
hdr * hce_hdr;
} hdr_cache_entry;
# define HDR_CACHE_SIZE 8 /* power of 2 */
# define DECLARE_HDR_CACHE \
hdr_cache_entry hdr_cache[HDR_CACHE_SIZE]
# define INIT_HDR_CACHE BZERO(hdr_cache, sizeof(hdr_cache));
# define HCE(h) hdr_cache + (((word)(h) >> LOG_HBLKSIZE) & (HDR_CACHE_SIZE-1))
# define HCE_VALID_FOR(hce,h) ((hce) -> block_addr == \
((word)(h) >> LOG_HBLKSIZE))
# define HCE_HDR(h) ((hce) -> hce_hdr)
/* Analogous to GET_HDR, except that in the case of large objects, it */
/* Returns the header for the object beginning, and updates p. */
/* Returns &GC_bad_header instead of 0. All of this saves a branch */
/* in the fast path. */
# define HC_GET_HDR(p, hhdr, source) \
{ \
hdr_cache_entry * hce = HCE(p); \
if (HCE_VALID_FOR(hce, p)) { \
HC_HIT(); \
hhdr = hce -> hce_hdr; \
} else { \
HC_MISS(); \
GET_HDR(p, hhdr); \
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { \
ADVANCE(p, hhdr, source); \
} else { \
hce -> block_addr = (word)(p) >> LOG_HBLKSIZE; \
hce -> hce_hdr = hhdr; \
} \
} \
}
#else /* !USE_HDR_CACHE */
# define DECLARE_HDR_CACHE
# define INIT_HDR_CACHE
# define HC_GET_HDR(p, hhdr, source) \
{ \
GET_HDR(p, hhdr); \
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { \
ADVANCE(p, hhdr, source); \
} \
}
#endif
typedef struct bi {
hdr * index[BOTTOM_SZ];
/*
+481
View File
@@ -0,0 +1,481 @@
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. 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.
*/
#ifndef GC_LOCKS_H
#define GC_LOCKS_H
/*
* Mutual exclusion between allocator/collector routines.
* Needed if there is more than one allocator thread.
* FASTLOCK() is assumed to try to acquire the lock in a cheap and
* dirty way that is acceptable for a few instructions, e.g. by
* inhibiting preemption. This is assumed to have succeeded only
* if a subsequent call to FASTLOCK_SUCCEEDED() returns TRUE.
* FASTUNLOCK() is called whether or not FASTLOCK_SUCCEEDED().
* If signals cannot be tolerated with the FASTLOCK held, then
* FASTLOCK should disable signals. The code executed under
* FASTLOCK is otherwise immune to interruption, provided it is
* not restarted.
* DCL_LOCK_STATE declares any local variables needed by LOCK and UNLOCK
* and/or DISABLE_SIGNALS and ENABLE_SIGNALS and/or FASTLOCK.
* (There is currently no equivalent for FASTLOCK.)
*
* In the PARALLEL_MARK case, we also need to define a number of
* other inline finctions here:
* GC_bool GC_compare_and_exchange( volatile GC_word *addr,
* GC_word old, GC_word new )
* GC_word GC_atomic_add( volatile GC_word *addr, GC_word how_much )
* void GC_memory_barrier( )
*
*/
# ifdef THREADS
void GC_noop1 GC_PROTO((word));
# ifdef PCR_OBSOLETE /* Faster, but broken with multiple lwp's */
# include "th/PCR_Th.h"
# include "th/PCR_ThCrSec.h"
extern struct PCR_Th_MLRep GC_allocate_ml;
# define DCL_LOCK_STATE PCR_sigset_t GC_old_sig_mask
# define LOCK() PCR_Th_ML_Acquire(&GC_allocate_ml)
# define UNLOCK() PCR_Th_ML_Release(&GC_allocate_ml)
# define UNLOCK() PCR_Th_ML_Release(&GC_allocate_ml)
# define FASTLOCK() PCR_ThCrSec_EnterSys()
/* Here we cheat (a lot): */
# define FASTLOCK_SUCCEEDED() (*(int *)(&GC_allocate_ml) == 0)
/* TRUE if nobody currently holds the lock */
# define FASTUNLOCK() PCR_ThCrSec_ExitSys()
# endif
# ifdef PCR
# include <base/PCR_Base.h>
# include <th/PCR_Th.h>
extern PCR_Th_ML GC_allocate_ml;
# define DCL_LOCK_STATE \
PCR_ERes GC_fastLockRes; PCR_sigset_t GC_old_sig_mask
# define LOCK() PCR_Th_ML_Acquire(&GC_allocate_ml)
# define UNLOCK() PCR_Th_ML_Release(&GC_allocate_ml)
# define FASTLOCK() (GC_fastLockRes = PCR_Th_ML_Try(&GC_allocate_ml))
# define FASTLOCK_SUCCEEDED() (GC_fastLockRes == PCR_ERes_okay)
# define FASTUNLOCK() {\
if( FASTLOCK_SUCCEEDED() ) PCR_Th_ML_Release(&GC_allocate_ml); }
# endif
# ifdef SRC_M3
extern GC_word RT0u__inCritical;
# define LOCK() RT0u__inCritical++
# define UNLOCK() RT0u__inCritical--
# endif
# ifdef SOLARIS_THREADS
# include <thread.h>
# include <signal.h>
extern mutex_t GC_allocate_ml;
# define LOCK() mutex_lock(&GC_allocate_ml);
# define UNLOCK() mutex_unlock(&GC_allocate_ml);
# endif
/* Try to define GC_TEST_AND_SET and a matching GC_CLEAR for spin lock */
/* acquisition and release. We need this for correct operation of the */
/* incremental GC. */
# ifdef __GNUC__
# if defined(I386)
inline static int GC_test_and_set(volatile unsigned int *addr) {
int oldval;
/* Note: the "xchg" instruction does not need a "lock" prefix */
__asm__ __volatile__("xchgl %0, %1"
: "=r"(oldval), "=m"(*(addr))
: "0"(1), "m"(*(addr)) : "memory");
return oldval;
}
# define GC_TEST_AND_SET_DEFINED
# endif
# if defined(IA64)
inline static int GC_test_and_set(volatile unsigned int *addr) {
long oldval, n = 1;
__asm__ __volatile__("xchg4 %0=%1,%2"
: "=r"(oldval), "=m"(*addr)
: "r"(n), "1"(*addr) : "memory");
return oldval;
}
# define GC_TEST_AND_SET_DEFINED
/* Should this handle post-increment addressing?? */
inline static void GC_clear(volatile unsigned int *addr) {
__asm__ __volatile__("st4.rel %0=r0" : "=m" (*addr) : : "memory");
}
# define GC_CLEAR_DEFINED
# endif
# ifdef SPARC
inline static int GC_test_and_set(volatile unsigned int *addr) {
int oldval;
__asm__ __volatile__("ldstub %1,%0"
: "=r"(oldval), "=m"(*addr)
: "m"(*addr) : "memory");
return oldval;
}
# define GC_TEST_AND_SET_DEFINED
# endif
# ifdef M68K
/* Contributed by Tony Mantler. I'm not sure how well it was */
/* tested. */
inline static int GC_test_and_set(volatile unsigned int *addr) {
char oldval; /* this must be no longer than 8 bits */
/* The return value is semi-phony. */
/* 'tas' sets bit 7 while the return */
/* value pretends bit 0 was set */
__asm__ __volatile__(
"tas %1@; sne %0; negb %0"
: "=d" (oldval)
: "a" (addr) : "memory");
return oldval;
}
# define GC_TEST_AND_SET_DEFINED
# endif
# if defined(POWERPC)
inline static int GC_test_and_set(volatile unsigned int *addr) {
int oldval;
int temp = 1; // locked value
__asm__ __volatile__(
"1:\tlwarx %0,0,%3\n" // load and reserve
"\tcmpwi %0, 0\n" // if load is
"\tbne 2f\n" // non-zero, return already set
"\tstwcx. %2,0,%1\n" // else store conditional
"\tbne- 1b\n" // retry if lost reservation
"2:\t\n" // oldval is zero if we set
: "=&r"(oldval), "=p"(addr)
: "r"(temp), "1"(addr)
: "memory");
return (int)oldval;
}
# define GC_TEST_AND_SET_DEFINED
inline static void GC_clear(volatile unsigned int *addr) {
__asm__ __volatile__("eieio" ::: "memory");
*(addr) = 0;
}
# define GC_CLEAR_DEFINED
# endif
# if defined(ALPHA)
inline static int GC_test_and_set(volatile unsigned int * addr)
{
unsigned long oldvalue;
unsigned long temp;
__asm__ __volatile__(
"1: ldl_l %0,%1\n"
" and %0,%3,%2\n"
" bne %2,2f\n"
" xor %0,%3,%0\n"
" stl_c %0,%1\n"
" beq %0,3f\n"
" mb\n"
"2:\n"
".section .text2,\"ax\"\n"
"3: br 1b\n"
".previous"
:"=&r" (temp), "=m" (*addr), "=&r" (oldvalue)
:"Ir" (1), "m" (*addr)
:"memory");
return oldvalue;
}
# define GC_TEST_AND_SET_DEFINED
/* Should probably also define GC_clear, since it needs */
/* a memory barrier ?? */
# endif /* ALPHA */
# ifdef ARM32
inline static int GC_test_and_set(volatile unsigned int *addr) {
int oldval;
/* SWP on ARM is very similar to XCHG on x86. Doesn't lock the
* bus because there are no SMP ARM machines. If/when there are,
* this code will likely need to be updated. */
/* See linuxthreads/sysdeps/arm/pt-machine.h in glibc-2.1 */
__asm__ __volatile__("swp %0, %1, [%2]"
: "=r"(oldval)
: "r"(1), "r"(addr)
: "memory");
return oldval;
}
# define GC_TEST_AND_SET_DEFINED
# endif /* ARM32 */
# endif /* __GNUC__ */
# if (defined(ALPHA) && !defined(__GNUC__))
# define GC_test_and_set(addr) __cxx_test_and_set_atomic(addr, 1)
# define GC_TEST_AND_SET_DEFINED
# endif
# if defined(MSWIN32)
# define GC_test_and_set(addr) InterlockedExchange((LPLONG)addr,1)
# define GC_TEST_AND_SET_DEFINED
# endif
# ifdef MIPS
# if __mips < 3 || !(defined (_ABIN32) || defined(_ABI64)) \
|| !defined(_COMPILER_VERSION) || _COMPILER_VERSION < 700
# define GC_test_and_set(addr, v) test_and_set(addr,v)
# else
# define GC_test_and_set(addr, v) __test_and_set(addr,v)
# define GC_clear(addr) __lock_release(addr);
# define GC_CLEAR_DEFINED
# endif
# define GC_TEST_AND_SET_DEFINED
# endif /* MIPS */
# if 0 /* defined(HP_PA) */
/* The official recommendation seems to be to not use ldcw from */
/* user mode. Since multithreaded incremental collection doesn't */
/* work anyway on HP_PA, this shouldn't be a major loss. */
/* "set" means 0 and "clear" means 1 here. */
# define GC_test_and_set(addr) !GC_test_and_clear(addr);
# define GC_TEST_AND_SET_DEFINED
# define GC_clear(addr) GC_noop1((word)(addr)); *(volatile unsigned int *)addr = 1;
/* The above needs a memory barrier! */
# define GC_CLEAR_DEFINED
# endif
# if defined(GC_TEST_AND_SET_DEFINED) && !defined(GC_CLEAR_DEFINED)
# ifdef __GNUC__
inline static void GC_clear(volatile unsigned int *addr) {
/* Try to discourage gcc from moving anything past this. */
__asm__ __volatile__(" " : : : "memory");
*(addr) = 0;
}
# else
/* The function call in the following should prevent the */
/* compiler from moving assignments to below the UNLOCK. */
# define GC_clear(addr) GC_noop1((word)(addr)); \
*((volatile unsigned int *)(addr)) = 0;
# endif
# define GC_CLEAR_DEFINED
# endif /* !GC_CLEAR_DEFINED */
# if !defined(GC_TEST_AND_SET_DEFINED)
# define USE_PTHREAD_LOCKS
# endif
# if defined(LINUX_THREADS) || defined(OSF1_THREADS) \
|| defined(HPUX_THREADS)
# define NO_THREAD (pthread_t)(-1)
# include <pthread.h>
# if defined(PARALLEL_MARK)
/* We need compare-and-swap to update mark bits, where it's */
/* performance critical. If USE_MARK_BYTES is defined, it is */
/* no longer needed for this purpose. However we use it in */
/* either case to implement atomic fetch-and-add, though that's */
/* less performance critical, and could perhaps be done with */
/* a lock. */
# if defined(GENERIC_COMPARE_AND_SWAP)
/* Probably not useful, except for debugging. */
/* We do use GENERIC_COMPARE_AND_SWAP on PA_RISC, but we */
/* minimize its use. */
extern pthread_mutex_t GC_compare_and_swap_lock;
/* Note that if GC_word updates are not atomic, a concurrent */
/* reader should acquire GC_compare_and_swap_lock. On */
/* currently supported platforms, such updates are atomic. */
extern GC_bool GC_compare_and_exchange(volatile GC_word *addr,
GC_word old, GC_word new_val);
# endif /* GENERIC_COMPARE_AND_SWAP */
# if defined(I386)
# if !defined(GENERIC_COMPARE_AND_SWAP)
/* Returns TRUE if the comparison succeeded. */
inline static GC_bool GC_compare_and_exchange(volatile GC_word *addr,
GC_word old,
GC_word new_val)
{
char result;
__asm__ __volatile__("lock; cmpxchgl %2, %0; setz %1"
: "=m"(*(addr)), "=r"(result)
: "r" (new_val), "0"(*(addr)), "a"(old) : "memory");
return (GC_bool) result;
}
# endif /* !GENERIC_COMPARE_AND_SWAP */
inline static void GC_memory_write_barrier()
{
/* We believe the processor ensures at least processor */
/* consistent ordering. Thus a compiler barrier */
/* should suffice. */
__asm__ __volatile__("" : : : "memory");
}
# endif /* I386 */
# if defined(IA64)
# if !defined(GENERIC_COMPARE_AND_SWAP)
inline static GC_bool GC_compare_and_exchange(volatile GC_word *addr,
GC_word old, GC_word new_val)
{
unsigned long oldval;
__asm__ __volatile__("mov ar.ccv=%4 ;; cmpxchg8.rel %0=%1,%2,ar.ccv"
: "=r"(oldval), "=m"(*addr)
: "r"(new_val), "1"(*addr), "r"(old) : "memory");
return (oldval == old);
}
# endif /* !GENERIC_COMPARE_AND_SWAP */
# if 0
/* Shouldn't be needed; we use volatile stores instead. */
inline static void GC_memory_write_barrier()
{
__asm__ __volatile__("mf" : : : "memory");
}
# endif /* 0 */
# endif /* IA64 */
# if !defined(GENERIC_COMPARE_AND_SWAP)
/* Returns the original value of *addr. */
inline static GC_word GC_atomic_add(volatile GC_word *addr,
GC_word how_much)
{
GC_word old;
do {
old = *addr;
} while (!GC_compare_and_exchange(addr, old, old+how_much));
return old;
}
# else /* GENERIC_COMPARE_AND_SWAP */
/* So long as a GC_word can be atomically updated, it should */
/* be OK to read *addr without a lock. */
extern GC_word GC_atomic_add(volatile GC_word *addr, GC_word how_much);
# endif /* GENERIC_COMPARE_AND_SWAP */
# endif /* PARALLEL_MARK */
# if !defined(THREAD_LOCAL_ALLOC) && !defined(USE_PTHREAD_LOCKS)
/* In the THREAD_LOCAL_ALLOC case, the allocation lock tends to */
/* be held for long periods, if it is held at all. Thus spinning */
/* and sleeping for fixed periods are likely to result in */
/* significant wasted time. We thus rely mostly on queued locks. */
# define USE_SPIN_LOCK
extern volatile unsigned int GC_allocate_lock;
extern void GC_lock(void);
/* Allocation lock holder. Only set if acquired by client through */
/* GC_call_with_alloc_lock. */
# ifdef GC_ASSERTIONS
# define LOCK() \
{ if (GC_test_and_set(&GC_allocate_lock)) GC_lock(); \
SET_LOCK_HOLDER(); }
# define UNLOCK() \
{ GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \
GC_clear(&GC_allocate_lock); }
# else
# define LOCK() \
{ if (GC_test_and_set(&GC_allocate_lock)) GC_lock(); }
# define UNLOCK() \
GC_clear(&GC_allocate_lock)
# endif /* !GC_ASSERTIONS */
# if 0
/* Another alternative for OSF1 might be: */
# include <sys/mman.h>
extern msemaphore GC_allocate_semaphore;
# define LOCK() { if (msem_lock(&GC_allocate_semaphore, MSEM_IF_NOWAIT) \
!= 0) GC_lock(); else GC_allocate_lock = 1; }
/* The following is INCORRECT, since the memory model is too weak. */
/* Is this true? Presumably msem_unlock has the right semantics? */
/* - HB */
# define UNLOCK() { GC_allocate_lock = 0; \
msem_unlock(&GC_allocate_semaphore, 0); }
# endif /* 0 */
# else /* THREAD_LOCAL_ALLOC || USE_PTHREAD_LOCKS */
# ifndef USE_PTHREAD_LOCKS
# define USE_PTHREAD_LOCKS
# endif
# endif /* THREAD_LOCAL_ALLOC */
# ifdef USE_PTHREAD_LOCKS
# include <pthread.h>
extern pthread_mutex_t GC_allocate_ml;
# ifdef GC_ASSERTIONS
# define LOCK() \
{ GC_lock(); \
SET_LOCK_HOLDER(); }
# define UNLOCK() \
{ GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \
pthread_mutex_unlock(&GC_allocate_ml); }
# else /* !GC_ASSERTIONS */
# define LOCK() \
{ if (0 != pthread_mutex_trylock(&GC_allocate_ml)) GC_lock(); }
# define UNLOCK() pthread_mutex_unlock(&GC_allocate_ml)
# endif /* !GC_ASSERTIONS */
# endif /* USE_PTHREAD_LOCKS */
# define SET_LOCK_HOLDER() GC_lock_holder = pthread_self()
# define UNSET_LOCK_HOLDER() GC_lock_holder = NO_THREAD
# define I_HOLD_LOCK() (pthread_equal(GC_lock_holder, pthread_self()))
extern VOLATILE GC_bool GC_collecting;
# define ENTER_GC() GC_collecting = 1;
# define EXIT_GC() GC_collecting = 0;
extern void GC_lock(void);
extern pthread_t GC_lock_holder;
# ifdef GC_ASSERTIONS
extern pthread_t GC_mark_lock_holder;
# endif
# endif /* LINUX_THREADS || OSF1_THREADS || HPUX_THREADS */
# if defined(IRIX_THREADS)
# include <pthread.h>
/* This probably should never be included, but I can't test */
/* on Irix anymore. */
# include <mutex.h>
extern unsigned long GC_allocate_lock;
/* This is not a mutex because mutexes that obey the (optional) */
/* POSIX scheduling rules are subject to convoys in high contention */
/* applications. This is basically a spin lock. */
extern pthread_t GC_lock_holder;
extern void GC_lock(void);
/* Allocation lock holder. Only set if acquired by client through */
/* GC_call_with_alloc_lock. */
# define SET_LOCK_HOLDER() GC_lock_holder = pthread_self()
# define NO_THREAD (pthread_t)(-1)
# define UNSET_LOCK_HOLDER() GC_lock_holder = NO_THREAD
# define I_HOLD_LOCK() (pthread_equal(GC_lock_holder, pthread_self()))
# define LOCK() { if (GC_test_and_set(&GC_allocate_lock, 1)) GC_lock(); }
# define UNLOCK() GC_clear(&GC_allocate_lock);
extern VOLATILE GC_bool GC_collecting;
# define ENTER_GC() \
{ \
GC_collecting = 1; \
}
# define EXIT_GC() GC_collecting = 0;
# endif /* IRIX_THREADS */
# ifdef WIN32_THREADS
# include <windows.h>
GC_API CRITICAL_SECTION GC_allocate_ml;
# define LOCK() EnterCriticalSection(&GC_allocate_ml);
# define UNLOCK() LeaveCriticalSection(&GC_allocate_ml);
# endif
# ifndef SET_LOCK_HOLDER
# define SET_LOCK_HOLDER()
# define UNSET_LOCK_HOLDER()
# define I_HOLD_LOCK() FALSE
/* Used on platforms were locks can be reacquired, */
/* so it doesn't matter if we lie. */
# endif
# else /* !THREADS */
# define LOCK()
# define UNLOCK()
# endif /* !THREADS */
# ifndef SET_LOCK_HOLDER
# define SET_LOCK_HOLDER()
# define UNSET_LOCK_HOLDER()
# define I_HOLD_LOCK() FALSE
/* Used on platforms were locks can be reacquired, */
/* so it doesn't matter if we lie. */
# endif
# ifndef ENTER_GC
# define ENTER_GC()
# define EXIT_GC()
# endif
# ifndef DCL_LOCK_STATE
# define DCL_LOCK_STATE
# endif
# ifndef FASTLOCK
# define FASTLOCK() LOCK()
# define FASTLOCK_SUCCEEDED() TRUE
# define FASTUNLOCK() UNLOCK()
# endif
#endif /* GC_LOCKS_H */
+388
View File
@@ -0,0 +1,388 @@
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 2001 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.
*
*/
/* Private declarations of GC marker data structures and macros */
/*
* Declarations of mark stack. Needed by marker and client supplied mark
* routines. Transitively include gc_priv.h.
* (Note that gc_priv.h should not be included before this, since this
* includes dbg_mlc.h, which wants to include gc_priv.h AFTER defining
* I_HIDE_POINTERS.)
*/
#ifndef GC_PMARK_H
# define GC_PMARK_H
# if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST)
# include "dbg_mlc.h"
# endif
# ifndef GC_MARK_H
# include "../gc_mark.h"
# endif
# ifndef GC_PRIVATE_H
# include "gc_priv.h"
# endif
/* The real declarations of the following is in gc_priv.h, so that */
/* we can avoid scanning the following table. */
/*
extern mark_proc GC_mark_procs[MAX_MARK_PROCS];
*/
/*
* Mark descriptor stuff that should remain private for now, mostly
* because it's hard to export WORDSZ without including gcconfig.h.
*/
# define BITMAP_BITS (WORDSZ - GC_DS_TAG_BITS)
# define PROC(descr) \
(GC_mark_procs[((descr) >> GC_DS_TAG_BITS) & (GC_MAX_MARK_PROCS-1)])
# define ENV(descr) \
((descr) >> (GC_DS_TAG_BITS + GC_LOG_MAX_MARK_PROCS))
# define MAX_ENV \
(((word)1 << (WORDSZ - GC_DS_TAG_BITS - GC_LOG_MAX_MARK_PROCS)) - 1)
extern word GC_n_mark_procs;
/* Number of mark stack entries to discard on overflow. */
#define GC_MARK_STACK_DISCARDS (INITIAL_MARK_STACK_SIZE/8)
typedef struct GC_ms_entry {
GC_word * mse_start; /* First word of object */
GC_word mse_descr; /* Descriptor; low order two bits are tags, */
/* identifying the upper 30 bits as one of the */
/* following: */
} mse;
extern word GC_mark_stack_size;
extern mse * GC_mark_stack_limit;
#ifdef PARALLEL_MARK
extern mse * VOLATILE GC_mark_stack_top;
#else
extern mse * GC_mark_stack_top;
#endif
extern mse * GC_mark_stack;
#ifdef PARALLEL_MARK
/*
* Allow multiple threads to participate in the marking process.
* This works roughly as follows:
* The main mark stack never shrinks, but it can grow.
*
* The initiating threads holds the GC lock, and sets GC_help_wanted.
*
* Other threads:
* 1) update helper_count (while holding mark_lock.)
* 2) allocate a local mark stack
* repeatedly:
* 3) Steal a global mark stack entry by atomically replacing
* its descriptor with 0.
* 4) Copy it to the local stack.
* 5) Mark on the local stack until it is empty, or
* it may be profitable to copy it back.
* 6) If necessary, copy local stack to global one,
* holding mark lock.
* 7) Stop when the global mark stack is empty.
* 8) decrement helper_count (holding mark_lock).
*
* This is an experiment to see if we can do something along the lines
* of the University of Tokyo SGC in a less intrusive, though probably
* also less performant, way.
*/
void GC_do_parallel_mark();
/* inititate parallel marking. */
extern GC_bool GC_help_wanted; /* Protected by mark lock */
extern unsigned GC_helper_count; /* Number of running helpers. */
/* Protected by mark lock */
extern unsigned GC_active_count; /* Number of active helpers. */
/* Protected by mark lock */
/* May increase and decrease */
/* within each mark cycle. But */
/* once it returns to 0, it */
/* stays zero for the cycle. */
/* GC_mark_stack_top is also protected by mark lock. */
extern mse * VOLATILE GC_first_nonempty;
/* Lowest entry on mark stack */
/* that may be nonempty. */
/* Updated only by initiating */
/* thread. */
/*
* GC_notify_all_marker() is used when GC_help_wanted is first set,
* when the last helper becomes inactive,
* when something is added to the global mark stack, and just after
* GC_mark_no is incremented.
* This could be split into multiple CVs (and probably should be to
* scale to really large numbers of processors.)
*/
#endif /* PARALLEL_MARK */
/* Return a pointer to within 1st page of object. */
/* Set *new_hdr_p to corr. hdr. */
#ifdef __STDC__
# ifdef PRINT_BLACK_LIST
ptr_t GC_find_start(ptr_t current, hdr *hhdr, hdr **new_hdr_p, word source);
# else
ptr_t GC_find_start(ptr_t current, hdr *hhdr, hdr **new_hdr_p);
# endif
#else
ptr_t GC_find_start();
#endif
mse * GC_signal_mark_stack_overflow();
# ifdef GATHERSTATS
# define ADD_TO_ATOMIC(sz) GC_atomic_in_use += (sz)
# define ADD_TO_COMPOSITE(sz) GC_composite_in_use += (sz)
# else
# define ADD_TO_ATOMIC(sz)
# define ADD_TO_COMPOSITE(sz)
# endif
/* Push the object obj with corresponding heap block header hhdr onto */
/* the mark stack. */
# define PUSH_OBJ(obj, hhdr, mark_stack_top, mark_stack_limit) \
{ \
register word _descr = (hhdr) -> hb_descr; \
\
if (_descr == 0) { \
ADD_TO_ATOMIC((hhdr) -> hb_sz); \
} else { \
ADD_TO_COMPOSITE((hhdr) -> hb_sz); \
mark_stack_top++; \
if (mark_stack_top >= mark_stack_limit) { \
mark_stack_top = GC_signal_mark_stack_overflow(mark_stack_top); \
} \
mark_stack_top -> mse_start = (obj); \
mark_stack_top -> mse_descr = _descr; \
} \
}
#ifdef PRINT_BLACK_LIST
# define GC_FIND_START(current, hhdr, new_hdr_p, source) \
GC_find_start(current, hhdr, new_hdr_p, source)
#else
# define GC_FIND_START(current, hhdr, new_hdr_p, source) \
GC_find_start(current, hhdr, new_hdr_p)
#endif
/* Push the contents of current onto the mark stack if it is a valid */
/* ptr to a currently unmarked object. Mark it. */
/* If we assumed a standard-conforming compiler, we could probably */
/* generate the exit_label transparently. */
# define PUSH_CONTENTS(current, mark_stack_top, mark_stack_limit, \
source, exit_label) \
{ \
hdr * my_hhdr; \
ptr_t my_current = current; \
\
GET_HDR(my_current, my_hhdr); \
if (IS_FORWARDING_ADDR_OR_NIL(my_hhdr)) { \
hdr * new_hdr = GC_invalid_header; \
my_current = GC_FIND_START(my_current, my_hhdr, \
&new_hdr, (word)source); \
my_hhdr = new_hdr; \
} \
PUSH_CONTENTS_HDR(my_current, mark_stack_top, mark_stack_limit, \
source, exit_label, my_hhdr); \
exit_label: ; \
}
/* As above, but use header cache for header lookup. */
# define HC_PUSH_CONTENTS(current, mark_stack_top, mark_stack_limit, \
source, exit_label) \
{ \
hdr * my_hhdr; \
ptr_t my_current = current; \
\
HC_GET_HDR(my_current, my_hhdr, source); \
PUSH_CONTENTS_HDR(my_current, mark_stack_top, mark_stack_limit, \
source, exit_label, my_hhdr); \
exit_label: ; \
}
/* Set mark bit, exit if it was already set. */
# ifdef USE_MARK_BYTES
/* Unlike the mark bit case, there is a race here, and we may set */
/* the bit twice in the concurrent case. This can result in the */
/* object being pushed twice. But that's only a performance issue. */
# define SET_MARK_BIT_EXIT_IF_SET(hhdr,displ,exit_label) \
{ \
register VOLATILE char * mark_byte_addr = \
hhdr -> hb_marks + ((displ) >> 1); \
register char mark_byte = *mark_byte_addr; \
\
if (mark_byte) goto exit_label; \
*mark_byte_addr = 1; \
}
# else
# define SET_MARK_BIT_EXIT_IF_SET(hhdr,displ,exit_label) \
{ \
register word * mark_word_addr = hhdr -> hb_marks + divWORDSZ(displ); \
register word mark_word = *mark_word_addr; \
\
OR_WORD_EXIT_IF_SET(mark_word_addr, (word)1 << modWORDSZ(displ), \
exit_label); \
}
# endif /* USE_MARK_BYTES */
/* If the mark bit corresponding to current is not set, set it, and */
/* push the contents of the object on the mark stack. For a small */
/* object we assume that current is the (possibly interior) pointer */
/* to the object. For large objects we assume that current points */
/* to somewhere inside the first page of the object. If */
/* GC_all_interior_pointers is set, it may have been previously */
/* adjusted to make that true. */
# define PUSH_CONTENTS_HDR(current, mark_stack_top, mark_stack_limit, \
source, exit_label, hhdr) \
{ \
int displ; /* Displacement in block; first bytes, then words */ \
int map_entry; \
\
displ = HBLKDISPL(current); \
map_entry = MAP_ENTRY((hhdr -> hb_map), displ); \
displ = BYTES_TO_WORDS(displ); \
if (map_entry > CPP_MAX_OFFSET) { \
if (map_entry == OFFSET_TOO_BIG) { \
map_entry = displ % (hhdr -> hb_sz); \
displ -= map_entry; \
if (displ + (hhdr -> hb_sz) > BYTES_TO_WORDS(HBLKSIZE)) { \
GC_ADD_TO_BLACK_LIST_NORMAL((word)current, source); \
goto exit_label; \
} \
} else { \
GC_ADD_TO_BLACK_LIST_NORMAL((word)current, source); goto exit_label; \
} \
} else { \
displ -= map_entry; \
} \
GC_ASSERT(displ >= 0 && displ < MARK_BITS_PER_HBLK); \
SET_MARK_BIT_EXIT_IF_SET(hhdr, displ, exit_label); \
GC_STORE_BACK_PTR((ptr_t)source, (ptr_t)HBLKPTR(current) \
+ WORDS_TO_BYTES(displ)); \
PUSH_OBJ(((word *)(HBLKPTR(current)) + displ), hhdr, \
mark_stack_top, mark_stack_limit) \
}
#if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
# define PUSH_ONE_CHECKED_STACK(p, source) \
GC_mark_and_push_stack(p, (ptr_t)(source))
#else
# define PUSH_ONE_CHECKED_STACK(p, source) \
GC_mark_and_push_stack(p)
#endif
/*
* Push a single value onto mark stack. Mark from the object pointed to by p.
* P is considered valid even if it is an interior pointer.
* Previously marked objects are not pushed. Hence we make progress even
* if the mark stack overflows.
*/
# define GC_PUSH_ONE_STACK(p, source) \
if ((ptr_t)(p) >= (ptr_t)GC_least_plausible_heap_addr \
&& (ptr_t)(p) < (ptr_t)GC_greatest_plausible_heap_addr) { \
PUSH_ONE_CHECKED_STACK(p, source); \
}
/*
* As above, but interior pointer recognition as for
* normal for heap pointers.
*/
# define GC_PUSH_ONE_HEAP(p,source) \
if ((ptr_t)(p) >= (ptr_t)GC_least_plausible_heap_addr \
&& (ptr_t)(p) < (ptr_t)GC_greatest_plausible_heap_addr) { \
GC_mark_stack_top = GC_mark_and_push( \
(GC_PTR)(p), GC_mark_stack_top, \
GC_mark_stack_limit, (GC_PTR *)(source)); \
}
/* Mark starting at mark stack entry top (incl.) down to */
/* mark stack entry bottom (incl.). Stop after performing */
/* about one page worth of work. Return the new mark stack */
/* top entry. */
mse * GC_mark_from GC_PROTO((mse * top, mse * bottom, mse *limit));
#define MARK_FROM_MARK_STACK() \
GC_mark_stack_top = GC_mark_from(GC_mark_stack_top, \
GC_mark_stack, \
GC_mark_stack + GC_mark_stack_size);
/*
* Mark from one finalizable object using the specified
* mark proc. May not mark the object pointed to by
* real_ptr. That is the job of the caller, if appropriate
*/
# define GC_MARK_FO(real_ptr, mark_proc) \
{ \
(*(mark_proc))(real_ptr); \
while (!GC_mark_stack_empty()) MARK_FROM_MARK_STACK(); \
if (GC_mark_state != MS_NONE) { \
GC_set_mark_bit(real_ptr); \
while (!GC_mark_some((ptr_t)0)) {} \
} \
}
extern GC_bool GC_mark_stack_too_small;
/* We need a larger mark stack. May be */
/* set by client supplied mark routines.*/
typedef int mark_state_t; /* Current state of marking, as follows:*/
/* Used to remember where we are during */
/* concurrent marking. */
/* We say something is dirty if it was */
/* written since the last time we */
/* retrieved dirty bits. We say it's */
/* grungy if it was marked dirty in the */
/* last set of bits we retrieved. */
/* Invariant I: all roots and marked */
/* objects p are either dirty, or point */
/* to objects q that are either marked */
/* or a pointer to q appears in a range */
/* on the mark stack. */
# define MS_NONE 0 /* No marking in progress. I holds. */
/* Mark stack is empty. */
# define MS_PUSH_RESCUERS 1 /* Rescuing objects are currently */
/* being pushed. I holds, except */
/* that grungy roots may point to */
/* unmarked objects, as may marked */
/* grungy objects above scan_ptr. */
# define MS_PUSH_UNCOLLECTABLE 2
/* I holds, except that marked */
/* uncollectable objects above scan_ptr */
/* may point to unmarked objects. */
/* Roots may point to unmarked objects */
# define MS_ROOTS_PUSHED 3 /* I holds, mark stack may be nonempty */
# define MS_PARTIALLY_INVALID 4 /* I may not hold, e.g. because of M.S. */
/* overflow. However marked heap */
/* objects below scan_ptr point to */
/* marked or stacked objects. */
# define MS_INVALID 5 /* I may not hold. */
extern mark_state_t GC_mark_state;
#endif /* GC_PMARK_H */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+34
View File
@@ -0,0 +1,34 @@
#ifdef SOLARIS_THREADS
/* The set of all known threads. We intercept thread creation and */
/* joins. We never actually create detached threads. We allocate all */
/* new thread stacks ourselves. These allow us to maintain this */
/* data structure. */
/* Protected by GC_thr_lock. */
/* Some of this should be declared volatile, but that's incosnsistent */
/* with some library routine declarations. In particular, the */
/* definition of cond_t doesn't mention volatile! */
typedef struct GC_Thread_Rep {
struct GC_Thread_Rep * next;
thread_t id;
word flags;
# define FINISHED 1 /* Thread has exited. */
# define DETACHED 2 /* Thread is intended to be detached. */
# define CLIENT_OWNS_STACK 4
/* Stack was supplied by client. */
# define SUSPENDED 8 /* Currently suspended. */
ptr_t stack;
size_t stack_size;
cond_t join_cv;
void * status;
} * GC_thread;
extern GC_thread GC_new_thread(thread_t id);
extern GC_bool GC_thr_initialized;
extern volatile GC_thread GC_threads[];
extern size_t GC_min_stack_sz;
extern size_t GC_page_sz;
extern void GC_thr_init(void);
# endif /* SOLARIS_THREADS */
+83
View File
@@ -0,0 +1,83 @@
/*
* This is a reimplementation of a subset of the pthread_getspecific/setspecific
* interface. This appears to outperform the standard linuxthreads one
* by a significant margin.
* The major restriction is that each thread may only make a single
* pthread_setspecific call on a single key. (The current data structure
* doesn't really require that. The restriction should be easily removable.)
* We don't currently support the destruction functions, though that
* could be done.
* We also currently assume that only one pthread_setspecific call
* can be executed at a time, though that assumption would be easy to remove
* by adding a lock.
*/
#include <errno.h>
/* Called during key creation or setspecific. */
/* For the GC we already hold lock. */
/* Currently allocated objects leak on thread exit. */
/* That's hard to fix, but OK if we allocate garbage */
/* collected memory. */
#define MALLOC_CLEAR(n) GC_INTERNAL_MALLOC(n, NORMAL)
#define PREFIXED(name) GC_##name
#define TS_CACHE_SIZE 1024
#define CACHE_HASH(n) (((((long)n) >> 8) ^ (long)n) & (TS_CACHE_SIZE - 1))
#define TS_HASH_SIZE 1024
#define HASH(n) (((((long)n) >> 8) ^ (long)n) & (TS_HASH_SIZE - 1))
typedef struct thread_specific_entry {
unsigned long qtid; /* quick thread id, only for cache */
void * value;
pthread_t thread;
struct thread_specific_entry *next;
} tse;
/* We represent each thread-specific datum as two tables. The first is */
/* a cache, index by a "quick thread identifier". The "quick" thread */
/* identifier is an easy to compute value, which is guaranteed to */
/* determine the thread, though a thread may correspond to more than */
/* one value. We typically use the address of a page in the stack. */
/* The second is a hash table, indexed by pthread_self(). It is used */
/* only as a backup. */
/* Return the "quick thread id". Default version. Assumes page size, */
/* or at least thread stack separation, is at least 4K. */
static __inline__ long quick_thread_id() {
int dummy;
return (long)(&dummy) >> 12;
}
#define INVALID_QTID ((unsigned long)(-1))
typedef struct thread_specific_data {
tse * volatile cache[TS_CACHE_SIZE];
/* A faster index to the hash table */
tse * hash[TS_HASH_SIZE];
pthread_mutex_t lock;
} tsd;
typedef tsd * PREFIXED(key_t);
extern int PREFIXED(key_create) (tsd ** key_ptr, void (* destructor)(void *));
extern int PREFIXED(setspecific) (tsd * key, void * value);
extern void PREFIXED(remove_specific) (tsd * key);
/* An internal version of getspecific that assumes a cache miss. */
void * PREFIXED(slow_getspecific) (tsd * key, unsigned long qtid,
tse * volatile * cache_entry);
static __inline__ void * PREFIXED(getspecific) (tsd * key) {
long qtid = quick_thread_id();
unsigned hash_val = CACHE_HASH(qtid);
tse * volatile * entry_ptr = key -> cache + hash_val;
tse * entry = *entry_ptr; /* Must be loaded only once. */
if (entry -> qtid == qtid) return entry -> value;
return PREFIXED(slow_getspecific) (key, qtid, entry_ptr);
}