159
150
/* This is now really controlled at startup, */
160
151
/* through GC_all_interior_pointers. */
162
#define PRINTSTATS /* Print garbage collection statistics */
163
/* For less verbose output, undefine in reclaim.c */
165
#define PRINTTIMES /* Print the amount of time consumed by each garbage */
168
#define PRINTBLOCKS /* Print object sizes associated with heap blocks, */
169
/* whether the objects are atomic or composite, and */
170
/* whether or not the block was found to be empty */
171
/* during the reclaim phase. Typically generates */
172
/* about one screenful per garbage collection. */
187
#if defined(PRINTSTATS) && !defined(GATHERSTATS)
191
#if defined(PRINTSTATS) || !defined(SMALL_CONFIG)
192
# define CONDPRINT /* Print some things if GC_print_stats is set */
195
154
#define GC_INVOKE_FINALIZERS() GC_notify_or_invoke_finalizers()
197
#define MERGE_SIZES /* Round up some object sizes, so that fewer distinct */
198
/* free lists are actually maintained. This applies */
199
/* only to the top level routines in misc.c, not to */
200
/* user generated code that calls GC_allocobj and */
201
/* GC_allocaobj directly. */
202
/* Slows down average programs slightly. May however */
203
/* substantially reduce fragmentation if allocation */
204
/* request sizes are widely scattered. */
205
/* May save significant amounts of space for obj_map */
208
#if defined(USE_MARK_BYTES) && !defined(ALIGN_DOUBLE)
209
# define ALIGN_DOUBLE
210
/* We use one byte for every 2 words, which doesn't allow for */
211
/* odd numbered words to have mark bits. */
214
#if defined(GC_GCJ_SUPPORT) && ALIGNMENT < 8 && !defined(ALIGN_DOUBLE)
215
/* GCJ's Hashtable synchronization code requires 64-bit alignment. */
216
# define ALIGN_DOUBLE
219
/* ALIGN_DOUBLE requires MERGE_SIZES at present. */
220
# if defined(ALIGN_DOUBLE) && !defined(MERGE_SIZES)
224
156
#if !defined(DONT_ADD_BYTE_AT_END)
225
157
# define EXTRA_BYTES GC_all_interior_pointers
158
# define MAX_EXTRA_BYTES 1
227
160
# define EXTRA_BYTES 0
161
# define MAX_EXTRA_BYTES 0
361
295
# define BCOPY(x,y,n) memcpy(y, x, (size_t)(n))
362
296
# define BZERO(x,n) memset(x, 0, (size_t)(n))
364
# define BCOPY(x,y,n) bcopy((char *)(x),(char *)(y),(int)(n))
365
# define BZERO(x,n) bzero((char *)(x),(int)(n))
368
/* Delay any interrupts or signals that may abort this thread. Data */
369
/* structures are in a consistent state outside this pair of calls. */
370
/* ANSI C allows both to be empty (though the standard isn't very */
371
/* clear on that point). Standard malloc implementations are usually */
372
/* neither interruptable nor thread-safe, and thus correspond to */
373
/* empty definitions. */
374
/* It probably doesn't make any sense to declare these to be nonempty */
375
/* if the code is being optimized, since signal safety relies on some */
376
/* ordering constraints that are typically not obeyed by optimizing */
379
# define DISABLE_SIGNALS() \
380
PCR_Th_SetSigMask(PCR_allSigsBlocked,&GC_old_sig_mask)
381
# define ENABLE_SIGNALS() \
382
PCR_Th_SetSigMask(&GC_old_sig_mask, NIL)
384
# if defined(THREADS) || defined(AMIGA) \
385
|| defined(MSWIN32) || defined(MSWINCE) || defined(MACOS) \
386
|| defined(DJGPP) || defined(NO_SIGNALS)
387
/* Also useful for debugging. */
388
/* Should probably use thr_sigsetmask for GC_SOLARIS_THREADS. */
389
# define DISABLE_SIGNALS()
390
# define ENABLE_SIGNALS()
392
# define DISABLE_SIGNALS() GC_disable_signals()
393
void GC_disable_signals();
394
# define ENABLE_SIGNALS() GC_enable_signals()
395
void GC_enable_signals();
298
# define BCOPY(x,y,n) bcopy((void *)(x),(void *)(y),(size_t)(n))
299
# define BZERO(x,n) bzero((void *)(x),(size_t)(n))
464
367
# define GETENV(name) 0
371
# if defined(POWERPC)
372
# if CPP_WORDSZ == 32
373
# define GC_THREAD_STATE_T ppc_thread_state_t
374
# define GC_MACH_THREAD_STATE PPC_THREAD_STATE
375
# define GC_MACH_THREAD_STATE_COUNT PPC_THREAD_STATE_COUNT
376
# define GC_MACH_HEADER mach_header
377
# define GC_MACH_SECTION section
378
# define GC_GETSECTBYNAME getsectbynamefromheader
380
# define GC_THREAD_STATE_T ppc_thread_state64_t
381
# define GC_MACH_THREAD_STATE PPC_THREAD_STATE64
382
# define GC_MACH_THREAD_STATE_COUNT PPC_THREAD_STATE64_COUNT
383
# define GC_MACH_HEADER mach_header_64
384
# define GC_MACH_SECTION section_64
385
# define GC_GETSECTBYNAME getsectbynamefromheader_64
387
# elif defined(I386) || defined(X86_64)
388
# if CPP_WORDSZ == 32
389
# define GC_THREAD_STATE_T x86_thread_state32_t
390
# define GC_MACH_THREAD_STATE x86_THREAD_STATE32
391
# define GC_MACH_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
392
# define GC_MACH_HEADER mach_header
393
# define GC_MACH_SECTION section
394
# define GC_GETSECTBYNAME getsectbynamefromheader
396
# define GC_THREAD_STATE_T x86_thread_state64_t
397
# define GC_MACH_THREAD_STATE x86_THREAD_STATE64
398
# define GC_MACH_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
399
# define GC_MACH_HEADER mach_header_64
400
# define GC_MACH_SECTION section_64
401
# define GC_GETSECTBYNAME getsectbynamefromheader_64
404
# error define GC_THREAD_STATE_T
405
# define GC_MACH_THREAD_STATE MACHINE_THREAD_STATE
406
# define GC_MACH_THREAD_STATE_COUNT MACHINE_THREAD_STATE_COUNT
408
/* Try to work out the right way to access thread state structure members.
409
The structure has changed its definition in different Darwin versions.
410
This now defaults to the (older) names without __, thus hopefully,
411
not breaking any existing Makefile.direct builds. */
412
# if defined (HAS_PPC_THREAD_STATE___R0) \
413
|| defined (HAS_PPC_THREAD_STATE64___R0) \
414
|| defined (HAS_X86_THREAD_STATE32___EAX) \
415
|| defined (HAS_X86_THREAD_STATE64___RAX)
416
# define THREAD_FLD(x) __ ## x
418
# define THREAD_FLD(x) x
467
422
/*********************************/
469
424
/* Word-size-dependent defines */
448
/* The first TINY_FREELISTS free lists correspond to the first */
449
/* TINY_FREELISTS multiples of GRANULE_BYTES, i.e. we keep */
450
/* separate free lists for each multiple of GRANULE_BYTES */
451
/* up to (TINY_FREELISTS-1) * GRANULE_BYTES. After that they */
452
/* may be spread out further. */
453
#include "../gc_tiny_fl.h"
454
#define GRANULE_BYTES GC_GRANULE_BYTES
455
#define TINY_FREELISTS GC_TINY_FREELISTS
493
457
#define WORDSZ ((word)CPP_WORDSZ)
494
458
#define SIGNB ((word)1 << (WORDSZ-1))
495
459
#define BYTES_PER_WORD ((word)(sizeof (word)))
496
460
#define ONES ((word)(signed_word)(-1))
497
461
#define divWORDSZ(n) ((n) >> LOGWL) /* divide n by size of word */
463
#if GRANULE_BYTES == 8
464
# define BYTES_TO_GRANULES(n) ((n)>>3)
465
# define GRANULES_TO_BYTES(n) ((n)<<3)
466
# if CPP_WORDSZ == 64
467
# define GRANULES_TO_WORDS(n) (n)
468
# elif CPP_WORDSZ == 32
469
# define GRANULES_TO_WORDS(n) ((n)<<1)
471
# define GRANULES_TO_WORDS(n) BYTES_TO_WORDS(GRANULES_TO_BYTES(n))
473
#elif GRANULE_BYTES == 16
474
# define BYTES_TO_GRANULES(n) ((n)>>4)
475
# define GRANULES_TO_BYTES(n) ((n)<<4)
476
# if CPP_WORDSZ == 64
477
# define GRANULES_TO_WORDS(n) ((n)<<1)
478
# elif CPP_WORDSZ == 32
479
# define GRANULES_TO_WORDS(n) ((n)<<2)
481
# define GRANULES_TO_WORDS(n) BYTES_TO_WORDS(GRANULES_TO_BYTES(n))
484
# error Bad GRANULE_BYTES value
499
487
/*********************/
501
489
/* Size Parameters */
503
491
/*********************/
505
/* heap block size, bytes. Should be power of 2 */
493
/* Heap block size, bytes. Should be power of 2. */
494
/* Incremental GC with MPROTECT_VDB currently requires the */
495
/* page size to be a multiple of HBLKSIZE. Since most modern */
496
/* architectures support variable page sizes down to 4K, and */
497
/* X86 is generally 4K, we now default to 4K, except for */
498
/* Alpha: Seems to be used with 8K pages. */
499
/* SMALL_CONFIG: Want less block-level fragmentation. */
508
502
# ifdef SMALL_CONFIG
509
503
# define CPP_LOG_HBLKSIZE 10
511
# if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
512
/* HPUX/PA seems to use 4K pages with the 64 bit ABI */
506
# define CPP_LOG_HBLKSIZE 13
513
508
# define CPP_LOG_HBLKSIZE 12
515
# define CPP_LOG_HBLKSIZE 13
567
564
# define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
569
# define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
566
# define HBLKDISPL(objptr) (((size_t) (objptr)) & (HBLKSIZE-1))
571
568
/* Round up byte allocation requests to integral number of words, etc. */
572
569
# define ROUNDED_UP_WORDS(n) \
573
570
BYTES_TO_WORDS((n) + (WORDS_TO_BYTES(1) - 1 + EXTRA_BYTES))
575
# define ALIGNED_WORDS(n) \
576
(BYTES_TO_WORDS((n) + WORDS_TO_BYTES(2) - 1 + EXTRA_BYTES) & ~1)
571
# define ROUNDED_UP_GRANULES(n) \
572
BYTES_TO_GRANULES((n) + (GRANULE_BYTES - 1 + EXTRA_BYTES))
573
# if MAX_EXTRA_BYTES == 0
574
# define SMALL_OBJ(bytes) EXPECT((bytes) <= (MAXOBJBYTES), 1)
578
# define ALIGNED_WORDS(n) ROUNDED_UP_WORDS(n)
576
# define SMALL_OBJ(bytes) \
577
(EXPECT((bytes) <= (MAXOBJBYTES - MAX_EXTRA_BYTES), 1) || \
578
(bytes) <= (MAXOBJBYTES - EXTRA_BYTES))
579
/* This really just tests bytes <= MAXOBJBYTES - EXTRA_BYTES. */
580
/* But we try to avoid looking up EXTRA_BYTES. */
580
# define SMALL_OBJ(bytes) ((bytes) <= (MAXOBJBYTES - EXTRA_BYTES))
581
582
# define ADD_SLOP(bytes) ((bytes) + EXTRA_BYTES)
582
583
# ifndef MIN_WORDS
583
/* MIN_WORDS is the size of the smallest allocated object. */
584
/* 1 and 2 are the only valid values. */
585
/* 2 must be used if: */
586
/* - GC_gcj_malloc can be used for objects of requested */
587
/* size smaller than 2 words, or */
588
/* - USE_MARK_BYTES is defined. */
589
# if defined(USE_MARK_BYTES) || defined(GC_GCJ_SUPPORT)
590
# define MIN_WORDS 2 /* Smallest allocated object. */
584
# define MIN_WORDS 2 /* FIXME: obsolete */
598
* Hash table representation of sets of pages. This assumes it is
599
* OK to add spurious entries to sets.
589
* Hash table representation of sets of pages.
590
* Implements a map from aligned HBLKSIZE chunks of the address space to one
592
* This assumes it is OK to spuriously set bits, e.g. because multiple
593
* addresses are represented by a single location.
600
594
* Used by black-listing code, and perhaps by dirty bit maintenance code.
603
597
# ifdef LARGE_CONFIG
604
# define LOG_PHT_ENTRIES 20 /* Collisions likely at 1M blocks, */
598
# if CPP_WORDSZ == 32
599
# define LOG_PHT_ENTRIES 20 /* Collisions likely at 1M blocks, */
605
600
/* which is >= 4GB. Each table takes */
606
601
/* 128KB, some of which may never be */
604
# define LOG_PHT_ENTRIES 21 /* Collisions likely at 2M blocks, */
605
/* which is >= 8GB. Each table takes */
606
/* 256KB, some of which may never be */
609
610
# ifdef SMALL_CONFIG
610
# define LOG_PHT_ENTRIES 14 /* Collisions are likely if heap grows */
611
/* to more than 16K hblks = 64MB. */
612
/* Each hash table occupies 2K bytes. */
611
# define LOG_PHT_ENTRIES 15 /* Collisions are likely if heap grows */
612
/* to more than 32K hblks = 128MB. */
613
/* Each hash table occupies 4K bytes. */
613
614
# else /* default "medium" configuration */
614
# define LOG_PHT_ENTRIES 16 /* Collisions are likely if heap grows */
615
/* to more than 64K hblks >= 256MB. */
616
/* Each hash table occupies 8K bytes. */
615
# define LOG_PHT_ENTRIES 18 /* Collisions are likely if heap grows */
616
/* to more than 256K hblks >= 1GB. */
617
/* Each hash table occupies 32K bytes. */
617
618
/* Even for somewhat smaller heaps, */
618
619
/* say half that, collisions may be an */
619
620
/* issue because we blacklist */
648
649
/* heap block header */
649
650
#define HBLKMASK (HBLKSIZE-1)
651
#define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
653
#define MARK_BITS_PER_HBLK (BITS_PER_HBLK/CPP_WORDSZ)
652
#define MARK_BITS_PER_HBLK (HBLKSIZE/GRANULE_BYTES)
654
653
/* upper bound */
655
/* We allocate 1 bit/word, unless USE_MARK_BYTES */
656
/* is defined. Only the first word */
657
/* in each object is actually marked. */
654
/* We allocate 1 bit per allocation granule. */
655
/* If MARK_BIT_PER_GRANULE is defined, we use */
656
/* every nth bit, where n is the number of */
657
/* allocation granules per object. If */
658
/* MARK_BIT_PER_OBJ is defined, we only use the */
659
/* initial group of mark bits, and it is safe */
660
/* to allocate smaller header for large objects. */
659
662
# ifdef USE_MARK_BYTES
660
# define MARK_BITS_SZ (MARK_BITS_PER_HBLK/2)
663
# define MARK_BITS_SZ (MARK_BITS_PER_HBLK + 1)
661
664
/* Unlike the other case, this is in units of bytes. */
662
/* We actually allocate only every second mark bit, since we */
663
/* force all objects to be doubleword aligned. */
664
/* However, each mark bit is allocated as a byte. */
665
/* Since we force doubleword alignment, we need at most one */
666
/* mark bit per 2 words. But we do allocate and set one */
667
/* extra mark bit to avoid an explicit check for the */
668
/* partial object at the end of each block. */
666
# define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
670
# define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ + 1)
674
# include <atomic_ops.h>
675
typedef AO_t counter_t;
677
typedef size_t counter_t;
669
680
/* We maintain layout maps for heap blocks containing objects of a given */
670
681
/* size. Each entry in this map describes a byte offset and has the */
671
682
/* following type. */
672
typedef unsigned char map_entry_type;
675
word hb_sz; /* If in use, size in words, of objects in the block. */
676
/* if free, the size in bytes of the whole block */
677
684
struct hblk * hb_next; /* Link field for hblk free list */
678
685
/* and for lists of chunks waiting to be */
680
687
struct hblk * hb_prev; /* Backwards link for free list. */
681
word hb_descr; /* object descriptor for marking. See */
683
map_entry_type * hb_map;
684
/* A pointer to a pointer validity map of the block. */
685
/* See GC_obj_map. */
686
/* Valid for all blocks with headers. */
687
/* Free blocks point to GC_invalid_map. */
688
struct hblk * hb_block; /* The corresponding block. */
688
689
unsigned char hb_obj_kind;
689
690
/* Kind of objects in the block. Each kind */
690
691
/* identifies a mark procedure and a set of */
707
709
/* when the header was allocated, or */
708
710
/* when the size of the block last */
712
size_t hb_sz; /* If in use, size in bytes, of objects in the block. */
713
/* if free, the size in bytes of the whole block */
714
/* We assume that this is convertible to signed_word */
715
/* without generating a negative result. We avoid */
716
/* generating free blocks larger than that. */
717
word hb_descr; /* object descriptor for marking. See */
719
# ifdef MARK_BIT_PER_OBJ
720
unsigned32 hb_inv_sz; /* A good upper bound for 2**32/hb_sz. */
721
/* For large objects, we use */
723
# define LARGE_INV_SZ (1 << 16)
725
unsigned char hb_large_block;
726
short * hb_map; /* Essentially a table of remainders */
727
/* mod BYTES_TO_GRANULES(hb_sz), except */
728
/* for large blocks. See GC_obj_map. */
730
counter_t hb_n_marks; /* Number of set mark bits, excluding */
731
/* the one always set at the end. */
732
/* Currently it is concurrently */
733
/* updated and hence only approximate. */
734
/* But a zero value does guarantee that */
735
/* the block contains no marked */
737
/* Ensuring this property means that we */
738
/* never decrement it to zero during a */
739
/* collection, and hence the count may */
740
/* be one too high. Due to concurrent */
741
/* updates, an arbitrary number of */
742
/* increments, but not all of them (!) */
743
/* may be lost, hence it may in theory */
744
/* be much too low. */
745
/* The count may also be too high if */
746
/* multiple mark threads mark the */
747
/* same object due to a race. */
748
/* Without parallel marking, the count */
710
750
# ifdef USE_MARK_BYTES
712
752
char _hb_marks[MARK_BITS_SZ];
713
753
/* The i'th byte is 1 if the object */
714
/* starting at word 2i is marked, 0 o.w. */
754
/* starting at granule i or object i is */
756
/* The mark bit for the "one past the */
757
/* end" object is always set to avoid a */
758
/* special case test in the marker. */
715
759
word dummy; /* Force word alignment of mark bytes. */
716
760
} _mark_byte_union;
717
761
# define hb_marks _mark_byte_union._hb_marks
719
763
word hb_marks[MARK_BITS_SZ];
720
/* Bit i in the array refers to the */
721
/* object starting at the ith word (header */
722
/* INCLUDED) in the heap block. */
723
/* The lsb of word 0 is numbered 0. */
724
/* Unused bits are invalid, and are */
725
/* occasionally set, e.g for uncollectable */
727
764
# endif /* !USE_MARK_BYTES */
767
# define ANY_INDEX 23 /* "Random" mark bit index for assertions */
730
769
/* heap block body */
732
# define BODY_SZ (HBLKSIZE/sizeof(word))
771
# define HBLK_WORDS (HBLKSIZE/sizeof(word))
772
# define HBLK_GRANULES (HBLKSIZE/GRANULE_BYTES)
774
/* The number of objects in a block dedicated to a certain size. */
775
/* may erroneously yield zero (instead of one) for large objects. */
776
# define HBLK_OBJS(sz_in_bytes) (HBLKSIZE/(sz_in_bytes))
735
word hb_body[BODY_SZ];
779
char hb_body[HBLKSIZE];
738
# define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
782
# define HBLK_IS_FREE(hdr) (((hdr) -> hb_flags & FREE_BLK) != 0)
740
# define OBJ_SZ_TO_BLOCKS(sz) \
741
divHBLKSZ(WORDS_TO_BYTES(sz) + HBLKSIZE-1)
784
# define OBJ_SZ_TO_BLOCKS(sz) divHBLKSZ(sz + HBLKSIZE-1)
742
785
/* Size of block (in units of HBLKSIZE) needed to hold objects of */
743
/* given sz (in words). */
786
/* given sz (in bytes). */
745
788
/* Object free list link */
746
# define obj_link(p) (*(ptr_t *)(p))
789
# define obj_link(p) (*(void **)(p))
748
791
# define LOG_MAX_MARK_PROCS 6
749
792
# define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
828
873
/* Maximum number of bytes that were ever allocated in */
829
874
/* large object blocks. This is used to help decide when it */
830
875
/* is safe to split up a large block. */
831
word _words_allocd_before_gc;
876
word _bytes_allocd_before_gc;
832
877
/* Number of words allocated before this */
833
878
/* collection cycle. */
834
879
# ifndef SEPARATE_GLOBALS
836
881
/* Number of words allocated during this collection cycle */
839
/* Number of words wasted due to internal fragmentation */
840
/* in large objects, or due to dropping blacklisted */
841
/* blocks, since last gc. Approximate. */
842
word _words_finalized;
843
/* Approximate number of words in objects (and headers) */
884
/* Number of black-listed bytes dropped during GC cycle */
885
/* as a result of repeated scanning during allocation */
886
/* attempts. These are treated largely as allocated, */
887
/* even though they are not useful to the client. */
888
word _bytes_finalized;
889
/* Approximate number of bytes in objects (and headers) */
844
890
/* That became ready for finalization in the last */
845
891
/* collection. */
846
892
word _non_gc_bytes_at_gc;
847
893
/* Number of explicitly managed bytes of storage */
848
894
/* at last collection. */
850
/* Number of explicitly deallocated words of memory */
896
/* Number of explicitly deallocated bytes of memory */
851
897
/* since last collection. */
852
word _finalizer_mem_freed;
853
/* Words of memory explicitly deallocated while */
898
word _finalizer_bytes_freed;
899
/* Bytes of memory explicitly deallocated while */
854
900
/* finalizers were running. Used to approximate mem. */
855
901
/* explicitly deallocated by finalizers. */
856
902
ptr_t _scratch_end_ptr;
863
909
/* by DS_PROC mark descriptors. See gc_mark.h. */
865
911
# ifndef SEPARATE_GLOBALS
866
ptr_t _objfreelist[MAXOBJSZ+1];
912
void *_objfreelist[MAXOBJGRANULES+1];
867
913
/* free list for objects */
868
ptr_t _aobjfreelist[MAXOBJSZ+1];
914
void *_aobjfreelist[MAXOBJGRANULES+1];
869
915
/* free list for atomic objs */
872
ptr_t _uobjfreelist[MAXOBJSZ+1];
918
void *_uobjfreelist[MAXOBJGRANULES+1];
873
919
/* uncollectable but traced objs */
874
920
/* objects on this and auobjfreelist */
875
921
/* are always marked, except during */
876
922
/* garbage collections. */
877
923
# ifdef ATOMIC_UNCOLLECTABLE
878
ptr_t _auobjfreelist[MAXOBJSZ+1];
924
void *_auobjfreelist[MAXOBJGRANULES+1];
880
926
/* uncollectable but traced objs */
883
928
word _composite_in_use;
884
929
/* Number of words in accessible composite */
886
931
word _atomic_in_use;
887
932
/* Number of words in accessible atomic */
890
934
# ifdef USE_MUNMAP
891
935
word _unmapped_bytes;
894
unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
938
size_t _size_map[MAXOBJBYTES+1];
895
939
/* Number of words to allocate for a given allocation request in */
899
942
# ifdef STUBBORN_ALLOC
900
ptr_t _sobjfreelist[MAXOBJSZ+1];
943
ptr_t _sobjfreelist[MAXOBJGRANULES+1];
902
945
/* free list for immutable objects */
903
map_entry_type * _obj_map[MAXOBJSZ+1];
946
# ifdef MARK_BIT_PER_GRANULE
947
short * _obj_map[MAXOBJGRANULES+1];
904
948
/* If not NIL, then a pointer to a map of valid */
905
/* object addresses. _obj_map[sz][i] is j if the */
906
/* address block_start+i is a valid pointer */
907
/* to an object at block_start + */
908
/* WORDS_TO_BYTES(BYTES_TO_WORDS(i) - j) */
909
/* I.e. j is a word displacement from the */
910
/* object beginning. */
911
/* The entry is OBJ_INVALID if the corresponding */
912
/* address is not a valid pointer. It is */
913
/* OFFSET_TOO_BIG if the value j would be too */
914
/* large to fit in the entry. (Note that the */
915
/* size of these entries matters, both for */
916
/* space consumption and for cache utilization.) */
917
# define OFFSET_TOO_BIG 0xfe
918
# define OBJ_INVALID 0xff
919
# define MAP_ENTRY(map, bytes) (map)[bytes]
920
# define MAP_ENTRIES HBLKSIZE
921
# define MAP_SIZE MAP_ENTRIES
922
# define CPP_MAX_OFFSET (OFFSET_TOO_BIG - 1)
923
# define MAX_OFFSET ((word)CPP_MAX_OFFSET)
924
/* The following are used only if GC_all_interior_ptrs != 0 */
925
# define VALID_OFFSET_SZ \
926
(CPP_MAX_OFFSET > WORDS_TO_BYTES(CPP_MAXOBJSZ)? \
928
: WORDS_TO_BYTES(CPP_MAXOBJSZ)+1)
929
char _valid_offsets[VALID_OFFSET_SZ];
949
/* object addresses. */
950
/* _obj_map[sz_in_granules][i] is */
951
/* i % sz_in_granules. */
952
/* This is now used purely to replace a */
953
/* division in the marker by a table lookup. */
954
/* _obj_map[0] is used for large objects and */
955
/* contains all nonzero entries. This gets us */
956
/* out of the marker fast path without an extra */
958
# define MAP_LEN BYTES_TO_GRANULES(HBLKSIZE)
960
# define VALID_OFFSET_SZ HBLKSIZE
961
char _valid_offsets[VALID_OFFSET_SZ];
930
962
/* GC_valid_offsets[i] == TRUE ==> i */
931
963
/* is registered as a displacement. */
932
char _modws_valid_offsets[sizeof(word)];
964
char _modws_valid_offsets[sizeof(word)];
933
965
/* GC_valid_offsets[i] ==> */
934
966
/* GC_modws_valid_offsets[i%sizeof(word)] */
935
# define OFFSET_VALID(displ) \
936
(GC_all_interior_pointers || GC_valid_offsets[displ])
937
967
# ifdef STUBBORN_ALLOC
938
968
page_hash_table _changed_pages;
939
969
/* Stubborn object pages that were changes since last call to */
1013
1054
# define GC_changed_pages GC_arrays._changed_pages
1014
1055
# define GC_prev_changed_pages GC_arrays._prev_changed_pages
1016
# define GC_obj_map GC_arrays._obj_map
1057
# ifdef MARK_BIT_PER_GRANULE
1058
# define GC_obj_map GC_arrays._obj_map
1017
1060
# define GC_last_heap_addr GC_arrays._last_heap_addr
1018
1061
# define GC_prev_heap_addr GC_arrays._prev_heap_addr
1019
# define GC_words_wasted GC_arrays._words_wasted
1020
1062
# define GC_large_free_bytes GC_arrays._large_free_bytes
1021
1063
# define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
1022
1064
# define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes
1023
# define GC_words_finalized GC_arrays._words_finalized
1065
# define GC_bytes_dropped GC_arrays._bytes_dropped
1066
# define GC_bytes_finalized GC_arrays._bytes_finalized
1024
1067
# define GC_non_gc_bytes_at_gc GC_arrays._non_gc_bytes_at_gc
1025
# define GC_mem_freed GC_arrays._mem_freed
1026
# define GC_finalizer_mem_freed GC_arrays._finalizer_mem_freed
1068
# define GC_bytes_freed GC_arrays._bytes_freed
1069
# define GC_finalizer_bytes_freed GC_arrays._finalizer_bytes_freed
1027
1070
# define GC_scratch_end_ptr GC_arrays._scratch_end_ptr
1028
1071
# define GC_scratch_last_end_ptr GC_arrays._scratch_last_end_ptr
1029
1072
# define GC_mark_procs GC_arrays._mark_procs
1030
1073
# define GC_heapsize GC_arrays._heapsize
1031
1074
# define GC_max_heapsize GC_arrays._max_heapsize
1032
1075
# define GC_requested_heapsize GC_arrays._requested_heapsize
1033
# define GC_words_allocd_before_gc GC_arrays._words_allocd_before_gc
1076
# define GC_bytes_allocd_before_gc GC_arrays._bytes_allocd_before_gc
1034
1077
# define GC_heap_sects GC_arrays._heap_sects
1078
# ifdef USE_PROC_FOR_LIBRARIES
1079
# define GC_our_memory GC_arrays._our_memory
1035
1081
# define GC_last_stack GC_arrays._last_stack
1083
#define GC_trace_addr GC_arrays._trace_addr
1036
1085
# ifdef USE_MUNMAP
1037
1086
# define GC_unmapped_bytes GC_arrays._unmapped_bytes
1207
1255
/* accessed. */
1208
1256
#ifdef PARALLEL_MARK
1209
1257
# define OR_WORD(addr, bits) \
1212
old = *((volatile word *)addr); \
1213
} while (!GC_compare_and_exchange((addr), old, old | (bits))); \
1215
# define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1217
word my_bits = (bits); \
1219
old = *((volatile word *)addr); \
1220
if (old & my_bits) goto exit_label; \
1221
} while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
1258
{ AO_or((volatile AO_t *)(addr), (AO_t)bits); }
1224
1260
# define OR_WORD(addr, bits) *(addr) |= (bits)
1225
# define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1227
word old = *(addr); \
1228
word my_bits = (bits); \
1229
if (old & my_bits) goto exit_label; \
1230
*(addr) = (old | my_bits); \
1234
1263
/* Mark bit operations */
1237
* Retrieve, set, clear the mark bit corresponding
1238
* to the nth word in a given heap block.
1266
* Retrieve, set, clear the nth mark bit in a given heap block.
1240
* (Recall that bit n corresponds to object beginning at word n
1268
* (Recall that bit n corresponds to nth object or allocation granule
1241
1269
* relative to the beginning of the block, including unused words)
1244
1272
#ifdef USE_MARK_BYTES
1245
# define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n) >> 1])
1246
# define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 1
1247
# define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[(n)>>1]) = 0
1273
# define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n])
1274
# define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n]) = 1
1275
# define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n]) = 0
1248
1276
#else /* !USE_MARK_BYTES */
1249
1277
# define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
1250
1278
>> (modWORDSZ(n))) & (word)1)
1255
1283
&= ~((word)1 << modWORDSZ(n))
1256
1284
#endif /* !USE_MARK_BYTES */
1286
#ifdef MARK_BIT_PER_OBJ
1287
# define MARK_BIT_NO(offset, sz) (((unsigned)(offset))/(sz))
1288
/* Get the mark bit index corresponding to the given byte */
1289
/* offset and size (in bytes). */
1290
# define MARK_BIT_OFFSET(sz) 1
1291
/* Spacing between useful mark bits. */
1292
# define IF_PER_OBJ(x) x
1293
# define FINAL_MARK_BIT(sz) ((sz) > MAXOBJBYTES? 1 : HBLK_OBJS(sz))
1294
/* Position of final, always set, mark bit. */
1295
#else /* MARK_BIT_PER_GRANULE */
1296
# define MARK_BIT_NO(offset, sz) BYTES_TO_GRANULES((unsigned)(offset))
1297
# define MARK_BIT_OFFSET(sz) BYTES_TO_GRANULES(sz)
1298
# define IF_PER_OBJ(x)
1299
# define FINAL_MARK_BIT(sz) \
1300
((sz) > MAXOBJBYTES? MARK_BITS_PER_HBLK \
1301
: BYTES_TO_GRANULES(sz * HBLK_OBJS(sz)))
1258
1304
/* Important internal collector routines */
1260
ptr_t GC_approx_sp GC_PROTO((void));
1262
GC_bool GC_should_collect GC_PROTO((void));
1264
void GC_apply_to_all_blocks GC_PROTO(( \
1265
void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
1306
ptr_t GC_approx_sp(void);
1308
GC_bool GC_should_collect(void);
1310
void GC_apply_to_all_blocks(void (*fn) (struct hblk *h, word client_data),
1267
1312
/* Invoke fn(hbp, client_data) for each */
1268
1313
/* allocated heap block. */
1269
struct hblk * GC_next_used_block GC_PROTO((struct hblk * h));
1314
struct hblk * GC_next_used_block(struct hblk * h);
1270
1315
/* Return first in-use block >= h */
1271
struct hblk * GC_prev_block GC_PROTO((struct hblk * h));
1316
struct hblk * GC_prev_block(struct hblk * h);
1272
1317
/* Return last block <= h. Returned block */
1273
1318
/* is managed by GC, but may or may not be in */
1275
void GC_mark_init GC_PROTO((void));
1276
void GC_clear_marks GC_PROTO((void)); /* Clear mark bits for all heap objects. */
1277
void GC_invalidate_mark_state GC_PROTO((void));
1320
void GC_mark_init(void);
1321
void GC_clear_marks(void); /* Clear mark bits for all heap objects. */
1322
void GC_invalidate_mark_state(void);
1278
1323
/* Tell the marker that marked */
1279
1324
/* objects may point to unmarked */
1280
1325
/* ones, and roots may point to */
1281
1326
/* unmarked objects. */
1282
1327
/* Reset mark stack. */
1283
GC_bool GC_mark_stack_empty GC_PROTO((void));
1284
GC_bool GC_mark_some GC_PROTO((ptr_t cold_gc_frame));
1328
GC_bool GC_mark_stack_empty(void);
1329
GC_bool GC_mark_some(ptr_t cold_gc_frame);
1285
1330
/* Perform about one pages worth of marking */
1286
1331
/* work of whatever kind is needed. Returns */
1287
1332
/* quickly if no collection is in progress. */
1288
1333
/* Return TRUE if mark phase finished. */
1289
void GC_initiate_gc GC_PROTO((void));
1334
void GC_initiate_gc(void);
1290
1335
/* initiate collection. */
1291
1336
/* If the mark state is invalid, this */
1292
1337
/* becomes full colleection. Otherwise */
1293
1338
/* it's partial. */
1294
void GC_push_all GC_PROTO((ptr_t bottom, ptr_t top));
1339
void GC_push_all(ptr_t bottom, ptr_t top);
1295
1340
/* Push everything in a range */
1296
1341
/* onto mark stack. */
1297
void GC_push_selected GC_PROTO(( \
1300
int (*dirty_fn) GC_PROTO((struct hblk *h)), \
1301
void (*push_fn) GC_PROTO((ptr_t bottom, ptr_t top)) ));
1342
void GC_push_selected(ptr_t bottom, ptr_t top,
1343
int (*dirty_fn) (struct hblk *h),
1344
void (*push_fn) (ptr_t bottom, ptr_t top) );
1302
1345
/* Push all pages h in [b,t) s.t. */
1303
1346
/* select_fn(h) != 0 onto mark stack. */
1304
1347
#ifndef SMALL_CONFIG
1305
void GC_push_conditional GC_PROTO((ptr_t b, ptr_t t, GC_bool all));
1348
void GC_push_conditional (ptr_t b, ptr_t t, GC_bool all);
1307
1350
# define GC_push_conditional(b, t, all) GC_push_all(b, t)
1309
1352
/* Do either of the above, depending */
1310
1353
/* on the third arg. */
1311
void GC_push_all_stack GC_PROTO((ptr_t b, ptr_t t));
1354
void GC_push_all_stack (ptr_t b, ptr_t t);
1312
1355
/* As above, but consider */
1313
1356
/* interior pointers as valid */
1314
void GC_push_all_eager GC_PROTO((ptr_t b, ptr_t t));
1357
void GC_push_all_eager (ptr_t b, ptr_t t);
1315
1358
/* Same as GC_push_all_stack, but */
1316
1359
/* ensures that stack is scanned */
1317
1360
/* immediately, not just scheduled */
1318
1361
/* for scanning. */
1319
1362
#ifndef THREADS
1320
void GC_push_all_stack_partially_eager GC_PROTO(( \
1321
ptr_t bottom, ptr_t top, ptr_t cold_gc_frame ));
1363
void GC_push_all_stack_partially_eager(ptr_t bottom, ptr_t top,
1364
ptr_t cold_gc_frame);
1322
1365
/* Similar to GC_push_all_eager, but only the */
1323
1366
/* part hotter than cold_gc_frame is scanned */
1324
1367
/* immediately. Needed to ensure that callee- */
1330
1373
/* stacks are scheduled for scanning in *GC_push_other_roots, which */
1331
1374
/* is thread-package-specific. */
1333
void GC_push_current_stack GC_PROTO((ptr_t cold_gc_frame));
1376
void GC_push_current_stack(ptr_t cold_gc_frame, void *context);
1334
1377
/* Push enough of the current stack eagerly to */
1335
1378
/* ensure that callee-save registers saved in */
1336
1379
/* GC frames are scanned. */
1337
1380
/* In the non-threads case, schedule entire */
1338
1381
/* stack for scanning. */
1339
void GC_push_roots GC_PROTO((GC_bool all, ptr_t cold_gc_frame));
1382
/* The second argument is a pointer to the */
1383
/* (possibly null) thread context, for */
1384
/* (currently hypothetical) more precise */
1385
/* stack scanning. */
1386
void GC_push_roots(GC_bool all, ptr_t cold_gc_frame);
1340
1387
/* Push all or dirty roots. */
1341
extern void (*GC_push_other_roots) GC_PROTO((void));
1388
extern void (*GC_push_other_roots)(void);
1342
1389
/* Push system or application specific roots */
1343
1390
/* onto the mark stack. In some environments */
1344
1391
/* (e.g. threads environments) this is */
1345
1392
/* predfined to be non-zero. A client supplied */
1346
1393
/* replacement should also call the original */
1347
1394
/* function. */
1348
extern void GC_push_gc_structures GC_PROTO((void));
1395
extern void GC_push_gc_structures(void);
1349
1396
/* Push GC internal roots. These are normally */
1350
1397
/* included in the static data segment, and */
1351
1398
/* Thus implicitly pushed. But we must do this */
1352
1399
/* explicitly if normal root processing is */
1353
1400
/* disabled. Calls the following: */
1354
extern void GC_push_finalizer_structures GC_PROTO((void));
1355
extern void GC_push_stubborn_structures GC_PROTO((void));
1401
extern void GC_push_finalizer_structures(void);
1402
extern void GC_push_stubborn_structures (void);
1356
1403
# ifdef THREADS
1357
extern void GC_push_thread_structures GC_PROTO((void));
1404
extern void GC_push_thread_structures (void);
1359
extern void (*GC_start_call_back) GC_PROTO((void));
1406
extern void (*GC_push_typed_structures) (void);
1407
/* A pointer such that we can avoid linking in */
1408
/* the typed allocation support if unused. */
1409
extern void (*GC_start_call_back) (void);
1360
1410
/* Called at start of full collections. */
1361
1411
/* Not called if 0. Called with allocation */
1362
1412
/* lock held. */
1363
1413
/* 0 by default. */
1364
# if defined(USE_GENERIC_PUSH_REGS)
1365
void GC_generic_push_regs GC_PROTO((ptr_t cold_gc_frame));
1367
void GC_push_regs GC_PROTO((void));
1414
void GC_push_regs_and_stack(ptr_t cold_gc_frame);
1416
void GC_push_regs(void);
1418
void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),
1369
1421
# if defined(SPARC) || defined(IA64)
1370
1422
/* Cause all stacked registers to be saved in memory. Return a */
1371
1423
/* pointer to the top of the corresponding memory stack. */
1372
word GC_save_regs_in_stack GC_PROTO((void));
1424
ptr_t GC_save_regs_in_stack(void);
1374
1426
/* Push register contents onto mark stack. */
1375
1427
/* If NURSERY is defined, the default push */
1392
1444
# if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS)
1393
void GC_mark_and_push_stack GC_PROTO((word p, ptr_t source));
1445
void GC_mark_and_push_stack(ptr_t p, ptr_t source);
1394
1446
/* Ditto, omits plausibility test */
1396
void GC_mark_and_push_stack GC_PROTO((word p));
1448
void GC_mark_and_push_stack(ptr_t p);
1398
void GC_push_marked GC_PROTO((struct hblk * h, hdr * hhdr));
1450
void GC_push_marked(struct hblk * h, hdr * hhdr);
1399
1451
/* Push contents of all marked objects in h onto */
1400
1452
/* mark stack. */
1401
1453
#ifdef SMALL_CONFIG
1402
1454
# define GC_push_next_marked_dirty(h) GC_push_next_marked(h)
1404
struct hblk * GC_push_next_marked_dirty GC_PROTO((struct hblk * h));
1456
struct hblk * GC_push_next_marked_dirty(struct hblk * h);
1405
1457
/* Invoke GC_push_marked on next dirty block above h. */
1406
1458
/* Return a pointer just past the end of this block. */
1407
1459
#endif /* !SMALL_CONFIG */
1408
struct hblk * GC_push_next_marked GC_PROTO((struct hblk * h));
1460
struct hblk * GC_push_next_marked(struct hblk * h);
1409
1461
/* Ditto, but also mark from clean pages. */
1410
struct hblk * GC_push_next_marked_uncollectable GC_PROTO((struct hblk * h));
1462
struct hblk * GC_push_next_marked_uncollectable(struct hblk * h);
1411
1463
/* Ditto, but mark only from uncollectable pages. */
1412
GC_bool GC_stopped_mark GC_PROTO((GC_stop_func stop_func));
1464
GC_bool GC_stopped_mark(GC_stop_func stop_func);
1413
1465
/* Stop world and mark from all roots */
1414
1466
/* and rescuers. */
1415
void GC_clear_hdr_marks GC_PROTO((hdr * hhdr));
1467
void GC_clear_hdr_marks(hdr * hhdr);
1416
1468
/* Clear the mark bits in a header */
1417
void GC_set_hdr_marks GC_PROTO((hdr * hhdr));
1469
void GC_set_hdr_marks(hdr * hhdr);
1418
1470
/* Set the mark bits in a header */
1419
void GC_set_fl_marks GC_PROTO((ptr_t p));
1471
void GC_set_fl_marks(ptr_t p);
1420
1472
/* Set all mark bits associated with */
1421
1473
/* a free list. */
1422
void GC_add_roots_inner GC_PROTO((char * b, char * e, GC_bool tmp));
1423
void GC_remove_roots_inner GC_PROTO((char * b, char * e));
1424
GC_bool GC_is_static_root GC_PROTO((ptr_t p));
1474
#ifdef GC_ASSERTIONS
1475
void GC_check_fl_marks(ptr_t p);
1476
/* Check that all mark bits */
1477
/* associated with a free list are */
1478
/* set. Abort if not. */
1480
void GC_add_roots_inner(ptr_t b, ptr_t e, GC_bool tmp);
1481
void GC_remove_roots_inner(ptr_t b, ptr_t e);
1482
GC_bool GC_is_static_root(ptr_t p);
1425
1483
/* Is the address p in one of the registered static */
1426
1484
/* root sections? */
1427
1485
# if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
1428
GC_bool GC_is_tmp_root GC_PROTO((ptr_t p));
1486
GC_bool GC_is_tmp_root(ptr_t p);
1429
1487
/* Is the address p in one of the temporary static */
1430
1488
/* root sections? */
1432
void GC_register_dynamic_libraries GC_PROTO((void));
1490
void GC_register_dynamic_libraries(void);
1433
1491
/* Add dynamic library data sections to the root set. */
1492
void GC_cond_register_dynamic_libraries(void);
1493
/* Remove and reregister dynamic libraries if we're */
1494
/* configured to do that at each GC. */
1435
GC_bool GC_register_main_static_data GC_PROTO((void));
1496
GC_bool GC_register_main_static_data(void);
1436
1497
/* We need to register the main data segment. Returns */
1437
1498
/* TRUE unless this is done implicitly as part of */
1438
1499
/* dynamic library registration. */
1440
1501
/* Machine dependent startup routines */
1441
ptr_t GC_get_stack_base GC_PROTO((void)); /* Cold end of stack */
1502
ptr_t GC_get_main_stack_base(void); /* Cold end of stack */
1443
ptr_t GC_get_register_stack_base GC_PROTO((void));
1504
ptr_t GC_get_register_stack_base(void);
1444
1505
/* Cold end of register stack. */
1446
void GC_register_data_segments GC_PROTO((void));
1507
void GC_register_data_segments(void);
1448
1509
/* Black listing: */
1449
void GC_bl_init GC_PROTO((void));
1510
void GC_bl_init(void);
1450
1511
# ifdef PRINT_BLACK_LIST
1451
void GC_add_to_black_list_normal GC_PROTO((word p, ptr_t source));
1512
void GC_add_to_black_list_normal(word p, ptr_t source);
1452
1513
/* Register bits as a possible future false */
1453
1514
/* reference from the heap or static data */
1454
1515
# define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1455
1516
if (GC_all_interior_pointers) { \
1456
GC_add_to_black_list_stack(bits, (ptr_t)(source)); \
1517
GC_add_to_black_list_stack((word)(bits), (source)); \
1458
GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
1519
GC_add_to_black_list_normal((word)(bits), (source)); \
1461
void GC_add_to_black_list_normal GC_PROTO((word p));
1522
void GC_add_to_black_list_normal(word p);
1462
1523
# define GC_ADD_TO_BLACK_LIST_NORMAL(bits, source) \
1463
1524
if (GC_all_interior_pointers) { \
1464
GC_add_to_black_list_stack(bits); \
1525
GC_add_to_black_list_stack((word)(bits)); \
1466
GC_add_to_black_list_normal(bits); \
1527
GC_add_to_black_list_normal((word)(bits)); \
1470
1531
# ifdef PRINT_BLACK_LIST
1471
void GC_add_to_black_list_stack GC_PROTO((word p, ptr_t source));
1532
void GC_add_to_black_list_stack(word p, ptr_t source);
1533
# define GC_ADD_TO_BLACK_LIST_STACK(bits, source) \
1534
GC_add_to_black_list_stack((word)(bits), (source))
1473
void GC_add_to_black_list_stack GC_PROTO((word p));
1536
void GC_add_to_black_list_stack(word p);
1537
# define GC_ADD_TO_BLACK_LIST_STACK(bits, source) \
1538
GC_add_to_black_list_stack((word)(bits))
1475
struct hblk * GC_is_black_listed GC_PROTO((struct hblk * h, word len));
1540
struct hblk * GC_is_black_listed(struct hblk * h, word len);
1476
1541
/* If there are likely to be false references */
1477
1542
/* to a block starting at h of the indicated */
1478
1543
/* length, then return the next plausible */
1479
1544
/* starting location for h that might avoid */
1480
1545
/* these false references. */
1481
void GC_promote_black_lists GC_PROTO((void));
1546
void GC_promote_black_lists(void);
1482
1547
/* Declare an end to a black listing phase. */
1483
void GC_unpromote_black_lists GC_PROTO((void));
1548
void GC_unpromote_black_lists(void);
1484
1549
/* Approximately undo the effect of the above. */
1485
1550
/* This actually loses some information, but */
1486
1551
/* only in a reasonably safe way. */
1487
word GC_number_stack_black_listed GC_PROTO(( \
1488
struct hblk *start, struct hblk *endp1));
1552
word GC_number_stack_black_listed(struct hblk *start, struct hblk *endp1);
1489
1553
/* Return the number of (stack) blacklisted */
1490
1554
/* blocks in the range for statistical */
1491
1555
/* purposes. */
1493
ptr_t GC_scratch_alloc GC_PROTO((word bytes));
1557
ptr_t GC_scratch_alloc(size_t bytes);
1494
1558
/* GC internal memory allocation for */
1495
1559
/* small objects. Deallocation is not */
1496
1560
/* possible. */
1498
1562
/* Heap block layout maps: */
1499
void GC_invalidate_map GC_PROTO((hdr * hhdr));
1500
/* Remove the object map associated */
1501
/* with the block. This identifies */
1502
/* the block as invalid to the mark */
1504
GC_bool GC_add_map_entry GC_PROTO((word sz));
1563
GC_bool GC_add_map_entry(size_t sz);
1505
1564
/* Add a heap block map for objects of */
1506
1565
/* size sz to obj_map. */
1507
1566
/* Return FALSE on failure. */
1508
void GC_register_displacement_inner GC_PROTO((word offset));
1567
void GC_register_displacement_inner(size_t offset);
1509
1568
/* Version of GC_register_displacement */
1510
1569
/* that assumes lock is already held */
1511
1570
/* and signals are already disabled. */
1572
void GC_initialize_offsets(void);
1573
/* Initialize GC_valid_offsets, */
1574
/* depending on current */
1575
/* GC_all_interior_pointers settings. */
1513
1577
/* hblk allocation: */
1514
void GC_new_hblk GC_PROTO((word size_in_words, int kind));
1578
void GC_new_hblk(size_t size_in_granules, int kind);
1515
1579
/* Allocate a new heap block, and build */
1516
1580
/* a free list in it. */
1518
ptr_t GC_build_fl GC_PROTO((struct hblk *h, word sz,
1519
GC_bool clear, ptr_t list));
1582
ptr_t GC_build_fl(struct hblk *h, size_t words, GC_bool clear, ptr_t list);
1520
1583
/* Build a free list for objects of */
1521
1584
/* size sz in block h. Append list to */
1522
1585
/* end of the free lists. Possibly */
1524
1587
/* called by GC_new_hblk, but also */
1525
1588
/* called explicitly without GC lock. */
1527
struct hblk * GC_allochblk GC_PROTO(( \
1528
word size_in_words, int kind, unsigned flags));
1590
struct hblk * GC_allochblk (size_t size_in_bytes, int kind,
1529
1592
/* Allocate a heap block, inform */
1530
1593
/* the marker that block is valid */
1531
1594
/* for objects of indicated size. */
1533
ptr_t GC_alloc_large GC_PROTO((word lw, int k, unsigned flags));
1534
/* Allocate a large block of size lw words. */
1596
ptr_t GC_alloc_large (size_t lb, int k, unsigned flags);
1597
/* Allocate a large block of size lb bytes. */
1535
1598
/* The block is not cleared. */
1536
1599
/* Flags is 0 or IGNORE_OFF_PAGE. */
1537
1600
/* Calls GC_allchblk to do the actual */
1538
1601
/* allocation, but also triggers GC and/or */
1539
1602
/* heap expansion as appropriate. */
1540
/* Does not update GC_words_allocd, but does */
1603
/* Does not update GC_bytes_allocd, but does */
1541
1604
/* other accounting. */
1543
ptr_t GC_alloc_large_and_clear GC_PROTO((word lw, int k, unsigned flags));
1606
ptr_t GC_alloc_large_and_clear(size_t lb, int k, unsigned flags);
1544
1607
/* As above, but clear block if appropriate */
1545
1608
/* for kind k. */
1547
void GC_freehblk GC_PROTO((struct hblk * p));
1610
void GC_freehblk(struct hblk * p);
1548
1611
/* Deallocate a heap block and mark it */
1549
1612
/* as invalid. */
1552
void GC_init_inner GC_PROTO((void));
1553
GC_bool GC_expand_hp_inner GC_PROTO((word n));
1554
void GC_start_reclaim GC_PROTO((int abort_if_found));
1615
void GC_init_inner(void);
1616
GC_bool GC_expand_hp_inner(word n);
1617
void GC_start_reclaim(int abort_if_found);
1555
1618
/* Restore unmarked objects to free */
1556
1619
/* lists, or (if abort_if_found is */
1557
1620
/* TRUE) report them. */
1558
1621
/* Sweeping of small object pages is */
1559
1622
/* largely deferred. */
1560
void GC_continue_reclaim GC_PROTO((word sz, int kind));
1623
void GC_continue_reclaim(size_t sz, int kind);
1561
1624
/* Sweep pages of the given size and */
1562
1625
/* kind, as long as possible, and */
1563
1626
/* as long as the corr. free list is */
1565
void GC_reclaim_or_delete_all GC_PROTO((void));
1627
/* empty. Sz is in granules. */
1628
void GC_reclaim_or_delete_all(void);
1566
1629
/* Arrange for all reclaim lists to be */
1567
1630
/* empty. Judiciously choose between */
1568
1631
/* sweeping and discarding each page. */
1569
GC_bool GC_reclaim_all GC_PROTO((GC_stop_func stop_func, GC_bool ignore_old));
1632
GC_bool GC_reclaim_all(GC_stop_func stop_func, GC_bool ignore_old);
1570
1633
/* Reclaim all blocks. Abort (in a */
1571
1634
/* consistent state) if f returns TRUE. */
1572
GC_bool GC_block_empty GC_PROTO((hdr * hhdr));
1635
ptr_t GC_reclaim_generic(struct hblk * hbp, hdr *hhdr, size_t sz,
1636
GC_bool init, ptr_t list, signed_word *count);
1637
/* Rebuild free list in hbp with */
1638
/* header hhdr, with objects of size sz */
1639
/* bytes. Add list to the end of the */
1640
/* free list. Add the number of */
1641
/* reclaimed bytes to *count. */
1642
GC_bool GC_block_empty(hdr * hhdr);
1573
1643
/* Block completely unmarked? */
1574
GC_bool GC_never_stop_func GC_PROTO((void));
1644
GC_bool GC_never_stop_func(void);
1575
1645
/* Returns FALSE. */
1576
GC_bool GC_try_to_collect_inner GC_PROTO((GC_stop_func f));
1646
GC_bool GC_try_to_collect_inner(GC_stop_func f);
1578
1648
/* Collect; caller must have acquired */
1579
1649
/* lock and disabled signals. */
1617
1686
/* communicate object layout info */
1618
1687
/* to the collector. */
1619
1688
/* The actual decl is in gc_mark.h. */
1620
ptr_t GC_generic_malloc_ignore_off_page GC_PROTO((size_t b, int k));
1689
void * GC_generic_malloc_ignore_off_page(size_t b, int k);
1621
1690
/* As above, but pointers past the */
1622
1691
/* first page of the resulting object */
1623
1692
/* are ignored. */
1624
ptr_t GC_generic_malloc_inner GC_PROTO((word lb, int k));
1693
void * GC_generic_malloc_inner(size_t lb, int k);
1625
1694
/* Ditto, but I already hold lock, etc. */
1626
ptr_t GC_generic_malloc_words_small_inner GC_PROTO((word lw, int k));
1627
/* Analogous to the above, but assumes */
1628
/* a small object size, and bypasses */
1629
/* MERGE_SIZES mechanism. */
1630
ptr_t GC_generic_malloc_words_small GC_PROTO((size_t lw, int k));
1631
/* As above, but size in units of words */
1632
/* Bypasses MERGE_SIZES. Assumes */
1633
/* words <= MAXOBJSZ. */
1634
ptr_t GC_generic_malloc_inner_ignore_off_page GC_PROTO((size_t lb, int k));
1695
void * GC_generic_malloc_inner_ignore_off_page(size_t lb, int k);
1635
1696
/* Allocate an object, where */
1636
1697
/* the client guarantees that there */
1637
1698
/* will always be a pointer to the */
1638
1699
/* beginning of the object while the */
1639
1700
/* object is live. */
1640
ptr_t GC_allocobj GC_PROTO((word sz, int kind));
1701
void GC_generic_malloc_many(size_t lb, int k, void **result);
1702
/* Store a pointer to a list of newly */
1703
/* allocated objects of kind k and size */
1704
/* lb in *result. */
1705
/* Caler must make sure that *result is */
1706
/* traced even if objects are ptrfree. */
1707
ptr_t GC_allocobj(size_t sz, int kind);
1641
1708
/* Make the indicated */
1642
1709
/* free list nonempty, and return its */
1645
void GC_free_inner(GC_PTR p);
1710
/* head. Sz is in granules. */
1712
/* Allocation routines that bypass the thread local cache. */
1713
/* Used internally. */
1714
#ifdef THREAD_LOCAL_ALLOC
1715
void * GC_core_malloc(size_t);
1716
void * GC_core_malloc_atomic(size_t);
1717
# ifdef GC_GCJ_SUPPORT
1718
void *GC_core_gcj_malloc(size_t, void *);
1720
#endif /* THREAD_LOCAL_ALLOC */
1722
void GC_free_inner(void * p);
1723
void GC_debug_free_inner(void * p);
1647
void GC_init_headers GC_PROTO((void));
1648
struct hblkhdr * GC_install_header GC_PROTO((struct hblk *h));
1725
void GC_init_headers(void);
1726
struct hblkhdr * GC_install_header(struct hblk *h);
1649
1727
/* Install a header for block h. */
1650
1728
/* Return 0 on failure, or the header */
1651
1729
/* otherwise. */
1652
GC_bool GC_install_counts GC_PROTO((struct hblk * h, word sz));
1730
GC_bool GC_install_counts(struct hblk * h, size_t sz);
1653
1731
/* Set up forwarding counts for block */
1654
1732
/* h of size sz. */
1655
1733
/* Return FALSE on failure. */
1656
void GC_remove_header GC_PROTO((struct hblk * h));
1734
void GC_remove_header(struct hblk * h);
1657
1735
/* Remove the header for block h. */
1658
void GC_remove_counts GC_PROTO((struct hblk * h, word sz));
1736
void GC_remove_counts(struct hblk * h, size_t sz);
1659
1737
/* Remove forwarding counts for h. */
1660
hdr * GC_find_header GC_PROTO((ptr_t h)); /* Debugging only. */
1738
hdr * GC_find_header(ptr_t h); /* Debugging only. */
1662
void GC_finalize GC_PROTO((void));
1740
void GC_finalize(void);
1663
1741
/* Perform all indicated finalization actions */
1664
1742
/* on unmarked objects. */
1665
1743
/* Unreachable finalizable objects are enqueued */
1666
1744
/* for processing by GC_invoke_finalizers. */
1667
1745
/* Invoked with lock. */
1669
void GC_notify_or_invoke_finalizers GC_PROTO((void));
1747
void GC_notify_or_invoke_finalizers(void);
1670
1748
/* If GC_finalize_on_demand is not set, invoke */
1671
1749
/* eligible finalizers. Otherwise: */
1672
1750
/* Call *GC_finalizer_notifier if there are */
1673
1751
/* finalizers to be run, and we haven't called */
1674
1752
/* this procedure yet this GC cycle. */
1676
GC_API GC_PTR GC_make_closure GC_PROTO((GC_finalization_proc fn, GC_PTR data));
1677
GC_API void GC_debug_invoke_finalizer GC_PROTO((GC_PTR obj, GC_PTR data));
1754
GC_API void * GC_make_closure(GC_finalization_proc fn, void * data);
1755
GC_API void GC_debug_invoke_finalizer(void * obj, void * data);
1678
1756
/* Auxiliary fns to make finalization work */
1679
1757
/* correctly with displaced pointers introduced */
1680
1758
/* by the debugging allocators. */
1682
void GC_add_to_heap GC_PROTO((struct hblk *p, word bytes));
1760
void GC_add_to_heap(struct hblk *p, size_t bytes);
1683
1761
/* Add a HBLKSIZE aligned chunk to the heap. */
1763
#ifdef USE_PROC_FOR_LIBRARIES
1764
void GC_add_to_our_memory(ptr_t p, size_t bytes);
1765
/* Add a chunk to GC_our_memory. */
1766
/* If p == 0, do nothing. */
1768
# define GC_add_to_our_memory(p, bytes)
1685
void GC_print_obj GC_PROTO((ptr_t p));
1771
void GC_print_obj(ptr_t p);
1686
1772
/* P points to somewhere inside an object with */
1687
1773
/* debugging info. Print a human readable */
1688
1774
/* description of the object to stderr. */
1689
extern void (*GC_check_heap) GC_PROTO((void));
1775
extern void (*GC_check_heap)(void);
1690
1776
/* Check that all objects in the heap with */
1691
1777
/* debugging info are intact. */
1692
1778
/* Add any that are not to GC_smashed list. */
1693
extern void (*GC_print_all_smashed) GC_PROTO((void));
1779
extern void (*GC_print_all_smashed) (void);
1694
1780
/* Print GC_smashed if it's not empty. */
1695
1781
/* Clear GC_smashed list. */
1696
extern void GC_print_all_errors GC_PROTO((void));
1782
extern void GC_print_all_errors (void);
1697
1783
/* Print smashed and leaked objects, if any. */
1698
1784
/* Clear the lists of such objects. */
1699
extern void (*GC_print_heap_obj) GC_PROTO((ptr_t p));
1785
extern void (*GC_print_heap_obj) (ptr_t p);
1700
1786
/* If possible print s followed by a more */
1701
1787
/* detailed description of the object */
1702
1788
/* referred to by p. */
1703
1789
#if defined(LINUX) && defined(__ELF__) && !defined(SMALL_CONFIG)
1704
void GC_print_address_map GC_PROTO((void));
1790
void GC_print_address_map (void);
1705
1791
/* Print an address map of the process. */
1708
1794
extern GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
1709
1795
/* Call error printing routine */
1710
1796
/* occasionally. */
1711
extern GC_bool GC_print_stats; /* Produce at least some logging output */
1712
/* Set from environment variable. */
1798
#ifndef SMALL_CONFIG
1799
extern int GC_print_stats; /* Nonzero generates basic GC log. */
1800
/* VERBOSE generates add'l messages. */
1802
# define GC_print_stats 0
1803
/* Will this keep the message character strings from the executable? */
1714
1808
#ifndef NO_DEBUGGING
1715
1809
extern GC_bool GC_dump_regularly; /* Generate regular debugging dumps. */
1758
1852
#ifdef USE_MUNMAP
1759
1853
void GC_unmap_old(void);
1760
1854
void GC_merge_unmapped(void);
1761
void GC_unmap(ptr_t start, word bytes);
1762
void GC_remap(ptr_t start, word bytes);
1763
void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2);
1855
void GC_unmap(ptr_t start, size_t bytes);
1856
void GC_remap(ptr_t start, size_t bytes);
1857
void GC_unmap_gap(ptr_t start1, size_t bytes1, ptr_t start2, size_t bytes2);
1766
1860
/* Virtual dirty bit implementation: */
1767
1861
/* Each implementation exports the following: */
1768
void GC_read_dirty GC_PROTO((void));
1862
void GC_read_dirty(void);
1769
1863
/* Retrieve dirty bits. */
1770
GC_bool GC_page_was_dirty GC_PROTO((struct hblk *h));
1864
GC_bool GC_page_was_dirty(struct hblk *h);
1771
1865
/* Read retrieved dirty bits. */
1772
GC_bool GC_page_was_ever_dirty GC_PROTO((struct hblk *h));
1866
GC_bool GC_page_was_ever_dirty(struct hblk *h);
1773
1867
/* Could the page contain valid heap pointers? */
1774
void GC_is_fresh GC_PROTO((struct hblk *h, word n));
1775
/* Assert the region currently contains no */
1776
/* valid pointers. */
1777
void GC_remove_protection GC_PROTO((struct hblk *h, word nblocks,
1778
GC_bool pointerfree));
1868
void GC_remove_protection(struct hblk *h, word nblocks,
1869
GC_bool pointerfree);
1779
1870
/* h is about to be writteni or allocated. Ensure */
1780
1871
/* that it's not write protected by the virtual */
1781
1872
/* dirty bit implementation. */
1783
void GC_dirty_init GC_PROTO((void));
1874
void GC_dirty_init(void);
1785
1876
/* Slow/general mark bit manipulation: */
1786
GC_API GC_bool GC_is_marked GC_PROTO((ptr_t p));
1787
void GC_clear_mark_bit GC_PROTO((ptr_t p));
1788
void GC_set_mark_bit GC_PROTO((ptr_t p));
1877
GC_API GC_bool GC_is_marked(ptr_t p);
1878
void GC_clear_mark_bit(ptr_t p);
1879
void GC_set_mark_bit(ptr_t p);
1790
1881
/* Stubborn objects: */
1791
void GC_read_changed GC_PROTO((void)); /* Analogous to GC_read_dirty */
1792
GC_bool GC_page_was_changed GC_PROTO((struct hblk * h));
1882
void GC_read_changed(void); /* Analogous to GC_read_dirty */
1883
GC_bool GC_page_was_changed(struct hblk * h);
1793
1884
/* Analogous to GC_page_was_dirty */
1794
void GC_clean_changing_list GC_PROTO((void));
1885
void GC_clean_changing_list(void);
1795
1886
/* Collect obsolete changing list entries */
1796
void GC_stubborn_init GC_PROTO((void));
1887
void GC_stubborn_init(void);
1798
1889
/* Debugging print routines: */
1799
void GC_print_block_list GC_PROTO((void));
1800
void GC_print_hblkfreelist GC_PROTO((void));
1801
void GC_print_heap_sects GC_PROTO((void));
1802
void GC_print_static_roots GC_PROTO((void));
1803
void GC_print_finalization_stats GC_PROTO((void));
1804
void GC_dump GC_PROTO((void));
1890
void GC_print_block_list(void);
1891
void GC_print_hblkfreelist(void);
1892
void GC_print_heap_sects(void);
1893
void GC_print_static_roots(void);
1894
void GC_print_finalization_stats(void);
1895
/* void GC_dump(void); - declared in gc.h */
1806
1897
#ifdef KEEP_BACK_PTRS
1807
1898
void GC_store_back_pointer(ptr_t source, ptr_t dest);
1827
void GC_noop1 GC_PROTO((word));
1918
void GC_noop1(word);
1829
1920
/* Logging and diagnostic output: */
1830
GC_API void GC_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1921
GC_API void GC_printf (const char * format, ...);
1831
1922
/* A version of printf that doesn't allocate, */
1832
/* is restricted to long arguments, and */
1833
/* (unfortunately) doesn't use varargs for */
1834
/* portability. Restricted to 6 args and */
1835
1923
/* 1K total output length. */
1836
1924
/* (We use sprintf. Hopefully that doesn't */
1837
1925
/* allocate for long arguments.) */
1838
# define GC_printf0(f) GC_printf(f, 0l, 0l, 0l, 0l, 0l, 0l)
1839
# define GC_printf1(f,a) GC_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1840
# define GC_printf2(f,a,b) GC_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1841
# define GC_printf3(f,a,b,c) GC_printf(f, (long)a, (long)b, (long)c, 0l, 0l, 0l)
1842
# define GC_printf4(f,a,b,c,d) GC_printf(f, (long)a, (long)b, (long)c, \
1844
# define GC_printf5(f,a,b,c,d,e) GC_printf(f, (long)a, (long)b, (long)c, \
1845
(long)d, (long)e, 0l)
1846
# define GC_printf6(f,a,b,c,d,e,g) GC_printf(f, (long)a, (long)b, (long)c, \
1847
(long)d, (long)e, (long)g)
1849
GC_API void GC_err_printf GC_PROTO((GC_CONST char * format, long, long, long, long, long, long));
1850
# define GC_err_printf0(f) GC_err_puts(f)
1851
# define GC_err_printf1(f,a) GC_err_printf(f, (long)a, 0l, 0l, 0l, 0l, 0l)
1852
# define GC_err_printf2(f,a,b) GC_err_printf(f, (long)a, (long)b, 0l, 0l, 0l, 0l)
1853
# define GC_err_printf3(f,a,b,c) GC_err_printf(f, (long)a, (long)b, (long)c, \
1855
# define GC_err_printf4(f,a,b,c,d) GC_err_printf(f, (long)a, (long)b, \
1856
(long)c, (long)d, 0l, 0l)
1857
# define GC_err_printf5(f,a,b,c,d,e) GC_err_printf(f, (long)a, (long)b, \
1860
# define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
1863
/* Ditto, writes to stderr. */
1865
void GC_err_puts GC_PROTO((GC_CONST char *s));
1926
GC_API void GC_err_printf(const char * format, ...);
1927
GC_API void GC_log_printf(const char * format, ...);
1928
void GC_err_puts(const char *s);
1866
1929
/* Write s to stderr, don't buffer, don't add */
1867
1930
/* newlines, don't ... */
1869
1932
#if defined(LINUX) && !defined(SMALL_CONFIG)
1870
void GC_err_write GC_PROTO((GC_CONST char *buf, size_t len));
1933
void GC_err_write(const char *buf, size_t len);
1871
1934
/* Write buf to stderr, don't buffer, don't add */
1872
1935
/* newlines, don't ... */
1956
2019
# endif /* !SIG_SUSPEND */
2023
/* Some macros for setjmp that works across signal handlers */
2024
/* were possible, and a couple of routines to facilitate */
2025
/* catching accesses to bad addresses when that's */
2026
/* possible/needed. */
2028
# include <setjmp.h>
2029
# if defined(SUNOS5SIGS) && !defined(FREEBSD)
2030
# include <sys/siginfo.h>
2032
/* Define SETJMP and friends to be the version that restores */
2033
/* the signal mask. */
2034
# define SETJMP(env) sigsetjmp(env, 1)
2035
# define LONGJMP(env, val) siglongjmp(env, val)
2036
# define JMP_BUF sigjmp_buf
2039
# define SETJMP(env) hal_setjmp(env)
2041
# define SETJMP(env) setjmp(env)
2043
# define LONGJMP(env, val) longjmp(env, val)
2044
# define JMP_BUF jmp_buf
2047
/* Do we need the GC_find_limit machinery to find the end of a */
2049
# if defined(HEURISTIC2) || defined(SEARCH_FOR_DATA_START)
2050
# define NEED_FIND_LIMIT
2053
# if !defined(STACKBOTTOM) && defined(HEURISTIC2)
2054
# define NEED_FIND_LIMIT
2057
# if (defined(SVR4) || defined(AUX) || defined(DGUX) \
2058
|| (defined(LINUX) && defined(SPARC))) && !defined(PCR)
2059
# define NEED_FIND_LIMIT
2062
#if defined(FREEBSD) && (defined(I386) || defined(X86_64) || defined(powerpc) \
2063
|| defined(__powerpc__))
2064
# include <machine/trap.h>
2066
# define NEED_FIND_LIMIT
2070
#if (defined(NETBSD) || defined(OPENBSD)) && defined(__ELF__) \
2071
&& !defined(NEED_FIND_LIMIT)
2072
/* Used by GC_init_netbsd_elf() in os_dep.c. */
2073
# define NEED_FIND_LIMIT
2076
#if defined(IA64) && !defined(NEED_FIND_LIMIT)
2077
# define NEED_FIND_LIMIT
2078
/* May be needed for register backing store base. */
2081
# if defined(NEED_FIND_LIMIT) || \
2082
defined(USE_PROC_FOR_LIBRARIES) && defined(THREADS)
2085
/* Set up a handler for address faults which will longjmp to */
2087
extern void GC_setup_temporary_fault_handler(void);
2089
/* Undo the effect of GC_setup_temporary_fault_handler. */
2090
extern void GC_reset_fault_handler(void);
2092
# endif /* Need to handle address faults. */
1960
2094
# endif /* GC_PRIVATE_H */