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.
22 #if defined(mips) && defined(SYSTYPE_BSD) && defined(sony_news)
23 /* sony RISC NEWS, NEWSOS 4 */
25 /* typedef long ptrdiff_t; -- necessary on some really old systems */
28 #if defined(mips) && defined(SYSTYPE_BSD43)
34 # include <sys/types.h>
35 # include <sys/time.h>
36 # include <sys/resource.h>
40 # include <sys/types.h>
41 # include <sys/time.h>
42 # include <sys/resource.h>
50 # include "../gc_mark.h"
54 typedef GC_signed_word signed_word;
60 typedef char * ptr_t; /* A generic pointer to which we can add */
61 /* byte displacements. */
62 /* Preferably identical to caddr_t, if it */
66 # include "gcconfig.h"
75 # if !(defined( sony_news ) )
78 # define VOLATILE volatile
86 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
87 /* This doesn't work in some earlier gcc versions */
88 # define EXPECT(expr, outcome) __builtin_expect(expr,outcome)
89 /* Equivalent to (expr), but predict that usually (expr)==outcome. */
91 # define EXPECT(expr, outcome) (expr)
95 # include "gc_locks.h"
98 # ifdef STACK_GROWS_DOWN
99 # define COOLER_THAN >
100 # define HOTTER_THAN <
101 # define MAKE_COOLER(x,y) if ((word)(x)+(y) > (word)(x)) {(x) += (y);} \
102 else {(x) = (word)ONES;}
103 # define MAKE_HOTTER(x,y) (x) -= (y)
105 # define COOLER_THAN <
106 # define HOTTER_THAN >
107 # define MAKE_COOLER(x,y) if ((word)(x)-(y) < (word)(x)) {(x) -= (y);} else {(x) = 0;}
108 # define MAKE_HOTTER(x,y) (x) += (y)
111 #if defined(AMIGA) && defined(__SASC)
112 # define GC_FAR __far
118 /*********************************/
120 /* Definitions for conservative */
123 /*********************************/
125 /*********************************/
127 /* Easily changeable parameters */
129 /*********************************/
131 /* #define STUBBORN_ALLOC */
132 /* Enable stubborm allocation, and thus a limited */
133 /* form of incremental collection w/o dirty bits. */
135 /* #define ALL_INTERIOR_POINTERS */
136 /* Forces all pointers into the interior of an */
137 /* object to be considered valid. Also causes the */
138 /* sizes of all objects to be inflated by at least */
139 /* one byte. This should suffice to guarantee */
140 /* that in the presence of a compiler that does */
141 /* not perform garbage-collector-unsafe */
142 /* optimizations, all portable, strictly ANSI */
143 /* conforming C programs should be safely usable */
144 /* with malloc replaced by GC_malloc and free */
145 /* calls removed. There are several disadvantages: */
146 /* 1. There are probably no interesting, portable, */
147 /* strictly ANSI conforming C programs. */
148 /* 2. This option makes it hard for the collector */
149 /* to allocate space that is not ``pointed to'' */
150 /* by integers, etc. Under SunOS 4.X with a */
151 /* statically linked libc, we empiricaly */
152 /* observed that it would be difficult to */
153 /* allocate individual objects larger than 100K. */
154 /* Even if only smaller objects are allocated, */
155 /* more swap space is likely to be needed. */
156 /* Fortunately, much of this will never be */
158 /* If you can easily avoid using this option, do. */
159 /* If not, try to keep individual objects small. */
160 /* This is now really controlled at startup, */
161 /* through GC_all_interior_pointers. */
163 #define PRINTSTATS /* Print garbage collection statistics */
164 /* For less verbose output, undefine in reclaim.c */
166 #define PRINTTIMES /* Print the amount of time consumed by each garbage */
169 #define PRINTBLOCKS /* Print object sizes associated with heap blocks, */
170 /* whether the objects are atomic or composite, and */
171 /* whether or not the block was found to be empty */
172 /* during the reclaim phase. Typically generates */
173 /* about one screenful per garbage collection. */
188 #if defined(PRINTSTATS) && !defined(GATHERSTATS)
192 #if defined(PRINTSTATS) || !defined(SMALL_CONFIG)
193 # define CONDPRINT /* Print some things if GC_print_stats is set */
196 #define GC_INVOKE_FINALIZERS() GC_notify_or_invoke_finalizers()
198 #define MERGE_SIZES /* Round up some object sizes, so that fewer distinct */
199 /* free lists are actually maintained. This applies */
200 /* only to the top level routines in misc.c, not to */
201 /* user generated code that calls GC_allocobj and */
202 /* GC_allocaobj directly. */
203 /* Slows down average programs slightly. May however */
204 /* substantially reduce fragmentation if allocation */
205 /* request sizes are widely scattered. */
206 /* May save significant amounts of space for obj_map */
209 #if defined(USE_MARK_BYTES) && !defined(ALIGN_DOUBLE)
210 # define ALIGN_DOUBLE
211 /* We use one byte for every 2 words, which doesn't allow for */
212 /* odd numbered words to have mark bits. */
215 #if defined(GC_GCJ_SUPPORT) && ALIGNMENT < 8 && !defined(ALIGN_DOUBLE)
216 /* GCJ's Hashtable synchronization code requires 64-bit alignment. */
217 # define ALIGN_DOUBLE
220 /* ALIGN_DOUBLE requires MERGE_SIZES at present. */
221 # if defined(ALIGN_DOUBLE) && !defined(MERGE_SIZES)
225 #if !defined(DONT_ADD_BYTE_AT_END)
226 # define EXTRA_BYTES GC_all_interior_pointers
228 # define EXTRA_BYTES 0
232 # ifndef LARGE_CONFIG
233 # define MINHINCR 16 /* Minimum heap increment, in blocks of HBLKSIZE */
234 /* Must be multiple of largest page size. */
235 # define MAXHINCR 2048 /* Maximum heap increment, in blocks */
238 # define MAXHINCR 4096
241 # define TIME_LIMIT 50 /* We try to keep pause times from exceeding */
242 /* this by much. In milliseconds. */
244 # define BL_LIMIT GC_black_list_spacing
245 /* If we need a block of N bytes, and we have */
246 /* a block of N + BL_LIMIT bytes available, */
247 /* and N > BL_LIMIT, */
248 /* but all possible positions in it are */
249 /* blacklisted, we just use it anyway (and */
250 /* print a warning, if warnings are enabled). */
251 /* This risks subsequently leaking the block */
252 /* due to a false reference. But not using */
253 /* the block risks unreasonable immediate */
256 /*********************************/
258 /* Stack saving for debugging */
260 /*********************************/
264 word ci_pc; /* Caller, not callee, pc */
266 word ci_arg[NARGS]; /* bit-wise complement to avoid retention */
268 # if defined(ALIGN_DOUBLE) && (NFRAMES * (NARGS + 1)) % 2 == 1
269 /* Likely alignment problem. */
275 #ifdef SAVE_CALL_CHAIN
277 /* Fill in the pc and argument information for up to NFRAMES of my */
278 /* callers. Ignore my frame and my callers frame. */
279 void GC_save_callers GC_PROTO((struct callinfo info[NFRAMES]));
281 void GC_print_callers GC_PROTO((struct callinfo info[NFRAMES]));
286 /*********************************/
288 /* OS interface routines */
290 /*********************************/
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 */
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 */
311 # if !defined(__STDC__) && defined(SPARC) && defined(SUNOS4)
312 clock_t clock(); /* Not in time.h, where it belongs */
314 # if defined(FREEBSD) && !defined(CLOCKS_PER_SEC)
315 # include <machine/limits.h>
316 # define CLOCKS_PER_SEC CLK_TCK
318 # if !defined(CLOCKS_PER_SEC)
319 # define CLOCKS_PER_SEC 1000000
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).
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))
335 # endif /* !MSWIN32 */
336 #endif /* !BSD_TIME */
338 /* We use bzero and bcopy internally. They may not be available. */
339 # if defined(SPARC) && defined(SUNOS4)
340 # define BCOPY_EXISTS
342 # if defined(M68K) && defined(AMIGA)
343 # define BCOPY_EXISTS
345 # if defined(M68K) && defined(NEXT)
346 # define BCOPY_EXISTS
349 # define BCOPY_EXISTS
353 # define BCOPY_EXISTS
357 # define BCOPY_EXISTS
360 # ifndef BCOPY_EXISTS
362 # define BCOPY(x,y,n) memcpy(y, x, (size_t)(n))
363 # define BZERO(x,n) memset(x, 0, (size_t)(n))
365 # define BCOPY(x,y,n) bcopy((char *)(x),(char *)(y),(int)(n))
366 # define BZERO(x,n) bzero((char *)(x),(int)(n))
370 # if defined(POWERPC)
371 # define GC_MACH_THREAD_STATE_FLAVOR PPC_THREAD_STATE
373 # define GC_MACH_THREAD_STATE_FLAVOR i386_THREAD_STATE
374 # elif defined(X86_64)
375 # define GC_MACH_THREAD_STATE_FLAVOR x86_THREAD_STATE64
377 # define GC_MACH_THREAD_STATE_FLAVOR MACHINE_THREAD_STATE
381 /* Delay any interrupts or signals that may abort this thread. Data */
382 /* structures are in a consistent state outside this pair of calls. */
383 /* ANSI C allows both to be empty (though the standard isn't very */
384 /* clear on that point). Standard malloc implementations are usually */
385 /* neither interruptable nor thread-safe, and thus correspond to */
386 /* empty definitions. */
387 /* It probably doesn't make any sense to declare these to be nonempty */
388 /* if the code is being optimized, since signal safety relies on some */
389 /* ordering constraints that are typically not obeyed by optimizing */
392 # define DISABLE_SIGNALS() \
393 PCR_Th_SetSigMask(PCR_allSigsBlocked,&GC_old_sig_mask)
394 # define ENABLE_SIGNALS() \
395 PCR_Th_SetSigMask(&GC_old_sig_mask, NIL)
397 # if defined(THREADS) || defined(AMIGA) \
398 || defined(MSWIN32) || defined(MSWINCE) || defined(MACOS) \
399 || defined(DJGPP) || defined(NO_SIGNALS)
400 /* Also useful for debugging. */
401 /* Should probably use thr_sigsetmask for GC_SOLARIS_THREADS. */
402 # define DISABLE_SIGNALS()
403 # define ENABLE_SIGNALS()
405 # define DISABLE_SIGNALS() GC_disable_signals()
406 void GC_disable_signals();
407 # define ENABLE_SIGNALS() GC_enable_signals()
408 void GC_enable_signals();
413 * Stop and restart mutator threads.
416 # include "th/PCR_ThCtl.h"
417 # define STOP_WORLD() \
418 PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_stopNormal, \
419 PCR_allSigsBlocked, \
421 # define START_WORLD() \
422 PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_null, \
423 PCR_allSigsBlocked, \
426 # if defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) \
427 || defined(GC_PTHREADS)
428 void GC_stop_world(void);
429 void GC_start_world(void);
430 # define STOP_WORLD() GC_stop_world()
431 # define START_WORLD() GC_start_world()
433 # define STOP_WORLD()
434 # define START_WORLD()
440 # define ABORT(s) PCR_Base_Panic(s)
443 # define ABORT(msg) abort();
445 GC_API void GC_abort GC_PROTO((GC_CONST char * msg));
446 # define ABORT(msg) GC_abort(msg);
450 /* Exit abnormally, but without making a mess (e.g. out of memory) */
452 # define EXIT() PCR_Base_Exit(1,PCR_waitForever)
454 # define EXIT() (void)exit(1)
457 /* Print warning message, e.g. almost out of memory. */
458 # define WARN(msg,arg) (*GC_current_warn_proc)("GC Warning: " msg, (GC_word)(arg))
459 extern GC_warn_proc GC_current_warn_proc;
461 /* Get environment entry */
462 #if !defined(NO_GETENV)
463 # if defined(EMPTY_GETENV_RESULTS)
464 /* Workaround for a reputed Wine bug. */
465 static inline char * fixed_getenv(const char *name)
467 char * tmp = getenv(name);
468 if (tmp == 0 || strlen(tmp) == 0)
472 # define GETENV(name) fixed_getenv(name)
474 # define GETENV(name) getenv(name)
477 # define GETENV(name) 0
480 /*********************************/
482 /* Word-size-dependent defines */
484 /*********************************/
487 # define WORDS_TO_BYTES(x) ((x)<<2)
488 # define BYTES_TO_WORDS(x) ((x)>>2)
489 # define LOGWL ((word)5) /* log[2] of CPP_WORDSZ */
490 # define modWORDSZ(n) ((n) & 0x1f) /* n mod size of word */
497 # define WORDS_TO_BYTES(x) ((x)<<3)
498 # define BYTES_TO_WORDS(x) ((x)>>3)
499 # define LOGWL ((word)6) /* log[2] of CPP_WORDSZ */
500 # define modWORDSZ(n) ((n) & 0x3f) /* n mod size of word */
506 #define WORDSZ ((word)CPP_WORDSZ)
507 #define SIGNB ((word)1 << (WORDSZ-1))
508 #define BYTES_PER_WORD ((word)(sizeof (word)))
509 #define ONES ((word)(signed_word)(-1))
510 #define divWORDSZ(n) ((n) >> LOGWL) /* divide n by size of word */
512 /*********************/
514 /* Size Parameters */
516 /*********************/
518 /* heap block size, bytes. Should be power of 2 */
522 # define CPP_LOG_HBLKSIZE 10
524 # if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
525 /* HPUX/PA seems to use 4K pages with the 64 bit ABI */
526 # define CPP_LOG_HBLKSIZE 12
528 # define CPP_LOG_HBLKSIZE 13
533 # define CPP_LOG_HBLKSIZE 9
535 # if HBLKSIZE == 1024
536 # define CPP_LOG_HBLKSIZE 10
538 # if HBLKSIZE == 2048
539 # define CPP_LOG_HBLKSIZE 11
541 # if HBLKSIZE == 4096
542 # define CPP_LOG_HBLKSIZE 12
544 # if HBLKSIZE == 8192
545 # define CPP_LOG_HBLKSIZE 13
547 # if HBLKSIZE == 16384
548 # define CPP_LOG_HBLKSIZE 14
550 # ifndef CPP_LOG_HBLKSIZE
555 # define CPP_HBLKSIZE (1 << CPP_LOG_HBLKSIZE)
556 # define LOG_HBLKSIZE ((word)CPP_LOG_HBLKSIZE)
557 # define HBLKSIZE ((word)CPP_HBLKSIZE)
560 /* max size objects supported by freelist (larger objects may be */
561 /* allocated, but less efficiently) */
563 #define CPP_MAXOBJBYTES (CPP_HBLKSIZE/2)
564 #define MAXOBJBYTES ((word)CPP_MAXOBJBYTES)
565 #define CPP_MAXOBJSZ BYTES_TO_WORDS(CPP_MAXOBJBYTES)
566 #define MAXOBJSZ ((word)CPP_MAXOBJSZ)
568 # define divHBLKSZ(n) ((n) >> LOG_HBLKSIZE)
570 # define HBLK_PTR_DIFF(p,q) divHBLKSZ((ptr_t)p - (ptr_t)q)
571 /* Equivalent to subtracting 2 hblk pointers. */
572 /* We do it this way because a compiler should */
573 /* find it hard to use an integer division */
574 /* instead of a shift. The bundled SunOS 4.1 */
575 /* o.w. sometimes pessimizes the subtraction to */
576 /* involve a call to .div. */
578 # define modHBLKSZ(n) ((n) & (HBLKSIZE-1))
580 # define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
582 # define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
584 /* Round up byte allocation requests to integral number of words, etc. */
585 # define ROUNDED_UP_WORDS(n) \
586 BYTES_TO_WORDS((n) + (WORDS_TO_BYTES(1) - 1 + EXTRA_BYTES))
588 # define ALIGNED_WORDS(n) \
589 (BYTES_TO_WORDS((n) + WORDS_TO_BYTES(2) - 1 + EXTRA_BYTES) & ~1)
591 # define ALIGNED_WORDS(n) ROUNDED_UP_WORDS(n)
593 # define SMALL_OBJ(bytes) ((bytes) <= (MAXOBJBYTES - EXTRA_BYTES))
594 # define ADD_SLOP(bytes) ((bytes) + EXTRA_BYTES)
596 /* MIN_WORDS is the size of the smallest allocated object. */
597 /* 1 and 2 are the only valid values. */
598 /* 2 must be used if: */
599 /* - GC_gcj_malloc can be used for objects of requested */
600 /* size smaller than 2 words, or */
601 /* - USE_MARK_BYTES is defined. */
602 # if defined(USE_MARK_BYTES) || defined(GC_GCJ_SUPPORT)
603 # define MIN_WORDS 2 /* Smallest allocated object. */
611 * Hash table representation of sets of pages. This assumes it is
612 * OK to add spurious entries to sets.
613 * Used by black-listing code, and perhaps by dirty bit maintenance code.
617 # define LOG_PHT_ENTRIES 20 /* Collisions likely at 1M blocks, */
618 /* which is >= 4GB. Each table takes */
619 /* 128KB, some of which may never be */
623 # define LOG_PHT_ENTRIES 14 /* Collisions are likely if heap grows */
624 /* to more than 16K hblks = 64MB. */
625 /* Each hash table occupies 2K bytes. */
626 # else /* default "medium" configuration */
627 # define LOG_PHT_ENTRIES 16 /* Collisions are likely if heap grows */
628 /* to more than 64K hblks >= 256MB. */
629 /* Each hash table occupies 8K bytes. */
630 /* Even for somewhat smaller heaps, */
631 /* say half that, collisions may be an */
632 /* issue because we blacklist */
633 /* addresses outside the heap. */
636 # define PHT_ENTRIES ((word)1 << LOG_PHT_ENTRIES)
637 # define PHT_SIZE (PHT_ENTRIES >> LOGWL)
638 typedef word page_hash_table[PHT_SIZE];
640 # define PHT_HASH(addr) ((((word)(addr)) >> LOG_HBLKSIZE) & (PHT_ENTRIES - 1))
642 # define get_pht_entry_from_index(bl, index) \
643 (((bl)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
644 # define set_pht_entry_from_index(bl, index) \
645 (bl)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
646 # define clear_pht_entry_from_index(bl, index) \
647 (bl)[divWORDSZ(index)] &= ~((word)1 << modWORDSZ(index))
648 /* And a dumb but thread-safe version of set_pht_entry_from_index. */
649 /* This sets (many) extra bits. */
650 # define set_pht_entry_from_index_safe(bl, index) \
651 (bl)[divWORDSZ(index)] = ONES
655 /********************************************/
657 /* H e a p B l o c k s */
659 /********************************************/
661 /* heap block header */
662 #define HBLKMASK (HBLKSIZE-1)
664 #define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
666 #define MARK_BITS_PER_HBLK (BITS_PER_HBLK/CPP_WORDSZ)
668 /* We allocate 1 bit/word, unless USE_MARK_BYTES */
669 /* is defined. Only the first word */
670 /* in each object is actually marked. */
672 # ifdef USE_MARK_BYTES
673 # define MARK_BITS_SZ (MARK_BITS_PER_HBLK/2)
674 /* Unlike the other case, this is in units of bytes. */
675 /* We actually allocate only every second mark bit, since we */
676 /* force all objects to be doubleword aligned. */
677 /* However, each mark bit is allocated as a byte. */
679 # define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
682 /* We maintain layout maps for heap blocks containing objects of a given */
683 /* size. Each entry in this map describes a byte offset and has the */
684 /* following type. */
685 typedef unsigned char map_entry_type;
688 word hb_sz; /* If in use, size in words, of objects in the block. */
689 /* if free, the size in bytes of the whole block */
690 struct hblk * hb_next; /* Link field for hblk free list */
691 /* and for lists of chunks waiting to be */
693 struct hblk * hb_prev; /* Backwards link for free list. */
694 word hb_descr; /* object descriptor for marking. See */
696 map_entry_type * hb_map;
697 /* A pointer to a pointer validity map of the block. */
698 /* See GC_obj_map. */
699 /* Valid for all blocks with headers. */
700 /* Free blocks point to GC_invalid_map. */
701 unsigned char hb_obj_kind;
702 /* Kind of objects in the block. Each kind */
703 /* identifies a mark procedure and a set of */
704 /* list headers. Sometimes called regions. */
705 unsigned char hb_flags;
706 # define IGNORE_OFF_PAGE 1 /* Ignore pointers that do not */
707 /* point to the first page of */
709 # define WAS_UNMAPPED 2 /* This is a free block, which has */
710 /* been unmapped from the address */
712 /* GC_remap must be invoked on it */
713 /* before it can be reallocated. */
714 /* Only set with USE_MUNMAP. */
715 unsigned short hb_last_reclaimed;
716 /* Value of GC_gc_no when block was */
717 /* last allocated or swept. May wrap. */
718 /* For a free block, this is maintained */
719 /* only for USE_MUNMAP, and indicates */
720 /* when the header was allocated, or */
721 /* when the size of the block last */
723 # ifdef USE_MARK_BYTES
725 char _hb_marks[MARK_BITS_SZ];
726 /* The i'th byte is 1 if the object */
727 /* starting at word 2i is marked, 0 o.w. */
728 word dummy; /* Force word alignment of mark bytes. */
730 # define hb_marks _mark_byte_union._hb_marks
732 word hb_marks[MARK_BITS_SZ];
733 /* Bit i in the array refers to the */
734 /* object starting at the ith word (header */
735 /* INCLUDED) in the heap block. */
736 /* The lsb of word 0 is numbered 0. */
737 /* Unused bits are invalid, and are */
738 /* occasionally set, e.g for uncollectable */
740 # endif /* !USE_MARK_BYTES */
743 /* heap block body */
745 # define BODY_SZ (HBLKSIZE/sizeof(word))
748 word hb_body[BODY_SZ];
751 # define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
753 # define OBJ_SZ_TO_BLOCKS(sz) \
754 divHBLKSZ(WORDS_TO_BYTES(sz) + HBLKSIZE-1)
755 /* Size of block (in units of HBLKSIZE) needed to hold objects of */
756 /* given sz (in words). */
758 /* Object free list link */
759 # define obj_link(p) (*(ptr_t *)(p))
761 # define LOG_MAX_MARK_PROCS 6
762 # define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
764 /* Root sets. Logically private to mark_rts.c. But we don't want the */
765 /* tables scanned, so we put them here. */
766 /* MAX_ROOT_SETS is the maximum number of ranges that can be */
767 /* registered as static roots. */
769 # define MAX_ROOT_SETS 4096
772 # define MAX_ROOT_SETS 1024
774 # if defined(MSWIN32) || defined(MSWINCE)
775 # define MAX_ROOT_SETS 1024
776 /* Under NT, we add only written pages, which can result */
777 /* in many small root sets. */
779 # define MAX_ROOT_SETS 1024
784 # define MAX_EXCLUSIONS (MAX_ROOT_SETS/4)
785 /* Maximum number of segments that can be excluded from root sets. */
788 * Data structure for excluded static roots.
795 /* Data structure for list of root sets. */
796 /* We keep a hash table, so that we can filter out duplicate additions. */
797 /* Under Win32, we need to do a better job of filtering overlaps, so */
798 /* we resort to sequential search, and pay the price. */
802 # if !defined(MSWIN32) && !defined(MSWINCE)
803 struct roots * r_next;
806 /* Delete before registering new dynamic libraries */
809 #if !defined(MSWIN32) && !defined(MSWINCE)
810 /* Size of hash table index to roots. */
811 # define LOG_RT_SIZE 6
812 # define RT_SIZE (1 << LOG_RT_SIZE) /* Power of 2, may be != MAX_ROOT_SETS */
815 /* Lists of all heap blocks and free lists */
816 /* as well as other random data structures */
817 /* that should not be scanned by the */
819 /* These are grouped together in a struct */
820 /* so that they can be easily skipped by the */
821 /* GC_mark routine. */
822 /* The ordering is weird to make GC_malloc */
823 /* faster by keeping the important fields */
824 /* sufficiently close together that a */
825 /* single load of a base register will do. */
826 /* Scalars that could easily appear to */
827 /* be pointers are also put here. */
828 /* The main fields should precede any */
829 /* conditionally included fields, so that */
830 /* gc_inl.h will work even if a different set */
831 /* of macros is defined when the client is */
837 word _requested_heapsize; /* Heap size due to explicit expansion */
838 ptr_t _last_heap_addr;
839 ptr_t _prev_heap_addr;
840 word _large_free_bytes;
841 /* Total bytes contained in blocks on large object free */
843 word _large_allocd_bytes;
844 /* Total number of bytes in allocated large objects blocks. */
845 /* For the purposes of this counter and the next one only, a */
846 /* large object is one that occupies a block of at least */
848 word _max_large_allocd_bytes;
849 /* Maximum number of bytes that were ever allocated in */
850 /* large object blocks. This is used to help decide when it */
851 /* is safe to split up a large block. */
852 word _words_allocd_before_gc;
853 /* Number of words allocated before this */
854 /* collection cycle. */
855 # ifndef SEPARATE_GLOBALS
857 /* Number of words allocated during this collection cycle */
860 /* Number of words wasted due to internal fragmentation */
861 /* in large objects, or due to dropping blacklisted */
862 /* blocks, since last gc. Approximate. */
863 word _words_finalized;
864 /* Approximate number of words in objects (and headers) */
865 /* That became ready for finalization in the last */
867 word _non_gc_bytes_at_gc;
868 /* Number of explicitly managed bytes of storage */
869 /* at last collection. */
871 /* Number of explicitly deallocated words of memory */
872 /* since last collection. */
873 word _finalizer_mem_freed;
874 /* Words of memory explicitly deallocated while */
875 /* finalizers were running. Used to approximate mem. */
876 /* explicitly deallocated by finalizers. */
877 ptr_t _scratch_end_ptr;
878 ptr_t _scratch_last_end_ptr;
879 /* Used by headers.c, and can easily appear to point to */
881 GC_mark_proc _mark_procs[MAX_MARK_PROCS];
882 /* Table of user-defined mark procedures. There is */
883 /* a small number of these, which can be referenced */
884 /* by DS_PROC mark descriptors. See gc_mark.h. */
886 # ifndef SEPARATE_GLOBALS
887 ptr_t _objfreelist[MAXOBJSZ+1];
888 /* free list for objects */
889 ptr_t _aobjfreelist[MAXOBJSZ+1];
890 /* free list for atomic objs */
893 ptr_t _uobjfreelist[MAXOBJSZ+1];
894 /* uncollectable but traced objs */
895 /* objects on this and auobjfreelist */
896 /* are always marked, except during */
897 /* garbage collections. */
898 # ifdef ATOMIC_UNCOLLECTABLE
899 ptr_t _auobjfreelist[MAXOBJSZ+1];
901 /* uncollectable but traced objs */
904 word _composite_in_use;
905 /* Number of words in accessible composite */
908 /* Number of words in accessible atomic */
912 word _unmapped_bytes;
915 unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
916 /* Number of words to allocate for a given allocation request in */
920 # ifdef STUBBORN_ALLOC
921 ptr_t _sobjfreelist[MAXOBJSZ+1];
923 /* free list for immutable objects */
924 map_entry_type * _obj_map[MAXOBJSZ+1];
925 /* If not NIL, then a pointer to a map of valid */
926 /* object addresses. _obj_map[sz][i] is j if the */
927 /* address block_start+i is a valid pointer */
928 /* to an object at block_start + */
929 /* WORDS_TO_BYTES(BYTES_TO_WORDS(i) - j) */
930 /* I.e. j is a word displacement from the */
931 /* object beginning. */
932 /* The entry is OBJ_INVALID if the corresponding */
933 /* address is not a valid pointer. It is */
934 /* OFFSET_TOO_BIG if the value j would be too */
935 /* large to fit in the entry. (Note that the */
936 /* size of these entries matters, both for */
937 /* space consumption and for cache utilization.) */
938 # define OFFSET_TOO_BIG 0xfe
939 # define OBJ_INVALID 0xff
940 # define MAP_ENTRY(map, bytes) (map)[bytes]
941 # define MAP_ENTRIES HBLKSIZE
942 # define MAP_SIZE MAP_ENTRIES
943 # define CPP_MAX_OFFSET (OFFSET_TOO_BIG - 1)
944 # define MAX_OFFSET ((word)CPP_MAX_OFFSET)
945 # define INIT_MAP(map) memset((map), OBJ_INVALID, MAP_SIZE)
946 /* The following are used only if GC_all_interior_ptrs != 0 */
947 # define VALID_OFFSET_SZ \
948 (CPP_MAX_OFFSET > WORDS_TO_BYTES(CPP_MAXOBJSZ)? \
950 : WORDS_TO_BYTES(CPP_MAXOBJSZ)+1)
951 char _valid_offsets[VALID_OFFSET_SZ];
952 /* GC_valid_offsets[i] == TRUE ==> i */
953 /* is registered as a displacement. */
954 char _modws_valid_offsets[sizeof(word)];
955 /* GC_valid_offsets[i] ==> */
956 /* GC_modws_valid_offsets[i%sizeof(word)] */
957 # define OFFSET_VALID(displ) \
958 (GC_all_interior_pointers || GC_valid_offsets[displ])
959 # ifdef STUBBORN_ALLOC
960 page_hash_table _changed_pages;
961 /* Stubborn object pages that were changes since last call to */
962 /* GC_read_changed. */
963 page_hash_table _prev_changed_pages;
964 /* Stubborn object pages that were changes before last call to */
965 /* GC_read_changed. */
967 # if defined(PROC_VDB) || defined(MPROTECT_VDB)
968 page_hash_table _grungy_pages; /* Pages that were dirty at last */
972 VOLATILE page_hash_table _dirty_pages;
973 /* Pages dirtied since last GC_read_dirty. */
976 page_hash_table _written_pages; /* Pages ever dirtied */
980 # define MAX_HEAP_SECTS 4096 /* overflows at roughly 64 GB */
982 # define MAX_HEAP_SECTS 768 /* Separately added heap sections. */
986 # define MAX_HEAP_SECTS 128 /* Roughly 256MB (128*2048*1K) */
988 # define MAX_HEAP_SECTS (384+128) /* Roughly 4GB */
992 ptr_t hs_start; word hs_bytes;
993 } _heap_sects[MAX_HEAP_SECTS];
994 # if defined(MSWIN32) || defined(MSWINCE)
995 ptr_t _heap_bases[MAX_HEAP_SECTS];
996 /* Start address of memory regions obtained from kernel. */
999 word _heap_lengths[MAX_HEAP_SECTS];
1000 /* Commited lengths of memory regions obtained from kernel. */
1002 struct roots _static_roots[MAX_ROOT_SETS];
1003 # if !defined(MSWIN32) && !defined(MSWINCE)
1004 struct roots * _root_index[RT_SIZE];
1006 struct exclusion _excl_table[MAX_EXCLUSIONS];
1007 /* Block header index; see gc_headers.h */
1008 bottom_index * _all_nils;
1009 bottom_index * _top_index [TOP_SZ];
1010 #ifdef SAVE_CALL_CHAIN
1011 struct callinfo _last_stack[NFRAMES]; /* Stack at last garbage collection.*/
1012 /* Useful for debugging mysterious */
1013 /* object disappearances. */
1014 /* In the multithreaded case, we */
1015 /* currently only save the calling */
1020 GC_API GC_FAR struct _GC_arrays GC_arrays;
1022 # ifndef SEPARATE_GLOBALS
1023 # define GC_objfreelist GC_arrays._objfreelist
1024 # define GC_aobjfreelist GC_arrays._aobjfreelist
1025 # define GC_words_allocd GC_arrays._words_allocd
1027 # define GC_uobjfreelist GC_arrays._uobjfreelist
1028 # ifdef ATOMIC_UNCOLLECTABLE
1029 # define GC_auobjfreelist GC_arrays._auobjfreelist
1031 # define GC_sobjfreelist GC_arrays._sobjfreelist
1032 # define GC_valid_offsets GC_arrays._valid_offsets
1033 # define GC_modws_valid_offsets GC_arrays._modws_valid_offsets
1034 # ifdef STUBBORN_ALLOC
1035 # define GC_changed_pages GC_arrays._changed_pages
1036 # define GC_prev_changed_pages GC_arrays._prev_changed_pages
1038 # define GC_obj_map GC_arrays._obj_map
1039 # define GC_last_heap_addr GC_arrays._last_heap_addr
1040 # define GC_prev_heap_addr GC_arrays._prev_heap_addr
1041 # define GC_words_wasted GC_arrays._words_wasted
1042 # define GC_large_free_bytes GC_arrays._large_free_bytes
1043 # define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
1044 # define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes
1045 # define GC_words_finalized GC_arrays._words_finalized
1046 # define GC_non_gc_bytes_at_gc GC_arrays._non_gc_bytes_at_gc
1047 # define GC_mem_freed GC_arrays._mem_freed
1048 # define GC_finalizer_mem_freed GC_arrays._finalizer_mem_freed
1049 # define GC_scratch_end_ptr GC_arrays._scratch_end_ptr
1050 # define GC_scratch_last_end_ptr GC_arrays._scratch_last_end_ptr
1051 # define GC_mark_procs GC_arrays._mark_procs
1052 # define GC_heapsize GC_arrays._heapsize
1053 # define GC_max_heapsize GC_arrays._max_heapsize
1054 # define GC_requested_heapsize GC_arrays._requested_heapsize
1055 # define GC_words_allocd_before_gc GC_arrays._words_allocd_before_gc
1056 # define GC_heap_sects GC_arrays._heap_sects
1057 # define GC_last_stack GC_arrays._last_stack
1059 # define GC_unmapped_bytes GC_arrays._unmapped_bytes
1061 # if defined(MSWIN32) || defined(MSWINCE)
1062 # define GC_heap_bases GC_arrays._heap_bases
1065 # define GC_heap_lengths GC_arrays._heap_lengths
1067 # define GC_static_roots GC_arrays._static_roots
1068 # define GC_root_index GC_arrays._root_index
1069 # define GC_excl_table GC_arrays._excl_table
1070 # define GC_all_nils GC_arrays._all_nils
1071 # define GC_top_index GC_arrays._top_index
1072 # if defined(PROC_VDB) || defined(MPROTECT_VDB)
1073 # define GC_grungy_pages GC_arrays._grungy_pages
1075 # ifdef MPROTECT_VDB
1076 # define GC_dirty_pages GC_arrays._dirty_pages
1079 # define GC_written_pages GC_arrays._written_pages
1082 # define GC_composite_in_use GC_arrays._composite_in_use
1083 # define GC_atomic_in_use GC_arrays._atomic_in_use
1086 # define GC_size_map GC_arrays._size_map
1089 # define beginGC_arrays ((ptr_t)(&GC_arrays))
1090 # define endGC_arrays (((ptr_t)(&GC_arrays)) + (sizeof GC_arrays))
1092 #define USED_HEAP_SIZE (GC_heapsize - GC_large_free_bytes)
1095 # define MAXOBJKINDS 16
1097 extern struct obj_kind {
1098 ptr_t *ok_freelist; /* Array of free listheaders for this kind of object */
1099 /* Point either to GC_arrays or to storage allocated */
1100 /* with GC_scratch_alloc. */
1101 struct hblk **ok_reclaim_list;
1102 /* List headers for lists of blocks waiting to be */
1104 word ok_descriptor; /* Descriptor template for objects in this */
1106 GC_bool ok_relocate_descr;
1107 /* Add object size in bytes to descriptor */
1108 /* template to obtain descriptor. Otherwise */
1109 /* template is used as is. */
1110 GC_bool ok_init; /* Clear objects before putting them on the free list. */
1111 } GC_obj_kinds[MAXOBJKINDS];
1113 # define beginGC_obj_kinds ((ptr_t)(&GC_obj_kinds))
1114 # define endGC_obj_kinds (beginGC_obj_kinds + (sizeof GC_obj_kinds))
1116 /* Variables that used to be in GC_arrays, but need to be accessed by */
1117 /* inline allocation code. If they were in GC_arrays, the inlined */
1118 /* allocation code would include GC_arrays offsets (as it did), which */
1119 /* introduce maintenance problems. */
1121 #ifdef SEPARATE_GLOBALS
1122 word GC_words_allocd;
1123 /* Number of words allocated during this collection cycle */
1124 ptr_t GC_objfreelist[MAXOBJSZ+1];
1125 /* free list for NORMAL objects */
1126 # define beginGC_objfreelist ((ptr_t)(&GC_objfreelist))
1127 # define endGC_objfreelist (beginGC_objfreelist + sizeof(GC_objfreelist))
1129 ptr_t GC_aobjfreelist[MAXOBJSZ+1];
1130 /* free list for atomic (PTRFREE) objs */
1131 # define beginGC_aobjfreelist ((ptr_t)(&GC_aobjfreelist))
1132 # define endGC_aobjfreelist (beginGC_aobjfreelist + sizeof(GC_aobjfreelist))
1135 /* Predefined kinds: */
1138 # define UNCOLLECTABLE 2
1139 # ifdef ATOMIC_UNCOLLECTABLE
1140 # define AUNCOLLECTABLE 3
1142 # define IS_UNCOLLECTABLE(k) (((k) & ~1) == UNCOLLECTABLE)
1145 # define IS_UNCOLLECTABLE(k) ((k) == UNCOLLECTABLE)
1148 extern int GC_n_kinds;
1150 GC_API word GC_fo_entries;
1152 extern word GC_n_heap_sects; /* Number of separately added heap */
1155 extern word GC_page_size;
1157 # if defined(MSWIN32) || defined(MSWINCE)
1158 struct _SYSTEM_INFO;
1159 extern struct _SYSTEM_INFO GC_sysinfo;
1160 extern word GC_n_heap_bases; /* See GC_heap_bases. */
1163 extern word GC_total_stack_black_listed;
1164 /* Number of bytes on stack blacklist. */
1166 extern word GC_black_list_spacing;
1167 /* Average number of bytes between blacklisted */
1168 /* blocks. Approximate. */
1169 /* Counts only blocks that are */
1170 /* "stack-blacklisted", i.e. that are */
1171 /* problematic in the interior of an object. */
1173 extern map_entry_type * GC_invalid_map;
1174 /* Pointer to the nowhere valid hblk map */
1175 /* Blocks pointing to this map are free. */
1177 extern struct hblk * GC_hblkfreelist[];
1178 /* List of completely empty heap blocks */
1179 /* Linked through hb_next field of */
1180 /* header structure associated with */
1183 extern GC_bool GC_objects_are_marked; /* There are marked objects in */
1186 #ifndef SMALL_CONFIG
1187 extern GC_bool GC_incremental;
1188 /* Using incremental/generational collection. */
1189 # define TRUE_INCREMENTAL \
1190 (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED)
1191 /* True incremental, not just generational, mode */
1193 # define GC_incremental FALSE
1194 /* Hopefully allow optimizer to remove some code. */
1195 # define TRUE_INCREMENTAL FALSE
1198 extern GC_bool GC_dirty_maintained;
1199 /* Dirty bits are being maintained, */
1200 /* either for incremental collection, */
1201 /* or to limit the root set. */
1203 extern word GC_root_size; /* Total size of registered root sections */
1205 extern GC_bool GC_debugging_started; /* GC_debug_malloc has been called. */
1207 extern long GC_large_alloc_warn_interval;
1208 /* Interval between unsuppressed warnings. */
1210 extern long GC_large_alloc_warn_suppressed;
1211 /* Number of warnings suppressed so far. */
1214 extern GC_bool GC_world_stopped;
1219 # define abs(x) ((x) < 0? (-(x)) : (x))
1223 /* Marks are in a reserved area in */
1224 /* each heap block. Each word has one mark bit associated */
1225 /* with it. Only those corresponding to the beginning of an */
1226 /* object are used. */
1228 /* Set mark bit correctly, even if mark bits may be concurrently */
1230 #ifdef PARALLEL_MARK
1231 # define OR_WORD(addr, bits) \
1234 old = *((volatile word *)addr); \
1235 } while (!GC_compare_and_exchange((addr), old, old | (bits))); \
1237 # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1239 word my_bits = (bits); \
1241 old = *((volatile word *)addr); \
1242 if (old & my_bits) goto exit_label; \
1243 } while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
1246 # define OR_WORD(addr, bits) *(addr) |= (bits)
1247 # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1249 word old = *(addr); \
1250 word my_bits = (bits); \
1251 if (old & my_bits) goto exit_label; \
1252 *(addr) = (old | my_bits); \
1256 /* Mark bit operations */
1259 * Retrieve, set, clear the mark bit corresponding
1260 * to the nth word in a given heap block.
1262 * (Recall that bit n corresponds to object beginning at word n
1263 * relative to the beginning of the block, including unused words)
1266 #ifdef USE_MARK_BYTES
1267 # define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n) >> 1])
1268 # define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 1
1269 # define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 0
1270 #else /* !USE_MARK_BYTES */
1271 # define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
1272 >> (modWORDSZ(n))) & (word)1)
1273 # define set_mark_bit_from_hdr(hhdr,n) \
1274 OR_WORD((hhdr)->hb_marks+divWORDSZ(n), \
1275 (word)1 << modWORDSZ(n))
1276 # define clear_mark_bit_from_hdr(hhdr,n) (hhdr)->hb_marks[divWORDSZ(n)] \
1277 &= ~((word)1 << modWORDSZ(n))
1278 #endif /* !USE_MARK_BYTES */
1280 /* Important internal collector routines */
1282 ptr_t GC_approx_sp GC_PROTO((void));
1284 GC_bool GC_should_collect GC_PROTO((void));
1286 void GC_apply_to_all_blocks GC_PROTO(( \
1287 void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
1289 /* Invoke fn(hbp, client_data) for each */
1290 /* allocated heap block. */
1291 struct hblk * GC_next_used_block GC_PROTO((struct hblk * h));
1292 /* Return first in-use block >= h */
1293 struct hblk * GC_prev_block GC_PROTO((struct hblk * h));
1294 /* Return last block <= h. Returned block */
1295 /* is managed by GC, but may or may not be in */
1297 void GC_mark_init GC_PROTO((void));
1298 void GC_clear_marks GC_PROTO((void)); /* Clear mark bits for all heap objects. */
1299 void GC_invalidate_mark_state GC_PROTO((void));
1300 /* Tell the marker that marked */
1301 /* objects may point to unmarked */
1302 /* ones, and roots may point to */
1303 /* unmarked objects. */
1304 /* Reset mark stack. */
1305 GC_bool GC_mark_stack_empty GC_PROTO((void));
1306 GC_bool GC_mark_some GC_PROTO((ptr_t cold_gc_frame));
1307 /* Perform about one pages worth of marking */
1308 /* work of whatever kind is needed. Returns */
1309 /* quickly if no collection is in progress. */
1310 /* Return TRUE if mark phase finished. */
1311 void GC_initiate_gc GC_PROTO((void));
1312 /* initiate collection. */
1313 /* If the mark state is invalid, this */
1314 /* becomes full colleection. Otherwise */
1316 void GC_push_all GC_PROTO((ptr_t bottom, ptr_t top));
1317 /* Push everything in a range */
1318 /* onto mark stack. */
1319 void GC_push_selected GC_PROTO(( \
1322 int (*dirty_fn) GC_PROTO((struct hblk *h)), \
1323 void (*push_fn) GC_PROTO((ptr_t bottom, ptr_t top)) ));
1324 /* Push all pages h in [b,t) s.t. */
1325 /* select_fn(h) != 0 onto mark stack. */
1326 #ifndef SMALL_CONFIG
1327 void GC_push_conditional GC_PROTO((ptr_t b, ptr_t t, GC_bool all));
1329 # define GC_push_conditional(b, t, all) GC_push_all(b, t)
1331 /* Do either of the above, depending */
1332 /* on the third arg. */
1333 void GC_push_all_stack GC_PROTO((ptr_t b, ptr_t t));
1334 /* As above, but consider */
1335 /* interior pointers as valid */
1336 void GC_push_all_eager GC_PROTO((ptr_t b, ptr_t t));
1337 /* Same as GC_push_all_stack, but */
1338 /* ensures that stack is scanned */
1339 /* immediately, not just scheduled */
1342 void GC_push_all_stack_partially_eager GC_PROTO(( \
1343 ptr_t bottom, ptr_t top, ptr_t cold_gc_frame ));
1344 /* Similar to GC_push_all_eager, but only the */
1345 /* part hotter than cold_gc_frame is scanned */
1346 /* immediately. Needed to ensure that callee- */
1347 /* save registers are not missed. */
1349 /* In the threads case, we push part of the current thread stack */
1350 /* with GC_push_all_eager when we push the registers. This gets the */
1351 /* callee-save registers that may disappear. The remainder of the */
1352 /* stacks are scheduled for scanning in *GC_push_other_roots, which */
1353 /* is thread-package-specific. */
1355 void GC_push_current_stack GC_PROTO((ptr_t cold_gc_frame));
1356 /* Push enough of the current stack eagerly to */
1357 /* ensure that callee-save registers saved in */
1358 /* GC frames are scanned. */
1359 /* In the non-threads case, schedule entire */
1360 /* stack for scanning. */
1361 void GC_push_roots GC_PROTO((GC_bool all, ptr_t cold_gc_frame));
1362 /* Push all or dirty roots. */
1363 extern void (*GC_push_other_roots) GC_PROTO((void));
1364 /* Push system or application specific roots */
1365 /* onto the mark stack. In some environments */
1366 /* (e.g. threads environments) this is */
1367 /* predfined to be non-zero. A client supplied */
1368 /* replacement should also call the original */
1370 extern void GC_push_gc_structures GC_PROTO((void));
1371 /* Push GC internal roots. These are normally */
1372 /* included in the static data segment, and */
1373 /* Thus implicitly pushed. But we must do this */
1374 /* explicitly if normal root processing is */
1375 /* disabled. Calls the following: */
1376 extern void GC_push_finalizer_structures GC_PROTO((void));
1377 extern void GC_push_stubborn_structures GC_PROTO((void));
1379 extern void GC_push_thread_structures GC_PROTO((void));
1381 extern void (*GC_start_call_back) GC_PROTO((void));
1382 /* Called at start of full collections. */
1383 /* Not called if 0. Called with allocation */
1386 # if defined(USE_GENERIC_PUSH_REGS)
1387 void GC_generic_push_regs GC_PROTO((ptr_t cold_gc_frame));
1389 void GC_push_regs GC_PROTO((void));
1391 # if defined(SPARC) || defined(IA64)
1392 /* Cause all stacked registers to be saved in memory. Return a */
1393 /* pointer to the top of the corresponding memory stack. */
1394 word GC_save_regs_in_stack GC_PROTO((void));
1396 /* Push register contents onto mark stack. */
1397 /* If NURSERY is defined, the default push */
1398 /* action can be overridden with GC_push_proc */
1401 extern void (*GC_push_proc)(ptr_t);
1403 # if defined(MSWIN32) || defined(MSWINCE)
1404 void __cdecl GC_push_one GC_PROTO((word p));
1406 void GC_push_one GC_PROTO((word p));
1407 /* If p points to an object, mark it */
1408 /* and push contents on the mark stack */
1409 /* Pointer recognition test always */
1410 /* accepts interior pointers, i.e. this */
1411 /* is appropriate for pointers found on */
1414 # if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
1415 void GC_mark_and_push_stack GC_PROTO((word p, ptr_t source));
1416 /* Ditto, omits plausibility test */
1418 void GC_mark_and_push_stack GC_PROTO((word p));
1420 void GC_push_marked GC_PROTO((struct hblk * h, hdr * hhdr));
1421 /* Push contents of all marked objects in h onto */
1424 # define GC_push_next_marked_dirty(h) GC_push_next_marked(h)
1426 struct hblk * GC_push_next_marked_dirty GC_PROTO((struct hblk * h));
1427 /* Invoke GC_push_marked on next dirty block above h. */
1428 /* Return a pointer just past the end of this block. */
1429 #endif /* !SMALL_CONFIG */
1430 struct hblk * GC_push_next_marked GC_PROTO((struct hblk * h));
1431 /* Ditto, but also mark from clean pages. */
1432 struct hblk * GC_push_next_marked_uncollectable GC_PROTO((struct hblk * h));
1433 /* Ditto, but mark only from uncollectable pages. */
1434 GC_bool GC_stopped_mark GC_PROTO((GC_stop_func stop_func));
1435 /* Stop world and mark from all roots */
1437 void GC_clear_hdr_marks GC_PROTO((hdr * hhdr));
1438 /* Clear the mark bits in a header */
1439 void GC_set_hdr_marks GC_PROTO((hdr * hhdr));
1440 /* Set the mark bits in a header */
1441 void GC_set_fl_marks GC_PROTO((ptr_t p));
1442 /* Set all mark bits associated with */
1444 void GC_add_roots_inner GC_PROTO((char * b, char * e, GC_bool tmp));
1445 void GC_remove_roots_inner GC_PROTO((char * b, char * e));
1446 GC_bool GC_is_static_root GC_PROTO((ptr_t p));
1447 /* Is the address p in one of the registered static */
1448 /* root sections? */
1449 # if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
1450 GC_bool GC_is_tmp_root GC_PROTO((ptr_t p));
1451 /* Is the address p in one of the temporary static */
1452 /* root sections? */
1454 void GC_register_dynamic_libraries GC_PROTO((void));
1455 /* Add dynamic library data sections to the root set. */
1457 GC_bool GC_register_main_static_data GC_PROTO((void));
1458 /* We need to register the main data segment. Returns */
1459 /* TRUE unless this is done implicitly as part of */
1460 /* dynamic library registration. */
1462 /* Machine dependent startup routines */
1463 ptr_t GC_get_stack_base GC_PROTO((void)); /* Cold end of stack */
1465 ptr_t GC_get_register_stack_base GC_PROTO((void));
1466 /* Cold end of register stack. */
1468 void GC_register_data_segments GC_PROTO((void));
1470 /* Black listing: */
1471 void GC_bl_init GC_PROTO((void));
1472 # ifdef PRINT_BLACK_LIST
1473 void GC_add_to_black_list_normal GC_PROTO((word p, ptr_t source));
1474 /* Register bits as a possible future false */
1475 /* reference from the heap or static data */
1476 # define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1477 if (GC_all_interior_pointers) { \
1478 GC_add_to_black_list_stack(bits, (ptr_t)(source)); \
1480 GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
1483 void GC_add_to_black_list_normal GC_PROTO((word p));
1484 # define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1485 if (GC_all_interior_pointers) { \
1486 GC_add_to_black_list_stack(bits); \
1488 GC_add_to_black_list_normal(bits); \
1492 # ifdef PRINT_BLACK_LIST
1493 void GC_add_to_black_list_stack GC_PROTO((word p, ptr_t source));
1495 void GC_add_to_black_list_stack GC_PROTO((word p));
1497 struct hblk * GC_is_black_listed GC_PROTO((struct hblk * h, word len));
1498 /* If there are likely to be false references */
1499 /* to a block starting at h of the indicated */
1500 /* length, then return the next plausible */
1501 /* starting location for h that might avoid */
1502 /* these false references. */
1503 void GC_promote_black_lists GC_PROTO((void));
1504 /* Declare an end to a black listing phase. */
1505 void GC_unpromote_black_lists GC_PROTO((void));
1506 /* Approximately undo the effect of the above. */
1507 /* This actually loses some information, but */
1508 /* only in a reasonably safe way. */
1509 word GC_number_stack_black_listed GC_PROTO(( \
1510 struct hblk *start, struct hblk *endp1));
1511 /* Return the number of (stack) blacklisted */
1512 /* blocks in the range for statistical */
1515 ptr_t GC_scratch_alloc GC_PROTO((word bytes));
1516 /* GC internal memory allocation for */
1517 /* small objects. Deallocation is not */
1520 /* Heap block layout maps: */
1521 void GC_invalidate_map GC_PROTO((hdr * hhdr));
1522 /* Remove the object map associated */
1523 /* with the block. This identifies */
1524 /* the block as invalid to the mark */
1526 GC_bool GC_add_map_entry GC_PROTO((word sz));
1527 /* Add a heap block map for objects of */
1528 /* size sz to obj_map. */
1529 /* Return FALSE on failure. */
1530 void GC_register_displacement_inner GC_PROTO((word offset));
1531 /* Version of GC_register_displacement */
1532 /* that assumes lock is already held */
1533 /* and signals are already disabled. */
1535 /* hblk allocation: */
1536 void GC_new_hblk GC_PROTO((word size_in_words, int kind));
1537 /* Allocate a new heap block, and build */
1538 /* a free list in it. */
1540 ptr_t GC_build_fl GC_PROTO((struct hblk *h, word sz,
1541 GC_bool clear, ptr_t list));
1542 /* Build a free list for objects of */
1543 /* size sz in block h. Append list to */
1544 /* end of the free lists. Possibly */
1545 /* clear objects on the list. Normally */
1546 /* called by GC_new_hblk, but also */
1547 /* called explicitly without GC lock. */
1549 struct hblk * GC_allochblk GC_PROTO(( \
1550 word size_in_words, int kind, unsigned flags));
1551 /* Allocate a heap block, inform */
1552 /* the marker that block is valid */
1553 /* for objects of indicated size. */
1555 ptr_t GC_alloc_large GC_PROTO((word lw, int k, unsigned flags));
1556 /* Allocate a large block of size lw words. */
1557 /* The block is not cleared. */
1558 /* Flags is 0 or IGNORE_OFF_PAGE. */
1559 /* Calls GC_allchblk to do the actual */
1560 /* allocation, but also triggers GC and/or */
1561 /* heap expansion as appropriate. */
1562 /* Does not update GC_words_allocd, but does */
1563 /* other accounting. */
1565 ptr_t GC_alloc_large_and_clear GC_PROTO((word lw, int k, unsigned flags));
1566 /* As above, but clear block if appropriate */
1569 void GC_freehblk GC_PROTO((struct hblk * p));
1570 /* Deallocate a heap block and mark it */
1574 void GC_init_inner GC_PROTO((void));
1575 GC_bool GC_expand_hp_inner GC_PROTO((word n));
1576 void GC_start_reclaim GC_PROTO((int abort_if_found));
1577 /* Restore unmarked objects to free */
1578 /* lists, or (if abort_if_found is */
1579 /* TRUE) report them. */
1580 /* Sweeping of small object pages is */
1581 /* largely deferred. */
1582 void GC_continue_reclaim GC_PROTO((word sz, int kind));
1583 /* Sweep pages of the given size and */
1584 /* kind, as long as possible, and */
1585 /* as long as the corr. free list is */
1587 void GC_reclaim_or_delete_all GC_PROTO((void));
1588 /* Arrange for all reclaim lists to be */
1589 /* empty. Judiciously choose between */
1590 /* sweeping and discarding each page. */
1591 GC_bool GC_reclaim_all GC_PROTO((GC_stop_func stop_func, GC_bool ignore_old));
1592 /* Reclaim all blocks. Abort (in a */
1593 /* consistent state) if f returns TRUE. */
1594 GC_bool GC_block_empty GC_PROTO((hdr * hhdr));
1595 /* Block completely unmarked? */
1596 GC_bool GC_never_stop_func GC_PROTO((void));
1597 /* Returns FALSE. */
1598 GC_bool GC_try_to_collect_inner GC_PROTO((GC_stop_func f));
1600 /* Collect; caller must have acquired */
1601 /* lock and disabled signals. */
1602 /* Collection is aborted if f returns */
1603 /* TRUE. Returns TRUE if it completes */
1605 # define GC_gcollect_inner() \
1606 (void) GC_try_to_collect_inner(GC_never_stop_func)
1607 void GC_finish_collection GC_PROTO((void));
1608 /* Finish collection. Mark bits are */
1609 /* consistent and lock is still held. */
1610 GC_bool GC_collect_or_expand GC_PROTO(( \
1611 word needed_blocks, GC_bool ignore_off_page));
1612 /* Collect or expand heap in an attempt */
1613 /* make the indicated number of free */
1614 /* blocks available. Should be called */
1615 /* until the blocks are available or */
1616 /* until it fails by returning FALSE. */
1618 extern GC_bool GC_is_initialized; /* GC_init() has been run. */
1620 #if defined(MSWIN32) || defined(MSWINCE)
1621 void GC_deinit GC_PROTO((void));
1622 /* Free any resources allocated by */
1626 void GC_collect_a_little_inner GC_PROTO((int n));
1627 /* Do n units worth of garbage */
1628 /* collection work, if appropriate. */
1629 /* A unit is an amount appropriate for */
1630 /* HBLKSIZE bytes of allocation. */
1631 /* ptr_t GC_generic_malloc GC_PROTO((word lb, int k)); */
1632 /* Allocate an object of the given */
1633 /* kind. By default, there are only */
1634 /* a few kinds: composite(pointerfree), */
1635 /* atomic, uncollectable, etc. */
1636 /* We claim it's possible for clever */
1637 /* client code that understands GC */
1638 /* internals to add more, e.g. to */
1639 /* communicate object layout info */
1640 /* to the collector. */
1641 /* The actual decl is in gc_mark.h. */
1642 ptr_t GC_generic_malloc_ignore_off_page GC_PROTO((size_t b, int k));
1643 /* As above, but pointers past the */
1644 /* first page of the resulting object */
1646 ptr_t GC_generic_malloc_inner GC_PROTO((word lb, int k));
1647 /* Ditto, but I already hold lock, etc. */
1648 ptr_t GC_generic_malloc_words_small_inner GC_PROTO((word lw, int k));
1649 /* Analogous to the above, but assumes */
1650 /* a small object size, and bypasses */
1651 /* MERGE_SIZES mechanism. */
1652 ptr_t GC_generic_malloc_words_small GC_PROTO((size_t lw, int k));
1653 /* As above, but size in units of words */
1654 /* Bypasses MERGE_SIZES. Assumes */
1655 /* words <= MAXOBJSZ. */
1656 ptr_t GC_generic_malloc_inner_ignore_off_page GC_PROTO((size_t lb, int k));
1657 /* Allocate an object, where */
1658 /* the client guarantees that there */
1659 /* will always be a pointer to the */
1660 /* beginning of the object while the */
1661 /* object is live. */
1662 ptr_t GC_allocobj GC_PROTO((word sz, int kind));
1663 /* Make the indicated */
1664 /* free list nonempty, and return its */
1667 void GC_free_inner(GC_PTR p);
1669 void GC_init_headers GC_PROTO((void));
1670 struct hblkhdr * GC_install_header GC_PROTO((struct hblk *h));
1671 /* Install a header for block h. */
1672 /* Return 0 on failure, or the header */
1674 GC_bool GC_install_counts GC_PROTO((struct hblk * h, word sz));
1675 /* Set up forwarding counts for block */
1677 /* Return FALSE on failure. */
1678 void GC_remove_header GC_PROTO((struct hblk * h));
1679 /* Remove the header for block h. */
1680 void GC_remove_counts GC_PROTO((struct hblk * h, word sz));
1681 /* Remove forwarding counts for h. */
1682 hdr * GC_find_header GC_PROTO((ptr_t h)); /* Debugging only. */
1684 void GC_finalize GC_PROTO((void));
1685 /* Perform all indicated finalization actions */
1686 /* on unmarked objects. */
1687 /* Unreachable finalizable objects are enqueued */
1688 /* for processing by GC_invoke_finalizers. */
1689 /* Invoked with lock. */
1691 void GC_notify_or_invoke_finalizers GC_PROTO((void));
1692 /* If GC_finalize_on_demand is not set, invoke */
1693 /* eligible finalizers. Otherwise: */
1694 /* Call *GC_finalizer_notifier if there are */
1695 /* finalizers to be run, and we haven't called */
1696 /* this procedure yet this GC cycle. */
1698 GC_API GC_PTR GC_make_closure GC_PROTO((GC_finalization_proc fn, GC_PTR data));
1699 GC_API void GC_debug_invoke_finalizer GC_PROTO((GC_PTR obj, GC_PTR data));
1700 /* Auxiliary fns to make finalization work */
1701 /* correctly with displaced pointers introduced */
1702 /* by the debugging allocators. */
1704 void GC_add_to_heap GC_PROTO((struct hblk *p, word bytes));
1705 /* Add a HBLKSIZE aligned chunk to the heap. */
1707 void GC_print_obj GC_PROTO((ptr_t p));
1708 /* P points to somewhere inside an object with */
1709 /* debugging info. Print a human readable */
1710 /* description of the object to stderr. */
1711 extern void (*GC_check_heap) GC_PROTO((void));
1712 /* Check that all objects in the heap with */
1713 /* debugging info are intact. */
1714 /* Add any that are not to GC_smashed list. */
1715 extern void (*GC_print_all_smashed) GC_PROTO((void));
1716 /* Print GC_smashed if it's not empty. */
1717 /* Clear GC_smashed list. */
1718 extern void GC_print_all_errors GC_PROTO((void));
1719 /* Print smashed and leaked objects, if any. */
1720 /* Clear the lists of such objects. */
1721 extern void (*GC_print_heap_obj) GC_PROTO((ptr_t p));
1722 /* If possible print s followed by a more */
1723 /* detailed description of the object */
1724 /* referred to by p. */
1725 #if defined(LINUX) && defined(__ELF__) && !defined(SMALL_CONFIG)
1726 void GC_print_address_map GC_PROTO((void));
1727 /* Print an address map of the process. */
1730 extern GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
1731 /* Call error printing routine */
1733 extern GC_bool GC_print_stats; /* Produce at least some logging output */
1734 /* Set from environment variable. */
1736 #ifndef NO_DEBUGGING
1737 extern GC_bool GC_dump_regularly; /* Generate regular debugging dumps. */
1738 # define COND_DUMP if (GC_dump_regularly) GC_dump();
1743 #ifdef KEEP_BACK_PTRS
1744 extern long GC_backtraces;
1745 void GC_generate_random_backtrace_no_gc(void);
1748 extern GC_bool GC_print_back_height;
1750 #ifdef MAKE_BACK_GRAPH
1751 void GC_print_back_graph_stats(void);
1754 /* Macros used for collector internal allocation. */
1755 /* These assume the collector lock is held. */
1757 extern GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k);
1758 extern GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
1760 # define GC_INTERNAL_MALLOC GC_debug_generic_malloc_inner
1761 # define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
1762 GC_debug_generic_malloc_inner_ignore_off_page
1764 # define GC_INTERNAL_FREE GC_debug_free_inner
1766 # define GC_INTERNAL_FREE GC_debug_free
1769 # define GC_INTERNAL_MALLOC GC_generic_malloc_inner
1770 # define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
1771 GC_generic_malloc_inner_ignore_off_page
1773 # define GC_INTERNAL_FREE GC_free_inner
1775 # define GC_INTERNAL_FREE GC_free
1779 /* Memory unmapping: */
1781 void GC_unmap_old(void);
1782 void GC_merge_unmapped(void);
1783 void GC_unmap(ptr_t start, word bytes);
1784 void GC_remap(ptr_t start, word bytes);
1785 void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2);
1788 /* Virtual dirty bit implementation: */
1789 /* Each implementation exports the following: */
1790 void GC_read_dirty GC_PROTO((void));
1791 /* Retrieve dirty bits. */
1792 GC_bool GC_page_was_dirty GC_PROTO((struct hblk *h));
1793 /* Read retrieved dirty bits. */
1794 GC_bool GC_page_was_ever_dirty GC_PROTO((struct hblk *h));
1795 /* Could the page contain valid heap pointers? */
1796 void GC_is_fresh GC_PROTO((struct hblk *h, word n));
1797 /* Assert the region currently contains no */
1798 /* valid pointers. */
1799 void GC_remove_protection GC_PROTO((struct hblk *h, word nblocks,
1800 GC_bool pointerfree));
1801 /* h is about to be writteni or allocated. Ensure */
1802 /* that it's not write protected by the virtual */
1803 /* dirty bit implementation. */
1805 void GC_dirty_init GC_PROTO((void));
1807 /* Slow/general mark bit manipulation: */
1808 GC_API GC_bool GC_is_marked GC_PROTO((ptr_t p));
1809 void GC_clear_mark_bit GC_PROTO((ptr_t p));
1810 void GC_set_mark_bit GC_PROTO((ptr_t p));
1812 /* Stubborn objects: */
1813 void GC_read_changed GC_PROTO((void)); /* Analogous to GC_read_dirty */
1814 GC_bool GC_page_was_changed GC_PROTO((struct hblk * h));
1815 /* Analogous to GC_page_was_dirty */
1816 void GC_clean_changing_list GC_PROTO((void));
1817 /* Collect obsolete changing list entries */
1818 void GC_stubborn_init GC_PROTO((void));
1820 /* Debugging print routines: */
1821 void GC_print_block_list GC_PROTO((void));
1822 void GC_print_hblkfreelist GC_PROTO((void));
1823 void GC_print_heap_sects GC_PROTO((void));
1824 void GC_print_static_roots GC_PROTO((void));
1825 void GC_print_finalization_stats GC_PROTO((void));
1826 void GC_dump GC_PROTO((void));
1828 #ifdef KEEP_BACK_PTRS
1829 void GC_store_back_pointer(ptr_t source, ptr_t dest);
1830 void GC_marked_for_finalization(ptr_t dest);
1831 # define GC_STORE_BACK_PTR(source, dest) GC_store_back_pointer(source, dest)
1832 # define GC_MARKED_FOR_FINALIZATION(dest) GC_marked_for_finalization(dest)
1834 # define GC_STORE_BACK_PTR(source, dest)
1835 # define GC_MARKED_FOR_FINALIZATION(dest)
1838 /* Make arguments appear live to compiler */
1840 void GC_noop(void*, ...);
1843 GC_API void GC_noop(...);
1845 GC_API void GC_noop(void*,...);
1849 void GC_noop1 GC_PROTO((word));
1851 /* Logging and diagnostic output: */
1852 GC_API void GC_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1853 /* A version of printf that doesn't allocate, */
1854 /* is restricted to long arguments, and */
1855 /* (unfortunately) doesn't use varargs for */
1856 /* portability. Restricted to 6 args and */
1857 /* 1K total output length. */
1858 /* (We use sprintf. Hopefully that doesn't */
1859 /* allocate for long arguments.) */
1860 # define GC_printf0(f) GC_printf(f, 0l, 0l, 0l, 0l, 0l, 0l)
1861 # define GC_printf1(f,a) GC_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1862 # define GC_printf2(f,a,b) GC_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1863 # define GC_printf3(f,a,b,c) GC_printf(f, (long)a, (long)b, (long)c, 0l, 0l, 0l)
1864 # define GC_printf4(f,a,b,c,d) GC_printf(f, (long)a, (long)b, (long)c, \
1866 # define GC_printf5(f,a,b,c,d,e) GC_printf(f, (long)a, (long)b, (long)c, \
1867 (long)d, (long)e, 0l)
1868 # define GC_printf6(f,a,b,c,d,e,g) GC_printf(f, (long)a, (long)b, (long)c, \
1869 (long)d, (long)e, (long)g)
1871 GC_API void GC_err_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1872 # define GC_err_printf0(f) GC_err_puts(f)
1873 # define GC_err_printf1(f,a) GC_err_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1874 # define GC_err_printf2(f,a,b) GC_err_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1875 # define GC_err_printf3(f,a,b,c) GC_err_printf(f, (long)a, (long)b, (long)c, \
1877 # define GC_err_printf4(f,a,b,c,d) GC_err_printf(f, (long)a, (long)b, \
1878 (long)c, (long)d, 0l, 0l)
1879 # define GC_err_printf5(f,a,b,c,d,e) GC_err_printf(f, (long)a, (long)b, \
1882 # define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
1885 /* Ditto, writes to stderr. */
1887 void GC_err_puts GC_PROTO((GC_CONST char *s));
1888 /* Write s to stderr, don't buffer, don't add */
1889 /* newlines, don't ... */
1891 #if defined(LINUX) && !defined(SMALL_CONFIG)
1892 void GC_err_write GC_PROTO((GC_CONST char *buf, size_t len));
1893 /* Write buf to stderr, don't buffer, don't add */
1894 /* newlines, don't ... */
1898 # ifdef GC_ASSERTIONS
1899 # define GC_ASSERT(expr) if(!(expr)) {\
1900 GC_err_printf2("Assertion failure: %s:%ld\n", \
1901 __FILE__, (unsigned long)__LINE__); \
1902 ABORT("assertion failure"); }
1904 # define GC_ASSERT(expr)
1907 /* Check a compile time assertion at compile time. The error */
1908 /* message for failure is a bit baroque, but ... */
1909 #if defined(mips) && !defined(__GNUC__)
1910 /* DOB: MIPSPro C gets an internal error taking the sizeof an array type.
1911 This code works correctly (ugliness is to avoid "unused var" warnings) */
1912 # define GC_STATIC_ASSERT(expr) do { if (0) { char j[(expr)? 1 : -1]; j[0]='\0'; j[0]=j[0]; } } while(0)
1914 # define GC_STATIC_ASSERT(expr) sizeof(char[(expr)? 1 : -1])
1917 # if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
1918 /* We need additional synchronization facilities from the thread */
1919 /* support. We believe these are less performance critical */
1920 /* than the main garbage collector lock; standard pthreads-based */
1921 /* implementations should be sufficient. */
1923 /* The mark lock and condition variable. If the GC lock is also */
1924 /* acquired, the GC lock must be acquired first. The mark lock is */
1925 /* used to both protect some variables used by the parallel */
1926 /* marker, and to protect GC_fl_builder_count, below. */
1927 /* GC_notify_all_marker() is called when */
1928 /* the state of the parallel marker changes */
1929 /* in some significant way (see gc_mark.h for details). The */
1930 /* latter set of events includes incrementing GC_mark_no. */
1931 /* GC_notify_all_builder() is called when GC_fl_builder_count */
1934 extern void GC_acquire_mark_lock(void);
1935 extern void GC_release_mark_lock(void);
1936 extern void GC_notify_all_builder(void);
1937 /* extern void GC_wait_builder(); */
1938 extern void GC_wait_for_reclaim(void);
1940 extern word GC_fl_builder_count; /* Protected by mark lock. */
1941 # endif /* PARALLEL_MARK || THREAD_LOCAL_ALLOC */
1942 # ifdef PARALLEL_MARK
1943 extern void GC_notify_all_marker(void);
1944 extern void GC_wait_marker(void);
1945 extern word GC_mark_no; /* Protected by mark lock. */
1947 extern void GC_help_marker(word my_mark_no);
1948 /* Try to help out parallel marker for mark cycle */
1949 /* my_mark_no. Returns if the mark cycle finishes or */
1950 /* was already done, or there was nothing to do for */
1951 /* some other reason. */
1952 # endif /* PARALLEL_MARK */
1954 # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
1955 /* We define the thread suspension signal here, so that we can refer */
1956 /* to it in the dirty bit implementation, if necessary. Ideally we */
1957 /* would allocate a (real-time ?) signal using the standard mechanism.*/
1958 /* unfortunately, there is no standard mechanism. (There is one */
1959 /* in Linux glibc, but it's not exported.) Thus we continue to use */
1960 /* the same hard-coded signals we've always used. */
1961 # if !defined(SIG_SUSPEND)
1962 # if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS) || defined(GC_NETBSD_THREADS)
1963 # if defined(SPARC) && !defined(SIGPWR)
1964 /* SPARC/Linux doesn't properly define SIGPWR in <signal.h>.
1965 * It is aliased to SIGLOST in asm/signal.h, though. */
1966 # define SIG_SUSPEND SIGLOST
1967 # elif defined(NACL)
1968 # define SIG_SUSPEND 0
1970 /* Linuxthreads itself uses SIGUSR1 and SIGUSR2. */
1971 # define SIG_SUSPEND SIGPWR
1973 # else /* !GC_LINUX_THREADS */
1974 # if defined(_SIGRTMIN)
1975 # define SIG_SUSPEND _SIGRTMIN + 6
1977 # define SIG_SUSPEND SIGRTMIN + 6
1980 # endif /* !SIG_SUSPEND */
1984 # endif /* GC_PRIVATE_H */