# ifndef GC_PRIVATE_H
# define GC_PRIVATE_H
#include <gc_config.h>
#if defined(mips) && defined(SYSTYPE_BSD) && defined(sony_news)
# define BSD_TIME
#endif
#if defined(mips) && defined(SYSTYPE_BSD43)
# define BSD_TIME
#endif
#ifdef DGUX
# include <sys/types.h>
# include <sys/time.h>
# include <sys/resource.h>
#endif
#ifdef BSD_TIME
# include <sys/types.h>
# include <sys/time.h>
# include <sys/resource.h>
#endif
# ifndef _GC_H
# include "../gc.h"
# endif
# ifndef GC_MARK_H
# include "../gc_mark.h"
# endif
typedef GC_word word;
typedef GC_signed_word signed_word;
typedef int GC_bool;
# define TRUE 1
# define FALSE 0
typedef char * ptr_t;
# ifndef GCCONFIG_H
# include "gcconfig.h"
# endif
# ifndef HEADERS_H
# include "gc_hdrs.h"
# endif
#if defined(__STDC__)
# include <stdlib.h>
# if !(defined( sony_news ) )
# include <stddef.h>
# endif
# define VOLATILE volatile
#else
# ifdef MSWIN32
# include <stdlib.h>
# endif
# define VOLATILE
#endif
#if 0
# define EXPECT(expr, outcome) __builtin_expect(expr,outcome)
#else
# define EXPECT(expr, outcome) (expr)
#endif
# ifndef GC_LOCKS_H
# include "gc_locks.h"
# endif
# ifdef STACK_GROWS_DOWN
# define COOLER_THAN >
# define HOTTER_THAN <
# define MAKE_COOLER(x,y) if ((word)(x)+(y) > (word)(x)) {(x) += (y);} \
else {(x) = (word)ONES;}
# define MAKE_HOTTER(x,y) (x) -= (y)
# else
# define COOLER_THAN <
# define HOTTER_THAN >
# define MAKE_COOLER(x,y) if ((word)(x)-(y) < (word)(x)) {(x) -= (y);} else {(x) = 0;}
# define MAKE_HOTTER(x,y) (x) += (y)
# endif
#if defined(AMIGA) && defined(__SASC)
# define GC_FAR __far
#else
# define GC_FAR
#endif
#define PRINTSTATS
#define PRINTTIMES
#define PRINTBLOCKS
#undef PRINTBLOCKS
#ifdef SILENT
# ifdef PRINTSTATS
# undef PRINTSTATS
# endif
# ifdef PRINTTIMES
# undef PRINTTIMES
# endif
# ifdef PRINTNBLOCKS
# undef PRINTNBLOCKS
# endif
#endif
#if defined(PRINTSTATS) && !defined(GATHERSTATS)
# define GATHERSTATS
#endif
#if defined(PRINTSTATS) || !defined(SMALL_CONFIG)
# define CONDPRINT
#endif
#define GC_INVOKE_FINALIZERS() GC_notify_or_invoke_finalizers()
#define MERGE_SIZES
#if defined(USE_MARK_BYTES) && !defined(ALIGN_DOUBLE)
# define ALIGN_DOUBLE
#endif
#if defined(GC_GCJ_SUPPORT) && ALIGNMENT < 8 && !defined(ALIGN_DOUBLE)
# define ALIGN_DOUBLE
#endif
# if defined(ALIGN_DOUBLE) && !defined(MERGE_SIZES)
# define MERGE_SIZES
# endif
#if !defined(DONT_ADD_BYTE_AT_END)
# define EXTRA_BYTES GC_all_interior_pointers
#else
# define EXTRA_BYTES 0
#endif
# ifndef LARGE_CONFIG
# define MINHINCR 16
# define MAXHINCR 2048
# else
# define MINHINCR 64
# define MAXHINCR 4096
# endif
# define TIME_LIMIT 50
# define BL_LIMIT GC_black_list_spacing
#ifdef SAVE_CALL_CHAIN
struct callinfo;
void GC_save_callers GC_PROTO((struct callinfo info[NFRAMES]));
void GC_print_callers GC_PROTO((struct callinfo info[NFRAMES]));
#endif
#ifdef NEED_CALLINFO
struct callinfo {
word ci_pc;
# if NARGS > 0
word ci_arg[NARGS];
# endif
# if defined(ALIGN_DOUBLE) && (NFRAMES * (NARGS + 1)) % 2 == 1
word ci_dummy;
# endif
};
#endif
#ifdef BSD_TIME
# undef CLOCK_TYPE
# undef GET_TIME
# undef MS_TIME_DIFF
# define CLOCK_TYPE struct timeval
# define GET_TIME(x) { struct rusage rusage; \
getrusage (RUSAGE_SELF, &rusage); \
x = rusage.ru_utime; }
# define MS_TIME_DIFF(a,b) ((double) (a.tv_sec - b.tv_sec) * 1000.0 \
+ (double) (a.tv_usec - b.tv_usec) / 1000.0)
#else
# if defined(MSWIN32) || defined(MSWINCE)
# include <windows.h>
# include <winbase.h>
# define CLOCK_TYPE DWORD
# define GET_TIME(x) x = GetTickCount()
# define MS_TIME_DIFF(a,b) ((long)((a)-(b)))
# else
# include <time.h>
# if !defined(__STDC__) && defined(SPARC) && defined(SUNOS4)
clock_t clock();
# endif
# if defined(FREEBSD) && !defined(CLOCKS_PER_SEC)
# include <machine/limits.h>
# define CLOCKS_PER_SEC CLK_TCK
# endif
# if !defined(CLOCKS_PER_SEC)
# define CLOCKS_PER_SEC 1000000
# endif
# define CLOCK_TYPE clock_t
# define GET_TIME(x) x = clock()
# define MS_TIME_DIFF(a,b) ((unsigned long) \
(1000.0*(double)((a)-(b))/(double)CLOCKS_PER_SEC))
# endif
#endif
# if defined(SPARC) && defined(SUNOS4)
# define BCOPY_EXISTS
# endif
# if defined(M68K) && defined(AMIGA)
# define BCOPY_EXISTS
# endif
# if defined(M68K) && defined(NEXT)
# define BCOPY_EXISTS
# endif
# if defined(VAX)
# define BCOPY_EXISTS
# endif
# if defined(AMIGA)
# include <string.h>
# define BCOPY_EXISTS
# endif
# if defined(DARWIN)
# include <string.h>
# define BCOPY_EXISTS
# endif
# ifndef BCOPY_EXISTS
# include <string.h>
# define BCOPY(x,y,n) memcpy(y, x, (size_t)(n))
# define BZERO(x,n) memset(x, 0, (size_t)(n))
# else
# define BCOPY(x,y,n) bcopy((char *)(x),(char *)(y),(int)(n))
# define BZERO(x,n) bzero((char *)(x),(int)(n))
# endif
# ifdef PCR
# define DISABLE_SIGNALS() \
PCR_Th_SetSigMask(PCR_allSigsBlocked,&GC_old_sig_mask)
# define ENABLE_SIGNALS() \
PCR_Th_SetSigMask(&GC_old_sig_mask, NIL)
# else
# if defined(THREADS) || defined(AMIGA) \
|| defined(MSWIN32) || defined(MSWINCE) || defined(MACOS) \
|| defined(DJGPP) || defined(NO_SIGNALS)
# define DISABLE_SIGNALS()
# define ENABLE_SIGNALS()
# else
# define DISABLE_SIGNALS() GC_disable_signals()
void GC_disable_signals();
# define ENABLE_SIGNALS() GC_enable_signals()
void GC_enable_signals();
# endif
# endif
# ifdef PCR
# include "th/PCR_ThCtl.h"
# define STOP_WORLD() \
PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_stopNormal, \
PCR_allSigsBlocked, \
PCR_waitForever)
# define START_WORLD() \
PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_null, \
PCR_allSigsBlocked, \
PCR_waitForever);
# else
# if defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) \
|| defined(GC_PTHREADS)
void GC_stop_world();
void GC_start_world();
# define STOP_WORLD() GC_stop_world()
# define START_WORLD() GC_start_world()
# else
# define STOP_WORLD()
# define START_WORLD()
# endif
# endif
# ifdef PCR
# define ABORT(s) PCR_Base_Panic(s)
# else
# ifdef SMALL_CONFIG
# define ABORT(msg) abort();
# else
GC_API void GC_abort GC_PROTO((GC_CONST char * msg));
# define ABORT(msg) GC_abort(msg);
# endif
# endif
# ifdef PCR
# define EXIT() PCR_Base_Exit(1,PCR_waitForever)
# else
# define EXIT() (void)exit(1)
# endif
# define WARN(msg,arg) (*GC_current_warn_proc)("GC Warning: " msg, (GC_word)(arg))
extern GC_warn_proc GC_current_warn_proc;
#if !defined(NO_GETENV)
# if defined(EMPTY_GETENV_RESULTS)
static inline char * fixed_getenv(const char *name)
{
char * tmp = getenv(name);
if (tmp == 0 || strlen(tmp) == 0)
return 0;
return tmp;
}
# define GETENV(name) fixed_getenv(name)
# else
# define GETENV(name) getenv(name)
# endif
#else
# define GETENV(name) 0
#endif
#if CPP_WORDSZ == 32
# define WORDS_TO_BYTES(x) ((x)<<2)
# define BYTES_TO_WORDS(x) ((x)>>2)
# define LOGWL ((word)5)
# define modWORDSZ(n) ((n) & 0x1f)
# if ALIGNMENT != 4
# define UNALIGNED
# endif
#endif
#if CPP_WORDSZ == 64
# define WORDS_TO_BYTES(x) ((x)<<3)
# define BYTES_TO_WORDS(x) ((x)>>3)
# define LOGWL ((word)6)
# define modWORDSZ(n) ((n) & 0x3f)
# if ALIGNMENT != 8
# define UNALIGNED
# endif
#endif
#define WORDSZ ((word)CPP_WORDSZ)
#define SIGNB ((word)1 << (WORDSZ-1))
#define BYTES_PER_WORD ((word)(sizeof (word)))
#define ONES ((word)(signed_word)(-1))
#define divWORDSZ(n) ((n) >> LOGWL)
#ifndef HBLKSIZE
# ifdef SMALL_CONFIG
# define CPP_LOG_HBLKSIZE 10
# else
# if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
# define CPP_LOG_HBLKSIZE 12
# else
# define CPP_LOG_HBLKSIZE 13
# endif
# endif
#else
# if HBLKSIZE == 512
# define CPP_LOG_HBLKSIZE 9
# endif
# if HBLKSIZE == 1024
# define CPP_LOG_HBLKSIZE 10
# endif
# if HBLKSIZE == 2048
# define CPP_LOG_HBLKSIZE 11
# endif
# if HBLKSIZE == 4096
# define CPP_LOG_HBLKSIZE 12
# endif
# if HBLKSIZE == 8192
# define CPP_LOG_HBLKSIZE 13
# endif
# if HBLKSIZE == 16384
# define CPP_LOG_HBLKSIZE 14
# endif
# ifndef CPP_LOG_HBLKSIZE
--> fix HBLKSIZE
# endif
# undef HBLKSIZE
#endif
# define CPP_HBLKSIZE (1 << CPP_LOG_HBLKSIZE)
# define LOG_HBLKSIZE ((word)CPP_LOG_HBLKSIZE)
# define HBLKSIZE ((word)CPP_HBLKSIZE)
#define CPP_MAXOBJBYTES (CPP_HBLKSIZE/2)
#define MAXOBJBYTES ((word)CPP_MAXOBJBYTES)
#define CPP_MAXOBJSZ BYTES_TO_WORDS(CPP_MAXOBJBYTES)
#define MAXOBJSZ ((word)CPP_MAXOBJSZ)
# define divHBLKSZ(n) ((n) >> LOG_HBLKSIZE)
# define HBLK_PTR_DIFF(p,q) divHBLKSZ((ptr_t)p - (ptr_t)q)
# define modHBLKSZ(n) ((n) & (HBLKSIZE-1))
# define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
# define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
# define ROUNDED_UP_WORDS(n) \
BYTES_TO_WORDS((n) + (WORDS_TO_BYTES(1) - 1 + EXTRA_BYTES))
# ifdef ALIGN_DOUBLE
# define ALIGNED_WORDS(n) \
(BYTES_TO_WORDS((n) + WORDS_TO_BYTES(2) - 1 + EXTRA_BYTES) & ~1)
# else
# define ALIGNED_WORDS(n) ROUNDED_UP_WORDS(n)
# endif
# define SMALL_OBJ(bytes) ((bytes) <= (MAXOBJBYTES - EXTRA_BYTES))
# define ADD_SLOP(bytes) ((bytes) + EXTRA_BYTES)
# ifndef MIN_WORDS
# if defined(USE_MARK_BYTES) || defined(GC_GCJ_SUPPORT)
# define MIN_WORDS 2
# else
# define MIN_WORDS 1
# endif
# endif
# ifdef LARGE_CONFIG
# define LOG_PHT_ENTRIES 20
# else
# ifdef SMALL_CONFIG
# define LOG_PHT_ENTRIES 14
# else
# define LOG_PHT_ENTRIES 16
# endif
# endif
# define PHT_ENTRIES ((word)1 << LOG_PHT_ENTRIES)
# define PHT_SIZE (PHT_ENTRIES >> LOGWL)
typedef word page_hash_table[PHT_SIZE];
# define PHT_HASH(addr) ((((word)(addr)) >> LOG_HBLKSIZE) & (PHT_ENTRIES - 1))
# define get_pht_entry_from_index(bl, index) \
(((bl)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
# define set_pht_entry_from_index(bl, index) \
(bl)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
# define clear_pht_entry_from_index(bl, index) \
(bl)[divWORDSZ(index)] &= ~((word)1 << modWORDSZ(index))
# define set_pht_entry_from_index_safe(bl, index) \
(bl)[divWORDSZ(index)] = ONES
#define HBLKMASK (HBLKSIZE-1)
#define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
#define MARK_BITS_PER_HBLK (BITS_PER_HBLK/CPP_WORDSZ)
# ifdef USE_MARK_BYTES
# define MARK_BITS_SZ (MARK_BITS_PER_HBLK/2)
# else
# define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
# endif
typedef unsigned char map_entry_type;
struct hblkhdr {
word hb_sz;
struct hblk * hb_next;
struct hblk * hb_prev;
word hb_descr;
map_entry_type * hb_map;
unsigned char hb_obj_kind;
unsigned char hb_flags;
# define IGNORE_OFF_PAGE 1
# define WAS_UNMAPPED 2
unsigned short hb_last_reclaimed;
# ifdef USE_MARK_BYTES
union {
char _hb_marks[MARK_BITS_SZ];
word dummy;
} _mark_byte_union;
# define hb_marks _mark_byte_union._hb_marks
# else
word hb_marks[MARK_BITS_SZ];
# endif
};
# define BODY_SZ (HBLKSIZE/sizeof(word))
struct hblk {
word hb_body[BODY_SZ];
};
# define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
# define OBJ_SZ_TO_BLOCKS(sz) \
divHBLKSZ(WORDS_TO_BYTES(sz) + HBLKSIZE-1)
# define obj_link(p) (*(ptr_t *)(p))
# define LOG_MAX_MARK_PROCS 6
# define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
# ifdef LARGE_CONFIG
# define MAX_ROOT_SETS 4096
# else
# ifdef PCR
# define MAX_ROOT_SETS 1024
# else
# if defined(MSWIN32) || defined(MSWINCE)
# define MAX_ROOT_SETS 1024
# else
# define MAX_ROOT_SETS 256
# endif
# endif
# endif
# define MAX_EXCLUSIONS (MAX_ROOT_SETS/4)
struct exclusion {
ptr_t e_start;
ptr_t e_end;
};
struct roots {
ptr_t r_start;
ptr_t r_end;
# if !defined(MSWIN32) && !defined(MSWINCE)
struct roots * r_next;
# endif
GC_bool r_tmp;
};
#if !defined(MSWIN32) && !defined(MSWINCE)
# define LOG_RT_SIZE 6
# define RT_SIZE (1 << LOG_RT_SIZE)
#endif
struct _GC_arrays {
word _heapsize;
word _max_heapsize;
word _requested_heapsize;
ptr_t _last_heap_addr;
ptr_t _prev_heap_addr;
word _large_free_bytes;
word _large_allocd_bytes;
word _max_large_allocd_bytes;
word _words_allocd_before_gc;
# ifndef SEPARATE_GLOBALS
word _words_allocd;
# endif
word _words_wasted;
word _words_finalized;
word _non_gc_bytes_at_gc;
word _mem_freed;
word _finalizer_mem_freed;
ptr_t _scratch_end_ptr;
ptr_t _scratch_last_end_ptr;
GC_mark_proc _mark_procs[MAX_MARK_PROCS];
# ifndef SEPARATE_GLOBALS
ptr_t _objfreelist[MAXOBJSZ+1];
ptr_t _aobjfreelist[MAXOBJSZ+1];
# endif
ptr_t _uobjfreelist[MAXOBJSZ+1];
# ifdef ATOMIC_UNCOLLECTABLE
ptr_t _auobjfreelist[MAXOBJSZ+1];
# endif
# ifdef GATHERSTATS
word _composite_in_use;
word _atomic_in_use;
# endif
# ifdef USE_MUNMAP
word _unmapped_bytes;
# endif
# ifdef MERGE_SIZES
unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
# endif
# ifdef STUBBORN_ALLOC
ptr_t _sobjfreelist[MAXOBJSZ+1];
# endif
map_entry_type * _obj_map[MAXOBJSZ+1];
# define OFFSET_TOO_BIG 0xfe
# define OBJ_INVALID 0xff
# define MAP_ENTRY(map, bytes) (map)[bytes]
# define MAP_ENTRIES HBLKSIZE
# define MAP_SIZE MAP_ENTRIES
# define CPP_MAX_OFFSET (OFFSET_TOO_BIG - 1)
# define MAX_OFFSET ((word)CPP_MAX_OFFSET)
# define VALID_OFFSET_SZ \
(CPP_MAX_OFFSET > WORDS_TO_BYTES(CPP_MAXOBJSZ)? \
CPP_MAX_OFFSET+1 \
: WORDS_TO_BYTES(CPP_MAXOBJSZ)+1)
char _valid_offsets[VALID_OFFSET_SZ];
char _modws_valid_offsets[sizeof(word)];
# define OFFSET_VALID(displ) \
(GC_all_interior_pointers || GC_valid_offsets[displ])
# ifdef STUBBORN_ALLOC
page_hash_table _changed_pages;
page_hash_table _prev_changed_pages;
# endif
# if defined(PROC_VDB) || defined(MPROTECT_VDB)
page_hash_table _grungy_pages;
# endif
# ifdef MPROTECT_VDB
VOLATILE page_hash_table _dirty_pages;
# endif
# ifdef PROC_VDB
page_hash_table _written_pages;
# endif
# ifdef LARGE_CONFIG
# if CPP_WORDSZ > 32
# define MAX_HEAP_SECTS 4096
# else
# define MAX_HEAP_SECTS 768
# endif
# else
# ifdef SMALL_CONFIG
# define MAX_HEAP_SECTS 128
# else
# define MAX_HEAP_SECTS 384
# endif
# endif
struct HeapSect {
ptr_t hs_start; word hs_bytes;
} _heap_sects[MAX_HEAP_SECTS];
# if defined(MSWIN32) || defined(MSWINCE)
ptr_t _heap_bases[MAX_HEAP_SECTS];
# endif
# ifdef MSWINCE
word _heap_lengths[MAX_HEAP_SECTS];
# endif
struct roots _static_roots[MAX_ROOT_SETS];
# if !defined(MSWIN32) && !defined(MSWINCE)
struct roots * _root_index[RT_SIZE];
# endif
struct exclusion _excl_table[MAX_EXCLUSIONS];
bottom_index * _all_nils;
bottom_index * _top_index [TOP_SZ];
#ifdef SAVE_CALL_CHAIN
struct callinfo _last_stack[NFRAMES];
#endif
};
GC_API GC_FAR struct _GC_arrays GC_arrays;
# ifndef SEPARATE_GLOBALS
# define GC_objfreelist GC_arrays._objfreelist
# define GC_aobjfreelist GC_arrays._aobjfreelist
# define GC_words_allocd GC_arrays._words_allocd
# endif
# define GC_uobjfreelist GC_arrays._uobjfreelist
# ifdef ATOMIC_UNCOLLECTABLE
# define GC_auobjfreelist GC_arrays._auobjfreelist
# endif
# define GC_sobjfreelist GC_arrays._sobjfreelist
# define GC_valid_offsets GC_arrays._valid_offsets
# define GC_modws_valid_offsets GC_arrays._modws_valid_offsets
# ifdef STUBBORN_ALLOC
# define GC_changed_pages GC_arrays._changed_pages
# define GC_prev_changed_pages GC_arrays._prev_changed_pages
# endif
# define GC_obj_map GC_arrays._obj_map
# define GC_last_heap_addr GC_arrays._last_heap_addr
# define GC_prev_heap_addr GC_arrays._prev_heap_addr
# define GC_words_wasted GC_arrays._words_wasted
# define GC_large_free_bytes GC_arrays._large_free_bytes
# define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
# define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes
# define GC_words_finalized GC_arrays._words_finalized
# define GC_non_gc_bytes_at_gc GC_arrays._non_gc_bytes_at_gc
# define GC_mem_freed GC_arrays._mem_freed
# define GC_finalizer_mem_freed GC_arrays._finalizer_mem_freed
# define GC_scratch_end_ptr GC_arrays._scratch_end_ptr
# define GC_scratch_last_end_ptr GC_arrays._scratch_last_end_ptr
# define GC_mark_procs GC_arrays._mark_procs
# define GC_heapsize GC_arrays._heapsize
# define GC_max_heapsize GC_arrays._max_heapsize
# define GC_requested_heapsize GC_arrays._requested_heapsize
# define GC_words_allocd_before_gc GC_arrays._words_allocd_before_gc
# define GC_heap_sects GC_arrays._heap_sects
# define GC_last_stack GC_arrays._last_stack
# ifdef USE_MUNMAP
# define GC_unmapped_bytes GC_arrays._unmapped_bytes
# endif
# if defined(MSWIN32) || defined(MSWINCE)
# define GC_heap_bases GC_arrays._heap_bases
# endif
# ifdef MSWINCE
# define GC_heap_lengths GC_arrays._heap_lengths
# endif
# define GC_static_roots GC_arrays._static_roots
# define GC_root_index GC_arrays._root_index
# define GC_excl_table GC_arrays._excl_table
# define GC_all_nils GC_arrays._all_nils
# define GC_top_index GC_arrays._top_index
# if defined(PROC_VDB) || defined(MPROTECT_VDB)
# define GC_grungy_pages GC_arrays._grungy_pages
# endif
# ifdef MPROTECT_VDB
# define GC_dirty_pages GC_arrays._dirty_pages
# endif
# ifdef PROC_VDB
# define GC_written_pages GC_arrays._written_pages
# endif
# ifdef GATHERSTATS
# define GC_composite_in_use GC_arrays._composite_in_use
# define GC_atomic_in_use GC_arrays._atomic_in_use
# endif
# ifdef MERGE_SIZES
# define GC_size_map GC_arrays._size_map
# endif
# define beginGC_arrays ((ptr_t)(&GC_arrays))
# define endGC_arrays (((ptr_t)(&GC_arrays)) + (sizeof GC_arrays))
#define USED_HEAP_SIZE (GC_heapsize - GC_large_free_bytes)
# define MAXOBJKINDS 16
extern struct obj_kind {
ptr_t *ok_freelist;
struct hblk **ok_reclaim_list;
word ok_descriptor;
GC_bool ok_relocate_descr;
GC_bool ok_init;
} GC_obj_kinds[MAXOBJKINDS];
# define beginGC_obj_kinds ((ptr_t)(&GC_obj_kinds))
# define endGC_obj_kinds (beginGC_obj_kinds + (sizeof GC_obj_kinds))
#ifdef SEPARATE_GLOBALS
word GC_words_allocd;
ptr_t GC_objfreelist[MAXOBJSZ+1];
# define beginGC_objfreelist ((ptr_t)(&GC_objfreelist))
# define endGC_objfreelist (beginGC_objfreelist + sizeof(GC_objfreelist))
ptr_t GC_aobjfreelist[MAXOBJSZ+1];
# define beginGC_aobjfreelist ((ptr_t)(&GC_aobjfreelist))
# define endGC_aobjfreelist (beginGC_aobjfreelist + sizeof(GC_aobjfreelist))
#endif
# define PTRFREE 0
# define NORMAL 1
# define UNCOLLECTABLE 2
# ifdef ATOMIC_UNCOLLECTABLE
# define AUNCOLLECTABLE 3
# define STUBBORN 4
# define IS_UNCOLLECTABLE(k) (((k) & ~1) == UNCOLLECTABLE)
# else
# define STUBBORN 3
# define IS_UNCOLLECTABLE(k) ((k) == UNCOLLECTABLE)
# endif
extern int GC_n_kinds;
GC_API word GC_fo_entries;
extern word GC_n_heap_sects;
extern word GC_page_size;
# if defined(MSWIN32) || defined(MSWINCE)
struct _SYSTEM_INFO;
extern struct _SYSTEM_INFO GC_sysinfo;
extern word GC_n_heap_bases;
# endif
extern word GC_total_stack_black_listed;
extern word GC_black_list_spacing;
extern map_entry_type * GC_invalid_map;
extern struct hblk * GC_hblkfreelist[];
extern GC_bool GC_objects_are_marked;
#ifndef SMALL_CONFIG
extern GC_bool GC_incremental;
# define TRUE_INCREMENTAL \
(GC_incremental && GC_time_limit != GC_TIME_UNLIMITED)
#else
# define GC_incremental FALSE
# define TRUE_INCREMENTAL FALSE
#endif
extern GC_bool GC_dirty_maintained;
extern word GC_root_size;
extern GC_bool GC_debugging_started;
extern long GC_large_alloc_warn_interval;
extern long GC_large_alloc_warn_suppressed;
#ifdef THREADS
extern GC_bool GC_world_stopped;
#endif
# ifndef abs
# define abs(x) ((x) < 0? (-(x)) : (x))
# endif
#ifdef PARALLEL_MARK
# define OR_WORD(addr, bits) \
{ word old; \
do { \
old = *((volatile word *)addr); \
} while (!GC_compare_and_exchange((addr), old, old | (bits))); \
}
# define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
{ word old; \
word my_bits = (bits); \
do { \
old = *((volatile word *)addr); \
if (old & my_bits) goto exit_label; \
} while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
}
#else
# define OR_WORD(addr, bits) *(addr) |= (bits)
# define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
{ \
word old = *(addr); \
word my_bits = (bits); \
if (old & my_bits) goto exit_label; \
*(addr) = (old | my_bits); \
}
#endif
#ifdef USE_MARK_BYTES
# define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n) >> 1])
# define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 1
# define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 0
#else
# define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
>> (modWORDSZ(n))) & (word)1)
# define set_mark_bit_from_hdr(hhdr,n) \
OR_WORD((hhdr)->hb_marks+divWORDSZ(n), \
(word)1 << modWORDSZ(n))
# define clear_mark_bit_from_hdr(hhdr,n) (hhdr)->hb_marks[divWORDSZ(n)] \
&= ~((word)1 << modWORDSZ(n))
#endif
ptr_t GC_approx_sp GC_PROTO((void));
GC_bool GC_should_collect GC_PROTO((void));
void GC_apply_to_all_blocks GC_PROTO(( \
void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
word client_data));
struct hblk * GC_next_used_block GC_PROTO((struct hblk * h));
struct hblk * GC_prev_block GC_PROTO((struct hblk * h));
void GC_mark_init GC_PROTO((void));
void GC_clear_marks GC_PROTO((void));
void GC_invalidate_mark_state GC_PROTO((void));
GC_bool GC_mark_stack_empty GC_PROTO((void));
GC_bool GC_mark_some GC_PROTO((ptr_t cold_gc_frame));
void GC_initiate_gc GC_PROTO((void));
void GC_push_all GC_PROTO((ptr_t bottom, ptr_t top));
void GC_push_selected GC_PROTO(( \
ptr_t bottom, \
ptr_t top, \
int (*dirty_fn) GC_PROTO((struct hblk *h)), \
void (*push_fn) GC_PROTO((ptr_t bottom, ptr_t top)) ));
#ifndef SMALL_CONFIG
void GC_push_conditional GC_PROTO((ptr_t b, ptr_t t, GC_bool all));
#else
# define GC_push_conditional(b, t, all) GC_push_all(b, t)
#endif
void GC_push_all_stack GC_PROTO((ptr_t b, ptr_t t));
void GC_push_all_eager GC_PROTO((ptr_t b, ptr_t t));
#ifndef THREADS
void GC_push_all_stack_partially_eager GC_PROTO(( \
ptr_t bottom, ptr_t top, ptr_t cold_gc_frame ));
#else
#endif
void GC_push_current_stack GC_PROTO((ptr_t cold_gc_frame));
void GC_push_roots GC_PROTO((GC_bool all, ptr_t cold_gc_frame));
extern void (*GC_push_other_roots) GC_PROTO((void));
extern void GC_push_gc_structures GC_PROTO((void));
extern void GC_push_finalizer_structures GC_PROTO((void));
extern void GC_push_stubborn_structures GC_PROTO((void));
# ifdef THREADS
extern void GC_push_thread_structures GC_PROTO((void));
# endif
extern void (*GC_start_call_back) GC_PROTO((void));
# if defined(USE_GENERIC_PUSH_REGS)
void GC_generic_push_regs GC_PROTO((ptr_t cold_gc_frame));
# else
void GC_push_regs GC_PROTO((void));
# endif
# if defined(SPARC) || defined(IA64)
word GC_save_regs_in_stack GC_PROTO((void));
# endif
# ifdef NURSERY
extern void (*GC_push_proc)(ptr_t);
# endif
# if defined(MSWIN32) || defined(MSWINCE)
void __cdecl GC_push_one GC_PROTO((word p));
# else
void GC_push_one GC_PROTO((word p));
# endif
# if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
void GC_mark_and_push_stack GC_PROTO((word p, ptr_t source));
# else
void GC_mark_and_push_stack GC_PROTO((word p));
# endif
void GC_push_marked GC_PROTO((struct hblk * h, hdr * hhdr));
#ifdef SMALL_CONFIG
# define GC_push_next_marked_dirty(h) GC_push_next_marked(h)
#else
struct hblk * GC_push_next_marked_dirty GC_PROTO((struct hblk * h));
#endif
struct hblk * GC_push_next_marked GC_PROTO((struct hblk * h));
struct hblk * GC_push_next_marked_uncollectable GC_PROTO((struct hblk * h));
GC_bool GC_stopped_mark GC_PROTO((GC_stop_func stop_func));
void GC_clear_hdr_marks GC_PROTO((hdr * hhdr));
void GC_set_hdr_marks GC_PROTO((hdr * hhdr));
void GC_set_fl_marks GC_PROTO((ptr_t p));
void GC_add_roots_inner GC_PROTO((char * b, char * e, GC_bool tmp));
void GC_remove_roots_inner GC_PROTO((char * b, char * e));
GC_bool GC_is_static_root GC_PROTO((ptr_t p));
# if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
GC_bool GC_is_tmp_root GC_PROTO((ptr_t p));
# endif
void GC_register_dynamic_libraries GC_PROTO((void));
GC_bool GC_register_main_static_data GC_PROTO((void));
ptr_t GC_get_stack_base GC_PROTO((void));
#ifdef IA64
ptr_t GC_get_register_stack_base GC_PROTO((void));
#endif
void GC_register_data_segments GC_PROTO((void));
void GC_bl_init GC_PROTO((void));
# ifdef PRINT_BLACK_LIST
void GC_add_to_black_list_normal GC_PROTO((word p, ptr_t source));
# define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
if (GC_all_interior_pointers) { \
GC_add_to_black_list_stack(bits, (ptr_t)(source)); \
} else { \
GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
}
# else
void GC_add_to_black_list_normal GC_PROTO((word p));
# define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
if (GC_all_interior_pointers) { \
GC_add_to_black_list_stack(bits); \
} else { \
GC_add_to_black_list_normal(bits); \
}
# endif
# ifdef PRINT_BLACK_LIST
void GC_add_to_black_list_stack GC_PROTO((word p, ptr_t source));
# else
void GC_add_to_black_list_stack GC_PROTO((word p));
# endif
struct hblk * GC_is_black_listed GC_PROTO((struct hblk * h, word len));
void GC_promote_black_lists GC_PROTO((void));
void GC_unpromote_black_lists GC_PROTO((void));
word GC_number_stack_black_listed GC_PROTO(( \
struct hblk *start, struct hblk *endp1));
ptr_t GC_scratch_alloc GC_PROTO((word bytes));
void GC_invalidate_map GC_PROTO((hdr * hhdr));
GC_bool GC_add_map_entry GC_PROTO((word sz));
void GC_register_displacement_inner GC_PROTO((word offset));
void GC_new_hblk GC_PROTO((word size_in_words, int kind));
ptr_t GC_build_fl GC_PROTO((struct hblk *h, word sz,
GC_bool clear, ptr_t list));
struct hblk * GC_allochblk GC_PROTO(( \
word size_in_words, int kind, unsigned flags));
ptr_t GC_alloc_large GC_PROTO((word lw, int k, unsigned flags));
ptr_t GC_alloc_large_and_clear GC_PROTO((word lw, int k, unsigned flags));
void GC_freehblk GC_PROTO((struct hblk * p));
void GC_init_inner GC_PROTO((void));
GC_bool GC_expand_hp_inner GC_PROTO((word n));
void GC_start_reclaim GC_PROTO((int abort_if_found));
void GC_continue_reclaim GC_PROTO((word sz, int kind));
void GC_reclaim_or_delete_all GC_PROTO((void));
GC_bool GC_reclaim_all GC_PROTO((GC_stop_func stop_func, GC_bool ignore_old));
GC_bool GC_block_empty GC_PROTO((hdr * hhdr));
GC_bool GC_never_stop_func GC_PROTO((void));
GC_bool GC_try_to_collect_inner GC_PROTO((GC_stop_func f));
# define GC_gcollect_inner() \
(void) GC_try_to_collect_inner(GC_never_stop_func)
void GC_finish_collection GC_PROTO((void));
GC_bool GC_collect_or_expand GC_PROTO(( \
word needed_blocks, GC_bool ignore_off_page));
extern GC_bool GC_is_initialized;
#if defined(MSWIN32) || defined(MSWINCE)
void GC_deinit GC_PROTO((void));
#endif
void GC_collect_a_little_inner GC_PROTO((int n));
ptr_t GC_generic_malloc_ignore_off_page GC_PROTO((size_t b, int k));
ptr_t GC_generic_malloc_inner GC_PROTO((word lb, int k));
ptr_t GC_generic_malloc_words_small_inner GC_PROTO((word lw, int k));
ptr_t GC_generic_malloc_words_small GC_PROTO((size_t lw, int k));
ptr_t GC_generic_malloc_inner_ignore_off_page GC_PROTO((size_t lb, int k));
ptr_t GC_allocobj GC_PROTO((word sz, int kind));
void GC_free_inner(GC_PTR p);
void GC_init_headers GC_PROTO((void));
struct hblkhdr * GC_install_header GC_PROTO((struct hblk *h));
GC_bool GC_install_counts GC_PROTO((struct hblk * h, word sz));
void GC_remove_header GC_PROTO((struct hblk * h));
void GC_remove_counts GC_PROTO((struct hblk * h, word sz));
hdr * GC_find_header GC_PROTO((ptr_t h));
void GC_finalize GC_PROTO((void));
void GC_notify_or_invoke_finalizers GC_PROTO((void));
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));
void GC_add_to_heap GC_PROTO((struct hblk *p, word bytes));
void GC_print_obj GC_PROTO((ptr_t p));
extern void (*GC_check_heap) GC_PROTO((void));
extern void (*GC_print_all_smashed) GC_PROTO((void));
extern void GC_print_all_errors GC_PROTO((void));
extern void (*GC_print_heap_obj) GC_PROTO((ptr_t p));
#if defined(LINUX) && defined(__ELF__) && !defined(SMALL_CONFIG)
void GC_print_address_map GC_PROTO((void));
#endif
extern GC_bool GC_have_errors;
extern GC_bool GC_print_stats;
#ifndef NO_DEBUGGING
extern GC_bool GC_dump_regularly;
# define COND_DUMP if (GC_dump_regularly) GC_dump();
#else
# define COND_DUMP
#endif
#ifdef KEEP_BACK_PTRS
extern long GC_backtraces;
void GC_generate_random_backtrace_no_gc(void);
#endif
extern GC_bool GC_print_back_height;
#ifdef MAKE_BACK_GRAPH
void GC_print_back_graph_stats(void);
#endif
#ifdef DBG_HDRS_ALL
extern GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k);
extern GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
int k);
# define GC_INTERNAL_MALLOC GC_debug_generic_malloc_inner
# define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
GC_debug_generic_malloc_inner_ignore_off_page
# ifdef THREADS
# define GC_INTERNAL_FREE GC_debug_free_inner
# else
# define GC_INTERNAL_FREE GC_debug_free
# endif
#else
# define GC_INTERNAL_MALLOC GC_generic_malloc_inner
# define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
GC_generic_malloc_inner_ignore_off_page
# ifdef THREADS
# define GC_INTERNAL_FREE GC_free_inner
# else
# define GC_INTERNAL_FREE GC_free
# endif
#endif
#ifdef USE_MUNMAP
void GC_unmap_old(void);
void GC_merge_unmapped(void);
void GC_unmap(ptr_t start, word bytes);
void GC_remap(ptr_t start, word bytes);
void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2);
#endif
void GC_read_dirty GC_PROTO((void));
GC_bool GC_page_was_dirty GC_PROTO((struct hblk *h));
GC_bool GC_page_was_ever_dirty GC_PROTO((struct hblk *h));
void GC_is_fresh GC_PROTO((struct hblk *h, word n));
void GC_remove_protection GC_PROTO((struct hblk *h, word nblocks,
GC_bool pointerfree));
void GC_dirty_init GC_PROTO((void));
GC_API GC_bool GC_is_marked GC_PROTO((ptr_t p));
void GC_clear_mark_bit GC_PROTO((ptr_t p));
void GC_set_mark_bit GC_PROTO((ptr_t p));
void GC_read_changed GC_PROTO((void));
GC_bool GC_page_was_changed GC_PROTO((struct hblk * h));
void GC_clean_changing_list GC_PROTO((void));
void GC_stubborn_init GC_PROTO((void));
void GC_print_block_list GC_PROTO((void));
void GC_print_hblkfreelist GC_PROTO((void));
void GC_print_heap_sects GC_PROTO((void));
void GC_print_static_roots GC_PROTO((void));
void GC_print_finalization_stats GC_PROTO((void));
void GC_dump GC_PROTO((void));
#ifdef KEEP_BACK_PTRS
void GC_store_back_pointer(ptr_t source, ptr_t dest);
void GC_marked_for_finalization(ptr_t dest);
# define GC_STORE_BACK_PTR(source, dest) GC_store_back_pointer(source, dest)
# define GC_MARKED_FOR_FINALIZATION(dest) GC_marked_for_finalization(dest)
#else
# define GC_STORE_BACK_PTR(source, dest)
# define GC_MARKED_FOR_FINALIZATION(dest)
#endif
# ifdef __WATCOMC__
void GC_noop(void*, ...);
# else
# ifdef __DMC__
GC_API void GC_noop(...);
# else
GC_API void GC_noop();
# endif
# endif
void GC_noop1 GC_PROTO((word));
GC_API void GC_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
# define GC_printf0(f) GC_printf(f, 0l, 0l, 0l, 0l, 0l, 0l)
# define GC_printf1(f,a) GC_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
# define GC_printf2(f,a,b) GC_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
# define GC_printf3(f,a,b,c) GC_printf(f, (long)a, (long)b, (long)c, 0l, 0l, 0l)
# define GC_printf4(f,a,b,c,d) GC_printf(f, (long)a, (long)b, (long)c, \
(long)d, 0l, 0l)
# define GC_printf5(f,a,b,c,d,e) GC_printf(f, (long)a, (long)b, (long)c, \
(long)d, (long)e, 0l)
# define GC_printf6(f,a,b,c,d,e,g) GC_printf(f, (long)a, (long)b, (long)c, \
(long)d, (long)e, (long)g)
GC_API void GC_err_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
# define GC_err_printf0(f) GC_err_puts(f)
# define GC_err_printf1(f,a) GC_err_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
# define GC_err_printf2(f,a,b) GC_err_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
# define GC_err_printf3(f,a,b,c) GC_err_printf(f, (long)a, (long)b, (long)c, \
0l, 0l, 0l)
# define GC_err_printf4(f,a,b,c,d) GC_err_printf(f, (long)a, (long)b, \
(long)c, (long)d, 0l, 0l)
# define GC_err_printf5(f,a,b,c,d,e) GC_err_printf(f, (long)a, (long)b, \
(long)c, (long)d, \
(long)e, 0l)
# define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
(long)c, (long)d, \
(long)e, (long)g)
void GC_err_puts GC_PROTO((GC_CONST char *s));
#if defined(LINUX) && !defined(SMALL_CONFIG)
void GC_err_write GC_PROTO((GC_CONST char *buf, size_t len));
#endif
# ifdef GC_ASSERTIONS
# define GC_ASSERT(expr) if(!(expr)) {\
GC_err_printf2("Assertion failure: %s:%ld\n", \
__FILE__, (unsigned long)__LINE__); \
ABORT("assertion failure"); }
# else
# define GC_ASSERT(expr)
# endif
#if defined(mips) && !defined(__GNUC__)
# define GC_STATIC_ASSERT(expr) do { if (0) { char j[(expr)? 1 : -1]; j[0]='\0'; j[0]=j[0]; } } while(0)
#else
# define GC_STATIC_ASSERT(expr) sizeof(char[(expr)? 1 : -1])
#endif
# if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
extern void GC_acquire_mark_lock();
extern void GC_release_mark_lock();
extern void GC_notify_all_builder();
extern void GC_wait_for_reclaim();
extern word GC_fl_builder_count;
# endif
# ifdef PARALLEL_MARK
extern void GC_notify_all_marker();
extern void GC_wait_marker();
extern word GC_mark_no;
extern void GC_help_marker(word my_mark_no);
# endif
# if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
# if !defined(SIG_SUSPEND)
# if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS)
# if defined(SPARC) && !defined(SIGPWR)
# define SIG_SUSPEND SIGLOST
# else
# define SIG_SUSPEND SIGPWR
# endif
# else
# if defined(_SIGRTMIN)
# define SIG_SUSPEND _SIGRTMIN + 6
# else
# define SIG_SUSPEND SIGRTMIN + 6
# endif
# endif
# endif
# endif
# endif