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