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