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
472 # if defined(POWERPC)
473 # if CPP_WORDSZ == 32
474 # define GC_THREAD_STATE_T ppc_thread_state_t
475 # define GC_MACH_HEADER mach_header
476 # define GC_MACH_SECTION section
478 # define GC_THREAD_STATE_T ppc_thread_state64_t
479 # define GC_MACH_HEADER mach_header_64
480 # define GC_MACH_SECTION section_64
482 # define GC_MACH_THREAD_STATE PPC_THREAD_STATE
483 # define GC_MACH_THREAD_STATE_COUNT PPC_THREAD_STATE_COUNT
484 # elif defined(I386) || defined(X86_64)
485 # if CPP_WORDSZ == 32
486 # define GC_THREAD_STATE_T x86_thread_state32_t
487 # define GC_MACH_THREAD_STATE x86_THREAD_STATE32
488 # define GC_MACH_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
489 # define GC_MACH_HEADER mach_header
490 # define GC_MACH_SECTION section
492 # define GC_THREAD_STATE_T x86_thread_state64_t
493 # define GC_MACH_THREAD_STATE x86_THREAD_STATE64
494 # define GC_MACH_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
495 # define GC_MACH_HEADER mach_header_64
496 # define GC_MACH_SECTION section_64
499 # error define GC_THREAD_STATE_T
500 # define GC_MACH_THREAD_STATE MACHINE_THREAD_STATE
501 # define GC_MACH_THREAD_STATE_COUNT MACHINE_THREAD_STATE_COUNT
504 /*********************************/
506 /* Word-size-dependent defines */
508 /*********************************/
511 # define WORDS_TO_BYTES(x) ((x)<<2)
512 # define BYTES_TO_WORDS(x) ((x)>>2)
513 # define LOGWL ((word)5) /* log[2] of CPP_WORDSZ */
514 # define modWORDSZ(n) ((n) & 0x1f) /* n mod size of word */
521 # define WORDS_TO_BYTES(x) ((x)<<3)
522 # define BYTES_TO_WORDS(x) ((x)>>3)
523 # define LOGWL ((word)6) /* log[2] of CPP_WORDSZ */
524 # define modWORDSZ(n) ((n) & 0x3f) /* n mod size of word */
530 #define WORDSZ ((word)CPP_WORDSZ)
531 #define SIGNB ((word)1 << (WORDSZ-1))
532 #define BYTES_PER_WORD ((word)(sizeof (word)))
533 #define ONES ((word)(signed_word)(-1))
534 #define divWORDSZ(n) ((n) >> LOGWL) /* divide n by size of word */
536 /*********************/
538 /* Size Parameters */
540 /*********************/
542 /* heap block size, bytes. Should be power of 2 */
546 # define CPP_LOG_HBLKSIZE 10
548 # if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
549 /* HPUX/PA seems to use 4K pages with the 64 bit ABI */
550 # define CPP_LOG_HBLKSIZE 12
552 # define CPP_LOG_HBLKSIZE 13
557 # define CPP_LOG_HBLKSIZE 9
559 # if HBLKSIZE == 1024
560 # define CPP_LOG_HBLKSIZE 10
562 # if HBLKSIZE == 2048
563 # define CPP_LOG_HBLKSIZE 11
565 # if HBLKSIZE == 4096
566 # define CPP_LOG_HBLKSIZE 12
568 # if HBLKSIZE == 8192
569 # define CPP_LOG_HBLKSIZE 13
571 # if HBLKSIZE == 16384
572 # define CPP_LOG_HBLKSIZE 14
574 # ifndef CPP_LOG_HBLKSIZE
579 # define CPP_HBLKSIZE (1 << CPP_LOG_HBLKSIZE)
580 # define LOG_HBLKSIZE ((word)CPP_LOG_HBLKSIZE)
581 # define HBLKSIZE ((word)CPP_HBLKSIZE)
584 /* max size objects supported by freelist (larger objects may be */
585 /* allocated, but less efficiently) */
587 #define CPP_MAXOBJBYTES (CPP_HBLKSIZE/2)
588 #define MAXOBJBYTES ((word)CPP_MAXOBJBYTES)
589 #define CPP_MAXOBJSZ BYTES_TO_WORDS(CPP_MAXOBJBYTES)
590 #define MAXOBJSZ ((word)CPP_MAXOBJSZ)
592 # define divHBLKSZ(n) ((n) >> LOG_HBLKSIZE)
594 # define HBLK_PTR_DIFF(p,q) divHBLKSZ((ptr_t)p - (ptr_t)q)
595 /* Equivalent to subtracting 2 hblk pointers. */
596 /* We do it this way because a compiler should */
597 /* find it hard to use an integer division */
598 /* instead of a shift. The bundled SunOS 4.1 */
599 /* o.w. sometimes pessimizes the subtraction to */
600 /* involve a call to .div. */
602 # define modHBLKSZ(n) ((n) & (HBLKSIZE-1))
604 # define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
606 # define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
608 /* Round up byte allocation requests to integral number of words, etc. */
609 # define ROUNDED_UP_WORDS(n) \
610 BYTES_TO_WORDS((n) + (WORDS_TO_BYTES(1) - 1 + EXTRA_BYTES))
612 # define ALIGNED_WORDS(n) \
613 (BYTES_TO_WORDS((n) + WORDS_TO_BYTES(2) - 1 + EXTRA_BYTES) & ~1)
615 # define ALIGNED_WORDS(n) ROUNDED_UP_WORDS(n)
617 # define SMALL_OBJ(bytes) ((bytes) <= (MAXOBJBYTES - EXTRA_BYTES))
618 # define ADD_SLOP(bytes) ((bytes) + EXTRA_BYTES)
620 /* MIN_WORDS is the size of the smallest allocated object. */
621 /* 1 and 2 are the only valid values. */
622 /* 2 must be used if: */
623 /* - GC_gcj_malloc can be used for objects of requested */
624 /* size smaller than 2 words, or */
625 /* - USE_MARK_BYTES is defined. */
626 # if defined(USE_MARK_BYTES) || defined(GC_GCJ_SUPPORT)
627 # define MIN_WORDS 2 /* Smallest allocated object. */
635 * Hash table representation of sets of pages. This assumes it is
636 * OK to add spurious entries to sets.
637 * Used by black-listing code, and perhaps by dirty bit maintenance code.
641 # define LOG_PHT_ENTRIES 20 /* Collisions likely at 1M blocks, */
642 /* which is >= 4GB. Each table takes */
643 /* 128KB, some of which may never be */
647 # define LOG_PHT_ENTRIES 14 /* Collisions are likely if heap grows */
648 /* to more than 16K hblks = 64MB. */
649 /* Each hash table occupies 2K bytes. */
650 # else /* default "medium" configuration */
651 # define LOG_PHT_ENTRIES 16 /* Collisions are likely if heap grows */
652 /* to more than 64K hblks >= 256MB. */
653 /* Each hash table occupies 8K bytes. */
654 /* Even for somewhat smaller heaps, */
655 /* say half that, collisions may be an */
656 /* issue because we blacklist */
657 /* addresses outside the heap. */
660 # define PHT_ENTRIES ((word)1 << LOG_PHT_ENTRIES)
661 # define PHT_SIZE (PHT_ENTRIES >> LOGWL)
662 typedef word page_hash_table[PHT_SIZE];
664 # define PHT_HASH(addr) ((((word)(addr)) >> LOG_HBLKSIZE) & (PHT_ENTRIES - 1))
666 # define get_pht_entry_from_index(bl, index) \
667 (((bl)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
668 # define set_pht_entry_from_index(bl, index) \
669 (bl)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
670 # define clear_pht_entry_from_index(bl, index) \
671 (bl)[divWORDSZ(index)] &= ~((word)1 << modWORDSZ(index))
672 /* And a dumb but thread-safe version of set_pht_entry_from_index. */
673 /* This sets (many) extra bits. */
674 # define set_pht_entry_from_index_safe(bl, index) \
675 (bl)[divWORDSZ(index)] = ONES
679 /********************************************/
681 /* H e a p B l o c k s */
683 /********************************************/
685 /* heap block header */
686 #define HBLKMASK (HBLKSIZE-1)
688 #define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
690 #define MARK_BITS_PER_HBLK (BITS_PER_HBLK/CPP_WORDSZ)
692 /* We allocate 1 bit/word, unless USE_MARK_BYTES */
693 /* is defined. Only the first word */
694 /* in each object is actually marked. */
696 # ifdef USE_MARK_BYTES
697 # define MARK_BITS_SZ (MARK_BITS_PER_HBLK/2)
698 /* Unlike the other case, this is in units of bytes. */
699 /* We actually allocate only every second mark bit, since we */
700 /* force all objects to be doubleword aligned. */
701 /* However, each mark bit is allocated as a byte. */
703 # define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
706 /* We maintain layout maps for heap blocks containing objects of a given */
707 /* size. Each entry in this map describes a byte offset and has the */
708 /* following type. */
709 typedef unsigned char map_entry_type;
712 word hb_sz; /* If in use, size in words, of objects in the block. */
713 /* if free, the size in bytes of the whole block */
714 struct hblk * hb_next; /* Link field for hblk free list */
715 /* and for lists of chunks waiting to be */
717 struct hblk * hb_prev; /* Backwards link for free list. */
718 word hb_descr; /* object descriptor for marking. See */
720 map_entry_type * hb_map;
721 /* A pointer to a pointer validity map of the block. */
722 /* See GC_obj_map. */
723 /* Valid for all blocks with headers. */
724 /* Free blocks point to GC_invalid_map. */
725 unsigned char hb_obj_kind;
726 /* Kind of objects in the block. Each kind */
727 /* identifies a mark procedure and a set of */
728 /* list headers. Sometimes called regions. */
729 unsigned char hb_flags;
730 # define IGNORE_OFF_PAGE 1 /* Ignore pointers that do not */
731 /* point to the first page of */
733 # define WAS_UNMAPPED 2 /* This is a free block, which has */
734 /* been unmapped from the address */
736 /* GC_remap must be invoked on it */
737 /* before it can be reallocated. */
738 /* Only set with USE_MUNMAP. */
739 unsigned short hb_last_reclaimed;
740 /* Value of GC_gc_no when block was */
741 /* last allocated or swept. May wrap. */
742 /* For a free block, this is maintained */
743 /* only for USE_MUNMAP, and indicates */
744 /* when the header was allocated, or */
745 /* when the size of the block last */
747 # ifdef USE_MARK_BYTES
749 char _hb_marks[MARK_BITS_SZ];
750 /* The i'th byte is 1 if the object */
751 /* starting at word 2i is marked, 0 o.w. */
752 word dummy; /* Force word alignment of mark bytes. */
754 # define hb_marks _mark_byte_union._hb_marks
756 word hb_marks[MARK_BITS_SZ];
757 /* Bit i in the array refers to the */
758 /* object starting at the ith word (header */
759 /* INCLUDED) in the heap block. */
760 /* The lsb of word 0 is numbered 0. */
761 /* Unused bits are invalid, and are */
762 /* occasionally set, e.g for uncollectable */
764 # endif /* !USE_MARK_BYTES */
767 /* heap block body */
769 # define BODY_SZ (HBLKSIZE/sizeof(word))
772 word hb_body[BODY_SZ];
775 # define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
777 # define OBJ_SZ_TO_BLOCKS(sz) \
778 divHBLKSZ(WORDS_TO_BYTES(sz) + HBLKSIZE-1)
779 /* Size of block (in units of HBLKSIZE) needed to hold objects of */
780 /* given sz (in words). */
782 /* Object free list link */
783 # define obj_link(p) (*(ptr_t *)(p))
785 # define LOG_MAX_MARK_PROCS 6
786 # define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
788 /* Root sets. Logically private to mark_rts.c. But we don't want the */
789 /* tables scanned, so we put them here. */
790 /* MAX_ROOT_SETS is the maximum number of ranges that can be */
791 /* registered as static roots. */
793 # define MAX_ROOT_SETS 4096
795 /* GCJ LOCAL: MAX_ROOT_SETS increased to permit more shared */
796 /* libraries to be loaded. */
797 # define MAX_ROOT_SETS 1024
800 # define MAX_EXCLUSIONS (MAX_ROOT_SETS/4)
801 /* Maximum number of segments that can be excluded from root sets. */
804 * Data structure for excluded static roots.
811 /* Data structure for list of root sets. */
812 /* We keep a hash table, so that we can filter out duplicate additions. */
813 /* Under Win32, we need to do a better job of filtering overlaps, so */
814 /* we resort to sequential search, and pay the price. */
818 # if !defined(MSWIN32) && !defined(MSWINCE)
819 struct roots * r_next;
822 /* Delete before registering new dynamic libraries */
825 #if !defined(MSWIN32) && !defined(MSWINCE)
826 /* Size of hash table index to roots. */
827 # define LOG_RT_SIZE 6
828 # define RT_SIZE (1 << LOG_RT_SIZE) /* Power of 2, may be != MAX_ROOT_SETS */
831 /* Lists of all heap blocks and free lists */
832 /* as well as other random data structures */
833 /* that should not be scanned by the */
835 /* These are grouped together in a struct */
836 /* so that they can be easily skipped by the */
837 /* GC_mark routine. */
838 /* The ordering is weird to make GC_malloc */
839 /* faster by keeping the important fields */
840 /* sufficiently close together that a */
841 /* single load of a base register will do. */
842 /* Scalars that could easily appear to */
843 /* be pointers are also put here. */
844 /* The main fields should precede any */
845 /* conditionally included fields, so that */
846 /* gc_inl.h will work even if a different set */
847 /* of macros is defined when the client is */
853 word _requested_heapsize; /* Heap size due to explicit expansion */
854 ptr_t _last_heap_addr;
855 ptr_t _prev_heap_addr;
856 word _large_free_bytes;
857 /* Total bytes contained in blocks on large object free */
859 word _large_allocd_bytes;
860 /* Total number of bytes in allocated large objects blocks. */
861 /* For the purposes of this counter and the next one only, a */
862 /* large object is one that occupies a block of at least */
864 word _max_large_allocd_bytes;
865 /* Maximum number of bytes that were ever allocated in */
866 /* large object blocks. This is used to help decide when it */
867 /* is safe to split up a large block. */
868 word _words_allocd_before_gc;
869 /* Number of words allocated before this */
870 /* collection cycle. */
871 # ifndef SEPARATE_GLOBALS
873 /* Number of words allocated during this collection cycle */
876 /* Number of words wasted due to internal fragmentation */
877 /* in large objects, or due to dropping blacklisted */
878 /* blocks, since last gc. Approximate. */
879 word _words_finalized;
880 /* Approximate number of words in objects (and headers) */
881 /* That became ready for finalization in the last */
883 word _non_gc_bytes_at_gc;
884 /* Number of explicitly managed bytes of storage */
885 /* at last collection. */
887 /* Number of explicitly deallocated words of memory */
888 /* since last collection. */
889 word _finalizer_mem_freed;
890 /* Words of memory explicitly deallocated while */
891 /* finalizers were running. Used to approximate mem. */
892 /* explicitly deallocated by finalizers. */
893 ptr_t _scratch_end_ptr;
894 ptr_t _scratch_last_end_ptr;
895 /* Used by headers.c, and can easily appear to point to */
897 GC_mark_proc _mark_procs[MAX_MARK_PROCS];
898 /* Table of user-defined mark procedures. There is */
899 /* a small number of these, which can be referenced */
900 /* by DS_PROC mark descriptors. See gc_mark.h. */
902 # ifndef SEPARATE_GLOBALS
903 ptr_t _objfreelist[MAXOBJSZ+1];
904 /* free list for objects */
905 ptr_t _aobjfreelist[MAXOBJSZ+1];
906 /* free list for atomic objs */
909 ptr_t _uobjfreelist[MAXOBJSZ+1];
910 /* uncollectable but traced objs */
911 /* objects on this and auobjfreelist */
912 /* are always marked, except during */
913 /* garbage collections. */
914 # ifdef ATOMIC_UNCOLLECTABLE
915 ptr_t _auobjfreelist[MAXOBJSZ+1];
917 /* uncollectable but traced objs */
920 word _composite_in_use;
921 /* Number of words in accessible composite */
924 /* Number of words in accessible atomic */
928 word _unmapped_bytes;
931 unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
932 /* Number of words to allocate for a given allocation request in */
936 # ifdef STUBBORN_ALLOC
937 ptr_t _sobjfreelist[MAXOBJSZ+1];
939 /* free list for immutable objects */
940 map_entry_type * _obj_map[MAXOBJSZ+1];
941 /* If not NIL, then a pointer to a map of valid */
942 /* object addresses. _obj_map[sz][i] is j if the */
943 /* address block_start+i is a valid pointer */
944 /* to an object at block_start + */
945 /* WORDS_TO_BYTES(BYTES_TO_WORDS(i) - j) */
946 /* I.e. j is a word displacement from the */
947 /* object beginning. */
948 /* The entry is OBJ_INVALID if the corresponding */
949 /* address is not a valid pointer. It is */
950 /* OFFSET_TOO_BIG if the value j would be too */
951 /* large to fit in the entry. (Note that the */
952 /* size of these entries matters, both for */
953 /* space consumption and for cache utilization.) */
954 # define OFFSET_TOO_BIG 0xfe
955 # define OBJ_INVALID 0xff
956 # define MAP_ENTRY(map, bytes) (map)[bytes]
957 # define MAP_ENTRIES HBLKSIZE
958 # define MAP_SIZE MAP_ENTRIES
959 # define CPP_MAX_OFFSET (OFFSET_TOO_BIG - 1)
960 # define MAX_OFFSET ((word)CPP_MAX_OFFSET)
961 /* The following are used only if GC_all_interior_ptrs != 0 */
962 # define VALID_OFFSET_SZ \
963 (CPP_MAX_OFFSET > WORDS_TO_BYTES(CPP_MAXOBJSZ)? \
965 : WORDS_TO_BYTES(CPP_MAXOBJSZ)+1)
966 char _valid_offsets[VALID_OFFSET_SZ];
967 /* GC_valid_offsets[i] == TRUE ==> i */
968 /* is registered as a displacement. */
969 char _modws_valid_offsets[sizeof(word)];
970 /* GC_valid_offsets[i] ==> */
971 /* GC_modws_valid_offsets[i%sizeof(word)] */
972 # define OFFSET_VALID(displ) \
973 (GC_all_interior_pointers || GC_valid_offsets[displ])
974 # ifdef STUBBORN_ALLOC
975 page_hash_table _changed_pages;
976 /* Stubborn object pages that were changes since last call to */
977 /* GC_read_changed. */
978 page_hash_table _prev_changed_pages;
979 /* Stubborn object pages that were changes before last call to */
980 /* GC_read_changed. */
982 # if defined(PROC_VDB) || defined(MPROTECT_VDB)
983 page_hash_table _grungy_pages; /* Pages that were dirty at last */
987 VOLATILE page_hash_table _dirty_pages;
988 /* Pages dirtied since last GC_read_dirty. */
991 page_hash_table _written_pages; /* Pages ever dirtied */
995 # define MAX_HEAP_SECTS 4096 /* overflows at roughly 64 GB */
997 # define MAX_HEAP_SECTS 768 /* Separately added heap sections. */
1000 # ifdef SMALL_CONFIG
1001 # define MAX_HEAP_SECTS 128 /* Roughly 256MB (128*2048*1K) */
1003 # define MAX_HEAP_SECTS 384 /* Roughly 3GB */
1007 ptr_t hs_start; word hs_bytes;
1008 } _heap_sects[MAX_HEAP_SECTS];
1009 # if defined(MSWIN32) || defined(MSWINCE)
1010 ptr_t _heap_bases[MAX_HEAP_SECTS];
1011 /* Start address of memory regions obtained from kernel. */
1014 word _heap_lengths[MAX_HEAP_SECTS];
1015 /* Commited lengths of memory regions obtained from kernel. */
1017 struct roots _static_roots[MAX_ROOT_SETS];
1018 # if !defined(MSWIN32) && !defined(MSWINCE)
1019 struct roots * _root_index[RT_SIZE];
1021 struct exclusion _excl_table[MAX_EXCLUSIONS];
1022 /* Block header index; see gc_headers.h */
1023 bottom_index * _all_nils;
1024 bottom_index * _top_index [TOP_SZ];
1025 #ifdef SAVE_CALL_CHAIN
1026 struct callinfo _last_stack[NFRAMES]; /* Stack at last garbage collection.*/
1027 /* Useful for debugging mysterious */
1028 /* object disappearances. */
1029 /* In the multithreaded case, we */
1030 /* currently only save the calling */
1035 GC_API GC_FAR struct _GC_arrays GC_arrays;
1037 # ifndef SEPARATE_GLOBALS
1038 # define GC_objfreelist GC_arrays._objfreelist
1039 # define GC_aobjfreelist GC_arrays._aobjfreelist
1040 # define GC_words_allocd GC_arrays._words_allocd
1042 # define GC_uobjfreelist GC_arrays._uobjfreelist
1043 # ifdef ATOMIC_UNCOLLECTABLE
1044 # define GC_auobjfreelist GC_arrays._auobjfreelist
1046 # define GC_sobjfreelist GC_arrays._sobjfreelist
1047 # define GC_valid_offsets GC_arrays._valid_offsets
1048 # define GC_modws_valid_offsets GC_arrays._modws_valid_offsets
1049 # ifdef STUBBORN_ALLOC
1050 # define GC_changed_pages GC_arrays._changed_pages
1051 # define GC_prev_changed_pages GC_arrays._prev_changed_pages
1053 # define GC_obj_map GC_arrays._obj_map
1054 # define GC_last_heap_addr GC_arrays._last_heap_addr
1055 # define GC_prev_heap_addr GC_arrays._prev_heap_addr
1056 # define GC_words_wasted GC_arrays._words_wasted
1057 # define GC_large_free_bytes GC_arrays._large_free_bytes
1058 # define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
1059 # define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes
1060 # define GC_words_finalized GC_arrays._words_finalized
1061 # define GC_non_gc_bytes_at_gc GC_arrays._non_gc_bytes_at_gc
1062 # define GC_mem_freed GC_arrays._mem_freed
1063 # define GC_finalizer_mem_freed GC_arrays._finalizer_mem_freed
1064 # define GC_scratch_end_ptr GC_arrays._scratch_end_ptr
1065 # define GC_scratch_last_end_ptr GC_arrays._scratch_last_end_ptr
1066 # define GC_mark_procs GC_arrays._mark_procs
1067 # define GC_heapsize GC_arrays._heapsize
1068 # define GC_max_heapsize GC_arrays._max_heapsize
1069 # define GC_requested_heapsize GC_arrays._requested_heapsize
1070 # define GC_words_allocd_before_gc GC_arrays._words_allocd_before_gc
1071 # define GC_heap_sects GC_arrays._heap_sects
1072 # define GC_last_stack GC_arrays._last_stack
1074 # define GC_unmapped_bytes GC_arrays._unmapped_bytes
1076 # if defined(MSWIN32) || defined(MSWINCE)
1077 # define GC_heap_bases GC_arrays._heap_bases
1080 # define GC_heap_lengths GC_arrays._heap_lengths
1082 # define GC_static_roots GC_arrays._static_roots
1083 # define GC_root_index GC_arrays._root_index
1084 # define GC_excl_table GC_arrays._excl_table
1085 # define GC_all_nils GC_arrays._all_nils
1086 # define GC_top_index GC_arrays._top_index
1087 # if defined(PROC_VDB) || defined(MPROTECT_VDB)
1088 # define GC_grungy_pages GC_arrays._grungy_pages
1090 # ifdef MPROTECT_VDB
1091 # define GC_dirty_pages GC_arrays._dirty_pages
1094 # define GC_written_pages GC_arrays._written_pages
1097 # define GC_composite_in_use GC_arrays._composite_in_use
1098 # define GC_atomic_in_use GC_arrays._atomic_in_use
1101 # define GC_size_map GC_arrays._size_map
1104 # define beginGC_arrays ((ptr_t)(&GC_arrays))
1105 # define endGC_arrays (((ptr_t)(&GC_arrays)) + (sizeof GC_arrays))
1107 #define USED_HEAP_SIZE (GC_heapsize - GC_large_free_bytes)
1110 # define MAXOBJKINDS 16
1112 extern struct obj_kind {
1113 ptr_t *ok_freelist; /* Array of free listheaders for this kind of object */
1114 /* Point either to GC_arrays or to storage allocated */
1115 /* with GC_scratch_alloc. */
1116 struct hblk **ok_reclaim_list;
1117 /* List headers for lists of blocks waiting to be */
1119 word ok_descriptor; /* Descriptor template for objects in this */
1121 GC_bool ok_relocate_descr;
1122 /* Add object size in bytes to descriptor */
1123 /* template to obtain descriptor. Otherwise */
1124 /* template is used as is. */
1125 GC_bool ok_init; /* Clear objects before putting them on the free list. */
1126 } GC_obj_kinds[MAXOBJKINDS];
1128 # define beginGC_obj_kinds ((ptr_t)(&GC_obj_kinds))
1129 # define endGC_obj_kinds (beginGC_obj_kinds + (sizeof GC_obj_kinds))
1131 /* Variables that used to be in GC_arrays, but need to be accessed by */
1132 /* inline allocation code. If they were in GC_arrays, the inlined */
1133 /* allocation code would include GC_arrays offsets (as it did), which */
1134 /* introduce maintenance problems. */
1136 #ifdef SEPARATE_GLOBALS
1137 word GC_words_allocd;
1138 /* Number of words allocated during this collection cycle */
1139 ptr_t GC_objfreelist[MAXOBJSZ+1];
1140 /* free list for NORMAL objects */
1141 # define beginGC_objfreelist ((ptr_t)(&GC_objfreelist))
1142 # define endGC_objfreelist (beginGC_objfreelist + sizeof(GC_objfreelist))
1144 ptr_t GC_aobjfreelist[MAXOBJSZ+1];
1145 /* free list for atomic (PTRFREE) objs */
1146 # define beginGC_aobjfreelist ((ptr_t)(&GC_aobjfreelist))
1147 # define endGC_aobjfreelist (beginGC_aobjfreelist + sizeof(GC_aobjfreelist))
1150 /* Predefined kinds: */
1153 # define UNCOLLECTABLE 2
1154 # ifdef ATOMIC_UNCOLLECTABLE
1155 # define AUNCOLLECTABLE 3
1157 # define IS_UNCOLLECTABLE(k) (((k) & ~1) == UNCOLLECTABLE)
1160 # define IS_UNCOLLECTABLE(k) ((k) == UNCOLLECTABLE)
1163 extern int GC_n_kinds;
1165 GC_API word GC_fo_entries;
1167 extern word GC_n_heap_sects; /* Number of separately added heap */
1170 extern word GC_page_size;
1172 # if defined(MSWIN32) || defined(MSWINCE)
1173 struct _SYSTEM_INFO;
1174 extern struct _SYSTEM_INFO GC_sysinfo;
1175 extern word GC_n_heap_bases; /* See GC_heap_bases. */
1178 extern word GC_total_stack_black_listed;
1179 /* Number of bytes on stack blacklist. */
1181 extern word GC_black_list_spacing;
1182 /* Average number of bytes between blacklisted */
1183 /* blocks. Approximate. */
1184 /* Counts only blocks that are */
1185 /* "stack-blacklisted", i.e. that are */
1186 /* problematic in the interior of an object. */
1188 extern map_entry_type * GC_invalid_map;
1189 /* Pointer to the nowhere valid hblk map */
1190 /* Blocks pointing to this map are free. */
1192 extern struct hblk * GC_hblkfreelist[];
1193 /* List of completely empty heap blocks */
1194 /* Linked through hb_next field of */
1195 /* header structure associated with */
1198 extern GC_bool GC_objects_are_marked; /* There are marked objects in */
1201 #ifndef SMALL_CONFIG
1202 extern GC_bool GC_incremental;
1203 /* Using incremental/generational collection. */
1204 # define TRUE_INCREMENTAL \
1205 (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED)
1206 /* True incremental, not just generational, mode */
1208 # define GC_incremental FALSE
1209 /* Hopefully allow optimizer to remove some code. */
1210 # define TRUE_INCREMENTAL FALSE
1213 extern GC_bool GC_dirty_maintained;
1214 /* Dirty bits are being maintained, */
1215 /* either for incremental collection, */
1216 /* or to limit the root set. */
1218 extern word GC_root_size; /* Total size of registered root sections */
1220 extern GC_bool GC_debugging_started; /* GC_debug_malloc has been called. */
1222 extern long GC_large_alloc_warn_interval;
1223 /* Interval between unsuppressed warnings. */
1225 extern long GC_large_alloc_warn_suppressed;
1226 /* Number of warnings suppressed so far. */
1229 extern GC_bool GC_world_stopped;
1234 # define abs(x) ((x) < 0? (-(x)) : (x))
1238 /* Marks are in a reserved area in */
1239 /* each heap block. Each word has one mark bit associated */
1240 /* with it. Only those corresponding to the beginning of an */
1241 /* object are used. */
1243 /* Set mark bit correctly, even if mark bits may be concurrently */
1245 #ifdef PARALLEL_MARK
1246 # define OR_WORD(addr, bits) \
1249 old = *((volatile word *)addr); \
1250 } while (!GC_compare_and_exchange((addr), old, old | (bits))); \
1252 # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1254 word my_bits = (bits); \
1256 old = *((volatile word *)addr); \
1257 if (old & my_bits) goto exit_label; \
1258 } while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
1261 # define OR_WORD(addr, bits) *(addr) |= (bits)
1262 # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1264 word old = *(addr); \
1265 word my_bits = (bits); \
1266 if (old & my_bits) goto exit_label; \
1267 *(addr) = (old | my_bits); \
1271 /* Mark bit operations */
1274 * Retrieve, set, clear the mark bit corresponding
1275 * to the nth word in a given heap block.
1277 * (Recall that bit n corresponds to object beginning at word n
1278 * relative to the beginning of the block, including unused words)
1281 #ifdef USE_MARK_BYTES
1282 # define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n) >> 1])
1283 # define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 1
1284 # define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 0
1285 #else /* !USE_MARK_BYTES */
1286 # define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
1287 >> (modWORDSZ(n))) & (word)1)
1288 # define set_mark_bit_from_hdr(hhdr,n) \
1289 OR_WORD((hhdr)->hb_marks+divWORDSZ(n), \
1290 (word)1 << modWORDSZ(n))
1291 # define clear_mark_bit_from_hdr(hhdr,n) (hhdr)->hb_marks[divWORDSZ(n)] \
1292 &= ~((word)1 << modWORDSZ(n))
1293 #endif /* !USE_MARK_BYTES */
1295 /* Important internal collector routines */
1297 ptr_t GC_approx_sp GC_PROTO((void));
1299 GC_bool GC_should_collect GC_PROTO((void));
1301 void GC_apply_to_all_blocks GC_PROTO(( \
1302 void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
1304 /* Invoke fn(hbp, client_data) for each */
1305 /* allocated heap block. */
1306 struct hblk * GC_next_used_block GC_PROTO((struct hblk * h));
1307 /* Return first in-use block >= h */
1308 struct hblk * GC_prev_block GC_PROTO((struct hblk * h));
1309 /* Return last block <= h. Returned block */
1310 /* is managed by GC, but may or may not be in */
1312 void GC_mark_init GC_PROTO((void));
1313 void GC_clear_marks GC_PROTO((void)); /* Clear mark bits for all heap objects. */
1314 void GC_invalidate_mark_state GC_PROTO((void));
1315 /* Tell the marker that marked */
1316 /* objects may point to unmarked */
1317 /* ones, and roots may point to */
1318 /* unmarked objects. */
1319 /* Reset mark stack. */
1320 GC_bool GC_mark_stack_empty GC_PROTO((void));
1321 GC_bool GC_mark_some GC_PROTO((ptr_t cold_gc_frame));
1322 /* Perform about one pages worth of marking */
1323 /* work of whatever kind is needed. Returns */
1324 /* quickly if no collection is in progress. */
1325 /* Return TRUE if mark phase finished. */
1326 void GC_initiate_gc GC_PROTO((void));
1327 /* initiate collection. */
1328 /* If the mark state is invalid, this */
1329 /* becomes full colleection. Otherwise */
1331 void GC_push_all GC_PROTO((ptr_t bottom, ptr_t top));
1332 /* Push everything in a range */
1333 /* onto mark stack. */
1334 void GC_push_selected GC_PROTO(( \
1337 int (*dirty_fn) GC_PROTO((struct hblk *h)), \
1338 void (*push_fn) GC_PROTO((ptr_t bottom, ptr_t top)) ));
1339 /* Push all pages h in [b,t) s.t. */
1340 /* select_fn(h) != 0 onto mark stack. */
1341 #ifndef SMALL_CONFIG
1342 void GC_push_conditional GC_PROTO((ptr_t b, ptr_t t, GC_bool all));
1344 # define GC_push_conditional(b, t, all) GC_push_all(b, t)
1346 /* Do either of the above, depending */
1347 /* on the third arg. */
1348 void GC_push_all_stack GC_PROTO((ptr_t b, ptr_t t));
1349 /* As above, but consider */
1350 /* interior pointers as valid */
1351 void GC_push_all_eager GC_PROTO((ptr_t b, ptr_t t));
1352 /* Same as GC_push_all_stack, but */
1353 /* ensures that stack is scanned */
1354 /* immediately, not just scheduled */
1357 void GC_push_all_stack_partially_eager GC_PROTO(( \
1358 ptr_t bottom, ptr_t top, ptr_t cold_gc_frame ));
1359 /* Similar to GC_push_all_eager, but only the */
1360 /* part hotter than cold_gc_frame is scanned */
1361 /* immediately. Needed to ensure that callee- */
1362 /* save registers are not missed. */
1364 /* In the threads case, we push part of the current thread stack */
1365 /* with GC_push_all_eager when we push the registers. This gets the */
1366 /* callee-save registers that may disappear. The remainder of the */
1367 /* stacks are scheduled for scanning in *GC_push_other_roots, which */
1368 /* is thread-package-specific. */
1370 void GC_push_current_stack GC_PROTO((ptr_t cold_gc_frame));
1371 /* Push enough of the current stack eagerly to */
1372 /* ensure that callee-save registers saved in */
1373 /* GC frames are scanned. */
1374 /* In the non-threads case, schedule entire */
1375 /* stack for scanning. */
1376 void GC_push_roots GC_PROTO((GC_bool all, ptr_t cold_gc_frame));
1377 /* Push all or dirty roots. */
1378 extern void (*GC_push_other_roots) GC_PROTO((void));
1379 /* Push system or application specific roots */
1380 /* onto the mark stack. In some environments */
1381 /* (e.g. threads environments) this is */
1382 /* predfined to be non-zero. A client supplied */
1383 /* replacement should also call the original */
1385 extern void GC_push_gc_structures GC_PROTO((void));
1386 /* Push GC internal roots. These are normally */
1387 /* included in the static data segment, and */
1388 /* Thus implicitly pushed. But we must do this */
1389 /* explicitly if normal root processing is */
1390 /* disabled. Calls the following: */
1391 extern void GC_push_finalizer_structures GC_PROTO((void));
1392 extern void GC_push_stubborn_structures GC_PROTO((void));
1394 extern void GC_push_thread_structures GC_PROTO((void));
1396 extern void (*GC_start_call_back) GC_PROTO((void));
1397 /* Called at start of full collections. */
1398 /* Not called if 0. Called with allocation */
1401 # if defined(USE_GENERIC_PUSH_REGS)
1402 void GC_generic_push_regs GC_PROTO((ptr_t cold_gc_frame));
1404 void GC_push_regs GC_PROTO((void));
1406 # if defined(SPARC) || defined(IA64)
1407 /* Cause all stacked registers to be saved in memory. Return a */
1408 /* pointer to the top of the corresponding memory stack. */
1409 word GC_save_regs_in_stack GC_PROTO((void));
1411 /* Push register contents onto mark stack. */
1412 /* If NURSERY is defined, the default push */
1413 /* action can be overridden with GC_push_proc */
1416 extern void (*GC_push_proc)(ptr_t);
1418 # if defined(MSWIN32) || defined(MSWINCE)
1419 void __cdecl GC_push_one GC_PROTO((word p));
1421 void GC_push_one GC_PROTO((word p));
1422 /* If p points to an object, mark it */
1423 /* and push contents on the mark stack */
1424 /* Pointer recognition test always */
1425 /* accepts interior pointers, i.e. this */
1426 /* is appropriate for pointers found on */
1429 # if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
1430 void GC_mark_and_push_stack GC_PROTO((word p, ptr_t source));
1431 /* Ditto, omits plausibility test */
1433 void GC_mark_and_push_stack GC_PROTO((word p));
1435 void GC_push_marked GC_PROTO((struct hblk * h, hdr * hhdr));
1436 /* Push contents of all marked objects in h onto */
1439 # define GC_push_next_marked_dirty(h) GC_push_next_marked(h)
1441 struct hblk * GC_push_next_marked_dirty GC_PROTO((struct hblk * h));
1442 /* Invoke GC_push_marked on next dirty block above h. */
1443 /* Return a pointer just past the end of this block. */
1444 #endif /* !SMALL_CONFIG */
1445 struct hblk * GC_push_next_marked GC_PROTO((struct hblk * h));
1446 /* Ditto, but also mark from clean pages. */
1447 struct hblk * GC_push_next_marked_uncollectable GC_PROTO((struct hblk * h));
1448 /* Ditto, but mark only from uncollectable pages. */
1449 GC_bool GC_stopped_mark GC_PROTO((GC_stop_func stop_func));
1450 /* Stop world and mark from all roots */
1452 void GC_clear_hdr_marks GC_PROTO((hdr * hhdr));
1453 /* Clear the mark bits in a header */
1454 void GC_set_hdr_marks GC_PROTO((hdr * hhdr));
1455 /* Set the mark bits in a header */
1456 void GC_set_fl_marks GC_PROTO((ptr_t p));
1457 /* Set all mark bits associated with */
1459 void GC_add_roots_inner GC_PROTO((char * b, char * e, GC_bool tmp));
1460 void GC_remove_roots_inner GC_PROTO((char * b, char * e));
1461 GC_bool GC_is_static_root GC_PROTO((ptr_t p));
1462 /* Is the address p in one of the registered static */
1463 /* root sections? */
1464 # if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
1465 GC_bool GC_is_tmp_root GC_PROTO((ptr_t p));
1466 /* Is the address p in one of the temporary static */
1467 /* root sections? */
1469 void GC_register_dynamic_libraries GC_PROTO((void));
1470 /* Add dynamic library data sections to the root set. */
1472 GC_bool GC_register_main_static_data GC_PROTO((void));
1473 /* We need to register the main data segment. Returns */
1474 /* TRUE unless this is done implicitly as part of */
1475 /* dynamic library registration. */
1477 /* Machine dependent startup routines */
1478 ptr_t GC_get_stack_base GC_PROTO((void)); /* Cold end of stack */
1480 ptr_t GC_get_register_stack_base GC_PROTO((void));
1481 /* Cold end of register stack. */
1483 void GC_register_data_segments GC_PROTO((void));
1485 /* Black listing: */
1486 void GC_bl_init GC_PROTO((void));
1487 # ifdef PRINT_BLACK_LIST
1488 void GC_add_to_black_list_normal GC_PROTO((word p, ptr_t source));
1489 /* Register bits as a possible future false */
1490 /* reference from the heap or static data */
1491 # define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1492 if (GC_all_interior_pointers) { \
1493 GC_add_to_black_list_stack(bits, (ptr_t)(source)); \
1495 GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
1498 void GC_add_to_black_list_normal GC_PROTO((word p));
1499 # define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1500 if (GC_all_interior_pointers) { \
1501 GC_add_to_black_list_stack(bits); \
1503 GC_add_to_black_list_normal(bits); \
1507 # ifdef PRINT_BLACK_LIST
1508 void GC_add_to_black_list_stack GC_PROTO((word p, ptr_t source));
1510 void GC_add_to_black_list_stack GC_PROTO((word p));
1512 struct hblk * GC_is_black_listed GC_PROTO((struct hblk * h, word len));
1513 /* If there are likely to be false references */
1514 /* to a block starting at h of the indicated */
1515 /* length, then return the next plausible */
1516 /* starting location for h that might avoid */
1517 /* these false references. */
1518 void GC_promote_black_lists GC_PROTO((void));
1519 /* Declare an end to a black listing phase. */
1520 void GC_unpromote_black_lists GC_PROTO((void));
1521 /* Approximately undo the effect of the above. */
1522 /* This actually loses some information, but */
1523 /* only in a reasonably safe way. */
1524 word GC_number_stack_black_listed GC_PROTO(( \
1525 struct hblk *start, struct hblk *endp1));
1526 /* Return the number of (stack) blacklisted */
1527 /* blocks in the range for statistical */
1530 ptr_t GC_scratch_alloc GC_PROTO((word bytes));
1531 /* GC internal memory allocation for */
1532 /* small objects. Deallocation is not */
1535 /* Heap block layout maps: */
1536 void GC_invalidate_map GC_PROTO((hdr * hhdr));
1537 /* Remove the object map associated */
1538 /* with the block. This identifies */
1539 /* the block as invalid to the mark */
1541 GC_bool GC_add_map_entry GC_PROTO((word sz));
1542 /* Add a heap block map for objects of */
1543 /* size sz to obj_map. */
1544 /* Return FALSE on failure. */
1545 void GC_register_displacement_inner GC_PROTO((word offset));
1546 /* Version of GC_register_displacement */
1547 /* that assumes lock is already held */
1548 /* and signals are already disabled. */
1550 /* hblk allocation: */
1551 void GC_new_hblk GC_PROTO((word size_in_words, int kind));
1552 /* Allocate a new heap block, and build */
1553 /* a free list in it. */
1555 ptr_t GC_build_fl GC_PROTO((struct hblk *h, word sz,
1556 GC_bool clear, ptr_t list));
1557 /* Build a free list for objects of */
1558 /* size sz in block h. Append list to */
1559 /* end of the free lists. Possibly */
1560 /* clear objects on the list. Normally */
1561 /* called by GC_new_hblk, but also */
1562 /* called explicitly without GC lock. */
1564 struct hblk * GC_allochblk GC_PROTO(( \
1565 word size_in_words, int kind, unsigned flags));
1566 /* Allocate a heap block, inform */
1567 /* the marker that block is valid */
1568 /* for objects of indicated size. */
1570 ptr_t GC_alloc_large GC_PROTO((word lw, int k, unsigned flags));
1571 /* Allocate a large block of size lw words. */
1572 /* The block is not cleared. */
1573 /* Flags is 0 or IGNORE_OFF_PAGE. */
1574 /* Calls GC_allchblk to do the actual */
1575 /* allocation, but also triggers GC and/or */
1576 /* heap expansion as appropriate. */
1577 /* Does not update GC_words_allocd, but does */
1578 /* other accounting. */
1580 ptr_t GC_alloc_large_and_clear GC_PROTO((word lw, int k, unsigned flags));
1581 /* As above, but clear block if appropriate */
1584 void GC_freehblk GC_PROTO((struct hblk * p));
1585 /* Deallocate a heap block and mark it */
1589 void GC_init_inner GC_PROTO((void));
1590 GC_bool GC_expand_hp_inner GC_PROTO((word n));
1591 void GC_start_reclaim GC_PROTO((int abort_if_found));
1592 /* Restore unmarked objects to free */
1593 /* lists, or (if abort_if_found is */
1594 /* TRUE) report them. */
1595 /* Sweeping of small object pages is */
1596 /* largely deferred. */
1597 void GC_continue_reclaim GC_PROTO((word sz, int kind));
1598 /* Sweep pages of the given size and */
1599 /* kind, as long as possible, and */
1600 /* as long as the corr. free list is */
1602 void GC_reclaim_or_delete_all GC_PROTO((void));
1603 /* Arrange for all reclaim lists to be */
1604 /* empty. Judiciously choose between */
1605 /* sweeping and discarding each page. */
1606 GC_bool GC_reclaim_all GC_PROTO((GC_stop_func stop_func, GC_bool ignore_old));
1607 /* Reclaim all blocks. Abort (in a */
1608 /* consistent state) if f returns TRUE. */
1609 GC_bool GC_block_empty GC_PROTO((hdr * hhdr));
1610 /* Block completely unmarked? */
1611 GC_bool GC_never_stop_func GC_PROTO((void));
1612 /* Returns FALSE. */
1613 GC_bool GC_try_to_collect_inner GC_PROTO((GC_stop_func f));
1615 /* Collect; caller must have acquired */
1616 /* lock and disabled signals. */
1617 /* Collection is aborted if f returns */
1618 /* TRUE. Returns TRUE if it completes */
1620 # define GC_gcollect_inner() \
1621 (void) GC_try_to_collect_inner(GC_never_stop_func)
1622 void GC_finish_collection GC_PROTO((void));
1623 /* Finish collection. Mark bits are */
1624 /* consistent and lock is still held. */
1625 GC_bool GC_collect_or_expand GC_PROTO(( \
1626 word needed_blocks, GC_bool ignore_off_page));
1627 /* Collect or expand heap in an attempt */
1628 /* make the indicated number of free */
1629 /* blocks available. Should be called */
1630 /* until the blocks are available or */
1631 /* until it fails by returning FALSE. */
1633 extern GC_bool GC_is_initialized; /* GC_init() has been run. */
1635 #if defined(MSWIN32) || defined(MSWINCE)
1636 void GC_deinit GC_PROTO((void));
1637 /* Free any resources allocated by */
1641 void GC_collect_a_little_inner GC_PROTO((int n));
1642 /* Do n units worth of garbage */
1643 /* collection work, if appropriate. */
1644 /* A unit is an amount appropriate for */
1645 /* HBLKSIZE bytes of allocation. */
1646 /* ptr_t GC_generic_malloc GC_PROTO((word lb, int k)); */
1647 /* Allocate an object of the given */
1648 /* kind. By default, there are only */
1649 /* a few kinds: composite(pointerfree), */
1650 /* atomic, uncollectable, etc. */
1651 /* We claim it's possible for clever */
1652 /* client code that understands GC */
1653 /* internals to add more, e.g. to */
1654 /* communicate object layout info */
1655 /* to the collector. */
1656 /* The actual decl is in gc_mark.h. */
1657 ptr_t GC_generic_malloc_ignore_off_page GC_PROTO((size_t b, int k));
1658 /* As above, but pointers past the */
1659 /* first page of the resulting object */
1661 ptr_t GC_generic_malloc_inner GC_PROTO((word lb, int k));
1662 /* Ditto, but I already hold lock, etc. */
1663 ptr_t GC_generic_malloc_words_small_inner GC_PROTO((word lw, int k));
1664 /* Analogous to the above, but assumes */
1665 /* a small object size, and bypasses */
1666 /* MERGE_SIZES mechanism. */
1667 ptr_t GC_generic_malloc_words_small GC_PROTO((size_t lw, int k));
1668 /* As above, but size in units of words */
1669 /* Bypasses MERGE_SIZES. Assumes */
1670 /* words <= MAXOBJSZ. */
1671 ptr_t GC_generic_malloc_inner_ignore_off_page GC_PROTO((size_t lb, int k));
1672 /* Allocate an object, where */
1673 /* the client guarantees that there */
1674 /* will always be a pointer to the */
1675 /* beginning of the object while the */
1676 /* object is live. */
1677 ptr_t GC_allocobj GC_PROTO((word sz, int kind));
1678 /* Make the indicated */
1679 /* free list nonempty, and return its */
1682 void GC_free_inner(GC_PTR p);
1684 void GC_init_headers GC_PROTO((void));
1685 struct hblkhdr * GC_install_header GC_PROTO((struct hblk *h));
1686 /* Install a header for block h. */
1687 /* Return 0 on failure, or the header */
1689 GC_bool GC_install_counts GC_PROTO((struct hblk * h, word sz));
1690 /* Set up forwarding counts for block */
1692 /* Return FALSE on failure. */
1693 void GC_remove_header GC_PROTO((struct hblk * h));
1694 /* Remove the header for block h. */
1695 void GC_remove_counts GC_PROTO((struct hblk * h, word sz));
1696 /* Remove forwarding counts for h. */
1697 hdr * GC_find_header GC_PROTO((ptr_t h)); /* Debugging only. */
1699 void GC_finalize GC_PROTO((void));
1700 /* Perform all indicated finalization actions */
1701 /* on unmarked objects. */
1702 /* Unreachable finalizable objects are enqueued */
1703 /* for processing by GC_invoke_finalizers. */
1704 /* Invoked with lock. */
1706 void GC_notify_or_invoke_finalizers GC_PROTO((void));
1707 /* If GC_finalize_on_demand is not set, invoke */
1708 /* eligible finalizers. Otherwise: */
1709 /* Call *GC_finalizer_notifier if there are */
1710 /* finalizers to be run, and we haven't called */
1711 /* this procedure yet this GC cycle. */
1713 GC_API GC_PTR GC_make_closure GC_PROTO((GC_finalization_proc fn, GC_PTR data));
1714 GC_API void GC_debug_invoke_finalizer GC_PROTO((GC_PTR obj, GC_PTR data));
1715 /* Auxiliary fns to make finalization work */
1716 /* correctly with displaced pointers introduced */
1717 /* by the debugging allocators. */
1719 void GC_add_to_heap GC_PROTO((struct hblk *p, word bytes));
1720 /* Add a HBLKSIZE aligned chunk to the heap. */
1722 void GC_print_obj GC_PROTO((ptr_t p));
1723 /* P points to somewhere inside an object with */
1724 /* debugging info. Print a human readable */
1725 /* description of the object to stderr. */
1726 extern void (*GC_check_heap) GC_PROTO((void));
1727 /* Check that all objects in the heap with */
1728 /* debugging info are intact. */
1729 /* Add any that are not to GC_smashed list. */
1730 extern void (*GC_print_all_smashed) GC_PROTO((void));
1731 /* Print GC_smashed if it's not empty. */
1732 /* Clear GC_smashed list. */
1733 extern void GC_print_all_errors GC_PROTO((void));
1734 /* Print smashed and leaked objects, if any. */
1735 /* Clear the lists of such objects. */
1736 extern void (*GC_print_heap_obj) GC_PROTO((ptr_t p));
1737 /* If possible print s followed by a more */
1738 /* detailed description of the object */
1739 /* referred to by p. */
1740 #if defined(LINUX) && defined(__ELF__) && !defined(SMALL_CONFIG)
1741 void GC_print_address_map GC_PROTO((void));
1742 /* Print an address map of the process. */
1745 extern GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
1746 /* Call error printing routine */
1748 extern GC_bool GC_print_stats; /* Produce at least some logging output */
1749 /* Set from environment variable. */
1751 #ifndef NO_DEBUGGING
1752 extern GC_bool GC_dump_regularly; /* Generate regular debugging dumps. */
1753 # define COND_DUMP if (GC_dump_regularly) GC_dump();
1758 #ifdef KEEP_BACK_PTRS
1759 extern long GC_backtraces;
1760 void GC_generate_random_backtrace_no_gc(void);
1763 extern GC_bool GC_print_back_height;
1765 #ifdef MAKE_BACK_GRAPH
1766 void GC_print_back_graph_stats(void);
1769 /* Macros used for collector internal allocation. */
1770 /* These assume the collector lock is held. */
1772 extern GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k);
1773 extern GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
1775 # define GC_INTERNAL_MALLOC GC_debug_generic_malloc_inner
1776 # define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
1777 GC_debug_generic_malloc_inner_ignore_off_page
1779 # define GC_INTERNAL_FREE GC_debug_free_inner
1781 # define GC_INTERNAL_FREE GC_debug_free
1784 # define GC_INTERNAL_MALLOC GC_generic_malloc_inner
1785 # define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
1786 GC_generic_malloc_inner_ignore_off_page
1788 # define GC_INTERNAL_FREE GC_free_inner
1790 # define GC_INTERNAL_FREE GC_free
1794 /* Memory unmapping: */
1796 void GC_unmap_old(void);
1797 void GC_merge_unmapped(void);
1798 void GC_unmap(ptr_t start, word bytes);
1799 void GC_remap(ptr_t start, word bytes);
1800 void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2);
1803 /* Virtual dirty bit implementation: */
1804 /* Each implementation exports the following: */
1805 void GC_read_dirty GC_PROTO((void));
1806 /* Retrieve dirty bits. */
1807 GC_bool GC_page_was_dirty GC_PROTO((struct hblk *h));
1808 /* Read retrieved dirty bits. */
1809 GC_bool GC_page_was_ever_dirty GC_PROTO((struct hblk *h));
1810 /* Could the page contain valid heap pointers? */
1811 void GC_is_fresh GC_PROTO((struct hblk *h, word n));
1812 /* Assert the region currently contains no */
1813 /* valid pointers. */
1814 void GC_remove_protection GC_PROTO((struct hblk *h, word nblocks,
1815 GC_bool pointerfree));
1816 /* h is about to be writteni or allocated. Ensure */
1817 /* that it's not write protected by the virtual */
1818 /* dirty bit implementation. */
1820 void GC_dirty_init GC_PROTO((void));
1822 /* Slow/general mark bit manipulation: */
1823 GC_API GC_bool GC_is_marked GC_PROTO((ptr_t p));
1824 void GC_clear_mark_bit GC_PROTO((ptr_t p));
1825 void GC_set_mark_bit GC_PROTO((ptr_t p));
1827 /* Stubborn objects: */
1828 void GC_read_changed GC_PROTO((void)); /* Analogous to GC_read_dirty */
1829 GC_bool GC_page_was_changed GC_PROTO((struct hblk * h));
1830 /* Analogous to GC_page_was_dirty */
1831 void GC_clean_changing_list GC_PROTO((void));
1832 /* Collect obsolete changing list entries */
1833 void GC_stubborn_init GC_PROTO((void));
1835 /* Debugging print routines: */
1836 void GC_print_block_list GC_PROTO((void));
1837 void GC_print_hblkfreelist GC_PROTO((void));
1838 void GC_print_heap_sects GC_PROTO((void));
1839 void GC_print_static_roots GC_PROTO((void));
1840 void GC_print_finalization_stats GC_PROTO((void));
1841 void GC_dump GC_PROTO((void));
1843 #ifdef KEEP_BACK_PTRS
1844 void GC_store_back_pointer(ptr_t source, ptr_t dest);
1845 void GC_marked_for_finalization(ptr_t dest);
1846 # define GC_STORE_BACK_PTR(source, dest) GC_store_back_pointer(source, dest)
1847 # define GC_MARKED_FOR_FINALIZATION(dest) GC_marked_for_finalization(dest)
1849 # define GC_STORE_BACK_PTR(source, dest)
1850 # define GC_MARKED_FOR_FINALIZATION(dest)
1853 /* Make arguments appear live to compiler */
1855 void GC_noop(void*, ...);
1858 GC_API void GC_noop(...);
1860 GC_API void GC_noop();
1864 void GC_noop1 GC_PROTO((word));
1866 /* Logging and diagnostic output: */
1867 GC_API void GC_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1868 /* A version of printf that doesn't allocate, */
1869 /* is restricted to long arguments, and */
1870 /* (unfortunately) doesn't use varargs for */
1871 /* portability. Restricted to 6 args and */
1872 /* 1K total output length. */
1873 /* (We use sprintf. Hopefully that doesn't */
1874 /* allocate for long arguments.) */
1875 # define GC_printf0(f) GC_printf(f, 0l, 0l, 0l, 0l, 0l, 0l)
1876 # define GC_printf1(f,a) GC_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1877 # define GC_printf2(f,a,b) GC_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1878 # define GC_printf3(f,a,b,c) GC_printf(f, (long)a, (long)b, (long)c, 0l, 0l, 0l)
1879 # define GC_printf4(f,a,b,c,d) GC_printf(f, (long)a, (long)b, (long)c, \
1881 # define GC_printf5(f,a,b,c,d,e) GC_printf(f, (long)a, (long)b, (long)c, \
1882 (long)d, (long)e, 0l)
1883 # define GC_printf6(f,a,b,c,d,e,g) GC_printf(f, (long)a, (long)b, (long)c, \
1884 (long)d, (long)e, (long)g)
1886 GC_API void GC_err_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1887 # define GC_err_printf0(f) GC_err_puts(f)
1888 # define GC_err_printf1(f,a) GC_err_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1889 # define GC_err_printf2(f,a,b) GC_err_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1890 # define GC_err_printf3(f,a,b,c) GC_err_printf(f, (long)a, (long)b, (long)c, \
1892 # define GC_err_printf4(f,a,b,c,d) GC_err_printf(f, (long)a, (long)b, \
1893 (long)c, (long)d, 0l, 0l)
1894 # define GC_err_printf5(f,a,b,c,d,e) GC_err_printf(f, (long)a, (long)b, \
1897 # define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
1900 /* Ditto, writes to stderr. */
1902 void GC_err_puts GC_PROTO((GC_CONST char *s));
1903 /* Write s to stderr, don't buffer, don't add */
1904 /* newlines, don't ... */
1906 #if defined(LINUX) && !defined(SMALL_CONFIG)
1907 void GC_err_write GC_PROTO((GC_CONST char *buf, size_t len));
1908 /* Write buf to stderr, don't buffer, don't add */
1909 /* newlines, don't ... */
1913 # ifdef GC_ASSERTIONS
1914 # define GC_ASSERT(expr) if(!(expr)) {\
1915 GC_err_printf2("Assertion failure: %s:%ld\n", \
1916 __FILE__, (unsigned long)__LINE__); \
1917 ABORT("assertion failure"); }
1919 # define GC_ASSERT(expr)
1922 /* Check a compile time assertion at compile time. The error */
1923 /* message for failure is a bit baroque, but ... */
1924 #if defined(mips) && !defined(__GNUC__)
1925 /* DOB: MIPSPro C gets an internal error taking the sizeof an array type.
1926 This code works correctly (ugliness is to avoid "unused var" warnings) */
1927 # define GC_STATIC_ASSERT(expr) do { if (0) { char j[(expr)? 1 : -1]; j[0]='\0'; j[0]=j[0]; } } while(0)
1929 # define GC_STATIC_ASSERT(expr) sizeof(char[(expr)? 1 : -1])
1932 # if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
1933 /* We need additional synchronization facilities from the thread */
1934 /* support. We believe these are less performance critical */
1935 /* than the main garbage collector lock; standard pthreads-based */
1936 /* implementations should be sufficient. */
1938 /* The mark lock and condition variable. If the GC lock is also */
1939 /* acquired, the GC lock must be acquired first. The mark lock is */
1940 /* used to both protect some variables used by the parallel */
1941 /* marker, and to protect GC_fl_builder_count, below. */
1942 /* GC_notify_all_marker() is called when */
1943 /* the state of the parallel marker changes */
1944 /* in some significant way (see gc_mark.h for details). The */
1945 /* latter set of events includes incrementing GC_mark_no. */
1946 /* GC_notify_all_builder() is called when GC_fl_builder_count */
1949 extern void GC_acquire_mark_lock();
1950 extern void GC_release_mark_lock();
1951 extern void GC_notify_all_builder();
1952 /* extern void GC_wait_builder(); */
1953 extern void GC_wait_for_reclaim();
1955 extern word GC_fl_builder_count; /* Protected by mark lock. */
1956 # endif /* PARALLEL_MARK || THREAD_LOCAL_ALLOC */
1957 # ifdef PARALLEL_MARK
1958 extern void GC_notify_all_marker();
1959 extern void GC_wait_marker();
1960 extern word GC_mark_no; /* Protected by mark lock. */
1962 extern void GC_help_marker(word my_mark_no);
1963 /* Try to help out parallel marker for mark cycle */
1964 /* my_mark_no. Returns if the mark cycle finishes or */
1965 /* was already done, or there was nothing to do for */
1966 /* some other reason. */
1967 # endif /* PARALLEL_MARK */
1969 # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
1970 /* We define the thread suspension signal here, so that we can refer */
1971 /* to it in the dirty bit implementation, if necessary. Ideally we */
1972 /* would allocate a (real-time ?) signal using the standard mechanism.*/
1973 /* unfortunately, there is no standard mechanism. (There is one */
1974 /* in Linux glibc, but it's not exported.) Thus we continue to use */
1975 /* the same hard-coded signals we've always used. */
1976 # if !defined(SIG_SUSPEND)
1977 # if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS)
1978 # if defined(SPARC) && !defined(SIGPWR)
1979 /* SPARC/Linux doesn't properly define SIGPWR in <signal.h>.
1980 * It is aliased to SIGLOST in asm/signal.h, though. */
1981 # define SIG_SUSPEND SIGLOST
1983 /* Linuxthreads itself uses SIGUSR1 and SIGUSR2. */
1984 # define SIG_SUSPEND SIGPWR
1986 # else /* !GC_LINUX_THREADS */
1987 # if defined(_SIGRTMIN)
1988 # define SIG_SUSPEND _SIGRTMIN + 6
1990 # define SIG_SUSPEND SIGRTMIN + 6
1993 # endif /* !SIG_SUSPEND */
1997 # endif /* GC_PRIVATE_H */