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