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 /* 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 */
29 /* typedef long ptrdiff_t; -- necessary on some really old systems */
32 #if defined(mips) && defined(SYSTYPE_BSD43)
38 # include <sys/types.h>
39 # include <sys/time.h>
40 # include <sys/resource.h>
44 # include <sys/types.h>
45 # include <sys/time.h>
46 # include <sys/resource.h>
54 # include "../gc_mark.h"
58 typedef GC_signed_word signed_word;
64 typedef char * ptr_t; /* A generic pointer to which we can add */
65 /* byte displacements. */
66 /* Preferably identical to caddr_t, if it */
70 # include "gcconfig.h"
79 # if !(defined( sony_news ) )
82 # define VOLATILE volatile
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. */
94 # define EXPECT(expr, outcome) (expr)
98 # include "gc_locks.h"
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)
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)
114 #if defined(AMIGA) && defined(__SASC)
115 # define GC_FAR __far
121 /*********************************/
123 /* Definitions for conservative */
126 /*********************************/
128 /*********************************/
130 /* Easily changeable parameters */
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 */
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 */
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. */
191 #if defined(PRINTSTATS) && !defined(GATHERSTATS)
195 #if defined(PRINTSTATS) || !defined(SMALL_CONFIG)
196 # define CONDPRINT /* Print some things if GC_print_stats is set */
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 */
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. */
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
223 /* ALIGN_DOUBLE requires MERGE_SIZES at present. */
224 # if defined(ALIGN_DOUBLE) && !defined(MERGE_SIZES)
228 #if !defined(DONT_ADD_BYTE_AT_END)
229 # define EXTRA_BYTES GC_all_interior_pointers
231 # define EXTRA_BYTES 0
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 */
241 # define MAXHINCR 4096
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 */
259 /*********************************/
261 /* Stack saving for debugging */
263 /*********************************/
267 word ci_pc; /* Caller, not callee, pc */
269 word ci_arg[NARGS]; /* bit-wise complement to avoid retention */
271 # if defined(ALIGN_DOUBLE) && (NFRAMES * (NARGS + 1)) % 2 == 1
272 /* Likely alignment problem. */
278 #ifdef SAVE_CALL_CHAIN
280 /* Fill in the pc and argument information for up to NFRAMES of my */
281 /* callers. Ignore my frame and my callers frame. */
282 void GC_save_callers GC_PROTO((struct callinfo info[NFRAMES]));
284 void GC_print_callers GC_PROTO((struct callinfo info[NFRAMES]));
289 /*********************************/
291 /* OS interface routines */
293 /*********************************/
299 # define CLOCK_TYPE struct timeval
300 # define GET_TIME(x) { struct rusage rusage; \
301 getrusage (RUSAGE_SELF, &rusage); \
302 x = rusage.ru_utime; }
303 # define MS_TIME_DIFF(a,b) ((double) (a.tv_sec - b.tv_sec) * 1000.0 \
304 + (double) (a.tv_usec - b.tv_usec) / 1000.0)
305 #else /* !BSD_TIME */
306 # if defined(MSWIN32) || defined(MSWINCE)
307 # include <windows.h>
308 # include <winbase.h>
309 # define CLOCK_TYPE DWORD
310 # define GET_TIME(x) x = GetTickCount()
311 # define MS_TIME_DIFF(a,b) ((long)((a)-(b)))
312 # else /* !MSWIN32, !MSWINCE, !BSD_TIME */
314 # if !defined(__STDC__) && defined(SPARC) && defined(SUNOS4)
315 clock_t clock(); /* Not in time.h, where it belongs */
317 # if defined(FREEBSD) && !defined(CLOCKS_PER_SEC)
318 # include <machine/limits.h>
319 # define CLOCKS_PER_SEC CLK_TCK
321 # if !defined(CLOCKS_PER_SEC)
322 # define CLOCKS_PER_SEC 1000000
324 * This is technically a bug in the implementation. ANSI requires that
325 * CLOCKS_PER_SEC be defined. But at least under SunOS4.1.1, it isn't.
326 * Also note that the combination of ANSI C and POSIX is incredibly gross
327 * here. The type clock_t is used by both clock() and times(). But on
328 * some machines these use different notions of a clock tick, CLOCKS_PER_SEC
329 * seems to apply only to clock. Hence we use it here. On many machines,
330 * including SunOS, clock actually uses units of microseconds (which are
331 * not really clock ticks).
334 # define CLOCK_TYPE clock_t
335 # define GET_TIME(x) x = clock()
336 # define MS_TIME_DIFF(a,b) ((unsigned long) \
337 (1000.0*(double)((a)-(b))/(double)CLOCKS_PER_SEC))
338 # endif /* !MSWIN32 */
339 #endif /* !BSD_TIME */
341 /* We use bzero and bcopy internally. They may not be available. */
342 # if defined(SPARC) && defined(SUNOS4)
343 # define BCOPY_EXISTS
345 # if defined(M68K) && defined(AMIGA)
346 # define BCOPY_EXISTS
348 # if defined(M68K) && defined(NEXT)
349 # define BCOPY_EXISTS
352 # define BCOPY_EXISTS
356 # define BCOPY_EXISTS
360 # define BCOPY_EXISTS
363 # ifndef BCOPY_EXISTS
365 # define BCOPY(x,y,n) memcpy(y, x, (size_t)(n))
366 # define BZERO(x,n) memset(x, 0, (size_t)(n))
368 # define BCOPY(x,y,n) bcopy((char *)(x),(char *)(y),(int)(n))
369 # define BZERO(x,n) bzero((char *)(x),(int)(n))
372 /* Delay any interrupts or signals that may abort this thread. Data */
373 /* structures are in a consistent state outside this pair of calls. */
374 /* ANSI C allows both to be empty (though the standard isn't very */
375 /* clear on that point). Standard malloc implementations are usually */
376 /* neither interruptable nor thread-safe, and thus correspond to */
377 /* empty definitions. */
378 /* It probably doesn't make any sense to declare these to be nonempty */
379 /* if the code is being optimized, since signal safety relies on some */
380 /* ordering constraints that are typically not obeyed by optimizing */
383 # define DISABLE_SIGNALS() \
384 PCR_Th_SetSigMask(PCR_allSigsBlocked,&GC_old_sig_mask)
385 # define ENABLE_SIGNALS() \
386 PCR_Th_SetSigMask(&GC_old_sig_mask, NIL)
388 # if defined(THREADS) || defined(AMIGA) \
389 || defined(MSWIN32) || defined(MSWINCE) || defined(MACOS) \
390 || defined(DJGPP) || defined(NO_SIGNALS)
391 /* Also useful for debugging. */
392 /* Should probably use thr_sigsetmask for GC_SOLARIS_THREADS. */
393 # define DISABLE_SIGNALS()
394 # define ENABLE_SIGNALS()
396 # define DISABLE_SIGNALS() GC_disable_signals()
397 void GC_disable_signals();
398 # define ENABLE_SIGNALS() GC_enable_signals()
399 void GC_enable_signals();
404 * Stop and restart mutator threads.
407 # include "th/PCR_ThCtl.h"
408 # define STOP_WORLD() \
409 PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_stopNormal, \
410 PCR_allSigsBlocked, \
412 # define START_WORLD() \
413 PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_null, \
414 PCR_allSigsBlocked, \
417 # if defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) \
418 || defined(GC_PTHREADS)
419 void GC_stop_world();
420 void GC_start_world();
421 # define STOP_WORLD() GC_stop_world()
422 # define START_WORLD() GC_start_world()
424 # define STOP_WORLD()
425 # define START_WORLD()
431 # define ABORT(s) PCR_Base_Panic(s)
434 # define ABORT(msg) abort();
436 GC_API void GC_abort GC_PROTO((GC_CONST char * msg));
437 # define ABORT(msg) GC_abort(msg);
441 /* Exit abnormally, but without making a mess (e.g. out of memory) */
443 # define EXIT() PCR_Base_Exit(1,PCR_waitForever)
445 # define EXIT() (void)exit(1)
448 /* Print warning message, e.g. almost out of memory. */
449 # define WARN(msg,arg) (*GC_current_warn_proc)("GC Warning: " msg, (GC_word)(arg))
450 extern GC_warn_proc GC_current_warn_proc;
452 /* Get environment entry */
453 #if !defined(NO_GETENV)
454 # if defined(EMPTY_GETENV_RESULTS)
455 /* Workaround for a reputed Wine bug. */
456 static inline char * fixed_getenv(const char *name)
458 char * tmp = getenv(name);
459 if (tmp == 0 || strlen(tmp) == 0)
463 # define GETENV(name) fixed_getenv(name)
465 # define GETENV(name) getenv(name)
468 # define GETENV(name) 0
471 /*********************************/
473 /* Word-size-dependent defines */
475 /*********************************/
478 # define WORDS_TO_BYTES(x) ((x)<<2)
479 # define BYTES_TO_WORDS(x) ((x)>>2)
480 # define LOGWL ((word)5) /* log[2] of CPP_WORDSZ */
481 # define modWORDSZ(n) ((n) & 0x1f) /* n mod size of word */
488 # define WORDS_TO_BYTES(x) ((x)<<3)
489 # define BYTES_TO_WORDS(x) ((x)>>3)
490 # define LOGWL ((word)6) /* log[2] of CPP_WORDSZ */
491 # define modWORDSZ(n) ((n) & 0x3f) /* n mod size of word */
497 #define WORDSZ ((word)CPP_WORDSZ)
498 #define SIGNB ((word)1 << (WORDSZ-1))
499 #define BYTES_PER_WORD ((word)(sizeof (word)))
500 #define ONES ((word)(signed_word)(-1))
501 #define divWORDSZ(n) ((n) >> LOGWL) /* divide n by size of word */
503 /*********************/
505 /* Size Parameters */
507 /*********************/
509 /* heap block size, bytes. Should be power of 2 */
513 # define CPP_LOG_HBLKSIZE 10
515 # if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
516 /* HPUX/PA seems to use 4K pages with the 64 bit ABI */
517 # define CPP_LOG_HBLKSIZE 12
519 # define CPP_LOG_HBLKSIZE 13
524 # define CPP_LOG_HBLKSIZE 9
526 # if HBLKSIZE == 1024
527 # define CPP_LOG_HBLKSIZE 10
529 # if HBLKSIZE == 2048
530 # define CPP_LOG_HBLKSIZE 11
532 # if HBLKSIZE == 4096
533 # define CPP_LOG_HBLKSIZE 12
535 # if HBLKSIZE == 8192
536 # define CPP_LOG_HBLKSIZE 13
538 # if HBLKSIZE == 16384
539 # define CPP_LOG_HBLKSIZE 14
541 # ifndef CPP_LOG_HBLKSIZE
546 # define CPP_HBLKSIZE (1 << CPP_LOG_HBLKSIZE)
547 # define LOG_HBLKSIZE ((word)CPP_LOG_HBLKSIZE)
548 # define HBLKSIZE ((word)CPP_HBLKSIZE)
551 /* max size objects supported by freelist (larger objects may be */
552 /* allocated, but less efficiently) */
554 #define CPP_MAXOBJBYTES (CPP_HBLKSIZE/2)
555 #define MAXOBJBYTES ((word)CPP_MAXOBJBYTES)
556 #define CPP_MAXOBJSZ BYTES_TO_WORDS(CPP_MAXOBJBYTES)
557 #define MAXOBJSZ ((word)CPP_MAXOBJSZ)
559 # define divHBLKSZ(n) ((n) >> LOG_HBLKSIZE)
561 # define HBLK_PTR_DIFF(p,q) divHBLKSZ((ptr_t)p - (ptr_t)q)
562 /* Equivalent to subtracting 2 hblk pointers. */
563 /* We do it this way because a compiler should */
564 /* find it hard to use an integer division */
565 /* instead of a shift. The bundled SunOS 4.1 */
566 /* o.w. sometimes pessimizes the subtraction to */
567 /* involve a call to .div. */
569 # define modHBLKSZ(n) ((n) & (HBLKSIZE-1))
571 # define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
573 # define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
575 /* Round up byte allocation requests to integral number of words, etc. */
576 # define ROUNDED_UP_WORDS(n) \
577 BYTES_TO_WORDS((n) + (WORDS_TO_BYTES(1) - 1 + EXTRA_BYTES))
579 # define ALIGNED_WORDS(n) \
580 (BYTES_TO_WORDS((n) + WORDS_TO_BYTES(2) - 1 + EXTRA_BYTES) & ~1)
582 # define ALIGNED_WORDS(n) ROUNDED_UP_WORDS(n)
584 # define SMALL_OBJ(bytes) ((bytes) <= (MAXOBJBYTES - EXTRA_BYTES))
585 # define ADD_SLOP(bytes) ((bytes) + EXTRA_BYTES)
587 /* MIN_WORDS is the size of the smallest allocated object. */
588 /* 1 and 2 are the only valid values. */
589 /* 2 must be used if: */
590 /* - GC_gcj_malloc can be used for objects of requested */
591 /* size smaller than 2 words, or */
592 /* - USE_MARK_BYTES is defined. */
593 # if defined(USE_MARK_BYTES) || defined(GC_GCJ_SUPPORT)
594 # define MIN_WORDS 2 /* Smallest allocated object. */
602 * Hash table representation of sets of pages. This assumes it is
603 * OK to add spurious entries to sets.
604 * Used by black-listing code, and perhaps by dirty bit maintenance code.
608 # define LOG_PHT_ENTRIES 20 /* Collisions likely at 1M blocks, */
609 /* which is >= 4GB. Each table takes */
610 /* 128KB, some of which may never be */
614 # define LOG_PHT_ENTRIES 14 /* Collisions are likely if heap grows */
615 /* to more than 16K hblks = 64MB. */
616 /* Each hash table occupies 2K bytes. */
617 # else /* default "medium" configuration */
618 # define LOG_PHT_ENTRIES 16 /* Collisions are likely if heap grows */
619 /* to more than 64K hblks >= 256MB. */
620 /* Each hash table occupies 8K bytes. */
621 /* Even for somewhat smaller heaps, */
622 /* say half that, collisions may be an */
623 /* issue because we blacklist */
624 /* addresses outside the heap. */
627 # define PHT_ENTRIES ((word)1 << LOG_PHT_ENTRIES)
628 # define PHT_SIZE (PHT_ENTRIES >> LOGWL)
629 typedef word page_hash_table[PHT_SIZE];
631 # define PHT_HASH(addr) ((((word)(addr)) >> LOG_HBLKSIZE) & (PHT_ENTRIES - 1))
633 # define get_pht_entry_from_index(bl, index) \
634 (((bl)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
635 # define set_pht_entry_from_index(bl, index) \
636 (bl)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
637 # define clear_pht_entry_from_index(bl, index) \
638 (bl)[divWORDSZ(index)] &= ~((word)1 << modWORDSZ(index))
639 /* And a dumb but thread-safe version of set_pht_entry_from_index. */
640 /* This sets (many) extra bits. */
641 # define set_pht_entry_from_index_safe(bl, index) \
642 (bl)[divWORDSZ(index)] = ONES
646 /********************************************/
648 /* H e a p B l o c k s */
650 /********************************************/
652 /* heap block header */
653 #define HBLKMASK (HBLKSIZE-1)
655 #define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
657 #define MARK_BITS_PER_HBLK (BITS_PER_HBLK/CPP_WORDSZ)
659 /* We allocate 1 bit/word, unless USE_MARK_BYTES */
660 /* is defined. Only the first word */
661 /* in each object is actually marked. */
663 # ifdef USE_MARK_BYTES
664 # define MARK_BITS_SZ (MARK_BITS_PER_HBLK/2)
665 /* Unlike the other case, this is in units of bytes. */
666 /* We actually allocate only every second mark bit, since we */
667 /* force all objects to be doubleword aligned. */
668 /* However, each mark bit is allocated as a byte. */
670 # define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
673 /* We maintain layout maps for heap blocks containing objects of a given */
674 /* size. Each entry in this map describes a byte offset and has the */
675 /* following type. */
676 typedef unsigned char map_entry_type;
679 word hb_sz; /* If in use, size in words, of objects in the block. */
680 /* if free, the size in bytes of the whole block */
681 struct hblk * hb_next; /* Link field for hblk free list */
682 /* and for lists of chunks waiting to be */
684 struct hblk * hb_prev; /* Backwards link for free list. */
685 word hb_descr; /* object descriptor for marking. See */
687 map_entry_type * hb_map;
688 /* A pointer to a pointer validity map of the block. */
689 /* See GC_obj_map. */
690 /* Valid for all blocks with headers. */
691 /* Free blocks point to GC_invalid_map. */
692 unsigned char hb_obj_kind;
693 /* Kind of objects in the block. Each kind */
694 /* identifies a mark procedure and a set of */
695 /* list headers. Sometimes called regions. */
696 unsigned char hb_flags;
697 # define IGNORE_OFF_PAGE 1 /* Ignore pointers that do not */
698 /* point to the first page of */
700 # define WAS_UNMAPPED 2 /* This is a free block, which has */
701 /* been unmapped from the address */
703 /* GC_remap must be invoked on it */
704 /* before it can be reallocated. */
705 /* Only set with USE_MUNMAP. */
706 unsigned short hb_last_reclaimed;
707 /* Value of GC_gc_no when block was */
708 /* last allocated or swept. May wrap. */
709 /* For a free block, this is maintained */
710 /* only for USE_MUNMAP, and indicates */
711 /* when the header was allocated, or */
712 /* when the size of the block last */
714 # ifdef USE_MARK_BYTES
716 char _hb_marks[MARK_BITS_SZ];
717 /* The i'th byte is 1 if the object */
718 /* starting at word 2i is marked, 0 o.w. */
719 word dummy; /* Force word alignment of mark bytes. */
721 # define hb_marks _mark_byte_union._hb_marks
723 word hb_marks[MARK_BITS_SZ];
724 /* Bit i in the array refers to the */
725 /* object starting at the ith word (header */
726 /* INCLUDED) in the heap block. */
727 /* The lsb of word 0 is numbered 0. */
728 /* Unused bits are invalid, and are */
729 /* occasionally set, e.g for uncollectable */
731 # endif /* !USE_MARK_BYTES */
734 /* heap block body */
736 # define BODY_SZ (HBLKSIZE/sizeof(word))
739 word hb_body[BODY_SZ];
742 # define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
744 # define OBJ_SZ_TO_BLOCKS(sz) \
745 divHBLKSZ(WORDS_TO_BYTES(sz) + HBLKSIZE-1)
746 /* Size of block (in units of HBLKSIZE) needed to hold objects of */
747 /* given sz (in words). */
749 /* Object free list link */
750 # define obj_link(p) (*(ptr_t *)(p))
752 # define LOG_MAX_MARK_PROCS 6
753 # define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
755 /* Root sets. Logically private to mark_rts.c. But we don't want the */
756 /* tables scanned, so we put them here. */
757 /* MAX_ROOT_SETS is the maximum number of ranges that can be */
758 /* registered as static roots. */
760 # define MAX_ROOT_SETS 4096
762 /* GCJ LOCAL: MAX_ROOT_SETS increased to permit more shared */
763 /* libraries to be loaded. */
764 # define MAX_ROOT_SETS 1024
767 # define MAX_EXCLUSIONS (MAX_ROOT_SETS/4)
768 /* Maximum number of segments that can be excluded from root sets. */
771 * Data structure for excluded static roots.
778 /* Data structure for list of root sets. */
779 /* We keep a hash table, so that we can filter out duplicate additions. */
780 /* Under Win32, we need to do a better job of filtering overlaps, so */
781 /* we resort to sequential search, and pay the price. */
785 # if !defined(MSWIN32) && !defined(MSWINCE)
786 struct roots * r_next;
789 /* Delete before registering new dynamic libraries */
792 #if !defined(MSWIN32) && !defined(MSWINCE)
793 /* Size of hash table index to roots. */
794 # define LOG_RT_SIZE 6
795 # define RT_SIZE (1 << LOG_RT_SIZE) /* Power of 2, may be != MAX_ROOT_SETS */
798 /* Lists of all heap blocks and free lists */
799 /* as well as other random data structures */
800 /* that should not be scanned by the */
802 /* These are grouped together in a struct */
803 /* so that they can be easily skipped by the */
804 /* GC_mark routine. */
805 /* The ordering is weird to make GC_malloc */
806 /* faster by keeping the important fields */
807 /* sufficiently close together that a */
808 /* single load of a base register will do. */
809 /* Scalars that could easily appear to */
810 /* be pointers are also put here. */
811 /* The main fields should precede any */
812 /* conditionally included fields, so that */
813 /* gc_inl.h will work even if a different set */
814 /* of macros is defined when the client is */
820 word _requested_heapsize; /* Heap size due to explicit expansion */
821 ptr_t _last_heap_addr;
822 ptr_t _prev_heap_addr;
823 word _large_free_bytes;
824 /* Total bytes contained in blocks on large object free */
826 word _large_allocd_bytes;
827 /* Total number of bytes in allocated large objects blocks. */
828 /* For the purposes of this counter and the next one only, a */
829 /* large object is one that occupies a block of at least */
831 word _max_large_allocd_bytes;
832 /* Maximum number of bytes that were ever allocated in */
833 /* large object blocks. This is used to help decide when it */
834 /* is safe to split up a large block. */
835 word _words_allocd_before_gc;
836 /* Number of words allocated before this */
837 /* collection cycle. */
838 # ifndef SEPARATE_GLOBALS
840 /* Number of words allocated during this collection cycle */
843 /* Number of words wasted due to internal fragmentation */
844 /* in large objects, or due to dropping blacklisted */
845 /* blocks, since last gc. Approximate. */
846 word _words_finalized;
847 /* Approximate number of words in objects (and headers) */
848 /* That became ready for finalization in the last */
850 word _non_gc_bytes_at_gc;
851 /* Number of explicitly managed bytes of storage */
852 /* at last collection. */
854 /* Number of explicitly deallocated words of memory */
855 /* since last collection. */
856 word _finalizer_mem_freed;
857 /* Words of memory explicitly deallocated while */
858 /* finalizers were running. Used to approximate mem. */
859 /* explicitly deallocated by finalizers. */
860 ptr_t _scratch_end_ptr;
861 ptr_t _scratch_last_end_ptr;
862 /* Used by headers.c, and can easily appear to point to */
864 GC_mark_proc _mark_procs[MAX_MARK_PROCS];
865 /* Table of user-defined mark procedures. There is */
866 /* a small number of these, which can be referenced */
867 /* by DS_PROC mark descriptors. See gc_mark.h. */
869 # ifndef SEPARATE_GLOBALS
870 ptr_t _objfreelist[MAXOBJSZ+1];
871 /* free list for objects */
872 ptr_t _aobjfreelist[MAXOBJSZ+1];
873 /* free list for atomic objs */
876 ptr_t _uobjfreelist[MAXOBJSZ+1];
877 /* uncollectable but traced objs */
878 /* objects on this and auobjfreelist */
879 /* are always marked, except during */
880 /* garbage collections. */
881 # ifdef ATOMIC_UNCOLLECTABLE
882 ptr_t _auobjfreelist[MAXOBJSZ+1];
884 /* uncollectable but traced objs */
887 word _composite_in_use;
888 /* Number of words in accessible composite */
891 /* Number of words in accessible atomic */
895 word _unmapped_bytes;
898 unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
899 /* Number of words to allocate for a given allocation request in */
903 # ifdef STUBBORN_ALLOC
904 ptr_t _sobjfreelist[MAXOBJSZ+1];
906 /* free list for immutable objects */
907 map_entry_type * _obj_map[MAXOBJSZ+1];
908 /* If not NIL, then a pointer to a map of valid */
909 /* object addresses. _obj_map[sz][i] is j if the */
910 /* address block_start+i is a valid pointer */
911 /* to an object at block_start + */
912 /* WORDS_TO_BYTES(BYTES_TO_WORDS(i) - j) */
913 /* I.e. j is a word displacement from the */
914 /* object beginning. */
915 /* The entry is OBJ_INVALID if the corresponding */
916 /* address is not a valid pointer. It is */
917 /* OFFSET_TOO_BIG if the value j would be too */
918 /* large to fit in the entry. (Note that the */
919 /* size of these entries matters, both for */
920 /* space consumption and for cache utilization.) */
921 # define OFFSET_TOO_BIG 0xfe
922 # define OBJ_INVALID 0xff
923 # define MAP_ENTRY(map, bytes) (map)[bytes]
924 # define MAP_ENTRIES HBLKSIZE
925 # define MAP_SIZE MAP_ENTRIES
926 # define CPP_MAX_OFFSET (OFFSET_TOO_BIG - 1)
927 # define MAX_OFFSET ((word)CPP_MAX_OFFSET)
928 /* The following are used only if GC_all_interior_ptrs != 0 */
929 # define VALID_OFFSET_SZ \
930 (CPP_MAX_OFFSET > WORDS_TO_BYTES(CPP_MAXOBJSZ)? \
932 : WORDS_TO_BYTES(CPP_MAXOBJSZ)+1)
933 char _valid_offsets[VALID_OFFSET_SZ];
934 /* GC_valid_offsets[i] == TRUE ==> i */
935 /* is registered as a displacement. */
936 char _modws_valid_offsets[sizeof(word)];
937 /* GC_valid_offsets[i] ==> */
938 /* GC_modws_valid_offsets[i%sizeof(word)] */
939 # define OFFSET_VALID(displ) \
940 (GC_all_interior_pointers || GC_valid_offsets[displ])
941 # ifdef STUBBORN_ALLOC
942 page_hash_table _changed_pages;
943 /* Stubborn object pages that were changes since last call to */
944 /* GC_read_changed. */
945 page_hash_table _prev_changed_pages;
946 /* Stubborn object pages that were changes before last call to */
947 /* GC_read_changed. */
949 # if defined(PROC_VDB) || defined(MPROTECT_VDB)
950 page_hash_table _grungy_pages; /* Pages that were dirty at last */
954 VOLATILE page_hash_table _dirty_pages;
955 /* Pages dirtied since last GC_read_dirty. */
958 page_hash_table _written_pages; /* Pages ever dirtied */
962 # define MAX_HEAP_SECTS 4096 /* overflows at roughly 64 GB */
964 # define MAX_HEAP_SECTS 768 /* Separately added heap sections. */
968 # define MAX_HEAP_SECTS 128 /* Roughly 256MB (128*2048*1K) */
970 # define MAX_HEAP_SECTS 384 /* Roughly 3GB */
974 ptr_t hs_start; word hs_bytes;
975 } _heap_sects[MAX_HEAP_SECTS];
976 # if defined(MSWIN32) || defined(MSWINCE)
977 ptr_t _heap_bases[MAX_HEAP_SECTS];
978 /* Start address of memory regions obtained from kernel. */
981 word _heap_lengths[MAX_HEAP_SECTS];
982 /* Commited lengths of memory regions obtained from kernel. */
984 struct roots _static_roots[MAX_ROOT_SETS];
985 # if !defined(MSWIN32) && !defined(MSWINCE)
986 struct roots * _root_index[RT_SIZE];
988 struct exclusion _excl_table[MAX_EXCLUSIONS];
989 /* Block header index; see gc_headers.h */
990 bottom_index * _all_nils;
991 bottom_index * _top_index [TOP_SZ];
992 #ifdef SAVE_CALL_CHAIN
993 struct callinfo _last_stack[NFRAMES]; /* Stack at last garbage collection.*/
994 /* Useful for debugging mysterious */
995 /* object disappearances. */
996 /* In the multithreaded case, we */
997 /* currently only save the calling */
1002 GC_API GC_FAR struct _GC_arrays GC_arrays;
1004 # ifndef SEPARATE_GLOBALS
1005 # define GC_objfreelist GC_arrays._objfreelist
1006 # define GC_aobjfreelist GC_arrays._aobjfreelist
1007 # define GC_words_allocd GC_arrays._words_allocd
1009 # define GC_uobjfreelist GC_arrays._uobjfreelist
1010 # ifdef ATOMIC_UNCOLLECTABLE
1011 # define GC_auobjfreelist GC_arrays._auobjfreelist
1013 # define GC_sobjfreelist GC_arrays._sobjfreelist
1014 # define GC_valid_offsets GC_arrays._valid_offsets
1015 # define GC_modws_valid_offsets GC_arrays._modws_valid_offsets
1016 # ifdef STUBBORN_ALLOC
1017 # define GC_changed_pages GC_arrays._changed_pages
1018 # define GC_prev_changed_pages GC_arrays._prev_changed_pages
1020 # define GC_obj_map GC_arrays._obj_map
1021 # define GC_last_heap_addr GC_arrays._last_heap_addr
1022 # define GC_prev_heap_addr GC_arrays._prev_heap_addr
1023 # define GC_words_wasted GC_arrays._words_wasted
1024 # define GC_large_free_bytes GC_arrays._large_free_bytes
1025 # define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
1026 # define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes
1027 # define GC_words_finalized GC_arrays._words_finalized
1028 # define GC_non_gc_bytes_at_gc GC_arrays._non_gc_bytes_at_gc
1029 # define GC_mem_freed GC_arrays._mem_freed
1030 # define GC_finalizer_mem_freed GC_arrays._finalizer_mem_freed
1031 # define GC_scratch_end_ptr GC_arrays._scratch_end_ptr
1032 # define GC_scratch_last_end_ptr GC_arrays._scratch_last_end_ptr
1033 # define GC_mark_procs GC_arrays._mark_procs
1034 # define GC_heapsize GC_arrays._heapsize
1035 # define GC_max_heapsize GC_arrays._max_heapsize
1036 # define GC_requested_heapsize GC_arrays._requested_heapsize
1037 # define GC_words_allocd_before_gc GC_arrays._words_allocd_before_gc
1038 # define GC_heap_sects GC_arrays._heap_sects
1039 # define GC_last_stack GC_arrays._last_stack
1041 # define GC_unmapped_bytes GC_arrays._unmapped_bytes
1043 # if defined(MSWIN32) || defined(MSWINCE)
1044 # define GC_heap_bases GC_arrays._heap_bases
1047 # define GC_heap_lengths GC_arrays._heap_lengths
1049 # define GC_static_roots GC_arrays._static_roots
1050 # define GC_root_index GC_arrays._root_index
1051 # define GC_excl_table GC_arrays._excl_table
1052 # define GC_all_nils GC_arrays._all_nils
1053 # define GC_top_index GC_arrays._top_index
1054 # if defined(PROC_VDB) || defined(MPROTECT_VDB)
1055 # define GC_grungy_pages GC_arrays._grungy_pages
1057 # ifdef MPROTECT_VDB
1058 # define GC_dirty_pages GC_arrays._dirty_pages
1061 # define GC_written_pages GC_arrays._written_pages
1064 # define GC_composite_in_use GC_arrays._composite_in_use
1065 # define GC_atomic_in_use GC_arrays._atomic_in_use
1068 # define GC_size_map GC_arrays._size_map
1071 # define beginGC_arrays ((ptr_t)(&GC_arrays))
1072 # define endGC_arrays (((ptr_t)(&GC_arrays)) + (sizeof GC_arrays))
1074 #define USED_HEAP_SIZE (GC_heapsize - GC_large_free_bytes)
1077 # define MAXOBJKINDS 16
1079 extern struct obj_kind {
1080 ptr_t *ok_freelist; /* Array of free listheaders for this kind of object */
1081 /* Point either to GC_arrays or to storage allocated */
1082 /* with GC_scratch_alloc. */
1083 struct hblk **ok_reclaim_list;
1084 /* List headers for lists of blocks waiting to be */
1086 word ok_descriptor; /* Descriptor template for objects in this */
1088 GC_bool ok_relocate_descr;
1089 /* Add object size in bytes to descriptor */
1090 /* template to obtain descriptor. Otherwise */
1091 /* template is used as is. */
1092 GC_bool ok_init; /* Clear objects before putting them on the free list. */
1093 } GC_obj_kinds[MAXOBJKINDS];
1095 # define beginGC_obj_kinds ((ptr_t)(&GC_obj_kinds))
1096 # define endGC_obj_kinds (beginGC_obj_kinds + (sizeof GC_obj_kinds))
1098 /* Variables that used to be in GC_arrays, but need to be accessed by */
1099 /* inline allocation code. If they were in GC_arrays, the inlined */
1100 /* allocation code would include GC_arrays offsets (as it did), which */
1101 /* introduce maintenance problems. */
1103 #ifdef SEPARATE_GLOBALS
1104 word GC_words_allocd;
1105 /* Number of words allocated during this collection cycle */
1106 ptr_t GC_objfreelist[MAXOBJSZ+1];
1107 /* free list for NORMAL objects */
1108 # define beginGC_objfreelist ((ptr_t)(&GC_objfreelist))
1109 # define endGC_objfreelist (beginGC_objfreelist + sizeof(GC_objfreelist))
1111 ptr_t GC_aobjfreelist[MAXOBJSZ+1];
1112 /* free list for atomic (PTRFREE) objs */
1113 # define beginGC_aobjfreelist ((ptr_t)(&GC_aobjfreelist))
1114 # define endGC_aobjfreelist (beginGC_aobjfreelist + sizeof(GC_aobjfreelist))
1117 /* Predefined kinds: */
1120 # define UNCOLLECTABLE 2
1121 # ifdef ATOMIC_UNCOLLECTABLE
1122 # define AUNCOLLECTABLE 3
1124 # define IS_UNCOLLECTABLE(k) (((k) & ~1) == UNCOLLECTABLE)
1127 # define IS_UNCOLLECTABLE(k) ((k) == UNCOLLECTABLE)
1130 extern int GC_n_kinds;
1132 GC_API word GC_fo_entries;
1134 extern word GC_n_heap_sects; /* Number of separately added heap */
1137 extern word GC_page_size;
1139 # if defined(MSWIN32) || defined(MSWINCE)
1140 struct _SYSTEM_INFO;
1141 extern struct _SYSTEM_INFO GC_sysinfo;
1142 extern word GC_n_heap_bases; /* See GC_heap_bases. */
1145 extern word GC_total_stack_black_listed;
1146 /* Number of bytes on stack blacklist. */
1148 extern word GC_black_list_spacing;
1149 /* Average number of bytes between blacklisted */
1150 /* blocks. Approximate. */
1151 /* Counts only blocks that are */
1152 /* "stack-blacklisted", i.e. that are */
1153 /* problematic in the interior of an object. */
1155 extern map_entry_type * GC_invalid_map;
1156 /* Pointer to the nowhere valid hblk map */
1157 /* Blocks pointing to this map are free. */
1159 extern struct hblk * GC_hblkfreelist[];
1160 /* List of completely empty heap blocks */
1161 /* Linked through hb_next field of */
1162 /* header structure associated with */
1165 extern GC_bool GC_objects_are_marked; /* There are marked objects in */
1168 #ifndef SMALL_CONFIG
1169 extern GC_bool GC_incremental;
1170 /* Using incremental/generational collection. */
1171 # define TRUE_INCREMENTAL \
1172 (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED)
1173 /* True incremental, not just generational, mode */
1175 # define GC_incremental FALSE
1176 /* Hopefully allow optimizer to remove some code. */
1177 # define TRUE_INCREMENTAL FALSE
1180 extern GC_bool GC_dirty_maintained;
1181 /* Dirty bits are being maintained, */
1182 /* either for incremental collection, */
1183 /* or to limit the root set. */
1185 extern word GC_root_size; /* Total size of registered root sections */
1187 extern GC_bool GC_debugging_started; /* GC_debug_malloc has been called. */
1189 extern long GC_large_alloc_warn_interval;
1190 /* Interval between unsuppressed warnings. */
1192 extern long GC_large_alloc_warn_suppressed;
1193 /* Number of warnings suppressed so far. */
1196 extern GC_bool GC_world_stopped;
1201 # define abs(x) ((x) < 0? (-(x)) : (x))
1205 /* Marks are in a reserved area in */
1206 /* each heap block. Each word has one mark bit associated */
1207 /* with it. Only those corresponding to the beginning of an */
1208 /* object are used. */
1210 /* Set mark bit correctly, even if mark bits may be concurrently */
1212 #ifdef PARALLEL_MARK
1213 # define OR_WORD(addr, bits) \
1216 old = *((volatile word *)addr); \
1217 } while (!GC_compare_and_exchange((addr), old, old | (bits))); \
1219 # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1221 word my_bits = (bits); \
1223 old = *((volatile word *)addr); \
1224 if (old & my_bits) goto exit_label; \
1225 } while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
1228 # define OR_WORD(addr, bits) *(addr) |= (bits)
1229 # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1231 word old = *(addr); \
1232 word my_bits = (bits); \
1233 if (old & my_bits) goto exit_label; \
1234 *(addr) = (old | my_bits); \
1238 /* Mark bit operations */
1241 * Retrieve, set, clear the mark bit corresponding
1242 * to the nth word in a given heap block.
1244 * (Recall that bit n corresponds to object beginning at word n
1245 * relative to the beginning of the block, including unused words)
1248 #ifdef USE_MARK_BYTES
1249 # define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n) >> 1])
1250 # define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 1
1251 # define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 0
1252 #else /* !USE_MARK_BYTES */
1253 # define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
1254 >> (modWORDSZ(n))) & (word)1)
1255 # define set_mark_bit_from_hdr(hhdr,n) \
1256 OR_WORD((hhdr)->hb_marks+divWORDSZ(n), \
1257 (word)1 << modWORDSZ(n))
1258 # define clear_mark_bit_from_hdr(hhdr,n) (hhdr)->hb_marks[divWORDSZ(n)] \
1259 &= ~((word)1 << modWORDSZ(n))
1260 #endif /* !USE_MARK_BYTES */
1262 /* Important internal collector routines */
1264 ptr_t GC_approx_sp GC_PROTO((void));
1266 GC_bool GC_should_collect GC_PROTO((void));
1268 void GC_apply_to_all_blocks GC_PROTO(( \
1269 void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
1271 /* Invoke fn(hbp, client_data) for each */
1272 /* allocated heap block. */
1273 struct hblk * GC_next_used_block GC_PROTO((struct hblk * h));
1274 /* Return first in-use block >= h */
1275 struct hblk * GC_prev_block GC_PROTO((struct hblk * h));
1276 /* Return last block <= h. Returned block */
1277 /* is managed by GC, but may or may not be in */
1279 void GC_mark_init GC_PROTO((void));
1280 void GC_clear_marks GC_PROTO((void)); /* Clear mark bits for all heap objects. */
1281 void GC_invalidate_mark_state GC_PROTO((void));
1282 /* Tell the marker that marked */
1283 /* objects may point to unmarked */
1284 /* ones, and roots may point to */
1285 /* unmarked objects. */
1286 /* Reset mark stack. */
1287 GC_bool GC_mark_stack_empty GC_PROTO((void));
1288 GC_bool GC_mark_some GC_PROTO((ptr_t cold_gc_frame));
1289 /* Perform about one pages worth of marking */
1290 /* work of whatever kind is needed. Returns */
1291 /* quickly if no collection is in progress. */
1292 /* Return TRUE if mark phase finished. */
1293 void GC_initiate_gc GC_PROTO((void));
1294 /* initiate collection. */
1295 /* If the mark state is invalid, this */
1296 /* becomes full colleection. Otherwise */
1298 void GC_push_all GC_PROTO((ptr_t bottom, ptr_t top));
1299 /* Push everything in a range */
1300 /* onto mark stack. */
1301 void GC_push_selected GC_PROTO(( \
1304 int (*dirty_fn) GC_PROTO((struct hblk *h)), \
1305 void (*push_fn) GC_PROTO((ptr_t bottom, ptr_t top)) ));
1306 /* Push all pages h in [b,t) s.t. */
1307 /* select_fn(h) != 0 onto mark stack. */
1308 #ifndef SMALL_CONFIG
1309 void GC_push_conditional GC_PROTO((ptr_t b, ptr_t t, GC_bool all));
1311 # define GC_push_conditional(b, t, all) GC_push_all(b, t)
1313 /* Do either of the above, depending */
1314 /* on the third arg. */
1315 void GC_push_all_stack GC_PROTO((ptr_t b, ptr_t t));
1316 /* As above, but consider */
1317 /* interior pointers as valid */
1318 void GC_push_all_eager GC_PROTO((ptr_t b, ptr_t t));
1319 /* Same as GC_push_all_stack, but */
1320 /* ensures that stack is scanned */
1321 /* immediately, not just scheduled */
1324 void GC_push_all_stack_partially_eager GC_PROTO(( \
1325 ptr_t bottom, ptr_t top, ptr_t cold_gc_frame ));
1326 /* Similar to GC_push_all_eager, but only the */
1327 /* part hotter than cold_gc_frame is scanned */
1328 /* immediately. Needed to ensure that callee- */
1329 /* save registers are not missed. */
1331 /* In the threads case, we push part of the current thread stack */
1332 /* with GC_push_all_eager when we push the registers. This gets the */
1333 /* callee-save registers that may disappear. The remainder of the */
1334 /* stacks are scheduled for scanning in *GC_push_other_roots, which */
1335 /* is thread-package-specific. */
1337 void GC_push_current_stack GC_PROTO((ptr_t cold_gc_frame));
1338 /* Push enough of the current stack eagerly to */
1339 /* ensure that callee-save registers saved in */
1340 /* GC frames are scanned. */
1341 /* In the non-threads case, schedule entire */
1342 /* stack for scanning. */
1343 void GC_push_roots GC_PROTO((GC_bool all, ptr_t cold_gc_frame));
1344 /* Push all or dirty roots. */
1345 extern void (*GC_push_other_roots) GC_PROTO((void));
1346 /* Push system or application specific roots */
1347 /* onto the mark stack. In some environments */
1348 /* (e.g. threads environments) this is */
1349 /* predfined to be non-zero. A client supplied */
1350 /* replacement should also call the original */
1352 extern void GC_push_gc_structures GC_PROTO((void));
1353 /* Push GC internal roots. These are normally */
1354 /* included in the static data segment, and */
1355 /* Thus implicitly pushed. But we must do this */
1356 /* explicitly if normal root processing is */
1357 /* disabled. Calls the following: */
1358 extern void GC_push_finalizer_structures GC_PROTO((void));
1359 extern void GC_push_stubborn_structures GC_PROTO((void));
1361 extern void GC_push_thread_structures GC_PROTO((void));
1363 extern void (*GC_start_call_back) GC_PROTO((void));
1364 /* Called at start of full collections. */
1365 /* Not called if 0. Called with allocation */
1368 # if defined(USE_GENERIC_PUSH_REGS)
1369 void GC_generic_push_regs GC_PROTO((ptr_t cold_gc_frame));
1371 void GC_push_regs GC_PROTO((void));
1373 # if defined(SPARC) || defined(IA64)
1374 /* Cause all stacked registers to be saved in memory. Return a */
1375 /* pointer to the top of the corresponding memory stack. */
1376 word GC_save_regs_in_stack GC_PROTO((void));
1378 /* Push register contents onto mark stack. */
1379 /* If NURSERY is defined, the default push */
1380 /* action can be overridden with GC_push_proc */
1383 extern void (*GC_push_proc)(ptr_t);
1385 # if defined(MSWIN32) || defined(MSWINCE)
1386 void __cdecl GC_push_one GC_PROTO((word p));
1388 void GC_push_one GC_PROTO((word p));
1389 /* If p points to an object, mark it */
1390 /* and push contents on the mark stack */
1391 /* Pointer recognition test always */
1392 /* accepts interior pointers, i.e. this */
1393 /* is appropriate for pointers found on */
1396 # if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
1397 void GC_mark_and_push_stack GC_PROTO((word p, ptr_t source));
1398 /* Ditto, omits plausibility test */
1400 void GC_mark_and_push_stack GC_PROTO((word p));
1402 void GC_push_marked GC_PROTO((struct hblk * h, hdr * hhdr));
1403 /* Push contents of all marked objects in h onto */
1406 # define GC_push_next_marked_dirty(h) GC_push_next_marked(h)
1408 struct hblk * GC_push_next_marked_dirty GC_PROTO((struct hblk * h));
1409 /* Invoke GC_push_marked on next dirty block above h. */
1410 /* Return a pointer just past the end of this block. */
1411 #endif /* !SMALL_CONFIG */
1412 struct hblk * GC_push_next_marked GC_PROTO((struct hblk * h));
1413 /* Ditto, but also mark from clean pages. */
1414 struct hblk * GC_push_next_marked_uncollectable GC_PROTO((struct hblk * h));
1415 /* Ditto, but mark only from uncollectable pages. */
1416 GC_bool GC_stopped_mark GC_PROTO((GC_stop_func stop_func));
1417 /* Stop world and mark from all roots */
1419 void GC_clear_hdr_marks GC_PROTO((hdr * hhdr));
1420 /* Clear the mark bits in a header */
1421 void GC_set_hdr_marks GC_PROTO((hdr * hhdr));
1422 /* Set the mark bits in a header */
1423 void GC_set_fl_marks GC_PROTO((ptr_t p));
1424 /* Set all mark bits associated with */
1426 void GC_add_roots_inner GC_PROTO((char * b, char * e, GC_bool tmp));
1427 void GC_remove_roots_inner GC_PROTO((char * b, char * e));
1428 GC_bool GC_is_static_root GC_PROTO((ptr_t p));
1429 /* Is the address p in one of the registered static */
1430 /* root sections? */
1431 # if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
1432 GC_bool GC_is_tmp_root GC_PROTO((ptr_t p));
1433 /* Is the address p in one of the temporary static */
1434 /* root sections? */
1436 void GC_register_dynamic_libraries GC_PROTO((void));
1437 /* Add dynamic library data sections to the root set. */
1439 GC_bool GC_register_main_static_data GC_PROTO((void));
1440 /* We need to register the main data segment. Returns */
1441 /* TRUE unless this is done implicitly as part of */
1442 /* dynamic library registration. */
1444 /* Machine dependent startup routines */
1445 ptr_t GC_get_stack_base GC_PROTO((void)); /* Cold end of stack */
1447 ptr_t GC_get_register_stack_base GC_PROTO((void));
1448 /* Cold end of register stack. */
1450 void GC_register_data_segments GC_PROTO((void));
1452 /* Black listing: */
1453 void GC_bl_init GC_PROTO((void));
1454 # ifdef PRINT_BLACK_LIST
1455 void GC_add_to_black_list_normal GC_PROTO((word p, ptr_t source));
1456 /* Register bits as a possible future false */
1457 /* reference from the heap or static data */
1458 # define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1459 if (GC_all_interior_pointers) { \
1460 GC_add_to_black_list_stack(bits, (ptr_t)(source)); \
1462 GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
1465 void GC_add_to_black_list_normal GC_PROTO((word p));
1466 # define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1467 if (GC_all_interior_pointers) { \
1468 GC_add_to_black_list_stack(bits); \
1470 GC_add_to_black_list_normal(bits); \
1474 # ifdef PRINT_BLACK_LIST
1475 void GC_add_to_black_list_stack GC_PROTO((word p, ptr_t source));
1477 void GC_add_to_black_list_stack GC_PROTO((word p));
1479 struct hblk * GC_is_black_listed GC_PROTO((struct hblk * h, word len));
1480 /* If there are likely to be false references */
1481 /* to a block starting at h of the indicated */
1482 /* length, then return the next plausible */
1483 /* starting location for h that might avoid */
1484 /* these false references. */
1485 void GC_promote_black_lists GC_PROTO((void));
1486 /* Declare an end to a black listing phase. */
1487 void GC_unpromote_black_lists GC_PROTO((void));
1488 /* Approximately undo the effect of the above. */
1489 /* This actually loses some information, but */
1490 /* only in a reasonably safe way. */
1491 word GC_number_stack_black_listed GC_PROTO(( \
1492 struct hblk *start, struct hblk *endp1));
1493 /* Return the number of (stack) blacklisted */
1494 /* blocks in the range for statistical */
1497 ptr_t GC_scratch_alloc GC_PROTO((word bytes));
1498 /* GC internal memory allocation for */
1499 /* small objects. Deallocation is not */
1502 /* Heap block layout maps: */
1503 void GC_invalidate_map GC_PROTO((hdr * hhdr));
1504 /* Remove the object map associated */
1505 /* with the block. This identifies */
1506 /* the block as invalid to the mark */
1508 GC_bool GC_add_map_entry GC_PROTO((word sz));
1509 /* Add a heap block map for objects of */
1510 /* size sz to obj_map. */
1511 /* Return FALSE on failure. */
1512 void GC_register_displacement_inner GC_PROTO((word offset));
1513 /* Version of GC_register_displacement */
1514 /* that assumes lock is already held */
1515 /* and signals are already disabled. */
1517 /* hblk allocation: */
1518 void GC_new_hblk GC_PROTO((word size_in_words, int kind));
1519 /* Allocate a new heap block, and build */
1520 /* a free list in it. */
1522 ptr_t GC_build_fl GC_PROTO((struct hblk *h, word sz,
1523 GC_bool clear, ptr_t list));
1524 /* Build a free list for objects of */
1525 /* size sz in block h. Append list to */
1526 /* end of the free lists. Possibly */
1527 /* clear objects on the list. Normally */
1528 /* called by GC_new_hblk, but also */
1529 /* called explicitly without GC lock. */
1531 struct hblk * GC_allochblk GC_PROTO(( \
1532 word size_in_words, int kind, unsigned flags));
1533 /* Allocate a heap block, inform */
1534 /* the marker that block is valid */
1535 /* for objects of indicated size. */
1537 ptr_t GC_alloc_large GC_PROTO((word lw, int k, unsigned flags));
1538 /* Allocate a large block of size lw words. */
1539 /* The block is not cleared. */
1540 /* Flags is 0 or IGNORE_OFF_PAGE. */
1541 /* Calls GC_allchblk to do the actual */
1542 /* allocation, but also triggers GC and/or */
1543 /* heap expansion as appropriate. */
1544 /* Does not update GC_words_allocd, but does */
1545 /* other accounting. */
1547 ptr_t GC_alloc_large_and_clear GC_PROTO((word lw, int k, unsigned flags));
1548 /* As above, but clear block if appropriate */
1551 void GC_freehblk GC_PROTO((struct hblk * p));
1552 /* Deallocate a heap block and mark it */
1556 void GC_init_inner GC_PROTO((void));
1557 GC_bool GC_expand_hp_inner GC_PROTO((word n));
1558 void GC_start_reclaim GC_PROTO((int abort_if_found));
1559 /* Restore unmarked objects to free */
1560 /* lists, or (if abort_if_found is */
1561 /* TRUE) report them. */
1562 /* Sweeping of small object pages is */
1563 /* largely deferred. */
1564 void GC_continue_reclaim GC_PROTO((word sz, int kind));
1565 /* Sweep pages of the given size and */
1566 /* kind, as long as possible, and */
1567 /* as long as the corr. free list is */
1569 void GC_reclaim_or_delete_all GC_PROTO((void));
1570 /* Arrange for all reclaim lists to be */
1571 /* empty. Judiciously choose between */
1572 /* sweeping and discarding each page. */
1573 GC_bool GC_reclaim_all GC_PROTO((GC_stop_func stop_func, GC_bool ignore_old));
1574 /* Reclaim all blocks. Abort (in a */
1575 /* consistent state) if f returns TRUE. */
1576 GC_bool GC_block_empty GC_PROTO((hdr * hhdr));
1577 /* Block completely unmarked? */
1578 GC_bool GC_never_stop_func GC_PROTO((void));
1579 /* Returns FALSE. */
1580 GC_bool GC_try_to_collect_inner GC_PROTO((GC_stop_func f));
1582 /* Collect; caller must have acquired */
1583 /* lock and disabled signals. */
1584 /* Collection is aborted if f returns */
1585 /* TRUE. Returns TRUE if it completes */
1587 # define GC_gcollect_inner() \
1588 (void) GC_try_to_collect_inner(GC_never_stop_func)
1589 void GC_finish_collection GC_PROTO((void));
1590 /* Finish collection. Mark bits are */
1591 /* consistent and lock is still held. */
1592 GC_bool GC_collect_or_expand GC_PROTO(( \
1593 word needed_blocks, GC_bool ignore_off_page));
1594 /* Collect or expand heap in an attempt */
1595 /* make the indicated number of free */
1596 /* blocks available. Should be called */
1597 /* until the blocks are available or */
1598 /* until it fails by returning FALSE. */
1600 extern GC_bool GC_is_initialized; /* GC_init() has been run. */
1602 #if defined(MSWIN32) || defined(MSWINCE)
1603 void GC_deinit GC_PROTO((void));
1604 /* Free any resources allocated by */
1608 void GC_collect_a_little_inner GC_PROTO((int n));
1609 /* Do n units worth of garbage */
1610 /* collection work, if appropriate. */
1611 /* A unit is an amount appropriate for */
1612 /* HBLKSIZE bytes of allocation. */
1613 /* ptr_t GC_generic_malloc GC_PROTO((word lb, int k)); */
1614 /* Allocate an object of the given */
1615 /* kind. By default, there are only */
1616 /* a few kinds: composite(pointerfree), */
1617 /* atomic, uncollectable, etc. */
1618 /* We claim it's possible for clever */
1619 /* client code that understands GC */
1620 /* internals to add more, e.g. to */
1621 /* communicate object layout info */
1622 /* to the collector. */
1623 /* The actual decl is in gc_mark.h. */
1624 ptr_t GC_generic_malloc_ignore_off_page GC_PROTO((size_t b, int k));
1625 /* As above, but pointers past the */
1626 /* first page of the resulting object */
1628 ptr_t GC_generic_malloc_inner GC_PROTO((word lb, int k));
1629 /* Ditto, but I already hold lock, etc. */
1630 ptr_t GC_generic_malloc_words_small_inner GC_PROTO((word lw, int k));
1631 /* Analogous to the above, but assumes */
1632 /* a small object size, and bypasses */
1633 /* MERGE_SIZES mechanism. */
1634 ptr_t GC_generic_malloc_words_small GC_PROTO((size_t lw, int k));
1635 /* As above, but size in units of words */
1636 /* Bypasses MERGE_SIZES. Assumes */
1637 /* words <= MAXOBJSZ. */
1638 ptr_t GC_generic_malloc_inner_ignore_off_page GC_PROTO((size_t lb, int k));
1639 /* Allocate an object, where */
1640 /* the client guarantees that there */
1641 /* will always be a pointer to the */
1642 /* beginning of the object while the */
1643 /* object is live. */
1644 ptr_t GC_allocobj GC_PROTO((word sz, int kind));
1645 /* Make the indicated */
1646 /* free list nonempty, and return its */
1649 void GC_free_inner(GC_PTR p);
1651 void GC_init_headers GC_PROTO((void));
1652 struct hblkhdr * GC_install_header GC_PROTO((struct hblk *h));
1653 /* Install a header for block h. */
1654 /* Return 0 on failure, or the header */
1656 GC_bool GC_install_counts GC_PROTO((struct hblk * h, word sz));
1657 /* Set up forwarding counts for block */
1659 /* Return FALSE on failure. */
1660 void GC_remove_header GC_PROTO((struct hblk * h));
1661 /* Remove the header for block h. */
1662 void GC_remove_counts GC_PROTO((struct hblk * h, word sz));
1663 /* Remove forwarding counts for h. */
1664 hdr * GC_find_header GC_PROTO((ptr_t h)); /* Debugging only. */
1666 void GC_finalize GC_PROTO((void));
1667 /* Perform all indicated finalization actions */
1668 /* on unmarked objects. */
1669 /* Unreachable finalizable objects are enqueued */
1670 /* for processing by GC_invoke_finalizers. */
1671 /* Invoked with lock. */
1673 void GC_notify_or_invoke_finalizers GC_PROTO((void));
1674 /* If GC_finalize_on_demand is not set, invoke */
1675 /* eligible finalizers. Otherwise: */
1676 /* Call *GC_finalizer_notifier if there are */
1677 /* finalizers to be run, and we haven't called */
1678 /* this procedure yet this GC cycle. */
1680 GC_API GC_PTR GC_make_closure GC_PROTO((GC_finalization_proc fn, GC_PTR data));
1681 GC_API void GC_debug_invoke_finalizer GC_PROTO((GC_PTR obj, GC_PTR data));
1682 /* Auxiliary fns to make finalization work */
1683 /* correctly with displaced pointers introduced */
1684 /* by the debugging allocators. */
1686 void GC_add_to_heap GC_PROTO((struct hblk *p, word bytes));
1687 /* Add a HBLKSIZE aligned chunk to the heap. */
1689 void GC_print_obj GC_PROTO((ptr_t p));
1690 /* P points to somewhere inside an object with */
1691 /* debugging info. Print a human readable */
1692 /* description of the object to stderr. */
1693 extern void (*GC_check_heap) GC_PROTO((void));
1694 /* Check that all objects in the heap with */
1695 /* debugging info are intact. */
1696 /* Add any that are not to GC_smashed list. */
1697 extern void (*GC_print_all_smashed) GC_PROTO((void));
1698 /* Print GC_smashed if it's not empty. */
1699 /* Clear GC_smashed list. */
1700 extern void GC_print_all_errors GC_PROTO((void));
1701 /* Print smashed and leaked objects, if any. */
1702 /* Clear the lists of such objects. */
1703 extern void (*GC_print_heap_obj) GC_PROTO((ptr_t p));
1704 /* If possible print s followed by a more */
1705 /* detailed description of the object */
1706 /* referred to by p. */
1707 #if defined(LINUX) && defined(__ELF__) && !defined(SMALL_CONFIG)
1708 void GC_print_address_map GC_PROTO((void));
1709 /* Print an address map of the process. */
1712 extern GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
1713 /* Call error printing routine */
1715 extern GC_bool GC_print_stats; /* Produce at least some logging output */
1716 /* Set from environment variable. */
1718 #ifndef NO_DEBUGGING
1719 extern GC_bool GC_dump_regularly; /* Generate regular debugging dumps. */
1720 # define COND_DUMP if (GC_dump_regularly) GC_dump();
1725 #ifdef KEEP_BACK_PTRS
1726 extern long GC_backtraces;
1727 void GC_generate_random_backtrace_no_gc(void);
1730 extern GC_bool GC_print_back_height;
1732 #ifdef MAKE_BACK_GRAPH
1733 void GC_print_back_graph_stats(void);
1736 /* Macros used for collector internal allocation. */
1737 /* These assume the collector lock is held. */
1739 extern GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k);
1740 extern GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
1742 # define GC_INTERNAL_MALLOC GC_debug_generic_malloc_inner
1743 # define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
1744 GC_debug_generic_malloc_inner_ignore_off_page
1746 # define GC_INTERNAL_FREE GC_debug_free_inner
1748 # define GC_INTERNAL_FREE GC_debug_free
1751 # define GC_INTERNAL_MALLOC GC_generic_malloc_inner
1752 # define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
1753 GC_generic_malloc_inner_ignore_off_page
1755 # define GC_INTERNAL_FREE GC_free_inner
1757 # define GC_INTERNAL_FREE GC_free
1761 /* Memory unmapping: */
1763 void GC_unmap_old(void);
1764 void GC_merge_unmapped(void);
1765 void GC_unmap(ptr_t start, word bytes);
1766 void GC_remap(ptr_t start, word bytes);
1767 void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2);
1770 /* Virtual dirty bit implementation: */
1771 /* Each implementation exports the following: */
1772 void GC_read_dirty GC_PROTO((void));
1773 /* Retrieve dirty bits. */
1774 GC_bool GC_page_was_dirty GC_PROTO((struct hblk *h));
1775 /* Read retrieved dirty bits. */
1776 GC_bool GC_page_was_ever_dirty GC_PROTO((struct hblk *h));
1777 /* Could the page contain valid heap pointers? */
1778 void GC_is_fresh GC_PROTO((struct hblk *h, word n));
1779 /* Assert the region currently contains no */
1780 /* valid pointers. */
1781 void GC_remove_protection GC_PROTO((struct hblk *h, word nblocks,
1782 GC_bool pointerfree));
1783 /* h is about to be writteni or allocated. Ensure */
1784 /* that it's not write protected by the virtual */
1785 /* dirty bit implementation. */
1787 void GC_dirty_init GC_PROTO((void));
1789 /* Slow/general mark bit manipulation: */
1790 GC_API GC_bool GC_is_marked GC_PROTO((ptr_t p));
1791 void GC_clear_mark_bit GC_PROTO((ptr_t p));
1792 void GC_set_mark_bit GC_PROTO((ptr_t p));
1794 /* Stubborn objects: */
1795 void GC_read_changed GC_PROTO((void)); /* Analogous to GC_read_dirty */
1796 GC_bool GC_page_was_changed GC_PROTO((struct hblk * h));
1797 /* Analogous to GC_page_was_dirty */
1798 void GC_clean_changing_list GC_PROTO((void));
1799 /* Collect obsolete changing list entries */
1800 void GC_stubborn_init GC_PROTO((void));
1802 /* Debugging print routines: */
1803 void GC_print_block_list GC_PROTO((void));
1804 void GC_print_hblkfreelist GC_PROTO((void));
1805 void GC_print_heap_sects GC_PROTO((void));
1806 void GC_print_static_roots GC_PROTO((void));
1807 void GC_print_finalization_stats GC_PROTO((void));
1808 void GC_dump GC_PROTO((void));
1810 #ifdef KEEP_BACK_PTRS
1811 void GC_store_back_pointer(ptr_t source, ptr_t dest);
1812 void GC_marked_for_finalization(ptr_t dest);
1813 # define GC_STORE_BACK_PTR(source, dest) GC_store_back_pointer(source, dest)
1814 # define GC_MARKED_FOR_FINALIZATION(dest) GC_marked_for_finalization(dest)
1816 # define GC_STORE_BACK_PTR(source, dest)
1817 # define GC_MARKED_FOR_FINALIZATION(dest)
1820 /* Make arguments appear live to compiler */
1822 void GC_noop(void*, ...);
1825 GC_API void GC_noop(...);
1827 GC_API void GC_noop();
1831 void GC_noop1 GC_PROTO((word));
1833 /* Logging and diagnostic output: */
1834 GC_API void GC_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1835 /* A version of printf that doesn't allocate, */
1836 /* is restricted to long arguments, and */
1837 /* (unfortunately) doesn't use varargs for */
1838 /* portability. Restricted to 6 args and */
1839 /* 1K total output length. */
1840 /* (We use sprintf. Hopefully that doesn't */
1841 /* allocate for long arguments.) */
1842 # define GC_printf0(f) GC_printf(f, 0l, 0l, 0l, 0l, 0l, 0l)
1843 # define GC_printf1(f,a) GC_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1844 # define GC_printf2(f,a,b) GC_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1845 # define GC_printf3(f,a,b,c) GC_printf(f, (long)a, (long)b, (long)c, 0l, 0l, 0l)
1846 # define GC_printf4(f,a,b,c,d) GC_printf(f, (long)a, (long)b, (long)c, \
1848 # define GC_printf5(f,a,b,c,d,e) GC_printf(f, (long)a, (long)b, (long)c, \
1849 (long)d, (long)e, 0l)
1850 # define GC_printf6(f,a,b,c,d,e,g) GC_printf(f, (long)a, (long)b, (long)c, \
1851 (long)d, (long)e, (long)g)
1853 GC_API void GC_err_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1854 # define GC_err_printf0(f) GC_err_puts(f)
1855 # define GC_err_printf1(f,a) GC_err_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1856 # define GC_err_printf2(f,a,b) GC_err_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1857 # define GC_err_printf3(f,a,b,c) GC_err_printf(f, (long)a, (long)b, (long)c, \
1859 # define GC_err_printf4(f,a,b,c,d) GC_err_printf(f, (long)a, (long)b, \
1860 (long)c, (long)d, 0l, 0l)
1861 # define GC_err_printf5(f,a,b,c,d,e) GC_err_printf(f, (long)a, (long)b, \
1864 # define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
1867 /* Ditto, writes to stderr. */
1869 void GC_err_puts GC_PROTO((GC_CONST char *s));
1870 /* Write s to stderr, don't buffer, don't add */
1871 /* newlines, don't ... */
1873 #if defined(LINUX) && !defined(SMALL_CONFIG)
1874 void GC_err_write GC_PROTO((GC_CONST char *buf, size_t len));
1875 /* Write buf to stderr, don't buffer, don't add */
1876 /* newlines, don't ... */
1880 # ifdef GC_ASSERTIONS
1881 # define GC_ASSERT(expr) if(!(expr)) {\
1882 GC_err_printf2("Assertion failure: %s:%ld\n", \
1883 __FILE__, (unsigned long)__LINE__); \
1884 ABORT("assertion failure"); }
1886 # define GC_ASSERT(expr)
1889 /* Check a compile time assertion at compile time. The error */
1890 /* message for failure is a bit baroque, but ... */
1891 #if defined(mips) && !defined(__GNUC__)
1892 /* DOB: MIPSPro C gets an internal error taking the sizeof an array type.
1893 This code works correctly (ugliness is to avoid "unused var" warnings) */
1894 # define GC_STATIC_ASSERT(expr) do { if (0) { char j[(expr)? 1 : -1]; j[0]='\0'; j[0]=j[0]; } } while(0)
1896 # define GC_STATIC_ASSERT(expr) sizeof(char[(expr)? 1 : -1])
1899 # if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
1900 /* We need additional synchronization facilities from the thread */
1901 /* support. We believe these are less performance critical */
1902 /* than the main garbage collector lock; standard pthreads-based */
1903 /* implementations should be sufficient. */
1905 /* The mark lock and condition variable. If the GC lock is also */
1906 /* acquired, the GC lock must be acquired first. The mark lock is */
1907 /* used to both protect some variables used by the parallel */
1908 /* marker, and to protect GC_fl_builder_count, below. */
1909 /* GC_notify_all_marker() is called when */
1910 /* the state of the parallel marker changes */
1911 /* in some significant way (see gc_mark.h for details). The */
1912 /* latter set of events includes incrementing GC_mark_no. */
1913 /* GC_notify_all_builder() is called when GC_fl_builder_count */
1916 extern void GC_acquire_mark_lock();
1917 extern void GC_release_mark_lock();
1918 extern void GC_notify_all_builder();
1919 /* extern void GC_wait_builder(); */
1920 extern void GC_wait_for_reclaim();
1922 extern word GC_fl_builder_count; /* Protected by mark lock. */
1923 # endif /* PARALLEL_MARK || THREAD_LOCAL_ALLOC */
1924 # ifdef PARALLEL_MARK
1925 extern void GC_notify_all_marker();
1926 extern void GC_wait_marker();
1927 extern word GC_mark_no; /* Protected by mark lock. */
1929 extern void GC_help_marker(word my_mark_no);
1930 /* Try to help out parallel marker for mark cycle */
1931 /* my_mark_no. Returns if the mark cycle finishes or */
1932 /* was already done, or there was nothing to do for */
1933 /* some other reason. */
1934 # endif /* PARALLEL_MARK */
1936 # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
1937 /* We define the thread suspension signal here, so that we can refer */
1938 /* to it in the dirty bit implementation, if necessary. Ideally we */
1939 /* would allocate a (real-time ?) signal using the standard mechanism.*/
1940 /* unfortunately, there is no standard mechanism. (There is one */
1941 /* in Linux glibc, but it's not exported.) Thus we continue to use */
1942 /* the same hard-coded signals we've always used. */
1943 # if !defined(SIG_SUSPEND)
1944 # if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS)
1945 # if defined(SPARC) && !defined(SIGPWR)
1946 /* SPARC/Linux doesn't properly define SIGPWR in <signal.h>.
1947 * It is aliased to SIGLOST in asm/signal.h, though. */
1948 # define SIG_SUSPEND SIGLOST
1950 /* Linuxthreads itself uses SIGUSR1 and SIGUSR2. */
1951 # define SIG_SUSPEND SIGPWR
1953 # else /* !GC_LINUX_THREADS */
1954 # if defined(_SIGRTMIN)
1955 # define SIG_SUSPEND _SIGRTMIN + 6
1957 # define SIG_SUSPEND SIGRTMIN + 6
1960 # endif /* !SIG_SUSPEND */
1964 # endif /* GC_PRIVATE_H */