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