[BACK]Return to gc_priv.h CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gc

Annotation of OpenXM_contrib/gc/gc_priv.h, Revision 1.1

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

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