[BACK]Return to gc_priv.h CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / gc / include / private

Annotation of OpenXM_contrib2/asir2000/gc/include/private/gc_priv.h, Revision 1.5

1.1       noro        1: /*
                      2:  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
                      3:  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
1.2       noro        4:  * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
1.3       noro        5:  * Copyright (c) 1999-2001 by Hewlett-Packard Company. All rights reserved.
1.2       noro        6:  *
1.1       noro        7:  *
                      8:  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
                      9:  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
                     10:  *
                     11:  * Permission is hereby granted to use or copy this program
                     12:  * for any purpose,  provided the above notices are retained on all copies.
                     13:  * Permission to modify the code and to distribute modified code is granted,
                     14:  * provided the above notices are retained, and a notice that the code was
                     15:  * modified is included with the above copyright notice.
                     16:  */
                     17:
                     18:
                     19: # ifndef GC_PRIVATE_H
                     20: # define GC_PRIVATE_H
                     21:
                     22: #if defined(mips) && defined(SYSTYPE_BSD) && defined(sony_news)
                     23:     /* sony RISC NEWS, NEWSOS 4 */
                     24: #   define BSD_TIME
                     25: /*    typedef long ptrdiff_t;   -- necessary on some really old systems        */
                     26: #endif
                     27:
                     28: #if defined(mips) && defined(SYSTYPE_BSD43)
                     29:     /* MIPS RISCOS 4 */
                     30: #   define BSD_TIME
                     31: #endif
                     32:
1.5     ! noro       33: #ifdef DGUX
        !            34: #   include <sys/types.h>
        !            35: #   include <sys/time.h>
        !            36: #   include <sys/resource.h>
        !            37: #endif /* DGUX */
        !            38:
1.1       noro       39: #ifdef BSD_TIME
                     40: #   include <sys/types.h>
                     41: #   include <sys/time.h>
                     42: #   include <sys/resource.h>
                     43: #endif /* BSD_TIME */
                     44:
                     45: # ifndef GC_H
                     46: #   include "gc.h"
                     47: # endif
                     48:
1.3       noro       49: # ifndef GC_MARK_H
                     50: #   include "../gc_mark.h"
                     51: # endif
1.1       noro       52:
1.3       noro       53: typedef GC_word word;
                     54: typedef GC_signed_word signed_word;
1.1       noro       55:
                     56: typedef int GC_bool;
                     57: # define TRUE 1
                     58: # define FALSE 0
                     59:
                     60: typedef char * ptr_t;  /* A generic pointer to which we can add        */
                     61:                        /* byte displacements.                          */
                     62:                        /* Preferably identical to caddr_t, if it       */
                     63:                        /* exists.                                      */
                     64:
1.5     ! noro       65: # ifndef GCCONFIG_H
        !            66: #   include "gcconfig.h"
        !            67: # endif
        !            68:
1.3       noro       69: # ifndef HEADERS_H
                     70: #   include "gc_hdrs.h"
                     71: # endif
                     72:
1.1       noro       73: #if defined(__STDC__)
                     74: #   include <stdlib.h>
                     75: #   if !(defined( sony_news ) )
                     76: #       include <stddef.h>
                     77: #   endif
                     78: #   define VOLATILE volatile
                     79: #else
                     80: #   ifdef MSWIN32
                     81: #      include <stdlib.h>
                     82: #   endif
                     83: #   define VOLATILE
                     84: #endif
                     85:
1.3       noro       86: #if 0 /* defined(__GNUC__) doesn't work yet */
                     87: # define EXPECT(expr, outcome) __builtin_expect(expr,outcome)
                     88:   /* Equivalent to (expr), but predict that usually (expr)==outcome. */
                     89: #else
                     90: # define EXPECT(expr, outcome) (expr)
                     91: #endif /* __GNUC__ */
                     92:
                     93: # ifndef GC_LOCKS_H
                     94: #   include "gc_locks.h"
                     95: # endif
1.2       noro       96:
1.3       noro       97: # ifdef STACK_GROWS_DOWN
                     98: #   define COOLER_THAN >
                     99: #   define HOTTER_THAN <
                    100: #   define MAKE_COOLER(x,y) if ((word)(x)+(y) > (word)(x)) {(x) += (y);} \
                    101:                            else {(x) = (word)ONES;}
                    102: #   define MAKE_HOTTER(x,y) (x) -= (y)
                    103: # else
                    104: #   define COOLER_THAN <
                    105: #   define HOTTER_THAN >
                    106: #   define MAKE_COOLER(x,y) if ((word)(x)-(y) < (word)(x)) {(x) -= (y);} else {(x) = 0;}
                    107: #   define MAKE_HOTTER(x,y) (x) += (y)
                    108: # endif
                    109:
                    110: #if defined(AMIGA) && defined(__SASC)
1.1       noro      111: #   define GC_FAR __far
                    112: #else
                    113: #   define GC_FAR
                    114: #endif
                    115:
1.3       noro      116:
1.1       noro      117: /*********************************/
                    118: /*                               */
                    119: /* Definitions for conservative  */
                    120: /* collector                     */
                    121: /*                               */
                    122: /*********************************/
                    123:
                    124: /*********************************/
                    125: /*                               */
                    126: /* Easily changeable parameters  */
                    127: /*                               */
                    128: /*********************************/
                    129:
1.3       noro      130: /* #define STUBBORN_ALLOC */
                    131:                    /* Enable stubborm allocation, and thus a limited   */
                    132:                    /* form of incremental collection w/o dirty bits.   */
1.1       noro      133:
                    134: /* #define ALL_INTERIOR_POINTERS */
                    135:                    /* Forces all pointers into the interior of an      */
                    136:                    /* object to be considered valid.  Also causes the  */
                    137:                    /* sizes of all objects to be inflated by at least  */
                    138:                    /* one byte.  This should suffice to guarantee      */
                    139:                    /* that in the presence of a compiler that does     */
                    140:                    /* not perform garbage-collector-unsafe             */
                    141:                    /* optimizations, all portable, strictly ANSI       */
                    142:                    /* conforming C programs should be safely usable    */
                    143:                    /* with malloc replaced by GC_malloc and free       */
                    144:                    /* calls removed.  There are several disadvantages: */
                    145:                    /* 1. There are probably no interesting, portable,  */
                    146:                    /*    strictly ANSI conforming C programs.          */
                    147:                    /* 2. This option makes it hard for the collector   */
                    148:                    /*    to allocate space that is not ``pointed to''  */
                    149:                    /*    by integers, etc.  Under SunOS 4.X with a     */
                    150:                    /*    statically linked libc, we empiricaly         */
                    151:                    /*    observed that it would be difficult to        */
                    152:                    /*    allocate individual objects larger than 100K. */
                    153:                    /*    Even if only smaller objects are allocated,   */
                    154:                    /*    more swap space is likely to be needed.       */
                    155:                    /*    Fortunately, much of this will never be       */
                    156:                    /*    touched.                                      */
                    157:                    /* If you can easily avoid using this option, do.   */
                    158:                    /* If not, try to keep individual objects small.    */
1.3       noro      159:                    /* This is now really controlled at startup,        */
                    160:                    /* through GC_all_interior_pointers.                */
1.1       noro      161:
                    162: #define PRINTSTATS  /* Print garbage collection statistics             */
                    163:                    /* For less verbose output, undefine in reclaim.c   */
                    164:
                    165: #define PRINTTIMES  /* Print the amount of time consumed by each garbage   */
                    166:                    /* collection.                                         */
                    167:
                    168: #define PRINTBLOCKS /* Print object sizes associated with heap blocks,     */
                    169:                    /* whether the objects are atomic or composite, and    */
                    170:                    /* whether or not the block was found to be empty      */
                    171:                    /* during the reclaim phase.  Typically generates       */
                    172:                    /* about one screenful per garbage collection.         */
                    173: #undef PRINTBLOCKS
                    174:
                    175: #ifdef SILENT
                    176: #  ifdef PRINTSTATS
                    177: #    undef PRINTSTATS
                    178: #  endif
                    179: #  ifdef PRINTTIMES
                    180: #    undef PRINTTIMES
                    181: #  endif
                    182: #  ifdef PRINTNBLOCKS
                    183: #    undef PRINTNBLOCKS
                    184: #  endif
                    185: #endif
                    186:
                    187: #if defined(PRINTSTATS) && !defined(GATHERSTATS)
                    188: #   define GATHERSTATS
                    189: #endif
                    190:
1.3       noro      191: #if defined(PRINTSTATS) || !defined(SMALL_CONFIG)
                    192: #   define CONDPRINT  /* Print some things if GC_print_stats is set */
1.1       noro      193: #endif
                    194:
1.3       noro      195: #define GC_INVOKE_FINALIZERS() GC_notify_or_invoke_finalizers()
                    196:
1.1       noro      197: #define MERGE_SIZES /* Round up some object sizes, so that fewer distinct */
                    198:                    /* free lists are actually maintained.  This applies  */
                    199:                    /* only to the top level routines in misc.c, not to   */
                    200:                    /* user generated code that calls GC_allocobj and     */
                    201:                    /* GC_allocaobj directly.                             */
                    202:                    /* Slows down average programs slightly.  May however */
                    203:                    /* substantially reduce fragmentation if allocation   */
                    204:                    /* request sizes are widely scattered.                */
                    205:                    /* May save significant amounts of space for obj_map  */
                    206:                    /* entries.                                           */
                    207:
1.3       noro      208: #if defined(USE_MARK_BYTES) && !defined(ALIGN_DOUBLE)
                    209: #  define ALIGN_DOUBLE
                    210:    /* We use one byte for every 2 words, which doesn't allow for       */
                    211:    /* odd numbered words to have mark bits.                            */
1.1       noro      212: #endif
                    213:
1.5     ! noro      214: #if defined(GC_GCJ_SUPPORT) && ALIGNMENT < 8 && !defined(ALIGN_DOUBLE)
        !           215:    /* GCJ's Hashtable synchronization code requires 64-bit alignment.  */
        !           216: #  define ALIGN_DOUBLE
        !           217: #endif
        !           218:
1.1       noro      219: /* ALIGN_DOUBLE requires MERGE_SIZES at present. */
                    220: # if defined(ALIGN_DOUBLE) && !defined(MERGE_SIZES)
                    221: #   define MERGE_SIZES
                    222: # endif
                    223:
1.3       noro      224: #if !defined(DONT_ADD_BYTE_AT_END)
                    225: # define EXTRA_BYTES GC_all_interior_pointers
                    226: #else
                    227: # define EXTRA_BYTES 0
1.1       noro      228: #endif
                    229:
                    230:
                    231: # ifndef LARGE_CONFIG
1.3       noro      232: #   define MINHINCR 16  /* Minimum heap increment, in blocks of HBLKSIZE  */
                    233:                         /* Must be multiple of largest page size.         */
                    234: #   define MAXHINCR 2048 /* Maximum heap increment, in blocks              */
1.1       noro      235: # else
                    236: #   define MINHINCR 64
                    237: #   define MAXHINCR 4096
                    238: # endif
                    239:
                    240: # define TIME_LIMIT 50    /* We try to keep pause times from exceeding  */
                    241:                           /* this by much. In milliseconds.             */
                    242:
                    243: # define BL_LIMIT GC_black_list_spacing
                    244:                           /* If we need a block of N bytes, and we have */
                    245:                           /* a block of N + BL_LIMIT bytes available,   */
                    246:                           /* and N > BL_LIMIT,                          */
                    247:                           /* but all possible positions in it are       */
                    248:                           /* blacklisted, we just use it anyway (and    */
                    249:                           /* print a warning, if warnings are enabled). */
                    250:                           /* This risks subsequently leaking the block  */
                    251:                           /* due to a false reference.  But not using   */
                    252:                           /* the block risks unreasonable immediate     */
                    253:                           /* heap growth.                               */
                    254:
                    255: /*********************************/
                    256: /*                               */
                    257: /* Stack saving for debugging   */
                    258: /*                               */
                    259: /*********************************/
                    260:
                    261: #ifdef SAVE_CALL_CHAIN
                    262:
                    263: /* Fill in the pc and argument information for up to NFRAMES of my     */
                    264: /* callers.  Ignore my frame and my callers frame.                     */
1.3       noro      265: struct callinfo;
                    266: void GC_save_callers GC_PROTO((struct callinfo info[NFRAMES]));
                    267:
                    268: void GC_print_callers GC_PROTO((struct callinfo info[NFRAMES]));
1.1       noro      269:
                    270: #endif
                    271:
                    272: #ifdef NEED_CALLINFO
                    273:     struct callinfo {
1.3       noro      274:        word ci_pc;     /* Caller, not callee, pc       */
1.1       noro      275: #      if NARGS > 0
                    276:            word ci_arg[NARGS]; /* bit-wise complement to avoid retention */
                    277: #      endif
                    278: #      if defined(ALIGN_DOUBLE) && (NFRAMES * (NARGS + 1)) % 2 == 1
                    279:            /* Likely alignment problem. */
                    280:            word ci_dummy;
                    281: #      endif
                    282:     };
                    283: #endif
                    284:
                    285:
                    286: /*********************************/
                    287: /*                               */
                    288: /* OS interface routines        */
                    289: /*                               */
                    290: /*********************************/
                    291:
                    292: #ifdef BSD_TIME
                    293: #   undef CLOCK_TYPE
                    294: #   undef GET_TIME
                    295: #   undef MS_TIME_DIFF
                    296: #   define CLOCK_TYPE struct timeval
                    297: #   define GET_TIME(x) { struct rusage rusage; \
                    298:                         getrusage (RUSAGE_SELF,  &rusage); \
                    299:                         x = rusage.ru_utime; }
                    300: #   define MS_TIME_DIFF(a,b) ((double) (a.tv_sec - b.tv_sec) * 1000.0 \
                    301:                                + (double) (a.tv_usec - b.tv_usec) / 1000.0)
                    302: #else /* !BSD_TIME */
1.3       noro      303: # if defined(MSWIN32) || defined(MSWINCE)
                    304: #   include <windows.h>
                    305: #   include <winbase.h>
                    306: #   define CLOCK_TYPE DWORD
                    307: #   define GET_TIME(x) x = GetTickCount()
                    308: #   define MS_TIME_DIFF(a,b) ((long)((a)-(b)))
                    309: # else /* !MSWIN32, !MSWINCE, !BSD_TIME */
1.1       noro      310: #   include <time.h>
                    311: #   if !defined(__STDC__) && defined(SPARC) && defined(SUNOS4)
                    312:       clock_t clock(); /* Not in time.h, where it belongs      */
                    313: #   endif
                    314: #   if defined(FREEBSD) && !defined(CLOCKS_PER_SEC)
                    315: #     include <machine/limits.h>
                    316: #     define CLOCKS_PER_SEC CLK_TCK
                    317: #   endif
                    318: #   if !defined(CLOCKS_PER_SEC)
                    319: #     define CLOCKS_PER_SEC 1000000
                    320: /*
                    321:  * This is technically a bug in the implementation.  ANSI requires that
                    322:  * CLOCKS_PER_SEC be defined.  But at least under SunOS4.1.1, it isn't.
                    323:  * Also note that the combination of ANSI C and POSIX is incredibly gross
                    324:  * here. The type clock_t is used by both clock() and times().  But on
                    325:  * some machines these use different notions of a clock tick,  CLOCKS_PER_SEC
                    326:  * seems to apply only to clock.  Hence we use it here.  On many machines,
                    327:  * including SunOS, clock actually uses units of microseconds (which are
                    328:  * not really clock ticks).
                    329:  */
                    330: #   endif
                    331: #   define CLOCK_TYPE clock_t
                    332: #   define GET_TIME(x) x = clock()
                    333: #   define MS_TIME_DIFF(a,b) ((unsigned long) \
                    334:                (1000.0*(double)((a)-(b))/(double)CLOCKS_PER_SEC))
1.3       noro      335: # endif /* !MSWIN32 */
1.1       noro      336: #endif /* !BSD_TIME */
                    337:
                    338: /* We use bzero and bcopy internally.  They may not be available.      */
                    339: # if defined(SPARC) && defined(SUNOS4)
                    340: #   define BCOPY_EXISTS
                    341: # endif
                    342: # if defined(M68K) && defined(AMIGA)
                    343: #   define BCOPY_EXISTS
                    344: # endif
                    345: # if defined(M68K) && defined(NEXT)
                    346: #   define BCOPY_EXISTS
                    347: # endif
                    348: # if defined(VAX)
                    349: #   define BCOPY_EXISTS
                    350: # endif
                    351: # if defined(AMIGA)
                    352: #   include <string.h>
                    353: #   define BCOPY_EXISTS
                    354: # endif
1.3       noro      355: # if defined(MACOSX)
                    356: #   define BCOPY_EXISTS
                    357: # endif
1.1       noro      358:
                    359: # ifndef BCOPY_EXISTS
                    360: #   include <string.h>
                    361: #   define BCOPY(x,y,n) memcpy(y, x, (size_t)(n))
                    362: #   define BZERO(x,n)  memset(x, 0, (size_t)(n))
                    363: # else
                    364: #   define BCOPY(x,y,n) bcopy((char *)(x),(char *)(y),(int)(n))
                    365: #   define BZERO(x,n) bzero((char *)(x),(int)(n))
                    366: # endif
                    367:
                    368: /* Delay any interrupts or signals that may abort this thread.  Data   */
                    369: /* structures are in a consistent state outside this pair of calls.    */
                    370: /* ANSI C allows both to be empty (though the standard isn't very      */
                    371: /* clear on that point).  Standard malloc implementations are usually  */
                    372: /* neither interruptable nor thread-safe, and thus correspond to       */
                    373: /* empty definitions.                                                  */
1.5     ! noro      374: /* It probably doesn't make any sense to declare these to be nonempty  */
        !           375: /* if the code is being optimized, since signal safety relies on some  */
        !           376: /* ordering constraints that are typically not obeyed by optimizing    */
        !           377: /* compilers.                                                          */
1.1       noro      378: # ifdef PCR
                    379: #   define DISABLE_SIGNALS() \
                    380:                 PCR_Th_SetSigMask(PCR_allSigsBlocked,&GC_old_sig_mask)
                    381: #   define ENABLE_SIGNALS() \
                    382:                PCR_Th_SetSigMask(&GC_old_sig_mask, NIL)
                    383: # else
1.5     ! noro      384: #   if defined(THREADS) || defined(AMIGA)  \
1.3       noro      385:        || defined(MSWIN32) || defined(MSWINCE) || defined(MACOS) \
1.5     ! noro      386:        || defined(DJGPP) || defined(NO_SIGNALS)
1.1       noro      387:                        /* Also useful for debugging.           */
1.5     ! noro      388:        /* Should probably use thr_sigsetmask for GC_SOLARIS_THREADS. */
1.1       noro      389: #     define DISABLE_SIGNALS()
                    390: #     define ENABLE_SIGNALS()
                    391: #   else
                    392: #     define DISABLE_SIGNALS() GC_disable_signals()
                    393:        void GC_disable_signals();
                    394: #     define ENABLE_SIGNALS() GC_enable_signals()
                    395:        void GC_enable_signals();
                    396: #   endif
                    397: # endif
                    398:
                    399: /*
                    400:  * Stop and restart mutator threads.
                    401:  */
                    402: # ifdef PCR
                    403: #     include "th/PCR_ThCtl.h"
                    404: #     define STOP_WORLD() \
                    405:        PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_stopNormal, \
                    406:                                   PCR_allSigsBlocked, \
                    407:                                   PCR_waitForever)
                    408: #     define START_WORLD() \
                    409:        PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_null, \
                    410:                                   PCR_allSigsBlocked, \
                    411:                                   PCR_waitForever);
                    412: # else
1.5     ! noro      413: #   if defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) \
        !           414:        || defined(GC_PTHREADS)
1.1       noro      415:       void GC_stop_world();
                    416:       void GC_start_world();
                    417: #     define STOP_WORLD() GC_stop_world()
                    418: #     define START_WORLD() GC_start_world()
                    419: #   else
                    420: #     define STOP_WORLD()
                    421: #     define START_WORLD()
                    422: #   endif
                    423: # endif
                    424:
                    425: /* Abandon ship */
                    426: # ifdef PCR
                    427: #   define ABORT(s) PCR_Base_Panic(s)
                    428: # else
                    429: #   ifdef SMALL_CONFIG
                    430: #      define ABORT(msg) abort();
                    431: #   else
1.5     ! noro      432:        GC_API void GC_abort GC_PROTO((GC_CONST char * msg));
1.1       noro      433: #       define ABORT(msg) GC_abort(msg);
                    434: #   endif
                    435: # endif
                    436:
                    437: /* Exit abnormally, but without making a mess (e.g. out of memory) */
                    438: # ifdef PCR
                    439: #   define EXIT() PCR_Base_Exit(1,PCR_waitForever)
                    440: # else
                    441: #   define EXIT() (void)exit(1)
                    442: # endif
                    443:
                    444: /* Print warning message, e.g. almost out of memory.   */
1.5     ! noro      445: # define WARN(msg,arg) (*GC_current_warn_proc)("GC Warning: " msg, (GC_word)(arg))
1.1       noro      446: extern GC_warn_proc GC_current_warn_proc;
                    447:
1.3       noro      448: /* Get environment entry */
                    449: #if !defined(NO_GETENV)
                    450: #   define GETENV(name) getenv(name)
                    451: #else
                    452: #   define GETENV(name) 0
                    453: #endif
                    454:
1.1       noro      455: /*********************************/
                    456: /*                               */
                    457: /* Word-size-dependent defines   */
                    458: /*                               */
                    459: /*********************************/
                    460:
                    461: #if CPP_WORDSZ == 32
                    462: #  define WORDS_TO_BYTES(x)   ((x)<<2)
                    463: #  define BYTES_TO_WORDS(x)   ((x)>>2)
                    464: #  define LOGWL               ((word)5)    /* log[2] of CPP_WORDSZ */
                    465: #  define modWORDSZ(n) ((n) & 0x1f)        /* n mod size of word           */
                    466: #  if ALIGNMENT != 4
                    467: #      define UNALIGNED
                    468: #  endif
                    469: #endif
                    470:
                    471: #if CPP_WORDSZ == 64
                    472: #  define WORDS_TO_BYTES(x)   ((x)<<3)
                    473: #  define BYTES_TO_WORDS(x)   ((x)>>3)
                    474: #  define LOGWL               ((word)6)    /* log[2] of CPP_WORDSZ */
                    475: #  define modWORDSZ(n) ((n) & 0x3f)        /* n mod size of word           */
                    476: #  if ALIGNMENT != 8
                    477: #      define UNALIGNED
                    478: #  endif
                    479: #endif
                    480:
                    481: #define WORDSZ ((word)CPP_WORDSZ)
                    482: #define SIGNB  ((word)1 << (WORDSZ-1))
                    483: #define BYTES_PER_WORD      ((word)(sizeof (word)))
1.3       noro      484: #define ONES                ((word)(signed_word)(-1))
1.1       noro      485: #define divWORDSZ(n) ((n) >> LOGWL)       /* divide n by size of word      */
                    486:
                    487: /*********************/
                    488: /*                   */
                    489: /*  Size Parameters  */
                    490: /*                   */
                    491: /*********************/
                    492:
                    493: /*  heap block size, bytes. Should be power of 2 */
                    494:
                    495: #ifndef HBLKSIZE
                    496: # ifdef SMALL_CONFIG
                    497: #   define CPP_LOG_HBLKSIZE 10
                    498: # else
1.5     ! noro      499: #   if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
        !           500:       /* HPUX/PA seems to use 4K pages with the 64 bit ABI */
1.1       noro      501: #     define CPP_LOG_HBLKSIZE 12
                    502: #   else
                    503: #     define CPP_LOG_HBLKSIZE 13
                    504: #   endif
                    505: # endif
                    506: #else
                    507: # if HBLKSIZE == 512
                    508: #   define CPP_LOG_HBLKSIZE 9
                    509: # endif
                    510: # if HBLKSIZE == 1024
                    511: #   define CPP_LOG_HBLKSIZE 10
                    512: # endif
                    513: # if HBLKSIZE == 2048
                    514: #   define CPP_LOG_HBLKSIZE 11
                    515: # endif
                    516: # if HBLKSIZE == 4096
                    517: #   define CPP_LOG_HBLKSIZE 12
                    518: # endif
                    519: # if HBLKSIZE == 8192
                    520: #   define CPP_LOG_HBLKSIZE 13
                    521: # endif
                    522: # if HBLKSIZE == 16384
                    523: #   define CPP_LOG_HBLKSIZE 14
                    524: # endif
                    525: # ifndef CPP_LOG_HBLKSIZE
                    526:     --> fix HBLKSIZE
                    527: # endif
                    528: # undef HBLKSIZE
                    529: #endif
                    530: # define CPP_HBLKSIZE (1 << CPP_LOG_HBLKSIZE)
                    531: # define LOG_HBLKSIZE   ((word)CPP_LOG_HBLKSIZE)
                    532: # define HBLKSIZE ((word)CPP_HBLKSIZE)
                    533:
                    534:
                    535: /*  max size objects supported by freelist (larger objects may be   */
                    536: /*  allocated, but less efficiently)                                */
                    537:
1.3       noro      538: #define CPP_MAXOBJBYTES (CPP_HBLKSIZE/2)
                    539: #define MAXOBJBYTES ((word)CPP_MAXOBJBYTES)
1.1       noro      540: #define CPP_MAXOBJSZ    BYTES_TO_WORDS(CPP_HBLKSIZE/2)
                    541: #define MAXOBJSZ ((word)CPP_MAXOBJSZ)
                    542:
                    543: # define divHBLKSZ(n) ((n) >> LOG_HBLKSIZE)
                    544:
                    545: # define HBLK_PTR_DIFF(p,q) divHBLKSZ((ptr_t)p - (ptr_t)q)
                    546:        /* Equivalent to subtracting 2 hblk pointers.   */
                    547:        /* We do it this way because a compiler should  */
                    548:        /* find it hard to use an integer division      */
                    549:        /* instead of a shift.  The bundled SunOS 4.1   */
                    550:        /* o.w. sometimes pessimizes the subtraction to */
                    551:        /* involve a call to .div.                      */
                    552:
                    553: # define modHBLKSZ(n) ((n) & (HBLKSIZE-1))
                    554:
                    555: # define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
                    556:
                    557: # define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
                    558:
                    559: /* Round up byte allocation requests to integral number of words, etc. */
1.3       noro      560: # define ROUNDED_UP_WORDS(n) \
                    561:        BYTES_TO_WORDS((n) + (WORDS_TO_BYTES(1) - 1 + EXTRA_BYTES))
                    562: # ifdef ALIGN_DOUBLE
                    563: #       define ALIGNED_WORDS(n) \
                    564:            (BYTES_TO_WORDS((n) + WORDS_TO_BYTES(2) - 1 + EXTRA_BYTES) & ~1)
                    565: # else
1.1       noro      566: #       define ALIGNED_WORDS(n) ROUNDED_UP_WORDS(n)
1.3       noro      567: # endif
1.5     ! noro      568: # define SMALL_OBJ(bytes) ((bytes) < (MAXOBJBYTES - EXTRA_BYTES))
1.3       noro      569: # define ADD_SLOP(bytes) ((bytes) + EXTRA_BYTES)
                    570: # ifndef MIN_WORDS
                    571:     /* MIN_WORDS is the size of the smallest allocated object. */
                    572:     /* 1 and 2 are the only valid values.                      */
                    573:     /* 2 must be used if:                                      */
                    574:     /* - GC_gcj_malloc can be used for objects of requested    */
                    575:     /*   size  smaller than 2 words, or                                */
                    576:     /* - USE_MARK_BYTES is defined.                            */
                    577: #   if defined(USE_MARK_BYTES) || defined(GC_GCJ_SUPPORT)
                    578: #     define MIN_WORDS 2       /* Smallest allocated object.   */
1.1       noro      579: #   else
1.3       noro      580: #     define MIN_WORDS 1
1.1       noro      581: #   endif
                    582: # endif
                    583:
                    584:
                    585: /*
                    586:  * Hash table representation of sets of pages.  This assumes it is
                    587:  * OK to add spurious entries to sets.
                    588:  * Used by black-listing code, and perhaps by dirty bit maintenance code.
                    589:  */
                    590:
                    591: # ifdef LARGE_CONFIG
1.3       noro      592: #   define LOG_PHT_ENTRIES  19  /* Collisions likely at 512K blocks,   */
                    593:                                /* which is >= 2GB.  Each table takes   */
                    594:                                /* 64KB.                                */
1.1       noro      595: # else
1.3       noro      596: #   ifdef SMALL_CONFIG
                    597: #     define LOG_PHT_ENTRIES  14 /* Collisions are likely if heap grows        */
                    598:                                 /* to more than 16K hblks = 64MB.      */
                    599:                                 /* Each hash table occupies 2K bytes.   */
                    600: #   else /* default "medium" configuration */
                    601: #     define LOG_PHT_ENTRIES  16 /* Collisions are likely if heap grows        */
                    602:                                 /* to more than 16K hblks >= 256MB.    */
                    603:                                 /* Each hash table occupies 8K bytes.  */
                    604: #   endif
1.1       noro      605: # endif
                    606: # define PHT_ENTRIES ((word)1 << LOG_PHT_ENTRIES)
                    607: # define PHT_SIZE (PHT_ENTRIES >> LOGWL)
                    608: typedef word page_hash_table[PHT_SIZE];
                    609:
                    610: # define PHT_HASH(addr) ((((word)(addr)) >> LOG_HBLKSIZE) & (PHT_ENTRIES - 1))
                    611:
                    612: # define get_pht_entry_from_index(bl, index) \
                    613:                (((bl)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
                    614: # define set_pht_entry_from_index(bl, index) \
                    615:                (bl)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
                    616: # define clear_pht_entry_from_index(bl, index) \
                    617:                (bl)[divWORDSZ(index)] &= ~((word)1 << modWORDSZ(index))
1.3       noro      618: /* And a dumb but thread-safe version of set_pht_entry_from_index.     */
                    619: /* This sets (many) extra bits.                                                */
                    620: # define set_pht_entry_from_index_safe(bl, index) \
                    621:                (bl)[divWORDSZ(index)] = ONES
1.1       noro      622:
                    623:
                    624:
                    625: /********************************************/
                    626: /*                                          */
                    627: /*    H e a p   B l o c k s                 */
                    628: /*                                          */
                    629: /********************************************/
                    630:
                    631: /*  heap block header */
                    632: #define HBLKMASK   (HBLKSIZE-1)
                    633:
1.3       noro      634: #define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
1.1       noro      635:
                    636: #define MARK_BITS_PER_HBLK (BITS_PER_HBLK/CPP_WORDSZ)
                    637:           /* upper bound                                    */
1.3       noro      638:           /* We allocate 1 bit/word, unless USE_MARK_BYTES  */
                    639:           /* is defined.  Only the first word               */
1.1       noro      640:           /* in each object is actually marked.             */
                    641:
1.3       noro      642: # ifdef USE_MARK_BYTES
                    643: #   define MARK_BITS_SZ (MARK_BITS_PER_HBLK/2)
                    644:        /* Unlike the other case, this is in units of bytes.            */
                    645:        /* We actually allocate only every second mark bit, since we    */
                    646:        /* force all objects to be doubleword aligned.                  */
                    647:        /* However, each mark bit is allocated as a byte.               */
1.1       noro      648: # else
1.3       noro      649: #   define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
1.1       noro      650: # endif
1.3       noro      651:
                    652: /* We maintain layout maps for heap blocks containing objects of a given */
                    653: /* size.  Each entry in this map describes a byte offset and has the    */
                    654: /* following type.                                                      */
                    655: typedef unsigned char map_entry_type;
1.1       noro      656:
                    657: struct hblkhdr {
                    658:     word hb_sz;  /* If in use, size in words, of objects in the block. */
                    659:                 /* if free, the size in bytes of the whole block      */
                    660:     struct hblk * hb_next;     /* Link field for hblk free list         */
                    661:                                /* and for lists of chunks waiting to be */
                    662:                                /* reclaimed.                            */
                    663:     struct hblk * hb_prev;     /* Backwards link for free list.        */
                    664:     word hb_descr;             /* object descriptor for marking.  See  */
                    665:                                /* mark.h.                              */
1.3       noro      666:     map_entry_type * hb_map;
                    667:                        /* A pointer to a pointer validity map of the block. */
1.1       noro      668:                        /* See GC_obj_map.                                   */
                    669:                        /* Valid for all blocks with headers.                */
                    670:                        /* Free blocks point to GC_invalid_map.              */
                    671:     unsigned char hb_obj_kind;
                    672:                         /* Kind of objects in the block.  Each kind    */
                    673:                         /* identifies a mark procedure and a set of    */
                    674:                         /* list headers.  Sometimes called regions.    */
                    675:     unsigned char hb_flags;
                    676: #      define IGNORE_OFF_PAGE  1       /* Ignore pointers that do not  */
                    677:                                        /* point to the first page of   */
                    678:                                        /* this object.                 */
                    679: #      define WAS_UNMAPPED 2   /* This is a free block, which has      */
                    680:                                /* been unmapped from the address       */
                    681:                                /* space.                               */
                    682:                                /* GC_remap must be invoked on it       */
                    683:                                /* before it can be reallocated.        */
                    684:                                /* Only set with USE_MUNMAP.            */
                    685:     unsigned short hb_last_reclaimed;
                    686:                                /* Value of GC_gc_no when block was     */
                    687:                                /* last allocated or swept. May wrap.   */
                    688:                                /* For a free block, this is maintained */
1.3       noro      689:                                /* only for USE_MUNMAP, and indicates   */
1.1       noro      690:                                /* when the header was allocated, or    */
                    691:                                /* when the size of the block last      */
                    692:                                /* changed.                             */
1.3       noro      693: #   ifdef USE_MARK_BYTES
                    694:       union {
                    695:         char _hb_marks[MARK_BITS_SZ];
                    696:                            /* The i'th byte is 1 if the object         */
                    697:                            /* starting at word 2i is marked, 0 o.w.    */
                    698:        word dummy;     /* Force word alignment of mark bytes. */
                    699:       } _mark_byte_union;
                    700: #     define hb_marks _mark_byte_union._hb_marks
                    701: #   else
                    702:       word hb_marks[MARK_BITS_SZ];
1.1       noro      703:                            /* Bit i in the array refers to the             */
                    704:                            /* object starting at the ith word (header      */
                    705:                            /* INCLUDED) in the heap block.                 */
                    706:                            /* The lsb of word 0 is numbered 0.             */
1.2       noro      707:                            /* Unused bits are invalid, and are             */
                    708:                            /* occasionally set, e.g for uncollectable      */
                    709:                            /* objects.                                     */
1.3       noro      710: #   endif /* !USE_MARK_BYTES */
1.1       noro      711: };
                    712:
                    713: /*  heap block body */
                    714:
1.3       noro      715: # define BODY_SZ (HBLKSIZE/sizeof(word))
1.1       noro      716:
                    717: struct hblk {
                    718:     word hb_body[BODY_SZ];
                    719: };
                    720:
1.5     ! noro      721: # define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
        !           722:
1.1       noro      723: # define OBJ_SZ_TO_BLOCKS(sz) \
1.3       noro      724:     divHBLKSZ(WORDS_TO_BYTES(sz) + HBLKSIZE-1)
1.1       noro      725:     /* Size of block (in units of HBLKSIZE) needed to hold objects of  */
                    726:     /* given sz (in words).                                            */
                    727:
                    728: /* Object free list link */
                    729: # define obj_link(p) (*(ptr_t *)(p))
                    730:
                    731: # define LOG_MAX_MARK_PROCS 6
                    732: # define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
                    733:
                    734: /* Root sets.  Logically private to mark_rts.c.  But we don't want the */
                    735: /* tables scanned, so we put them here.                                        */
                    736: /* MAX_ROOT_SETS is the maximum number of ranges that can be   */
                    737: /* registered as static roots.                                         */
                    738: # ifdef LARGE_CONFIG
                    739: #   define MAX_ROOT_SETS 4096
                    740: # else
                    741: #   ifdef PCR
                    742: #     define MAX_ROOT_SETS 1024
                    743: #   else
1.3       noro      744: #     if defined(MSWIN32) || defined(MSWINCE)
                    745: #      define MAX_ROOT_SETS 1024
1.1       noro      746:            /* Under NT, we add only written pages, which can result    */
                    747:            /* in many small root sets.                                 */
                    748: #     else
1.3       noro      749: #       define MAX_ROOT_SETS 256
1.1       noro      750: #     endif
                    751: #   endif
                    752: # endif
                    753:
                    754: # define MAX_EXCLUSIONS (MAX_ROOT_SETS/4)
                    755: /* Maximum number of segments that can be excluded from root sets.     */
                    756:
                    757: /*
                    758:  * Data structure for excluded static roots.
                    759:  */
                    760: struct exclusion {
                    761:     ptr_t e_start;
                    762:     ptr_t e_end;
                    763: };
                    764:
                    765: /* Data structure for list of root sets.                               */
                    766: /* We keep a hash table, so that we can filter out duplicate additions.        */
                    767: /* Under Win32, we need to do a better job of filtering overlaps, so   */
                    768: /* we resort to sequential search, and pay the price.                  */
                    769: struct roots {
                    770:        ptr_t r_start;
                    771:        ptr_t r_end;
1.3       noro      772: #      if !defined(MSWIN32) && !defined(MSWINCE)
1.1       noro      773:          struct roots * r_next;
                    774: #      endif
                    775:        GC_bool r_tmp;
                    776:                /* Delete before registering new dynamic libraries */
                    777: };
                    778:
1.3       noro      779: #if !defined(MSWIN32) && !defined(MSWINCE)
1.1       noro      780:     /* Size of hash table index to roots.      */
                    781: #   define LOG_RT_SIZE 6
                    782: #   define RT_SIZE (1 << LOG_RT_SIZE) /* Power of 2, may be != MAX_ROOT_SETS */
                    783: #endif
                    784:
                    785: /* Lists of all heap blocks and free lists     */
                    786: /* as well as other random data structures     */
                    787: /* that should not be scanned by the           */
                    788: /* collector.                                  */
                    789: /* These are grouped together in a struct      */
                    790: /* so that they can be easily skipped by the   */
                    791: /* GC_mark routine.                            */
                    792: /* The ordering is weird to make GC_malloc     */
                    793: /* faster by keeping the important fields      */
                    794: /* sufficiently close together that a          */
                    795: /* single load of a base register will do.     */
                    796: /* Scalars that could easily appear to         */
                    797: /* be pointers are also put here.              */
                    798: /* The main fields should precede any          */
                    799: /* conditionally included fields, so that      */
                    800: /* gc_inl.h will work even if a different set  */
                    801: /* of macros is defined when the client is     */
                    802: /* compiled.                                   */
                    803:
                    804: struct _GC_arrays {
                    805:   word _heapsize;
                    806:   word _max_heapsize;
1.3       noro      807:   word _requested_heapsize;    /* Heap size due to explicit expansion */
1.1       noro      808:   ptr_t _last_heap_addr;
                    809:   ptr_t _prev_heap_addr;
                    810:   word _large_free_bytes;
                    811:        /* Total bytes contained in blocks on large object free */
                    812:        /* list.                                                */
1.3       noro      813:   word _large_allocd_bytes;
                    814:        /* Total number of bytes in allocated large objects blocks.     */
                    815:        /* For the purposes of this counter and the next one only, a    */
                    816:        /* large object is one that occupies a block of at least        */
                    817:        /* 2*HBLKSIZE.                                                  */
                    818:   word _max_large_allocd_bytes;
                    819:        /* Maximum number of bytes that were ever allocated in          */
                    820:        /* large object blocks.  This is used to help decide when it    */
                    821:        /* is safe to split up a large block.                           */
1.1       noro      822:   word _words_allocd_before_gc;
                    823:                /* Number of words allocated before this        */
                    824:                /* collection cycle.                            */
1.3       noro      825: # ifndef SEPARATE_GLOBALS
                    826:     word _words_allocd;
1.1       noro      827:        /* Number of words allocated during this collection cycle */
1.3       noro      828: # endif
1.1       noro      829:   word _words_wasted;
                    830:        /* Number of words wasted due to internal fragmentation */
                    831:        /* in large objects, or due to dropping blacklisted     */
                    832:        /* blocks, since last gc.  Approximate.                 */
                    833:   word _words_finalized;
                    834:        /* Approximate number of words in objects (and headers) */
                    835:        /* That became ready for finalization in the last       */
                    836:        /* collection.                                          */
                    837:   word _non_gc_bytes_at_gc;
                    838:        /* Number of explicitly managed bytes of storage        */
                    839:        /* at last collection.                                  */
                    840:   word _mem_freed;
                    841:        /* Number of explicitly deallocated words of memory     */
                    842:        /* since last collection.                               */
1.5     ! noro      843:   word _finalizer_mem_freed;
        !           844:        /* Words of memory explicitly deallocated while         */
        !           845:        /* finalizers were running.  Used to approximate mem.   */
        !           846:        /* explicitly deallocated by finalizers.                */
1.3       noro      847:   ptr_t _scratch_end_ptr;
                    848:   ptr_t _scratch_last_end_ptr;
                    849:        /* Used by headers.c, and can easily appear to point to */
                    850:        /* heap.                                                */
                    851:   GC_mark_proc _mark_procs[MAX_MARK_PROCS];
1.1       noro      852:        /* Table of user-defined mark procedures.  There is     */
                    853:        /* a small number of these, which can be referenced     */
                    854:        /* by DS_PROC mark descriptors.  See gc_mark.h.         */
1.3       noro      855:
                    856: # ifndef SEPARATE_GLOBALS
                    857:     ptr_t _objfreelist[MAXOBJSZ+1];
1.1       noro      858:                          /* free list for objects */
1.3       noro      859:     ptr_t _aobjfreelist[MAXOBJSZ+1];
1.1       noro      860:                          /* free list for atomic objs  */
1.3       noro      861: # endif
1.1       noro      862:
                    863:   ptr_t _uobjfreelist[MAXOBJSZ+1];
                    864:                          /* uncollectable but traced objs      */
                    865:                          /* objects on this and auobjfreelist  */
                    866:                          /* are always marked, except during   */
                    867:                          /* garbage collections.               */
                    868: # ifdef ATOMIC_UNCOLLECTABLE
                    869:     ptr_t _auobjfreelist[MAXOBJSZ+1];
                    870: # endif
                    871:                          /* uncollectable but traced objs      */
                    872:
                    873: # ifdef GATHERSTATS
                    874:     word _composite_in_use;
                    875:                /* Number of words in accessible composite      */
                    876:                /* objects.                                     */
                    877:     word _atomic_in_use;
                    878:                /* Number of words in accessible atomic         */
                    879:                /* objects.                                     */
                    880: # endif
                    881: # ifdef USE_MUNMAP
                    882:     word _unmapped_bytes;
                    883: # endif
                    884: # ifdef MERGE_SIZES
                    885:     unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
                    886:        /* Number of words to allocate for a given allocation request in */
                    887:        /* bytes.                                                        */
                    888: # endif
                    889:
                    890: # ifdef STUBBORN_ALLOC
                    891:     ptr_t _sobjfreelist[MAXOBJSZ+1];
                    892: # endif
                    893:                          /* free list for immutable objects    */
1.3       noro      894:   map_entry_type * _obj_map[MAXOBJSZ+1];
1.1       noro      895:                        /* If not NIL, then a pointer to a map of valid  */
                    896:                       /* object addresses. _obj_map[sz][i] is j if the */
                    897:                       /* address block_start+i is a valid pointer      */
1.3       noro      898:                       /* to an object at block_start +                 */
                    899:                       /* WORDS_TO_BYTES(BYTES_TO_WORDS(i) - j)         */
                    900:                       /* I.e. j is a word displacement from the        */
                    901:                       /* object beginning.                             */
                    902:                       /* The entry is OBJ_INVALID if the corresponding */
                    903:                       /* address is not a valid pointer.  It is        */
                    904:                       /* OFFSET_TOO_BIG if the value j would be too    */
                    905:                       /* large to fit in the entry.  (Note that the    */
                    906:                       /* size of these entries matters, both for       */
                    907:                       /* space consumption and for cache utilization.  */
                    908: #   define OFFSET_TOO_BIG 0xfe
                    909: #   define OBJ_INVALID 0xff
                    910: #   define MAP_ENTRY(map, bytes) (map)[bytes]
                    911: #   define MAP_ENTRIES HBLKSIZE
                    912: #   define MAP_SIZE MAP_ENTRIES
                    913: #   define CPP_MAX_OFFSET (OFFSET_TOO_BIG - 1)
                    914: #   define MAX_OFFSET ((word)CPP_MAX_OFFSET)
                    915:     /* The following are used only if GC_all_interior_ptrs != 0 */
1.1       noro      916: #      define VALID_OFFSET_SZ \
                    917:          (CPP_MAX_OFFSET > WORDS_TO_BYTES(CPP_MAXOBJSZ)? \
                    918:           CPP_MAX_OFFSET+1 \
                    919:           : WORDS_TO_BYTES(CPP_MAXOBJSZ)+1)
                    920:        char _valid_offsets[VALID_OFFSET_SZ];
                    921:                                /* GC_valid_offsets[i] == TRUE ==> i    */
                    922:                                /* is registered as a displacement.     */
1.3       noro      923: #      define OFFSET_VALID(displ) \
                    924:          (GC_all_interior_pointers || GC_valid_offsets[displ])
1.1       noro      925:        char _modws_valid_offsets[sizeof(word)];
                    926:                                /* GC_valid_offsets[i] ==>                */
                    927:                                /* GC_modws_valid_offsets[i%sizeof(word)] */
                    928: # ifdef STUBBORN_ALLOC
                    929:     page_hash_table _changed_pages;
                    930:         /* Stubborn object pages that were changes since last call to  */
                    931:        /* GC_read_changed.                                             */
                    932:     page_hash_table _prev_changed_pages;
                    933:         /* Stubborn object pages that were changes before last call to */
                    934:        /* GC_read_changed.                                             */
                    935: # endif
                    936: # if defined(PROC_VDB) || defined(MPROTECT_VDB)
                    937:     page_hash_table _grungy_pages; /* Pages that were dirty at last       */
                    938:                                     /* GC_read_dirty.                     */
                    939: # endif
                    940: # ifdef MPROTECT_VDB
                    941:     VOLATILE page_hash_table _dirty_pages;
                    942:                        /* Pages dirtied since last GC_read_dirty. */
                    943: # endif
                    944: # ifdef PROC_VDB
                    945:     page_hash_table _written_pages;    /* Pages ever dirtied   */
                    946: # endif
                    947: # ifdef LARGE_CONFIG
                    948: #   if CPP_WORDSZ > 32
                    949: #     define MAX_HEAP_SECTS 4096       /* overflows at roughly 64 GB      */
                    950: #   else
                    951: #     define MAX_HEAP_SECTS 768                /* Separately added heap sections. */
                    952: #   endif
                    953: # else
1.3       noro      954: #   ifdef SMALL_CONFIG
                    955: #     define MAX_HEAP_SECTS 128                /* Roughly 1GB                  */
                    956: #   else
                    957: #     define MAX_HEAP_SECTS 384                /* Roughly 3GB                  */
                    958: #   endif
1.1       noro      959: # endif
                    960:   struct HeapSect {
                    961:       ptr_t hs_start; word hs_bytes;
                    962:   } _heap_sects[MAX_HEAP_SECTS];
1.3       noro      963: # if defined(MSWIN32) || defined(MSWINCE)
1.1       noro      964:     ptr_t _heap_bases[MAX_HEAP_SECTS];
                    965:                /* Start address of memory regions obtained from kernel. */
                    966: # endif
1.3       noro      967: # ifdef MSWINCE
                    968:     word _heap_lengths[MAX_HEAP_SECTS];
                    969:                /* Commited lengths of memory regions obtained from kernel. */
                    970: # endif
1.1       noro      971:   struct roots _static_roots[MAX_ROOT_SETS];
1.3       noro      972: # if !defined(MSWIN32) && !defined(MSWINCE)
1.1       noro      973:     struct roots * _root_index[RT_SIZE];
                    974: # endif
                    975:   struct exclusion _excl_table[MAX_EXCLUSIONS];
                    976:   /* Block header index; see gc_headers.h */
                    977:   bottom_index * _all_nils;
                    978:   bottom_index * _top_index [TOP_SZ];
                    979: #ifdef SAVE_CALL_CHAIN
                    980:   struct callinfo _last_stack[NFRAMES];        /* Stack at last garbage collection.*/
                    981:                                        /* Useful for debugging mysterious  */
                    982:                                        /* object disappearances.           */
                    983:                                        /* In the multithreaded case, we    */
                    984:                                        /* currently only save the calling  */
                    985:                                        /* stack.                           */
                    986: #endif
                    987: };
                    988:
                    989: GC_API GC_FAR struct _GC_arrays GC_arrays;
                    990:
1.3       noro      991: # ifndef SEPARATE_GLOBALS
                    992: #   define GC_objfreelist GC_arrays._objfreelist
                    993: #   define GC_aobjfreelist GC_arrays._aobjfreelist
                    994: #   define GC_words_allocd GC_arrays._words_allocd
                    995: # endif
1.1       noro      996: # define GC_uobjfreelist GC_arrays._uobjfreelist
                    997: # ifdef ATOMIC_UNCOLLECTABLE
                    998: #   define GC_auobjfreelist GC_arrays._auobjfreelist
                    999: # endif
                   1000: # define GC_sobjfreelist GC_arrays._sobjfreelist
                   1001: # define GC_valid_offsets GC_arrays._valid_offsets
                   1002: # define GC_modws_valid_offsets GC_arrays._modws_valid_offsets
                   1003: # ifdef STUBBORN_ALLOC
                   1004: #    define GC_changed_pages GC_arrays._changed_pages
                   1005: #    define GC_prev_changed_pages GC_arrays._prev_changed_pages
                   1006: # endif
                   1007: # define GC_obj_map GC_arrays._obj_map
                   1008: # define GC_last_heap_addr GC_arrays._last_heap_addr
                   1009: # define GC_prev_heap_addr GC_arrays._prev_heap_addr
                   1010: # define GC_words_wasted GC_arrays._words_wasted
                   1011: # define GC_large_free_bytes GC_arrays._large_free_bytes
1.3       noro     1012: # define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
                   1013: # define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes
1.1       noro     1014: # define GC_words_finalized GC_arrays._words_finalized
                   1015: # define GC_non_gc_bytes_at_gc GC_arrays._non_gc_bytes_at_gc
                   1016: # define GC_mem_freed GC_arrays._mem_freed
1.5     ! noro     1017: # define GC_finalizer_mem_freed GC_arrays._finalizer_mem_freed
1.3       noro     1018: # define GC_scratch_end_ptr GC_arrays._scratch_end_ptr
                   1019: # define GC_scratch_last_end_ptr GC_arrays._scratch_last_end_ptr
1.1       noro     1020: # define GC_mark_procs GC_arrays._mark_procs
                   1021: # define GC_heapsize GC_arrays._heapsize
                   1022: # define GC_max_heapsize GC_arrays._max_heapsize
1.3       noro     1023: # define GC_requested_heapsize GC_arrays._requested_heapsize
1.1       noro     1024: # define GC_words_allocd_before_gc GC_arrays._words_allocd_before_gc
                   1025: # define GC_heap_sects GC_arrays._heap_sects
                   1026: # define GC_last_stack GC_arrays._last_stack
                   1027: # ifdef USE_MUNMAP
                   1028: #   define GC_unmapped_bytes GC_arrays._unmapped_bytes
                   1029: # endif
1.3       noro     1030: # if defined(MSWIN32) || defined(MSWINCE)
1.1       noro     1031: #   define GC_heap_bases GC_arrays._heap_bases
                   1032: # endif
1.3       noro     1033: # ifdef MSWINCE
                   1034: #   define GC_heap_lengths GC_arrays._heap_lengths
                   1035: # endif
1.1       noro     1036: # define GC_static_roots GC_arrays._static_roots
                   1037: # define GC_root_index GC_arrays._root_index
                   1038: # define GC_excl_table GC_arrays._excl_table
                   1039: # define GC_all_nils GC_arrays._all_nils
                   1040: # define GC_top_index GC_arrays._top_index
                   1041: # if defined(PROC_VDB) || defined(MPROTECT_VDB)
                   1042: #   define GC_grungy_pages GC_arrays._grungy_pages
                   1043: # endif
                   1044: # ifdef MPROTECT_VDB
                   1045: #   define GC_dirty_pages GC_arrays._dirty_pages
                   1046: # endif
                   1047: # ifdef PROC_VDB
                   1048: #   define GC_written_pages GC_arrays._written_pages
                   1049: # endif
                   1050: # ifdef GATHERSTATS
                   1051: #   define GC_composite_in_use GC_arrays._composite_in_use
                   1052: #   define GC_atomic_in_use GC_arrays._atomic_in_use
                   1053: # endif
                   1054: # ifdef MERGE_SIZES
                   1055: #   define GC_size_map GC_arrays._size_map
                   1056: # endif
                   1057:
                   1058: # define beginGC_arrays ((ptr_t)(&GC_arrays))
                   1059: # define endGC_arrays (((ptr_t)(&GC_arrays)) + (sizeof GC_arrays))
                   1060:
1.3       noro     1061: #define USED_HEAP_SIZE (GC_heapsize - GC_large_free_bytes)
                   1062:
1.1       noro     1063: /* Object kinds: */
                   1064: # define MAXOBJKINDS 16
                   1065:
                   1066: extern struct obj_kind {
                   1067:    ptr_t *ok_freelist; /* Array of free listheaders for this kind of object */
                   1068:                        /* Point either to GC_arrays or to storage allocated */
                   1069:                        /* with GC_scratch_alloc.                            */
                   1070:    struct hblk **ok_reclaim_list;
                   1071:                        /* List headers for lists of blocks waiting to be */
                   1072:                        /* swept.                                         */
                   1073:    word ok_descriptor;  /* Descriptor template for objects in this     */
                   1074:                        /* block.                                       */
                   1075:    GC_bool ok_relocate_descr;
                   1076:                        /* Add object size in bytes to descriptor       */
                   1077:                        /* template to obtain descriptor.  Otherwise    */
                   1078:                        /* template is used as is.                      */
                   1079:    GC_bool ok_init;   /* Clear objects before putting them on the free list. */
                   1080: } GC_obj_kinds[MAXOBJKINDS];
                   1081:
1.3       noro     1082: # define beginGC_obj_kinds ((ptr_t)(&GC_obj_kinds))
                   1083: # define endGC_obj_kinds (beginGC_obj_kinds + (sizeof GC_obj_kinds))
1.1       noro     1084:
1.3       noro     1085: /* Variables that used to be in GC_arrays, but need to be accessed by  */
                   1086: /* inline allocation code.  If they were in GC_arrays, the inlined     */
                   1087: /* allocation code would include GC_arrays offsets (as it did), which  */
                   1088: /* introduce maintenance problems.                                     */
                   1089:
                   1090: #ifdef SEPARATE_GLOBALS
                   1091:   word GC_words_allocd;
                   1092:        /* Number of words allocated during this collection cycle */
                   1093:   ptr_t GC_objfreelist[MAXOBJSZ+1];
                   1094:                          /* free list for NORMAL objects */
                   1095: # define beginGC_objfreelist ((ptr_t)(&GC_objfreelist))
                   1096: # define endGC_objfreelist (beginGC_objfreelist + sizeof(GC_objfreelist))
                   1097:
                   1098:   ptr_t GC_aobjfreelist[MAXOBJSZ+1];
                   1099:                          /* free list for atomic (PTRFREE) objs        */
                   1100: # define beginGC_aobjfreelist ((ptr_t)(&GC_aobjfreelist))
                   1101: # define endGC_aobjfreelist (beginGC_aobjfreelist + sizeof(GC_aobjfreelist))
                   1102: #endif
1.1       noro     1103:
                   1104: /* Predefined kinds: */
                   1105: # define PTRFREE 0
                   1106: # define NORMAL  1
                   1107: # define UNCOLLECTABLE 2
                   1108: # ifdef ATOMIC_UNCOLLECTABLE
                   1109: #   define AUNCOLLECTABLE 3
                   1110: #   define STUBBORN 4
                   1111: #   define IS_UNCOLLECTABLE(k) (((k) & ~1) == UNCOLLECTABLE)
                   1112: # else
                   1113: #   define STUBBORN 3
                   1114: #   define IS_UNCOLLECTABLE(k) ((k) == UNCOLLECTABLE)
                   1115: # endif
                   1116:
                   1117: extern int GC_n_kinds;
                   1118:
                   1119: GC_API word GC_fo_entries;
                   1120:
                   1121: extern word GC_n_heap_sects;   /* Number of separately added heap      */
                   1122:                                /* sections.                            */
                   1123:
                   1124: extern word GC_page_size;
                   1125:
1.3       noro     1126: # if defined(MSWIN32) || defined(MSWINCE)
                   1127:   struct _SYSTEM_INFO;
                   1128:   extern struct _SYSTEM_INFO GC_sysinfo;
                   1129:   extern word GC_n_heap_bases; /* See GC_heap_bases.   */
1.1       noro     1130: # endif
                   1131:
                   1132: extern word GC_total_stack_black_listed;
                   1133:                        /* Number of bytes on stack blacklist.  */
                   1134:
                   1135: extern word GC_black_list_spacing;
                   1136:                        /* Average number of bytes between blacklisted  */
                   1137:                        /* blocks. Approximate.                         */
                   1138:                        /* Counts only blocks that are                  */
                   1139:                        /* "stack-blacklisted", i.e. that are           */
                   1140:                        /* problematic in the interior of an object.    */
                   1141:
1.3       noro     1142: extern map_entry_type * GC_invalid_map;
1.1       noro     1143:                        /* Pointer to the nowhere valid hblk map */
                   1144:                        /* Blocks pointing to this map are free. */
                   1145:
                   1146: extern struct hblk * GC_hblkfreelist[];
                   1147:                                /* List of completely empty heap blocks */
                   1148:                                /* Linked through hb_next field of      */
                   1149:                                /* header structure associated with     */
                   1150:                                /* block.                               */
                   1151:
                   1152: extern GC_bool GC_objects_are_marked;  /* There are marked objects in  */
                   1153:                                        /* the heap.                    */
                   1154:
                   1155: #ifndef SMALL_CONFIG
                   1156:   extern GC_bool GC_incremental;
                   1157:                        /* Using incremental/generational collection. */
1.5     ! noro     1158: # define TRUE_INCREMENTAL \
        !          1159:        (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED)
        !          1160:        /* True incremental, not just generational, mode */
1.1       noro     1161: #else
1.3       noro     1162: # define GC_incremental FALSE
1.1       noro     1163:                        /* Hopefully allow optimizer to remove some code. */
1.5     ! noro     1164: # define TRUE_INCREMENTAL FALSE
1.1       noro     1165: #endif
                   1166:
                   1167: extern GC_bool GC_dirty_maintained;
                   1168:                                /* Dirty bits are being maintained,     */
                   1169:                                /* either for incremental collection,   */
                   1170:                                /* or to limit the root set.            */
                   1171:
                   1172: extern word GC_root_size;      /* Total size of registered root sections */
                   1173:
                   1174: extern GC_bool GC_debugging_started;   /* GC_debug_malloc has been called. */
                   1175:
1.5     ! noro     1176: extern long GC_large_alloc_warn_interval;
        !          1177:        /* Interval between unsuppressed warnings.      */
        !          1178:
        !          1179: extern long GC_large_alloc_warn_suppressed;
        !          1180:        /* Number of warnings suppressed so far.        */
        !          1181:
1.1       noro     1182: /* Operations */
                   1183: # ifndef abs
                   1184: #   define abs(x)  ((x) < 0? (-(x)) : (x))
                   1185: # endif
                   1186:
                   1187:
                   1188: /*  Marks are in a reserved area in                          */
                   1189: /*  each heap block.  Each word has one mark bit associated  */
                   1190: /*  with it. Only those corresponding to the beginning of an */
                   1191: /*  object are used.                                         */
                   1192:
1.3       noro     1193: /* Set mark bit correctly, even if mark bits may be concurrently       */
                   1194: /* accessed.                                                           */
                   1195: #ifdef PARALLEL_MARK
                   1196: # define OR_WORD(addr, bits) \
                   1197:        { word old; \
                   1198:          do { \
                   1199:            old = *((volatile word *)addr); \
                   1200:          } while (!GC_compare_and_exchange((addr), old, old | (bits))); \
                   1201:        }
                   1202: # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
                   1203:        { word old; \
                   1204:          word my_bits = (bits); \
                   1205:          do { \
                   1206:            old = *((volatile word *)addr); \
                   1207:            if (old & my_bits) goto exit_label; \
                   1208:          } while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
                   1209:        }
                   1210: #else
                   1211: # define OR_WORD(addr, bits) *(addr) |= (bits)
                   1212: # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
                   1213:        { \
                   1214:          word old = *(addr); \
                   1215:          word my_bits = (bits); \
                   1216:          if (old & my_bits) goto exit_label; \
                   1217:          *(addr) = (old | my_bits); \
                   1218:        }
                   1219: #endif
1.1       noro     1220:
                   1221: /* Mark bit operations */
                   1222:
                   1223: /*
                   1224:  * Retrieve, set, clear the mark bit corresponding
                   1225:  * to the nth word in a given heap block.
                   1226:  *
                   1227:  * (Recall that bit n corresponds to object beginning at word n
                   1228:  * relative to the beginning of the block, including unused words)
                   1229:  */
                   1230:
1.3       noro     1231: #ifdef USE_MARK_BYTES
                   1232: # define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n) >> 1])
                   1233: # define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 1
                   1234: # define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 0
                   1235: #else /* !USE_MARK_BYTES */
1.1       noro     1236: # define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
                   1237:                            >> (modWORDSZ(n))) & (word)1)
1.3       noro     1238: # define set_mark_bit_from_hdr(hhdr,n) \
                   1239:                            OR_WORD((hhdr)->hb_marks+divWORDSZ(n), \
                   1240:                                    (word)1 << modWORDSZ(n))
1.1       noro     1241: # define clear_mark_bit_from_hdr(hhdr,n) (hhdr)->hb_marks[divWORDSZ(n)] \
                   1242:                                &= ~((word)1 << modWORDSZ(n))
1.3       noro     1243: #endif /* !USE_MARK_BYTES */
1.1       noro     1244:
                   1245: /* Important internal collector routines */
                   1246:
1.3       noro     1247: ptr_t GC_approx_sp GC_PROTO((void));
                   1248:
                   1249: GC_bool GC_should_collect GC_PROTO((void));
                   1250:
                   1251: void GC_apply_to_all_blocks GC_PROTO(( \
                   1252:     void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
                   1253:     word client_data));
                   1254:                        /* Invoke fn(hbp, client_data) for each         */
                   1255:                        /* allocated heap block.                        */
                   1256: struct hblk * GC_next_used_block GC_PROTO((struct hblk * h));
                   1257:                        /* Return first in-use block >= h       */
                   1258: struct hblk * GC_prev_block GC_PROTO((struct hblk * h));
                   1259:                        /* Return last block <= h.  Returned block      */
                   1260:                        /* is managed by GC, but may or may not be in   */
1.1       noro     1261:                        /* use.                                         */
1.3       noro     1262: void GC_mark_init GC_PROTO((void));
                   1263: void GC_clear_marks GC_PROTO((void));  /* Clear mark bits for all heap objects. */
                   1264: void GC_invalidate_mark_state GC_PROTO((void));
                   1265:                                        /* Tell the marker that marked     */
                   1266:                                        /* objects may point to unmarked   */
                   1267:                                        /* ones, and roots may point to    */
                   1268:                                        /* unmarked objects.               */
                   1269:                                        /* Reset mark stack.               */
                   1270: GC_bool GC_mark_stack_empty GC_PROTO((void));
                   1271: GC_bool GC_mark_some GC_PROTO((ptr_t cold_gc_frame));
                   1272:                        /* Perform about one pages worth of marking     */
                   1273:                        /* work of whatever kind is needed.  Returns    */
                   1274:                        /* quickly if no collection is in progress.     */
                   1275:                        /* Return TRUE if mark phase finished.          */
                   1276: void GC_initiate_gc GC_PROTO((void));
                   1277:                                /* initiate collection.                 */
                   1278:                                /* If the mark state is invalid, this   */
                   1279:                                /* becomes full colleection.  Otherwise */
                   1280:                                /* it's partial.                        */
                   1281: void GC_push_all GC_PROTO((ptr_t bottom, ptr_t top));
                   1282:                                /* Push everything in a range           */
                   1283:                                /* onto mark stack.                     */
                   1284: void GC_push_selected GC_PROTO(( \
                   1285:     ptr_t bottom, \
                   1286:     ptr_t top, \
                   1287:     int (*dirty_fn) GC_PROTO((struct hblk *h)), \
                   1288:     void (*push_fn) GC_PROTO((ptr_t bottom, ptr_t top)) ));
                   1289:                                  /* Push all pages h in [b,t) s.t.     */
                   1290:                                  /* select_fn(h) != 0 onto mark stack. */
1.1       noro     1291: #ifndef SMALL_CONFIG
1.3       noro     1292:   void GC_push_conditional GC_PROTO((ptr_t b, ptr_t t, GC_bool all));
1.1       noro     1293: #else
                   1294: # define GC_push_conditional(b, t, all) GC_push_all(b, t)
                   1295: #endif
                   1296:                                 /* Do either of the above, depending   */
                   1297:                                /* on the third arg.                    */
1.3       noro     1298: void GC_push_all_stack GC_PROTO((ptr_t b, ptr_t t));
                   1299:                                    /* As above, but consider           */
1.1       noro     1300:                                    /*  interior pointers as valid      */
1.3       noro     1301: void GC_push_all_eager GC_PROTO((ptr_t b, ptr_t t));
                   1302:                                    /* Same as GC_push_all_stack, but   */
1.1       noro     1303:                                    /* ensures that stack is scanned    */
                   1304:                                    /* immediately, not just scheduled  */
                   1305:                                    /* for scanning.                    */
                   1306: #ifndef THREADS
1.3       noro     1307:   void GC_push_all_stack_partially_eager GC_PROTO(( \
                   1308:       ptr_t bottom, ptr_t top, ptr_t cold_gc_frame ));
1.1       noro     1309:                        /* Similar to GC_push_all_eager, but only the   */
                   1310:                        /* part hotter than cold_gc_frame is scanned    */
1.3       noro     1311:                        /* immediately.  Needed to ensure that callee-  */
1.1       noro     1312:                        /* save registers are not missed.               */
                   1313: #else
                   1314:   /* In the threads case, we push part of the current thread stack     */
                   1315:   /* with GC_push_all_eager when we push the registers.  This gets the  */
                   1316:   /* callee-save registers that may disappear.  The remainder of the   */
                   1317:   /* stacks are scheduled for scanning in *GC_push_other_roots, which  */
                   1318:   /* is thread-package-specific.                                       */
                   1319: #endif
1.3       noro     1320: void GC_push_current_stack GC_PROTO((ptr_t cold_gc_frame));
                   1321:                        /* Push enough of the current stack eagerly to  */
                   1322:                        /* ensure that callee-save registers saved in   */
                   1323:                        /* GC frames are scanned.                       */
                   1324:                        /* In the non-threads case, schedule entire     */
                   1325:                        /* stack for scanning.                          */
                   1326: void GC_push_roots GC_PROTO((GC_bool all, ptr_t cold_gc_frame));
                   1327:                        /* Push all or dirty roots.     */
                   1328: extern void (*GC_push_other_roots) GC_PROTO((void));
                   1329:                        /* Push system or application specific roots    */
                   1330:                        /* onto the mark stack.  In some environments   */
                   1331:                        /* (e.g. threads environments) this is          */
                   1332:                        /* predfined to be non-zero.  A client supplied */
                   1333:                        /* replacement should also call the original    */
                   1334:                        /* function.                                    */
                   1335: extern void GC_push_gc_structures GC_PROTO((void));
                   1336:                        /* Push GC internal roots.  These are normally  */
                   1337:                        /* included in the static data segment, and     */
                   1338:                        /* Thus implicitly pushed.  But we must do this */
                   1339:                        /* explicitly if normal root processing is      */
                   1340:                        /* disabled.  Calls the following:              */
                   1341:        extern void GC_push_finalizer_structures GC_PROTO((void));
                   1342:        extern void GC_push_stubborn_structures GC_PROTO((void));
                   1343: #      ifdef THREADS
                   1344:          extern void GC_push_thread_structures GC_PROTO((void));
                   1345: #      endif
                   1346: extern void (*GC_start_call_back) GC_PROTO((void));
                   1347:                        /* Called at start of full collections.         */
                   1348:                        /* Not called if 0.  Called with allocation     */
                   1349:                        /* lock held.                                   */
                   1350:                        /* 0 by default.                                */
                   1351: # if defined(USE_GENERIC_PUSH_REGS)
                   1352:   void GC_generic_push_regs GC_PROTO((ptr_t cold_gc_frame));
                   1353: # else
                   1354:   void GC_push_regs GC_PROTO((void));
                   1355: # endif
                   1356:                        /* Push register contents onto mark stack.      */
                   1357:                        /* If NURSERY is defined, the default push      */
                   1358:                        /* action can be overridden with GC_push_proc   */
1.2       noro     1359:
                   1360: # ifdef NURSERY
                   1361:     extern void (*GC_push_proc)(ptr_t);
                   1362: # endif
1.3       noro     1363: # if defined(MSWIN32) || defined(MSWINCE)
                   1364:   void __cdecl GC_push_one GC_PROTO((word p));
1.1       noro     1365: # else
1.3       noro     1366:   void GC_push_one GC_PROTO((word p));
                   1367:                              /* If p points to an object, mark it    */
1.1       noro     1368:                               /* and push contents on the mark stack  */
1.3       noro     1369:                              /* Pointer recognition test always      */
                   1370:                              /* accepts interior pointers, i.e. this */
                   1371:                              /* is appropriate for pointers found on */
                   1372:                              /* stack.                               */
                   1373: # endif
                   1374: # if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
                   1375:   void GC_mark_and_push_stack GC_PROTO((word p, ptr_t source));
                   1376:                                /* Ditto, omits plausibility test       */
                   1377: # else
                   1378:   void GC_mark_and_push_stack GC_PROTO((word p));
1.1       noro     1379: # endif
1.3       noro     1380: void GC_push_marked GC_PROTO((struct hblk * h, hdr * hhdr));
1.1       noro     1381:                /* Push contents of all marked objects in h onto        */
                   1382:                /* mark stack.                                          */
                   1383: #ifdef SMALL_CONFIG
                   1384: # define GC_push_next_marked_dirty(h) GC_push_next_marked(h)
                   1385: #else
1.3       noro     1386:   struct hblk * GC_push_next_marked_dirty GC_PROTO((struct hblk * h));
1.1       noro     1387:                /* Invoke GC_push_marked on next dirty block above h.   */
                   1388:                /* Return a pointer just past the end of this block.    */
                   1389: #endif /* !SMALL_CONFIG */
1.3       noro     1390: struct hblk * GC_push_next_marked GC_PROTO((struct hblk * h));
                   1391:                /* Ditto, but also mark from clean pages.       */
                   1392: struct hblk * GC_push_next_marked_uncollectable GC_PROTO((struct hblk * h));
                   1393:                /* Ditto, but mark only from uncollectable pages.       */
                   1394: GC_bool GC_stopped_mark GC_PROTO((GC_stop_func stop_func));
                   1395:                        /* Stop world and mark from all roots   */
                   1396:                        /* and rescuers.                        */
                   1397: void GC_clear_hdr_marks GC_PROTO((hdr * hhdr));
                   1398:                                    /* Clear the mark bits in a header */
                   1399: void GC_set_hdr_marks GC_PROTO((hdr * hhdr));
                   1400:                                    /* Set the mark bits in a header */
1.5     ! noro     1401: void GC_set_fl_marks GC_PROTO((ptr_t p));
        !          1402:                                    /* Set all mark bits associated with */
        !          1403:                                    /* a free list.                      */
1.3       noro     1404: void GC_add_roots_inner GC_PROTO((char * b, char * e, GC_bool tmp));
                   1405: GC_bool GC_is_static_root GC_PROTO((ptr_t p));
                   1406:                /* Is the address p in one of the registered static     */
                   1407:                /* root sections?                                       */
                   1408: # if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
                   1409: GC_bool GC_is_tmp_root GC_PROTO((ptr_t p));
                   1410:                /* Is the address p in one of the temporary static      */
1.1       noro     1411:                /* root sections?                                       */
1.3       noro     1412: # endif
                   1413: void GC_register_dynamic_libraries GC_PROTO((void));
                   1414:                /* Add dynamic library data sections to the root set. */
                   1415:
1.1       noro     1416: /* Machine dependent startup routines */
1.3       noro     1417: ptr_t GC_get_stack_base GC_PROTO((void));      /* Cold end of stack */
                   1418: #ifdef IA64
                   1419:   ptr_t GC_get_register_stack_base GC_PROTO((void));
                   1420:                                        /* Cold end of register stack.  */
                   1421: #endif
                   1422: void GC_register_data_segments GC_PROTO((void));
                   1423:
1.1       noro     1424: /* Black listing: */
1.3       noro     1425: void GC_bl_init GC_PROTO((void));
                   1426: # ifdef PRINT_BLACK_LIST
                   1427:       void GC_add_to_black_list_normal GC_PROTO((word p, ptr_t source));
1.1       noro     1428:                        /* Register bits as a possible future false     */
                   1429:                        /* reference from the heap or static data       */
                   1430: #     define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1.3       noro     1431:                if (GC_all_interior_pointers) { \
1.5     ! noro     1432:                  GC_add_to_black_list_stack(bits, (ptr_t)(source)); \
1.3       noro     1433:                } else { \
1.5     ! noro     1434:                  GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
1.3       noro     1435:                }
1.1       noro     1436: # else
1.3       noro     1437:       void GC_add_to_black_list_normal GC_PROTO((word p));
1.1       noro     1438: #     define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1.3       noro     1439:                if (GC_all_interior_pointers) { \
                   1440:                  GC_add_to_black_list_stack(bits); \
                   1441:                } else { \
                   1442:                  GC_add_to_black_list_normal(bits); \
                   1443:                }
1.1       noro     1444: # endif
                   1445:
1.3       noro     1446: # ifdef PRINT_BLACK_LIST
                   1447:     void GC_add_to_black_list_stack GC_PROTO((word p, ptr_t source));
                   1448: # else
                   1449:     void GC_add_to_black_list_stack GC_PROTO((word p));
                   1450: # endif
                   1451: struct hblk * GC_is_black_listed GC_PROTO((struct hblk * h, word len));
                   1452:                        /* If there are likely to be false references   */
                   1453:                        /* to a block starting at h of the indicated    */
                   1454:                        /* length, then return the next plausible       */
                   1455:                        /* starting location for h that might avoid     */
                   1456:                        /* these false references.                      */
                   1457: void GC_promote_black_lists GC_PROTO((void));
                   1458:                        /* Declare an end to a black listing phase.     */
                   1459: void GC_unpromote_black_lists GC_PROTO((void));
                   1460:                        /* Approximately undo the effect of the above.  */
                   1461:                        /* This actually loses some information, but    */
                   1462:                        /* only in a reasonably safe way.               */
                   1463: word GC_number_stack_black_listed GC_PROTO(( \
                   1464:        struct hblk *start, struct hblk *endp1));
                   1465:                        /* Return the number of (stack) blacklisted     */
                   1466:                        /* blocks in the range for statistical          */
                   1467:                        /* purposes.                                    */
                   1468:
                   1469: ptr_t GC_scratch_alloc GC_PROTO((word bytes));
                   1470:                                /* GC internal memory allocation for    */
                   1471:                                /* small objects.  Deallocation is not  */
                   1472:                                /* possible.                            */
                   1473:
1.1       noro     1474: /* Heap block layout maps: */
1.3       noro     1475: void GC_invalidate_map GC_PROTO((hdr * hhdr));
                   1476:                                /* Remove the object map associated     */
                   1477:                                /* with the block.  This identifies     */
                   1478:                                /* the block as invalid to the mark     */
                   1479:                                /* routines.                            */
                   1480: GC_bool GC_add_map_entry GC_PROTO((word sz));
                   1481:                                /* Add a heap block map for objects of  */
                   1482:                                /* size sz to obj_map.                  */
                   1483:                                /* Return FALSE on failure.             */
                   1484: void GC_register_displacement_inner GC_PROTO((word offset));
                   1485:                                /* Version of GC_register_displacement  */
                   1486:                                /* that assumes lock is already held    */
                   1487:                                /* and signals are already disabled.    */
                   1488:
1.1       noro     1489: /*  hblk allocation: */
1.3       noro     1490: void GC_new_hblk GC_PROTO((word size_in_words, int kind));
                   1491:                                /* Allocate a new heap block, and build */
                   1492:                                /* a free list in it.                   */
                   1493:
                   1494: ptr_t GC_build_fl GC_PROTO((struct hblk *h, word sz,
                   1495:                           GC_bool clear,  ptr_t list));
                   1496:                                /* Build a free list for objects of     */
                   1497:                                /* size sz in block h.  Append list to  */
                   1498:                                /* end of the free lists.  Possibly     */
                   1499:                                /* clear objects on the list.  Normally */
                   1500:                                /* called by GC_new_hblk, but also      */
                   1501:                                /* called explicitly without GC lock.   */
                   1502:
                   1503: struct hblk * GC_allochblk GC_PROTO(( \
                   1504:        word size_in_words, int kind, unsigned flags));
                   1505:                                /* Allocate a heap block, inform        */
1.1       noro     1506:                                /* the marker that block is valid       */
                   1507:                                /* for objects of indicated size.       */
1.3       noro     1508:
                   1509: ptr_t GC_alloc_large GC_PROTO((word lw, int k, unsigned flags));
                   1510:                        /* Allocate a large block of size lw words.     */
                   1511:                        /* The block is not cleared.                    */
                   1512:                        /* Flags is 0 or IGNORE_OFF_PAGE.               */
                   1513:                        /* Calls GC_allchblk to do the actual           */
                   1514:                        /* allocation, but also triggers GC and/or      */
                   1515:                        /* heap expansion as appropriate.               */
                   1516:                        /* Does not update GC_words_allocd, but does    */
                   1517:                        /* other accounting.                            */
                   1518:
                   1519: ptr_t GC_alloc_large_and_clear GC_PROTO((word lw, int k, unsigned flags));
                   1520:                        /* As above, but clear block if appropriate     */
                   1521:                        /* for kind k.                                  */
                   1522:
                   1523: void GC_freehblk GC_PROTO((struct hblk * p));
                   1524:                                /* Deallocate a heap block and mark it  */
                   1525:                                /* as invalid.                          */
                   1526:
1.1       noro     1527: /*  Misc GC: */
1.3       noro     1528: void GC_init_inner GC_PROTO((void));
                   1529: GC_bool GC_expand_hp_inner GC_PROTO((word n));
                   1530: void GC_start_reclaim GC_PROTO((int abort_if_found));
                   1531:                                /* Restore unmarked objects to free     */
                   1532:                                /* lists, or (if abort_if_found is      */
                   1533:                                /* TRUE) report them.                   */
                   1534:                                /* Sweeping of small object pages is    */
                   1535:                                /* largely deferred.                    */
                   1536: void GC_continue_reclaim GC_PROTO((word sz, int kind));
                   1537:                                /* Sweep pages of the given size and    */
                   1538:                                /* kind, as long as possible, and       */
                   1539:                                /* as long as the corr. free list is    */
                   1540:                                /* empty.                               */
                   1541: void GC_reclaim_or_delete_all GC_PROTO((void));
                   1542:                                /* Arrange for all reclaim lists to be  */
                   1543:                                /* empty.  Judiciously choose between   */
                   1544:                                /* sweeping and discarding each page.   */
                   1545: GC_bool GC_reclaim_all GC_PROTO((GC_stop_func stop_func, GC_bool ignore_old));
                   1546:                                /* Reclaim all blocks.  Abort (in a     */
                   1547:                                /* consistent state) if f returns TRUE. */
                   1548: GC_bool GC_block_empty GC_PROTO((hdr * hhdr));
                   1549:                                /* Block completely unmarked?   */
                   1550: GC_bool GC_never_stop_func GC_PROTO((void));
                   1551:                                /* Returns FALSE.               */
                   1552: GC_bool GC_try_to_collect_inner GC_PROTO((GC_stop_func f));
                   1553:
1.1       noro     1554:                                /* Collect; caller must have acquired   */
                   1555:                                /* lock and disabled signals.           */
                   1556:                                /* Collection is aborted if f returns   */
                   1557:                                /* TRUE.  Returns TRUE if it completes  */
                   1558:                                /* successfully.                        */
                   1559: # define GC_gcollect_inner() \
                   1560:        (void) GC_try_to_collect_inner(GC_never_stop_func)
1.3       noro     1561: void GC_finish_collection GC_PROTO((void));
                   1562:                                /* Finish collection.  Mark bits are    */
                   1563:                                /* consistent and lock is still held.   */
                   1564: GC_bool GC_collect_or_expand GC_PROTO(( \
                   1565:        word needed_blocks, GC_bool ignore_off_page));
                   1566:                                /* Collect or expand heap in an attempt */
                   1567:                                /* make the indicated number of free    */
                   1568:                                /* blocks available.  Should be called  */
                   1569:                                /* until the blocks are available or    */
                   1570:                                /* until it fails by returning FALSE.   */
1.5     ! noro     1571:
        !          1572: extern GC_bool GC_is_initialized;      /* GC_init() has been run.      */
1.3       noro     1573:
                   1574: #if defined(MSWIN32) || defined(MSWINCE)
                   1575:   void GC_deinit GC_PROTO((void));
                   1576:                                 /* Free any resources allocated by      */
                   1577:                                 /* GC_init                              */
                   1578: #endif
                   1579:
                   1580: void GC_collect_a_little_inner GC_PROTO((int n));
                   1581:                                /* Do n units worth of garbage          */
                   1582:                                /* collection work, if appropriate.     */
                   1583:                                /* A unit is an amount appropriate for  */
                   1584:                                /* HBLKSIZE bytes of allocation.        */
                   1585: ptr_t GC_generic_malloc GC_PROTO((word lb, int k));
                   1586:                                /* Allocate an object of the given      */
                   1587:                                /* kind.  By default, there are only    */
                   1588:                                /* a few kinds: composite(pointerfree), */
1.1       noro     1589:                                /* atomic, uncollectable, etc.          */
                   1590:                                /* We claim it's possible for clever    */
                   1591:                                /* client code that understands GC      */
                   1592:                                /* internals to add more, e.g. to       */
                   1593:                                /* communicate object layout info       */
                   1594:                                /* to the collector.                    */
1.3       noro     1595: ptr_t GC_generic_malloc_ignore_off_page GC_PROTO((size_t b, int k));
                   1596:                                /* As above, but pointers past the      */
                   1597:                                /* first page of the resulting object   */
                   1598:                                /* are ignored.                         */
                   1599: ptr_t GC_generic_malloc_inner GC_PROTO((word lb, int k));
                   1600:                                /* Ditto, but I already hold lock, etc. */
                   1601: ptr_t GC_generic_malloc_words_small GC_PROTO((size_t lw, int k));
                   1602:                                /* As above, but size in units of words */
                   1603:                                /* Bypasses MERGE_SIZES.  Assumes       */
                   1604:                                /* words <= MAXOBJSZ.                   */
                   1605: ptr_t GC_generic_malloc_inner_ignore_off_page GC_PROTO((size_t lb, int k));
                   1606:                                /* Allocate an object, where            */
                   1607:                                /* the client guarantees that there     */
                   1608:                                /* will always be a pointer to the      */
                   1609:                                /* beginning of the object while the    */
                   1610:                                /* object is live.                      */
                   1611: ptr_t GC_allocobj GC_PROTO((word sz, int kind));
                   1612:                                /* Make the indicated                   */
                   1613:                                /* free list nonempty, and return its   */
                   1614:                                /* head.                                */
                   1615:
                   1616: void GC_init_headers GC_PROTO((void));
                   1617: struct hblkhdr * GC_install_header GC_PROTO((struct hblk *h));
                   1618:                                /* Install a header for block h.        */
                   1619:                                /* Return 0 on failure, or the header   */
                   1620:                                /* otherwise.                           */
                   1621: GC_bool GC_install_counts GC_PROTO((struct hblk * h, word sz));
                   1622:                                /* Set up forwarding counts for block   */
                   1623:                                /* h of size sz.                        */
                   1624:                                /* Return FALSE on failure.             */
                   1625: void GC_remove_header GC_PROTO((struct hblk * h));
                   1626:                                /* Remove the header for block h.       */
                   1627: void GC_remove_counts GC_PROTO((struct hblk * h, word sz));
                   1628:                                /* Remove forwarding counts for h.      */
                   1629: hdr * GC_find_header GC_PROTO((ptr_t h)); /* Debugging only.           */
                   1630:
                   1631: void GC_finalize GC_PROTO((void));
                   1632:                        /* Perform all indicated finalization actions   */
                   1633:                        /* on unmarked objects.                         */
                   1634:                        /* Unreachable finalizable objects are enqueued */
                   1635:                        /* for processing by GC_invoke_finalizers.      */
                   1636:                        /* Invoked with lock.                           */
                   1637:
                   1638: void GC_notify_or_invoke_finalizers GC_PROTO((void));
                   1639:                        /* If GC_finalize_on_demand is not set, invoke  */
                   1640:                        /* eligible finalizers. Otherwise:              */
                   1641:                        /* Call *GC_finalizer_notifier if there are     */
                   1642:                        /* finalizers to be run, and we haven't called  */
                   1643:                        /* this procedure yet this GC cycle.            */
                   1644:
                   1645: void GC_add_to_heap GC_PROTO((struct hblk *p, word bytes));
                   1646:                        /* Add a HBLKSIZE aligned chunk to the heap.    */
                   1647:
                   1648: void GC_print_obj GC_PROTO((ptr_t p));
                   1649:                        /* P points to somewhere inside an object with  */
                   1650:                        /* debugging info.  Print a human readable      */
                   1651:                        /* description of the object to stderr.         */
                   1652: extern void (*GC_check_heap) GC_PROTO((void));
                   1653:                        /* Check that all objects in the heap with      */
1.5     ! noro     1654:                        /* debugging info are intact.                   */
        !          1655:                        /* Add any that are not to GC_smashed list.     */
        !          1656: extern void (*GC_print_all_smashed) GC_PROTO((void));
        !          1657:                        /* Print GC_smashed if it's not empty.          */
        !          1658:                        /* Clear GC_smashed list.                       */
1.3       noro     1659: extern void (*GC_print_heap_obj) GC_PROTO((ptr_t p));
                   1660:                        /* If possible print s followed by a more       */
                   1661:                        /* detailed description of the object           */
                   1662:                        /* referred to by p.                            */
                   1663:
                   1664: extern GC_bool GC_print_stats; /* Produce at least some logging output */
                   1665:                                /* Set from environment variable.       */
                   1666:
                   1667: /* Macros used for collector internal allocation.      */
                   1668: /* These assume the collector lock is held.            */
                   1669: #ifdef DBG_HDRS_ALL
                   1670:     extern GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k);
                   1671:     extern GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
                   1672:                                                                int k);
                   1673: #   define GC_INTERNAL_MALLOC GC_debug_generic_malloc_inner
                   1674: #   define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
                   1675:                 GC_debug_generic_malloc_inner_ignore_off_page
                   1676: #   ifdef THREADS
                   1677: #       define GC_INTERNAL_FREE GC_debug_free_inner
                   1678: #   else
                   1679: #       define GC_INTERNAL_FREE GC_debug_free
                   1680: #   endif
                   1681: #else
                   1682: #   define GC_INTERNAL_MALLOC GC_generic_malloc_inner
                   1683: #   define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
                   1684:                 GC_generic_malloc_inner_ignore_off_page
                   1685: #   ifdef THREADS
                   1686: #       define GC_INTERNAL_FREE GC_free_inner
                   1687: #   else
                   1688: #       define GC_INTERNAL_FREE GC_free
                   1689: #   endif
                   1690: #endif
1.1       noro     1691:
                   1692: /* Memory unmapping: */
                   1693: #ifdef USE_MUNMAP
                   1694:   void GC_unmap_old(void);
                   1695:   void GC_merge_unmapped(void);
                   1696:   void GC_unmap(ptr_t start, word bytes);
                   1697:   void GC_remap(ptr_t start, word bytes);
                   1698:   void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2);
                   1699: #endif
                   1700:
                   1701: /* Virtual dirty bit implementation:           */
                   1702: /* Each implementation exports the following:  */
1.3       noro     1703: void GC_read_dirty GC_PROTO((void));
                   1704:                        /* Retrieve dirty bits. */
                   1705: GC_bool GC_page_was_dirty GC_PROTO((struct hblk *h));
                   1706:                        /* Read retrieved dirty bits.   */
                   1707: GC_bool GC_page_was_ever_dirty GC_PROTO((struct hblk *h));
                   1708:                        /* Could the page contain valid heap pointers?  */
                   1709: void GC_is_fresh GC_PROTO((struct hblk *h, word n));
                   1710:                        /* Assert the region currently contains no      */
                   1711:                        /* valid pointers.                              */
1.5     ! noro     1712: void GC_remove_protection GC_PROTO((struct hblk *h, word nblocks,
        !          1713:                                    GC_bool pointerfree));
        !          1714:                        /* h is about to be writteni or allocated.  Ensure  */
        !          1715:                        /* that it's not write protected by the virtual     */
        !          1716:                        /* dirty bit implementation.                        */
        !          1717:
1.3       noro     1718: void GC_dirty_init GC_PROTO((void));
                   1719:
1.1       noro     1720: /* Slow/general mark bit manipulation: */
1.3       noro     1721: GC_API GC_bool GC_is_marked GC_PROTO((ptr_t p));
                   1722: void GC_clear_mark_bit GC_PROTO((ptr_t p));
                   1723: void GC_set_mark_bit GC_PROTO((ptr_t p));
                   1724:
1.1       noro     1725: /* Stubborn objects: */
1.3       noro     1726: void GC_read_changed GC_PROTO((void)); /* Analogous to GC_read_dirty */
                   1727: GC_bool GC_page_was_changed GC_PROTO((struct hblk * h));
                   1728:                                /* Analogous to GC_page_was_dirty */
                   1729: void GC_clean_changing_list GC_PROTO((void));
                   1730:                                /* Collect obsolete changing list entries */
                   1731: void GC_stubborn_init GC_PROTO((void));
                   1732:
1.1       noro     1733: /* Debugging print routines: */
1.3       noro     1734: void GC_print_block_list GC_PROTO((void));
                   1735: void GC_print_hblkfreelist GC_PROTO((void));
                   1736: void GC_print_heap_sects GC_PROTO((void));
                   1737: void GC_print_static_roots GC_PROTO((void));
                   1738: void GC_dump GC_PROTO((void));
1.1       noro     1739:
                   1740: #ifdef KEEP_BACK_PTRS
                   1741:    void GC_store_back_pointer(ptr_t source, ptr_t dest);
                   1742:    void GC_marked_for_finalization(ptr_t dest);
                   1743: #  define GC_STORE_BACK_PTR(source, dest) GC_store_back_pointer(source, dest)
                   1744: #  define GC_MARKED_FOR_FINALIZATION(dest) GC_marked_for_finalization(dest)
                   1745: #else
                   1746: #  define GC_STORE_BACK_PTR(source, dest)
                   1747: #  define GC_MARKED_FOR_FINALIZATION(dest)
                   1748: #endif
                   1749:
                   1750: /* Make arguments appear live to compiler */
                   1751: # ifdef __WATCOMC__
1.5     ! noro     1752:     void GC_noop(void*, ...);
1.1       noro     1753: # else
1.5     ! noro     1754: #   ifdef __DMC__
        !          1755:       GC_API void GC_noop(...);
        !          1756: #   else
        !          1757:       GC_API void GC_noop();
        !          1758: #   endif
1.1       noro     1759: # endif
                   1760:
1.5     ! noro     1761: void GC_noop1 GC_PROTO((word));
1.1       noro     1762:
                   1763: /* Logging and diagnostic output:      */
1.3       noro     1764: GC_API void GC_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1.1       noro     1765:                        /* A version of printf that doesn't allocate,   */
                   1766:                        /* is restricted to long arguments, and         */
                   1767:                        /* (unfortunately) doesn't use varargs for      */
                   1768:                        /* portability.  Restricted to 6 args and       */
                   1769:                        /* 1K total output length.                      */
                   1770:                        /* (We use sprintf.  Hopefully that doesn't     */
                   1771:                        /* allocate for long arguments.)                */
                   1772: # define GC_printf0(f) GC_printf(f, 0l, 0l, 0l, 0l, 0l, 0l)
                   1773: # define GC_printf1(f,a) GC_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
                   1774: # define GC_printf2(f,a,b) GC_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
                   1775: # define GC_printf3(f,a,b,c) GC_printf(f, (long)a, (long)b, (long)c, 0l, 0l, 0l)
                   1776: # define GC_printf4(f,a,b,c,d) GC_printf(f, (long)a, (long)b, (long)c, \
                   1777:                                            (long)d, 0l, 0l)
                   1778: # define GC_printf5(f,a,b,c,d,e) GC_printf(f, (long)a, (long)b, (long)c, \
                   1779:                                              (long)d, (long)e, 0l)
                   1780: # define GC_printf6(f,a,b,c,d,e,g) GC_printf(f, (long)a, (long)b, (long)c, \
                   1781:                                                (long)d, (long)e, (long)g)
                   1782:
1.3       noro     1783: GC_API void GC_err_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1.1       noro     1784: # define GC_err_printf0(f) GC_err_puts(f)
                   1785: # define GC_err_printf1(f,a) GC_err_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
                   1786: # define GC_err_printf2(f,a,b) GC_err_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
                   1787: # define GC_err_printf3(f,a,b,c) GC_err_printf(f, (long)a, (long)b, (long)c, \
                   1788:                                                  0l, 0l, 0l)
                   1789: # define GC_err_printf4(f,a,b,c,d) GC_err_printf(f, (long)a, (long)b, \
                   1790:                                                    (long)c, (long)d, 0l, 0l)
                   1791: # define GC_err_printf5(f,a,b,c,d,e) GC_err_printf(f, (long)a, (long)b, \
                   1792:                                                      (long)c, (long)d, \
                   1793:                                                      (long)e, 0l)
                   1794: # define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
                   1795:                                                        (long)c, (long)d, \
                   1796:                                                        (long)e, (long)g)
                   1797:                        /* Ditto, writes to stderr.                     */
                   1798:
1.3       noro     1799: void GC_err_puts GC_PROTO((GC_CONST char *s));
1.1       noro     1800:                        /* Write s to stderr, don't buffer, don't add   */
                   1801:                        /* newlines, don't ...                          */
                   1802:
1.3       noro     1803: #if defined(LINUX) && !defined(SMALL_CONFIG)
                   1804:   void GC_err_write GC_PROTO((GC_CONST char *buf, size_t len));
                   1805:                        /* Write buf to stderr, don't buffer, don't add */
                   1806:                        /* newlines, don't ...                          */
                   1807: #endif
                   1808:
1.1       noro     1809:
1.3       noro     1810: # ifdef GC_ASSERTIONS
1.1       noro     1811: #      define GC_ASSERT(expr) if(!(expr)) {\
                   1812:                GC_err_printf2("Assertion failure: %s:%ld\n", \
                   1813:                                __FILE__, (unsigned long)__LINE__); \
                   1814:                ABORT("assertion failure"); }
1.3       noro     1815: # else
1.1       noro     1816: #      define GC_ASSERT(expr)
1.3       noro     1817: # endif
                   1818:
1.5     ! noro     1819: # if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
1.3       noro     1820:     /* We need additional synchronization facilities from the thread   */
                   1821:     /* support.  We believe these are less performance critical                */
                   1822:     /* than the main garbage collector lock; standard pthreads-based   */
                   1823:     /* implementations should be sufficient.                           */
                   1824:
                   1825:     /* The mark lock and condition variable.  If the GC lock is also   */
                   1826:     /* acquired, the GC lock must be acquired first.  The mark lock is */
                   1827:     /* used to both protect some variables used by the parallel                */
                   1828:     /* marker, and to protect GC_fl_builder_count, below.              */
                   1829:     /* GC_notify_all_marker() is called when                           */
                   1830:     /* the state of the parallel marker changes                                */
                   1831:     /* in some significant way (see gc_mark.h for details).  The       */
                   1832:     /* latter set of events includes incrementing GC_mark_no.          */
                   1833:     /* GC_notify_all_builder() is called when GC_fl_builder_count      */
                   1834:     /* reaches 0.                                                      */
                   1835:
                   1836:      extern void GC_acquire_mark_lock();
                   1837:      extern void GC_release_mark_lock();
                   1838:      extern void GC_notify_all_builder();
                   1839:      /* extern void GC_wait_builder(); */
                   1840:      extern void GC_wait_for_reclaim();
                   1841:
                   1842:      extern word GC_fl_builder_count;  /* Protected by mark lock.      */
1.5     ! noro     1843: # endif /* PARALLEL_MARK || THREAD_LOCAL_ALLOC */
        !          1844: # ifdef PARALLEL_MARK
        !          1845:      extern void GC_notify_all_marker();
        !          1846:      extern void GC_wait_marker();
1.3       noro     1847:      extern word GC_mark_no;           /* Protected by mark lock.      */
                   1848:
                   1849:      extern void GC_help_marker(word my_mark_no);
                   1850:                /* Try to help out parallel marker for mark cycle       */
                   1851:                /* my_mark_no.  Returns if the mark cycle finishes or   */
                   1852:                /* was already done, or there was nothing to do for     */
                   1853:                /* some other reason.                                   */
                   1854: # endif /* PARALLEL_MARK */
1.5     ! noro     1855:
        !          1856: # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
        !          1857:   /* We define the thread suspension signal here, so that we can refer */
        !          1858:   /* to it in the dirty bit implementation, if necessary.  Ideally we  */
        !          1859:   /* would allocate a (real-time ?) signal using the standard mechanism.*/
        !          1860:   /* unfortunately, there is no standard mechanism.  (There is one     */
        !          1861:   /* in Linux glibc, but it's not exported.)  Thus we continue to use  */
        !          1862:   /* the same hard-coded signals we've always used.                    */
        !          1863: #  if !defined(SIG_SUSPEND)
        !          1864: #   if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS)
        !          1865: #    if defined(SPARC) && !defined(SIGPWR)
        !          1866:        /* SPARC/Linux doesn't properly define SIGPWR in <signal.h>.
        !          1867:         * It is aliased to SIGLOST in asm/signal.h, though.            */
        !          1868: #      define SIG_SUSPEND SIGLOST
        !          1869: #    else
        !          1870:        /* Linuxthreads itself uses SIGUSR1 and SIGUSR2.                        */
        !          1871: #      define SIG_SUSPEND SIGPWR
        !          1872: #    endif
        !          1873: #   else  /* !GC_LINUX_THREADS */
        !          1874: #     if defined(_SIGRTMIN)
        !          1875: #       define SIG_SUSPEND _SIGRTMIN + 6
        !          1876: #     else
        !          1877: #       define SIG_SUSPEND SIGRTMIN + 6
        !          1878: #     endif
        !          1879: #   endif
        !          1880: #  endif /* !SIG_SUSPEND */
        !          1881:
        !          1882: # endif
1.1       noro     1883:
                   1884: # endif /* GC_PRIVATE_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>