~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to include/private/gc_priv.h

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3
3
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
4
4
 * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
5
 
 * Copyright (c) 1999-2001 by Hewlett-Packard Company. All rights reserved.
 
5
 * Copyright (c) 1999-2004 Hewlett-Packard Development Company, L.P.
6
6
 *
7
7
 *
8
8
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
19
19
# ifndef GC_PRIVATE_H
20
20
# define GC_PRIVATE_H
21
21
 
22
 
#if defined(mips) && defined(SYSTYPE_BSD) && defined(sony_news)
23
 
    /* sony RISC NEWS, NEWSOS 4 */
24
 
#   define BSD_TIME
25
 
/*    typedef long ptrdiff_t;   -- necessary on some really old systems */
26
 
#endif
27
 
 
28
 
#if defined(mips) && defined(SYSTYPE_BSD43)
29
 
    /* MIPS RISCOS 4 */
30
 
#   define BSD_TIME
31
 
#endif
 
22
# include <stdlib.h>
 
23
# if !(defined( sony_news ) )
 
24
#   include <stddef.h>
 
25
# endif
32
26
 
33
27
#ifdef DGUX
34
28
#   include <sys/types.h>
42
36
#   include <sys/resource.h>
43
37
#endif /* BSD_TIME */
44
38
 
45
 
# ifndef _GC_H
 
39
#ifdef PARALLEL_MARK
 
40
#   define AO_REQUIRE_CAS
 
41
#endif
 
42
 
 
43
#ifndef _GC_H
46
44
#   include "../gc.h"
47
 
# endif
48
 
 
49
 
# ifndef GC_MARK_H
 
45
#endif
 
46
 
 
47
#ifndef GC_TINY_FL_H
 
48
#   include "../gc_tiny_fl.h"
 
49
#endif
 
50
 
 
51
#ifndef GC_MARK_H
50
52
#   include "../gc_mark.h"
51
 
# endif
 
53
#endif
52
54
 
53
55
typedef GC_word word;
54
56
typedef GC_signed_word signed_word;
 
57
typedef unsigned int unsigned32;
55
58
 
56
59
typedef int GC_bool;
57
60
# define TRUE 1
58
61
# define FALSE 0
59
62
 
60
63
typedef char * ptr_t;   /* A generic pointer to which we can add        */
61
 
                        /* byte displacements.                          */
62
 
                        /* Preferably identical to caddr_t, if it       */
63
 
                        /* exists.                                      */
64
 
                        
 
64
                        /* byte displacements and which can be used     */
 
65
                        /* for address comparisons.                     */
 
66
 
65
67
# ifndef GCCONFIG_H
66
68
#   include "gcconfig.h"
67
69
# endif
70
72
#   include "gc_hdrs.h"
71
73
# endif
72
74
 
73
 
#if defined(__STDC__)
74
 
#   include <stdlib.h>
75
 
#   if !(defined( sony_news ) )
76
 
#       include <stddef.h>
77
 
#   endif
78
 
#   define VOLATILE volatile
79
 
#else
80
 
#   ifdef MSWIN32
81
 
#       include <stdlib.h>
82
 
#   endif
83
 
#   define VOLATILE
84
 
#endif
85
 
 
86
 
#if 0 /* defined(__GNUC__) doesn't work yet */
 
75
#if __GNUC__ >= 3
87
76
# define EXPECT(expr, outcome) __builtin_expect(expr,outcome)
88
77
  /* Equivalent to (expr), but predict that usually (expr)==outcome. */
 
78
# define INLINE inline
89
79
#else
90
80
# define EXPECT(expr, outcome) (expr)
 
81
# define INLINE
91
82
#endif /* __GNUC__ */
92
83
 
93
84
# ifndef GC_LOCKS_H
97
88
# ifdef STACK_GROWS_DOWN
98
89
#   define COOLER_THAN >
99
90
#   define HOTTER_THAN <
100
 
#   define MAKE_COOLER(x,y) if ((word)(x)+(y) > (word)(x)) {(x) += (y);} \
101
 
                            else {(x) = (word)ONES;}
 
91
#   define MAKE_COOLER(x,y) if ((x)+(y) > (x)) {(x) += (y);} \
 
92
                            else {(x) = (ptr_t)ONES;}
102
93
#   define MAKE_HOTTER(x,y) (x) -= (y)
103
94
# else
104
95
#   define COOLER_THAN <
105
96
#   define HOTTER_THAN >
106
 
#   define MAKE_COOLER(x,y) if ((word)(x)-(y) < (word)(x)) {(x) -= (y);} else {(x) = 0;}
 
97
#   define MAKE_COOLER(x,y) if ((x)-(y) < (x)) {(x) -= (y);} else {(x) = 0;}
107
98
#   define MAKE_HOTTER(x,y) (x) += (y)
108
99
# endif
109
100
 
159
150
                    /* This is now really controlled at startup,        */
160
151
                    /* through GC_all_interior_pointers.                */
161
152
                    
162
 
#define PRINTSTATS  /* Print garbage collection statistics              */
163
 
                    /* For less verbose output, undefine in reclaim.c   */
164
 
 
165
 
#define PRINTTIMES  /* Print the amount of time consumed by each garbage   */
166
 
                    /* collection.                                         */
167
 
 
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.         */
173
 
#undef PRINTBLOCKS
174
 
 
175
 
#ifdef SILENT
176
 
#  ifdef PRINTSTATS
177
 
#    undef PRINTSTATS
178
 
#  endif
179
 
#  ifdef PRINTTIMES
180
 
#    undef PRINTTIMES
181
 
#  endif
182
 
#  ifdef PRINTNBLOCKS
183
 
#    undef PRINTNBLOCKS
184
 
#  endif
185
 
#endif
186
 
 
187
 
#if defined(PRINTSTATS) && !defined(GATHERSTATS)
188
 
#   define GATHERSTATS
189
 
#endif
190
 
 
191
 
#if defined(PRINTSTATS) || !defined(SMALL_CONFIG)
192
 
#   define CONDPRINT  /* Print some things if GC_print_stats is set */
193
 
#endif
194
153
 
195
154
#define GC_INVOKE_FINALIZERS() GC_notify_or_invoke_finalizers()
196
155
 
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  */
206
 
                    /* entries.                                           */
207
 
 
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.                             */
212
 
#endif
213
 
 
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
217
 
#endif
218
 
 
219
 
/* ALIGN_DOUBLE requires MERGE_SIZES at present. */
220
 
# if defined(ALIGN_DOUBLE) && !defined(MERGE_SIZES)
221
 
#   define MERGE_SIZES
222
 
# endif
223
 
 
224
156
#if !defined(DONT_ADD_BYTE_AT_END)
225
157
# define EXTRA_BYTES GC_all_interior_pointers
 
158
# define MAX_EXTRA_BYTES 1
226
159
#else
227
160
# define EXTRA_BYTES 0
 
161
# define MAX_EXTRA_BYTES 0
228
162
#endif
229
163
 
230
164
 
264
198
#       if NARGS > 0
265
199
            word ci_arg[NARGS]; /* bit-wise complement to avoid retention */
266
200
#       endif
267
 
#       if defined(ALIGN_DOUBLE) && (NFRAMES * (NARGS + 1)) % 2 == 1
 
201
#       if (NFRAMES * (NARGS + 1)) % 2 == 1
268
202
            /* Likely alignment problem. */
269
203
            word ci_dummy;
270
204
#       endif
275
209
 
276
210
/* Fill in the pc and argument information for up to NFRAMES of my      */
277
211
/* callers.  Ignore my frame and my callers frame.                      */
278
 
void GC_save_callers GC_PROTO((struct callinfo info[NFRAMES]));
 
212
void GC_save_callers(struct callinfo info[NFRAMES]);
279
213
  
280
 
void GC_print_callers GC_PROTO((struct callinfo info[NFRAMES]));
 
214
void GC_print_callers(struct callinfo info[NFRAMES]);
281
215
 
282
216
#endif
283
217
 
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))
363
297
# else
364
 
#   define BCOPY(x,y,n) bcopy((char *)(x),(char *)(y),(int)(n))
365
 
#   define BZERO(x,n) bzero((char *)(x),(int)(n))
366
 
# endif
367
 
 
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     */
377
 
/* compilers.                                                           */
378
 
# ifdef PCR
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)
383
 
# else
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()
391
 
#   else
392
 
#     define DISABLE_SIGNALS() GC_disable_signals()
393
 
        void GC_disable_signals();
394
 
#     define ENABLE_SIGNALS() GC_enable_signals()
395
 
        void GC_enable_signals();
396
 
#   endif
 
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))
397
300
# endif
398
301
 
399
302
/*
427
330
#   define ABORT(s) PCR_Base_Panic(s)
428
331
# else
429
332
#   ifdef SMALL_CONFIG
430
 
#       define ABORT(msg) abort();
 
333
#       define ABORT(msg) abort()
431
334
#   else
432
 
        GC_API void GC_abort GC_PROTO((GC_CONST char * msg));
433
 
#       define ABORT(msg) GC_abort(msg);
 
335
        GC_API void GC_abort(const char * msg);
 
336
#       define ABORT(msg) GC_abort(msg)
434
337
#   endif
435
338
# endif
436
339
 
464
367
#   define GETENV(name) 0
465
368
#endif
466
369
 
 
370
#if defined(DARWIN)
 
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
 
379
#               else
 
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
 
386
#               endif
 
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
 
395
#               else
 
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
 
402
#               endif
 
403
#       else
 
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
 
407
#       endif
 
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
 
417
#       else
 
418
#         define THREAD_FLD(x) x
 
419
#       endif
 
420
#endif
 
421
 
467
422
/*********************************/
468
423
/*                               */
469
424
/* Word-size-dependent defines   */
490
445
#  endif
491
446
#endif
492
447
 
 
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
 
456
 
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      */
498
462
 
 
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)
 
470
# else
 
471
#   define GRANULES_TO_WORDS(n) BYTES_TO_WORDS(GRANULES_TO_BYTES(n))
 
472
# endif
 
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)
 
480
# else
 
481
#   define GRANULES_TO_WORDS(n) BYTES_TO_WORDS(GRANULES_TO_BYTES(n))
 
482
# endif
 
483
#else
 
484
# error Bad GRANULE_BYTES value
 
485
#endif
 
486
 
499
487
/*********************/
500
488
/*                   */
501
489
/*  Size Parameters  */
502
490
/*                   */
503
491
/*********************/
504
492
 
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.         */
506
500
 
507
501
#ifndef HBLKSIZE
508
502
# ifdef SMALL_CONFIG
509
503
#   define CPP_LOG_HBLKSIZE 10
510
504
# else
511
 
#   if (CPP_WORDSZ == 32) || (defined(HPUX) && defined(HP_PA))
512
 
      /* HPUX/PA seems to use 4K pages with the 64 bit ABI */
 
505
#   if defined(ALPHA)
 
506
#     define CPP_LOG_HBLKSIZE 13
 
507
#   else
513
508
#     define CPP_LOG_HBLKSIZE 12
514
 
#   else
515
 
#     define CPP_LOG_HBLKSIZE 13
516
509
#   endif
517
510
# endif
518
511
#else
539
532
# endif
540
533
# undef HBLKSIZE
541
534
#endif
 
535
 
542
536
# define CPP_HBLKSIZE (1 << CPP_LOG_HBLKSIZE)
543
 
# define LOG_HBLKSIZE   ((word)CPP_LOG_HBLKSIZE)
544
 
# define HBLKSIZE ((word)CPP_HBLKSIZE)
545
 
 
546
 
 
547
 
/*  max size objects supported by freelist (larger objects may be   */
548
 
/*  allocated, but less efficiently)                                */
 
537
# define LOG_HBLKSIZE   ((size_t)CPP_LOG_HBLKSIZE)
 
538
# define HBLKSIZE ((size_t)CPP_HBLKSIZE)
 
539
 
 
540
 
 
541
/*  max size objects supported by freelist (larger objects are  */
 
542
/*  allocated directly with allchblk(), by rounding to the next */
 
543
/*  multiple of HBLKSIZE.                                       */
549
544
 
550
545
#define CPP_MAXOBJBYTES (CPP_HBLKSIZE/2)
551
 
#define MAXOBJBYTES ((word)CPP_MAXOBJBYTES)
552
 
#define CPP_MAXOBJSZ    BYTES_TO_WORDS(CPP_MAXOBJBYTES)
553
 
#define MAXOBJSZ ((word)CPP_MAXOBJSZ)
 
546
#define MAXOBJBYTES ((size_t)CPP_MAXOBJBYTES)
 
547
#define CPP_MAXOBJWORDS BYTES_TO_WORDS(CPP_MAXOBJBYTES)
 
548
#define MAXOBJWORDS ((size_t)CPP_MAXOBJWORDS)
 
549
#define CPP_MAXOBJGRANULES BYTES_TO_GRANULES(CPP_MAXOBJBYTES)
 
550
#define MAXOBJGRANULES ((size_t)CPP_MAXOBJGRANULES)
554
551
                
555
552
# define divHBLKSZ(n) ((n) >> LOG_HBLKSIZE)
556
553
 
566
563
 
567
564
# define HBLKPTR(objptr) ((struct hblk *)(((word) (objptr)) & ~(HBLKSIZE-1)))
568
565
 
569
 
# define HBLKDISPL(objptr) (((word) (objptr)) & (HBLKSIZE-1))
 
566
# define HBLKDISPL(objptr) (((size_t) (objptr)) & (HBLKSIZE-1))
570
567
 
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))
574
 
# ifdef ALIGN_DOUBLE
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)
577
575
# else
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.                  */
579
581
# endif
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.   */
591
 
#   else
592
 
#     define MIN_WORDS 1
593
 
#   endif
 
584
#  define MIN_WORDS 2   /* FIXME: obsolete */
594
585
# endif
595
586
 
596
587
 
597
588
/*
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
 
591
 * bit each.
 
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.
601
595
 */
602
596
 
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    */
607
602
                                /* touched.                             */
 
603
#   else
 
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    */
 
607
                                /* touched.                             */
 
608
#   endif
608
609
# else
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)
650
651
 
651
 
#define BITS_PER_HBLK (CPP_HBLKSIZE * 8)
652
 
 
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.  */
658
661
 
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.                     */
665
669
# else
666
 
#   define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ)
 
670
#   define MARK_BITS_SZ (MARK_BITS_PER_HBLK/CPP_WORDSZ + 1)
667
671
# endif
668
672
 
 
673
#ifdef PARALLEL_MARK
 
674
# include <atomic_ops.h>
 
675
  typedef AO_t counter_t;
 
676
#else
 
677
  typedef size_t counter_t;
 
678
#endif
 
679
 
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;
673
 
 
674
683
struct hblkhdr {
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 */
679
686
                                /* reclaimed.                            */
680
687
    struct hblk * hb_prev;      /* Backwards link for free list.        */
681
 
    word hb_descr;              /* object descriptor for marking.  See  */
682
 
                                /* mark.h.                              */
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    */
699
700
                                /* GC_remap must be invoked on it       */
700
701
                                /* before it can be reallocated.        */
701
702
                                /* Only set with USE_MUNMAP.            */
 
703
#       define FREE_BLK 4       /* Block is free, i.e. not in use.      */
702
704
    unsigned short hb_last_reclaimed;
703
705
                                /* Value of GC_gc_no when block was     */
704
706
                                /* last allocated or swept. May wrap.   */
707
709
                                /* when the header was allocated, or    */
708
710
                                /* when the size of the block last      */
709
711
                                /* changed.                             */
 
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  */
 
718
                                /* mark.h.                              */
 
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            */
 
722
                                /* LARGE_INV_SZ.                        */
 
723
#     define LARGE_INV_SZ (1 << 16)
 
724
#   else
 
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.   */
 
729
#   endif
 
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         */
 
736
                                /* objects.                             */
 
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  */
 
749
                                /* is accurate.                         */
710
750
#   ifdef USE_MARK_BYTES
711
751
      union {
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     */
 
755
                            /* marked, 0 o.w.                           */
 
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
718
762
#   else
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      */
726
 
                            /* objects.                                     */
727
764
#   endif /* !USE_MARK_BYTES */
728
765
};
729
766
 
 
767
# define ANY_INDEX 23   /* "Random" mark bit index for assertions */
 
768
 
730
769
/*  heap block body */
731
770
 
732
 
# define BODY_SZ (HBLKSIZE/sizeof(word))
 
771
# define HBLK_WORDS (HBLKSIZE/sizeof(word))
 
772
# define HBLK_GRANULES (HBLKSIZE/GRANULE_BYTES)
 
773
 
 
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))
733
777
 
734
778
struct hblk {
735
 
    word hb_body[BODY_SZ];
 
779
    char hb_body[HBLKSIZE];
736
780
};
737
781
 
738
 
# define HBLK_IS_FREE(hdr) ((hdr) -> hb_map == GC_invalid_map)
 
782
# define HBLK_IS_FREE(hdr) (((hdr) -> hb_flags & FREE_BLK) != 0)
739
783
 
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).                                             */
744
787
 
745
788
/* Object free list link */
746
 
# define obj_link(p) (*(ptr_t *)(p))
 
789
# define obj_link(p) (*(void  **)(p))
747
790
 
748
791
# define LOG_MAX_MARK_PROCS 6
749
792
# define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
753
796
/* MAX_ROOT_SETS is the maximum number of ranges that can be    */
754
797
/* registered as static roots.                                  */
755
798
# ifdef LARGE_CONFIG
756
 
#   define MAX_ROOT_SETS 4096
 
799
#   define MAX_ROOT_SETS 8192
757
800
# else
758
 
    /* GCJ LOCAL: MAX_ROOT_SETS increased to permit more shared */
759
 
    /* libraries to be loaded.                                  */ 
760
 
#   define MAX_ROOT_SETS 1024
 
801
#   ifdef SMALL_CONFIG
 
802
#     define MAX_ROOT_SETS 512
 
803
#   else
 
804
#     define MAX_ROOT_SETS 2048
 
805
#   endif
761
806
# endif
762
807
 
763
808
# define MAX_EXCLUSIONS (MAX_ROOT_SETS/4)
811
856
/* compiled.                                    */
812
857
 
813
858
struct _GC_arrays {
814
 
  word _heapsize;
 
859
  word _heapsize;               /* Heap size in bytes.                  */
815
860
  word _max_heapsize;
816
861
  word _requested_heapsize;     /* Heap size due to explicit expansion */
817
862
  ptr_t _last_heap_addr;
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
835
 
    word _words_allocd;
 
880
    word _bytes_allocd;
836
881
        /* Number of words allocated during this collection cycle */
837
882
# endif
838
 
  word _words_wasted;
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) */
 
883
  word _bytes_dropped;
 
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.                                  */
849
 
  word _mem_freed;
850
 
        /* Number of explicitly deallocated words of memory     */
 
895
  word _bytes_freed;
 
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.         */
864
910
 
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  */
870
916
# endif
871
917
 
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];
879
925
# endif
880
926
                          /* uncollectable but traced objs      */
881
927
 
882
 
# ifdef GATHERSTATS
883
928
    word _composite_in_use;
884
929
                /* Number of words in accessible composite      */
885
930
                /* objects.                                     */
886
931
    word _atomic_in_use;
887
932
                /* Number of words in accessible atomic         */
888
933
                /* objects.                                     */
889
 
# endif
890
934
# ifdef USE_MUNMAP
891
935
    word _unmapped_bytes;
892
936
# endif
893
 
# ifdef MERGE_SIZES
894
 
    unsigned _size_map[WORDS_TO_BYTES(MAXOBJSZ+1)];
 
937
 
 
938
    size_t _size_map[MAXOBJBYTES+1];
895
939
        /* Number of words to allocate for a given allocation request in */
896
940
        /* bytes.                                                        */
897
 
# endif 
898
941
 
899
942
# ifdef STUBBORN_ALLOC
900
 
    ptr_t _sobjfreelist[MAXOBJSZ+1];
 
943
    ptr_t _sobjfreelist[MAXOBJGRANULES+1];
901
944
# endif
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)? \
927
 
           CPP_MAX_OFFSET+1 \
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  */
 
957
                       /* test.                                         */
 
958
#   define MAP_LEN BYTES_TO_GRANULES(HBLKSIZE)
 
959
# endif
 
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   */
942
972
        /* Stubborn object pages that were changes before last call to  */
943
973
        /* GC_read_changed.                                             */
944
974
# endif
945
 
# if defined(PROC_VDB) || defined(MPROTECT_VDB)
 
975
# if defined(PROC_VDB) || defined(MPROTECT_VDB) || \
 
976
     defined(GWW_VDB) || defined(MANUAL_VDB)
946
977
    page_hash_table _grungy_pages; /* Pages that were dirty at last        */
947
978
                                     /* GC_read_dirty.                     */
948
979
# endif
949
 
# ifdef MPROTECT_VDB
950
 
    VOLATILE page_hash_table _dirty_pages;      
 
980
# if defined(MPROTECT_VDB) || defined(MANUAL_VDB)
 
981
    volatile page_hash_table _dirty_pages;      
951
982
                        /* Pages dirtied since last GC_read_dirty. */
952
983
# endif
953
 
# ifdef PROC_VDB
 
984
# if defined(PROC_VDB) || defined(GWW_VDB)
954
985
    page_hash_table _written_pages;     /* Pages ever dirtied   */
955
986
# endif
956
987
# ifdef LARGE_CONFIG
967
998
#   endif
968
999
# endif
969
1000
  struct HeapSect {
970
 
      ptr_t hs_start; word hs_bytes;
971
 
  } _heap_sects[MAX_HEAP_SECTS];
 
1001
      ptr_t hs_start; size_t hs_bytes;
 
1002
  } _heap_sects[MAX_HEAP_SECTS];        /* Heap segments potentially    */
 
1003
                                        /* client objects.              */
 
1004
# if defined(USE_PROC_FOR_LIBRARIES)
 
1005
     struct HeapSect _our_memory[MAX_HEAP_SECTS];
 
1006
                                        /* All GET_MEM allocated        */
 
1007
                                        /* memory.  Includes block      */
 
1008
                                        /* headers and the like.        */
 
1009
# endif
972
1010
# if defined(MSWIN32) || defined(MSWINCE)
973
1011
    ptr_t _heap_bases[MAX_HEAP_SECTS];
974
1012
                /* Start address of memory regions obtained from kernel. */
985
1023
  /* Block header index; see gc_headers.h */
986
1024
  bottom_index * _all_nils;
987
1025
  bottom_index * _top_index [TOP_SZ];
 
1026
#ifdef ENABLE_TRACE
 
1027
  ptr_t _trace_addr;
 
1028
#endif
988
1029
#ifdef SAVE_CALL_CHAIN
989
1030
  struct callinfo _last_stack[NFRAMES]; /* Stack at last garbage collection.*/
990
1031
                                        /* Useful for debugging mysterious  */
1000
1041
# ifndef SEPARATE_GLOBALS
1001
1042
#   define GC_objfreelist GC_arrays._objfreelist
1002
1043
#   define GC_aobjfreelist GC_arrays._aobjfreelist
1003
 
#   define GC_words_allocd GC_arrays._words_allocd
 
1044
#   define GC_bytes_allocd GC_arrays._bytes_allocd
1004
1045
# endif
1005
1046
# define GC_uobjfreelist GC_arrays._uobjfreelist
1006
1047
# ifdef ATOMIC_UNCOLLECTABLE
1013
1054
#    define GC_changed_pages GC_arrays._changed_pages
1014
1055
#    define GC_prev_changed_pages GC_arrays._prev_changed_pages
1015
1056
# endif
1016
 
# define GC_obj_map GC_arrays._obj_map
 
1057
# ifdef MARK_BIT_PER_GRANULE
 
1058
#   define GC_obj_map GC_arrays._obj_map
 
1059
# endif
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
 
1080
# endif
1035
1081
# define GC_last_stack GC_arrays._last_stack
 
1082
#ifdef ENABLE_TRACE
 
1083
#define GC_trace_addr GC_arrays._trace_addr
 
1084
#endif
1036
1085
# ifdef USE_MUNMAP
1037
1086
#   define GC_unmapped_bytes GC_arrays._unmapped_bytes
1038
1087
# endif
1047
1096
# define GC_excl_table GC_arrays._excl_table
1048
1097
# define GC_all_nils GC_arrays._all_nils
1049
1098
# define GC_top_index GC_arrays._top_index
1050
 
# if defined(PROC_VDB) || defined(MPROTECT_VDB)
 
1099
# if defined(PROC_VDB) || defined(MPROTECT_VDB) || \
 
1100
     defined(GWW_VDB) || defined(MANUAL_VDB)
1051
1101
#   define GC_grungy_pages GC_arrays._grungy_pages
1052
1102
# endif
1053
 
# ifdef MPROTECT_VDB
 
1103
# if defined(MPROTECT_VDB) || defined(MANUAL_VDB)
1054
1104
#   define GC_dirty_pages GC_arrays._dirty_pages
1055
1105
# endif
1056
 
# ifdef PROC_VDB
 
1106
# if defined(PROC_VDB) || defined(GWW_VDB)
1057
1107
#   define GC_written_pages GC_arrays._written_pages
1058
1108
# endif
1059
 
# ifdef GATHERSTATS
1060
 
#   define GC_composite_in_use GC_arrays._composite_in_use
1061
 
#   define GC_atomic_in_use GC_arrays._atomic_in_use
1062
 
# endif
1063
 
# ifdef MERGE_SIZES
1064
 
#   define GC_size_map GC_arrays._size_map
1065
 
# endif
 
1109
# define GC_composite_in_use GC_arrays._composite_in_use
 
1110
# define GC_atomic_in_use GC_arrays._atomic_in_use
 
1111
# define GC_size_map GC_arrays._size_map
1066
1112
 
1067
1113
# define beginGC_arrays ((ptr_t)(&GC_arrays))
1068
1114
# define endGC_arrays (((ptr_t)(&GC_arrays)) + (sizeof GC_arrays))
1073
1119
# define MAXOBJKINDS 16
1074
1120
 
1075
1121
extern struct obj_kind {
1076
 
   ptr_t *ok_freelist;  /* Array of free listheaders for this kind of object */
 
1122
   void **ok_freelist;  /* Array of free listheaders for this kind of object */
1077
1123
                        /* Point either to GC_arrays or to storage allocated */
1078
1124
                        /* with GC_scratch_alloc.                            */
1079
1125
   struct hblk **ok_reclaim_list;
1080
1126
                        /* List headers for lists of blocks waiting to be */
1081
1127
                        /* swept.                                         */
 
1128
                        /* Indexed by object size in granules.            */
1082
1129
   word ok_descriptor;  /* Descriptor template for objects in this      */
1083
1130
                        /* block.                                       */
1084
1131
   GC_bool ok_relocate_descr;
1097
1144
/* introduce maintenance problems.                                      */
1098
1145
 
1099
1146
#ifdef SEPARATE_GLOBALS
1100
 
  word GC_words_allocd;
 
1147
  word GC_bytes_allocd;
1101
1148
        /* Number of words allocated during this collection cycle */
1102
 
  ptr_t GC_objfreelist[MAXOBJSZ+1];
 
1149
  ptr_t GC_objfreelist[MAXOBJGRANULES+1];
1103
1150
                          /* free list for NORMAL objects */
1104
1151
# define beginGC_objfreelist ((ptr_t)(&GC_objfreelist))
1105
1152
# define endGC_objfreelist (beginGC_objfreelist + sizeof(GC_objfreelist))
1106
1153
 
1107
 
  ptr_t GC_aobjfreelist[MAXOBJSZ+1];
 
1154
  ptr_t GC_aobjfreelist[MAXOBJGRANULES+1];
1108
1155
                          /* free list for atomic (PTRFREE) objs        */
1109
1156
# define beginGC_aobjfreelist ((ptr_t)(&GC_aobjfreelist))
1110
1157
# define endGC_aobjfreelist (beginGC_aobjfreelist + sizeof(GC_aobjfreelist))
1123
1170
#   define IS_UNCOLLECTABLE(k) ((k) == UNCOLLECTABLE)
1124
1171
# endif
1125
1172
 
1126
 
extern int GC_n_kinds;
 
1173
extern unsigned GC_n_kinds;
1127
1174
 
1128
1175
GC_API word GC_fo_entries;
1129
1176
 
1130
1177
extern word GC_n_heap_sects;    /* Number of separately added heap      */
1131
1178
                                /* sections.                            */
1132
1179
 
 
1180
#ifdef USE_PROC_FOR_LIBRARIES
 
1181
  extern word GC_n_memory;      /* Number of GET_MEM allocated memory   */
 
1182
                                /* sections.                            */
 
1183
#endif
 
1184
 
1133
1185
extern word GC_page_size;
1134
1186
 
1135
1187
# if defined(MSWIN32) || defined(MSWINCE)
1148
1200
                        /* "stack-blacklisted", i.e. that are           */
1149
1201
                        /* problematic in the interior of an object.    */
1150
1202
 
1151
 
extern map_entry_type * GC_invalid_map;
1152
 
                        /* Pointer to the nowhere valid hblk map */
1153
 
                        /* Blocks pointing to this map are free. */
1154
 
 
1155
1203
extern struct hblk * GC_hblkfreelist[];
1156
1204
                                /* List of completely empty heap blocks */
1157
1205
                                /* Linked through hb_next field of      */
1207
1255
/* accessed.                                                            */
1208
1256
#ifdef PARALLEL_MARK
1209
1257
# define OR_WORD(addr, bits) \
1210
 
        { word old; \
1211
 
          do { \
1212
 
            old = *((volatile word *)addr); \
1213
 
          } while (!GC_compare_and_exchange((addr), old, old | (bits))); \
1214
 
        }
1215
 
# define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1216
 
        { word old; \
1217
 
          word my_bits = (bits); \
1218
 
          do { \
1219
 
            old = *((volatile word *)addr); \
1220
 
            if (old & my_bits) goto exit_label; \
1221
 
          } while (!GC_compare_and_exchange((addr), old, old | my_bits)); \
1222
 
        }
 
1258
        { AO_or((volatile AO_t *)(addr), (AO_t)bits); }
1223
1259
#else
1224
1260
# define OR_WORD(addr, bits) *(addr) |= (bits)
1225
 
# define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
1226
 
        { \
1227
 
          word old = *(addr); \
1228
 
          word my_bits = (bits); \
1229
 
          if (old & my_bits) goto exit_label; \
1230
 
          *(addr) = (old | my_bits); \
1231
 
        }
1232
1261
#endif
1233
1262
 
1234
1263
/* Mark bit operations */
1235
1264
 
1236
1265
/*
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.
1239
1267
 *
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)
1242
1270
 */
1243
1271
 
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 */
1257
1285
 
 
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)))
 
1302
#endif
 
1303
 
1258
1304
/* Important internal collector routines */
1259
1305
 
1260
 
ptr_t GC_approx_sp GC_PROTO((void));
1261
 
  
1262
 
GC_bool GC_should_collect GC_PROTO((void));
1263
 
  
1264
 
void GC_apply_to_all_blocks GC_PROTO(( \
1265
 
    void (*fn) GC_PROTO((struct hblk *h, word client_data)), \
1266
 
    word client_data));
 
1306
ptr_t GC_approx_sp(void);
 
1307
  
 
1308
GC_bool GC_should_collect(void);
 
1309
  
 
1310
void GC_apply_to_all_blocks(void (*fn) (struct hblk *h, word client_data),
 
1311
                            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   */
1274
1319
                        /* use.                                         */
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(( \
1298
 
    ptr_t bottom, \
1299
 
    ptr_t top, \
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);
1306
1349
#else
1307
1350
# define GC_push_conditional(b, t, all) GC_push_all(b, t)
1308
1351
#endif
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.                                        */
1332
1375
#endif
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);
1358
1405
#       endif
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));
1366
 
# else
1367
 
  void GC_push_regs GC_PROTO((void));
1368
 
# endif
 
1414
void GC_push_regs_and_stack(ptr_t cold_gc_frame);
 
1415
 
 
1416
void GC_push_regs(void);
 
1417
 
 
1418
void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),
 
1419
                                 ptr_t arg);
 
1420
 
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);
1373
1425
# endif
1374
1426
                        /* Push register contents onto mark stack.      */
1375
1427
                        /* If NURSERY is defined, the default push      */
1379
1431
    extern void (*GC_push_proc)(ptr_t);
1380
1432
# endif
1381
1433
# if defined(MSWIN32) || defined(MSWINCE)
1382
 
  void __cdecl GC_push_one GC_PROTO((word p));
 
1434
  void __cdecl GC_push_one(word p);
1383
1435
# else
1384
 
  void GC_push_one GC_PROTO((word p));
 
1436
  void GC_push_one(word p);
1385
1437
                              /* If p points to an object, mark it    */
1386
1438
                              /* and push contents on the mark stack  */
1387
1439
                              /* Pointer recognition test always      */
1390
1442
                              /* stack.                               */
1391
1443
# endif
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       */
1395
1447
# else
1396
 
  void GC_mark_and_push_stack GC_PROTO((word p));
 
1448
  void GC_mark_and_push_stack(ptr_t p);
1397
1449
# endif
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)
1403
1455
#else
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.              */
 
1479
#endif
 
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?                                       */
1431
1489
# endif
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.                    */
1434
1495
 
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.                        */
1439
1500
  
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 */
1442
1503
#ifdef IA64
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.  */
1445
1506
#endif
1446
 
void GC_register_data_segments GC_PROTO((void));
 
1507
void GC_register_data_segments(void);
1447
1508
  
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)); \
1457
1518
                } else { \
1458
 
                  GC_add_to_black_list_normal(bits, (ptr_t)(source)); \
 
1519
                  GC_add_to_black_list_normal((word)(bits), (source)); \
1459
1520
                }
1460
1521
# else
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)); \
1465
1526
                } else { \
1466
 
                  GC_add_to_black_list_normal(bits); \
 
1527
                  GC_add_to_black_list_normal((word)(bits)); \
1467
1528
                }
1468
1529
# endif
1469
1530
 
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))
1472
1535
# else
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))
1474
1539
# endif
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.                                    */
1492
1556
                        
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.                            */
1497
1561
        
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     */
1503
 
                                /* routines.                            */
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.    */
 
1571
 
 
1572
void GC_initialize_offsets(void);
 
1573
                                /* Initialize GC_valid_offsets,         */
 
1574
                                /* depending on current                 */
 
1575
                                /* GC_all_interior_pointers settings.   */
1512
1576
  
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.                   */                              
1517
1581
 
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.   */
1526
1589
 
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,
 
1591
                            unsigned flags);
1529
1592
                                /* Allocate a heap block, inform        */
1530
1593
                                /* the marker that block is valid       */
1531
1594
                                /* for objects of indicated size.       */
1532
1595
 
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.                            */
1542
1605
 
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.                                  */
1546
1609
 
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.                          */
1550
1613
                                
1551
1614
/*  Misc GC: */
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    */
1564
 
                                /* empty.                               */
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);
1577
1647
 
1578
1648
                                /* Collect; caller must have acquired   */
1579
1649
                                /* lock and disabled signals.           */
1582
1652
                                /* successfully.                        */
1583
1653
# define GC_gcollect_inner() \
1584
1654
        (void) GC_try_to_collect_inner(GC_never_stop_func)
1585
 
void GC_finish_collection GC_PROTO((void));
 
1655
void GC_finish_collection(void);
1586
1656
                                /* Finish collection.  Mark bits are    */
1587
1657
                                /* consistent and lock is still held.   */
1588
 
GC_bool GC_collect_or_expand GC_PROTO(( \
1589
 
        word needed_blocks, GC_bool ignore_off_page));
 
1658
GC_bool GC_collect_or_expand(word needed_blocks, GC_bool ignore_off_page);
1590
1659
                                /* Collect or expand heap in an attempt */
1591
1660
                                /* make the indicated number of free    */
1592
1661
                                /* blocks available.  Should be called  */
1596
1665
extern GC_bool GC_is_initialized;       /* GC_init() has been run.      */
1597
1666
 
1598
1667
#if defined(MSWIN32) || defined(MSWINCE)
1599
 
  void GC_deinit GC_PROTO((void));
 
1668
  void GC_deinit(void);
1600
1669
                                /* Free any resources allocated by      */
1601
1670
                                /* GC_init                              */
1602
1671
#endif
1603
1672
 
1604
 
void GC_collect_a_little_inner GC_PROTO((int n));
 
1673
void GC_collect_a_little_inner(int n);
1605
1674
                                /* Do n units worth of garbage          */
1606
1675
                                /* collection work, if appropriate.     */
1607
1676
                                /* A unit is an amount appropriate for  */
1608
1677
                                /* HBLKSIZE bytes of allocation.        */
1609
 
/* ptr_t GC_generic_malloc GC_PROTO((word lb, int k)); */
 
1678
/* void * GC_generic_malloc(size_t lb, int k); */
1610
1679
                                /* Allocate an object of the given      */
1611
1680
                                /* kind.  By default, there are only    */
1612
1681
                                /* a few kinds: composite(pointerfree), */
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   */
1643
 
                                /* head.                                */
1644
 
 
1645
 
void GC_free_inner(GC_PTR p);
 
1710
                                /* head.  Sz is in granules.            */
 
1711
 
 
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 *); 
 
1719
# endif
 
1720
#endif /* THREAD_LOCAL_ALLOC */
 
1721
 
 
1722
void GC_free_inner(void * p);
 
1723
void GC_debug_free_inner(void * p);
1646
1724
  
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.               */
1661
1739
  
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.                           */
1668
1746
 
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.            */
1675
1753
 
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.                 */
1681
1759
                        
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.    */
 
1762
 
 
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.               */
 
1767
#else
 
1768
# define GC_add_to_our_memory(p, bytes)
 
1769
#endif
1684
1770
  
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.         */
1706
1792
#endif
1707
1793
 
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.       */
 
1797
 
 
1798
#ifndef SMALL_CONFIG
 
1799
  extern int GC_print_stats;    /* Nonzero generates basic GC log.      */
 
1800
                                /* VERBOSE generates add'l messages.    */
 
1801
#else
 
1802
# define GC_print_stats 0
 
1803
        /* Will this keep the message character strings from the executable? */
 
1804
        /* It should ...                                                     */
 
1805
#endif
 
1806
#define VERBOSE 2
1713
1807
 
1714
1808
#ifndef NO_DEBUGGING
1715
1809
  extern GC_bool GC_dump_regularly;  /* Generate regular debugging dumps. */
1732
1826
/* Macros used for collector internal allocation.       */
1733
1827
/* These assume the collector lock is held.             */
1734
1828
#ifdef DBG_HDRS_ALL
1735
 
    extern GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k);
1736
 
    extern GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
 
1829
    extern void * GC_debug_generic_malloc_inner(size_t lb, int k);
 
1830
    extern void * GC_debug_generic_malloc_inner_ignore_off_page(size_t lb,
1737
1831
                                                                int k);
1738
1832
#   define GC_INTERNAL_MALLOC GC_debug_generic_malloc_inner
1739
1833
#   define GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE \
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);
1764
1858
#endif
1765
1859
 
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.                        */
1782
1873
                        
1783
 
void GC_dirty_init GC_PROTO((void));
 
1874
void GC_dirty_init(void);
1784
1875
  
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);
1789
1880
  
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);
1797
1888
  
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 */
1805
1896
 
1806
1897
#ifdef KEEP_BACK_PTRS
1807
1898
   void GC_store_back_pointer(ptr_t source, ptr_t dest);
1824
1915
#   endif
1825
1916
# endif
1826
1917
 
1827
 
void GC_noop1 GC_PROTO((word));
 
1918
void GC_noop1(word);
1828
1919
 
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, \
1843
 
                                            (long)d, 0l, 0l)
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)
1848
 
 
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, \
1854
 
                                                  0l, 0l, 0l)
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, \
1858
 
                                                      (long)c, (long)d, \
1859
 
                                                      (long)e, 0l)
1860
 
# define GC_err_printf6(f,a,b,c,d,e,g) GC_err_printf(f, (long)a, (long)b, \
1861
 
                                                        (long)c, (long)d, \
1862
 
                                                        (long)e, (long)g)
1863
 
                        /* Ditto, writes to stderr.                     */
1864
 
                        
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 ...                          */
1868
1931
 
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 ...                          */
1873
1936
#endif
1875
1938
 
1876
1939
# ifdef GC_ASSERTIONS
1877
1940
#       define GC_ASSERT(expr) if(!(expr)) {\
1878
 
                GC_err_printf2("Assertion failure: %s:%ld\n", \
 
1941
                GC_err_printf("Assertion failure: %s:%ld\n", \
1879
1942
                                __FILE__, (unsigned long)__LINE__); \
1880
1943
                ABORT("assertion failure"); }
1881
1944
# else 
1929
1992
                /* some other reason.                                   */
1930
1993
# endif /* PARALLEL_MARK */
1931
1994
 
1932
 
# if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
 
1995
# if defined(GC_PTHREADS)
1933
1996
  /* We define the thread suspension signal here, so that we can refer  */
1934
1997
  /* to it in the dirty bit implementation, if necessary.  Ideally we   */
1935
1998
  /* would allocate a (real-time ?) signal using the standard mechanism.*/
1956
2019
#  endif /* !SIG_SUSPEND */
1957
2020
  
1958
2021
# endif
 
2022
     
 
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.                                             */
 
2027
#ifdef UNIX_LIKE
 
2028
# include <setjmp.h>
 
2029
# if defined(SUNOS5SIGS) && !defined(FREEBSD)
 
2030
#  include <sys/siginfo.h>
 
2031
# endif
 
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
 
2037
#else
 
2038
# ifdef ECOS
 
2039
#   define SETJMP(env)  hal_setjmp(env)
 
2040
# else
 
2041
#   define SETJMP(env) setjmp(env)
 
2042
# endif
 
2043
# define LONGJMP(env, val) longjmp(env, val)
 
2044
# define JMP_BUF jmp_buf
 
2045
#endif
 
2046
 
 
2047
/* Do we need the GC_find_limit machinery to find the end of a  */
 
2048
/* data segment.                                                */
 
2049
# if defined(HEURISTIC2) || defined(SEARCH_FOR_DATA_START)
 
2050
#   define NEED_FIND_LIMIT
 
2051
# endif
 
2052
 
 
2053
# if !defined(STACKBOTTOM) && defined(HEURISTIC2)
 
2054
#   define NEED_FIND_LIMIT
 
2055
# endif
 
2056
 
 
2057
# if (defined(SVR4) || defined(AUX) || defined(DGUX) \
 
2058
      || (defined(LINUX) && defined(SPARC))) && !defined(PCR)
 
2059
#   define NEED_FIND_LIMIT
 
2060
# endif
 
2061
 
 
2062
#if defined(FREEBSD) && (defined(I386) || defined(X86_64) || defined(powerpc) \
 
2063
    || defined(__powerpc__))
 
2064
#  include <machine/trap.h>
 
2065
#  if !defined(PCR)
 
2066
#    define NEED_FIND_LIMIT
 
2067
#  endif
 
2068
#endif
 
2069
 
 
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
 
2074
#endif
 
2075
 
 
2076
#if defined(IA64) && !defined(NEED_FIND_LIMIT)
 
2077
#  define NEED_FIND_LIMIT
 
2078
     /* May be needed for register backing store base. */
 
2079
#endif
 
2080
 
 
2081
# if defined(NEED_FIND_LIMIT) || \
 
2082
     defined(USE_PROC_FOR_LIBRARIES) && defined(THREADS)
 
2083
JMP_BUF GC_jmp_buf;
 
2084
 
 
2085
/* Set up a handler for address faults which will longjmp to    */
 
2086
/* GC_jmp_buf;                                                  */
 
2087
extern void GC_setup_temporary_fault_handler(void);
 
2088
 
 
2089
/* Undo the effect of GC_setup_temporary_fault_handler.         */
 
2090
extern void GC_reset_fault_handler(void);
 
2091
 
 
2092
# endif /* Need to handle address faults.       */
1959
2093
 
1960
2094
# endif /* GC_PRIVATE_H */