2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1996 by Xerox Corporation. All rights reserved.
4 * Copyright (c) 1998 by Silicon Graphics. All rights reserved.
5 * Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
24 # include <sys/types.h>
28 * Separate free lists are maintained for different sized objects
30 * The call GC_allocobj(i,k) ensures that the freelist for
31 * kind k objects of size i points to a non-empty
32 * free list. It returns a pointer to the first entry on the free list.
33 * In a single-threaded world, GC_allocobj may be called to allocate
34 * an object of (small) size i as follows:
36 * opp = &(GC_objfreelist[i]);
37 * if (*opp == 0) GC_allocobj(i, NORMAL);
39 * *opp = obj_link(ptr);
41 * Note that this is very fast if the free list is non-empty; it should
42 * only involve the execution of 4 or 5 simple instructions.
43 * All composite objects on freelists are cleared, except for
48 * The allocator uses GC_allochblk to allocate large chunks of objects.
49 * These chunks all start on addresses which are multiples of
50 * HBLKSZ. Each allocated chunk has an associated header,
51 * which can be located quickly based on the address of the chunk.
52 * (See headers.c for details.)
53 * This makes it possible to check quickly whether an
54 * arbitrary address corresponds to an object administered by the
58 word GC_non_gc_bytes
= 0; /* Number of bytes not intended to be collected */
63 int GC_incremental
= 0; /* By default, stop the world. */
66 int GC_full_freq
= 19; /* Every 20th collection is a full */
67 /* collection, whether we need it */
70 GC_bool GC_need_full_gc
= FALSE
;
71 /* Need full GC do to heap growth. */
73 word GC_used_heap_size_after_full
= 0;
75 char * GC_copyright
[] =
76 {"Copyright 1988,1989 Hans-J. Boehm and Alan J. Demers ",
77 "Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved. ",
78 "Copyright (c) 1996-1998 by Silicon Graphics. All rights reserved. ",
79 "THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY",
80 " EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.",
81 "See source code for details." };
85 /* some more variables */
87 extern signed_word GC_mem_found
; /* Number of reclaimed longwords */
88 /* after garbage collection */
90 GC_bool GC_dont_expand
= 0;
92 word GC_free_space_divisor
= 3;
94 extern GC_bool
GC_collection_in_progress();
95 /* Collection is in progress, or was abandoned. */
97 int GC_never_stop_func
GC_PROTO((void)) { return(0); }
99 CLOCK_TYPE GC_start_time
; /* Time at which we stopped world. */
100 /* used only in GC_timeout_stop_func. */
102 int GC_n_attempts
= 0; /* Number of attempts at finishing */
103 /* collection within TIME_LIMIT */
106 # define GC_timeout_stop_func GC_never_stop_func
108 int GC_timeout_stop_func
GC_PROTO((void))
110 CLOCK_TYPE current_time
;
111 static unsigned count
= 0;
112 unsigned long time_diff
;
114 if ((count
++ & 3) != 0) return(0);
116 GET_TIME(current_time
);
117 time_diff
= MS_TIME_DIFF(current_time
,GC_start_time
);
118 if (time_diff
>= TIME_LIMIT
) {
120 GC_printf0("Abandoning stopped marking after ");
121 GC_printf1("%lu msecs", (unsigned long)time_diff
);
122 GC_printf1("(attempt %d)\n", (unsigned long) GC_n_attempts
);
129 #endif /* !SMALL_CONFIG */
131 /* Return the minimum number of words that must be allocated between */
132 /* collections to amortize the collection cost. */
133 static word
min_words_allocd()
136 /* We punt, for now. */
137 register signed_word stack_size
= 10000;
140 register signed_word stack_size
= (ptr_t
)(&dummy
) - GC_stackbottom
;
142 word total_root_size
; /* includes double stack size, */
143 /* since the stack is expensive */
145 word scan_size
; /* Estimate of memory to be scanned */
146 /* during normal GC. */
148 if (stack_size
< 0) stack_size
= -stack_size
;
149 total_root_size
= 2 * stack_size
+ GC_root_size
;
150 scan_size
= BYTES_TO_WORDS(GC_heapsize
- GC_large_free_bytes
151 + (GC_large_free_bytes
>> 2)
152 /* use a bit more of large empty heap */
154 if (GC_incremental
) {
155 return scan_size
/ (2 * GC_free_space_divisor
);
157 return scan_size
/ GC_free_space_divisor
;
161 /* Return the number of words allocated, adjusted for explicit storage */
162 /* management, etc.. This number is used in deciding when to trigger */
164 word
GC_adj_words_allocd()
166 register signed_word result
;
167 register signed_word expl_managed
=
168 BYTES_TO_WORDS((long)GC_non_gc_bytes
169 - (long)GC_non_gc_bytes_at_gc
);
171 /* Don't count what was explicitly freed, or newly allocated for */
172 /* explicit management. Note that deallocating an explicitly */
173 /* managed object should not alter result, assuming the client */
174 /* is playing by the rules. */
175 result
= (signed_word
)GC_words_allocd
176 - (signed_word
)GC_mem_freed
- expl_managed
;
177 if (result
> (signed_word
)GC_words_allocd
) {
178 result
= GC_words_allocd
;
179 /* probably client bug or unfortunate scheduling */
181 result
+= GC_words_finalized
;
182 /* We count objects enqueued for finalization as though they */
183 /* had been reallocated this round. Finalization is user */
184 /* visible progress. And if we don't count this, we have */
185 /* stability problems for programs that finalize all objects. */
186 result
+= GC_words_wasted
;
187 /* This doesn't reflect useful work. But if there is lots of */
188 /* new fragmentation, the same is probably true of the heap, */
189 /* and the collection will be correspondingly cheaper. */
190 if (result
< (signed_word
)(GC_words_allocd
>> 3)) {
191 /* Always count at least 1/8 of the allocations. We don't want */
192 /* to collect too infrequently, since that would inhibit */
193 /* coalescing of free storage blocks. */
194 /* This also makes us partially robust against client bugs. */
195 return(GC_words_allocd
>> 3);
202 /* Clear up a few frames worth of garbage left at the top of the stack. */
203 /* This is used to prevent us from accidentally treating garbade left */
204 /* on the stack by other parts of the collector as roots. This */
205 /* differs from the code in misc.c, which actually tries to keep the */
206 /* stack clear of long-lived, client-generated garbage. */
207 void GC_clear_a_few_frames()
213 for (i
= 0; i
< NWORDS
; i
++) frames
[i
] = 0;
216 /* Have we allocated enough to amortize a collection? */
217 GC_bool
GC_should_collect()
219 return(GC_adj_words_allocd() >= min_words_allocd());
223 void GC_notify_full_gc()
225 if (GC_start_call_back
!= (void (*)())0) {
226 (*GC_start_call_back
)();
230 GC_bool GC_is_full_gc
= FALSE
;
233 * Initiate a garbage collection if appropriate.
235 * between partial, full, and stop-world collections.
236 * Assumes lock held, signals disabled.
240 static int n_partial_gcs
= 0;
242 if (GC_should_collect()) {
243 if (!GC_incremental
) {
248 } else if (GC_need_full_gc
|| n_partial_gcs
>= GC_full_freq
) {
251 "***>Full mark for collection %lu after %ld allocd bytes\n",
252 (unsigned long) GC_gc_no
+1,
253 (long)WORDS_TO_BYTES(GC_words_allocd
));
255 GC_promote_black_lists();
256 (void)GC_reclaim_all((GC_stop_func
)0, TRUE
);
260 GC_is_full_gc
= TRUE
;
264 /* We try to mark with the world stopped. */
265 /* If we run out of time, this turns into */
266 /* incremental marking. */
268 GET_TIME(GC_start_time
);
270 if (GC_stopped_mark(GC_timeout_stop_func
)) {
271 # ifdef SAVE_CALL_CHAIN
272 GC_save_callers(GC_last_stack
);
274 GC_finish_collection();
276 if (!GC_is_full_gc
) {
277 /* Count this as the first attempt */
286 * Stop the world garbage collection. Assumes lock held, signals disabled.
287 * If stop_func is not GC_never_stop_func, then abort if stop_func returns TRUE.
289 GC_bool
GC_try_to_collect_inner(stop_func
)
290 GC_stop_func stop_func
;
292 if (GC_incremental
&& GC_collection_in_progress()) {
295 "GC_try_to_collect_inner: finishing collection in progress\n");
296 # endif /* PRINTSTATS */
297 /* Just finish collection already in progress. */
298 while(GC_collection_in_progress()) {
299 if (stop_func()) return(FALSE
);
300 GC_collect_a_little_inner(1);
305 "Initiating full world-stop collection %lu after %ld allocd bytes\n",
306 (unsigned long) GC_gc_no
+1,
307 (long)WORDS_TO_BYTES(GC_words_allocd
));
309 GC_promote_black_lists();
310 /* Make sure all blocks have been reclaimed, so sweep routines */
311 /* don't see cleared mark bits. */
312 /* If we're guaranteed to finish, then this is unnecessary. */
313 if (stop_func
!= GC_never_stop_func
314 && !GC_reclaim_all(stop_func
, FALSE
)) {
315 /* Aborted. So far everything is still consistent. */
318 GC_invalidate_mark_state(); /* Flush mark stack. */
320 # ifdef SAVE_CALL_CHAIN
321 GC_save_callers(GC_last_stack
);
323 GC_is_full_gc
= TRUE
;
324 if (!GC_stopped_mark(stop_func
)) {
325 if (!GC_incremental
) {
326 /* We're partially done and have no way to complete or use */
327 /* current work. Reestablish invariants as cheaply as */
329 GC_invalidate_mark_state();
330 GC_unpromote_black_lists();
331 } /* else we claim the world is already still consistent. We'll */
332 /* finish incrementally. */
335 GC_finish_collection();
342 * Perform n units of garbage collection work. A unit is intended to touch
343 * roughly GC_RATE pages. Every once in a while, we do more than that.
344 * This needa to be a fairly large number with our current incremental
345 * GC strategy, since otherwise we allocate too much during GC, and the
346 * cleanup gets expensive.
349 # define MAX_PRIOR_ATTEMPTS 1
350 /* Maximum number of prior attempts at world stop marking */
351 /* A value of 1 means that we finish the seconf time, no matter */
352 /* how long it takes. Doesn't count the initial root scan */
355 int GC_deficit
= 0; /* The number of extra calls to GC_mark_some */
356 /* that we have made. */
358 void GC_collect_a_little_inner(n
)
363 if (GC_incremental
&& GC_collection_in_progress()) {
364 for (i
= GC_deficit
; i
< GC_RATE
*n
; i
++) {
365 if (GC_mark_some((ptr_t
)0)) {
366 /* Need to finish a collection */
367 # ifdef SAVE_CALL_CHAIN
368 GC_save_callers(GC_last_stack
);
370 if (GC_n_attempts
< MAX_PRIOR_ATTEMPTS
) {
371 GET_TIME(GC_start_time
);
372 if (!GC_stopped_mark(GC_timeout_stop_func
)) {
377 (void)GC_stopped_mark(GC_never_stop_func
);
379 GC_finish_collection();
383 if (GC_deficit
> 0) GC_deficit
-= GC_RATE
*n
;
384 if (GC_deficit
< 0) GC_deficit
= 0;
390 int GC_collect_a_little
GC_PROTO(())
397 GC_collect_a_little_inner(1);
398 result
= (int)GC_collection_in_progress();
405 * Assumes lock is held, signals are disabled.
407 * If stop_func() ever returns TRUE, we may fail and return FALSE.
408 * Increment GC_gc_no if we succeed.
410 GC_bool
GC_stopped_mark(stop_func
)
411 GC_stop_func stop_func
;
416 CLOCK_TYPE start_time
, current_time
;
421 GET_TIME(start_time
);
422 GC_printf1("--> Marking for collection %lu ",
423 (unsigned long) GC_gc_no
+ 1);
424 GC_printf2("after %lu allocd bytes + %lu wasted bytes\n",
425 (unsigned long) WORDS_TO_BYTES(GC_words_allocd
),
426 (unsigned long) WORDS_TO_BYTES(GC_words_wasted
));
429 /* Mark from all roots. */
430 /* Minimize junk left in my registers and on the stack */
431 GC_clear_a_few_frames();
432 GC_noop(0,0,0,0,0,0);
435 if ((*stop_func
)()) {
437 GC_printf0("Abandoned stopped marking after ");
438 GC_printf1("%lu iterations\n",
441 GC_deficit
= i
; /* Give the mutator a chance. */
445 if (GC_mark_some((ptr_t
)(&dummy
))) break;
450 GC_printf2("Collection %lu reclaimed %ld bytes",
451 (unsigned long) GC_gc_no
- 1,
452 (long)WORDS_TO_BYTES(GC_mem_found
));
453 GC_printf1(" ---> heapsize = %lu bytes\n",
454 (unsigned long) GC_heapsize
);
455 /* Printf arguments may be pushed in funny places. Clear the */
460 /* Check all debugged objects for consistency */
461 if (GC_debugging_started
) {
466 GET_TIME(current_time
);
467 GC_printf1("World-stopped marking took %lu msecs\n",
468 MS_TIME_DIFF(current_time
,start_time
));
475 /* Finish up a collection. Assumes lock is held, signals are disabled, */
476 /* but the world is otherwise running. */
477 void GC_finish_collection()
480 CLOCK_TYPE start_time
;
481 CLOCK_TYPE finalize_time
;
482 CLOCK_TYPE done_time
;
484 GET_TIME(start_time
);
485 finalize_time
= start_time
;
492 /* Mark all objects on the free list. All objects should be */
493 /* marked when we're done. */
495 register word size
; /* current object size */
496 register ptr_t p
; /* pointer to current object */
497 register struct hblk
* h
; /* pointer to block containing *p */
499 register int word_no
; /* "index" of *p in *q */
502 for (kind
= 0; kind
< GC_n_kinds
; kind
++) {
503 for (size
= 1; size
<= MAXOBJSZ
; size
++) {
504 for (p
= GC_obj_kinds
[kind
].ok_freelist
[size
];
505 p
!= 0; p
=obj_link(p
)){
508 word_no
= (((word
*)p
) - ((word
*)h
));
509 set_mark_bit_from_hdr(hhdr
, word_no
);
514 GC_start_reclaim(TRUE
);
515 /* The above just checks; it doesn't really reclaim anything. */
519 # ifdef STUBBORN_ALLOC
520 GC_clean_changing_list();
524 GET_TIME(finalize_time
);
527 /* Clear free list mark bits, in case they got accidentally marked */
528 /* Note: HBLKPTR(p) == pointer to head of block containing *p */
529 /* (or GC_find_leak is set and they were intentionally marked.) */
530 /* Also subtract memory remaining from GC_mem_found count. */
531 /* Note that composite objects on free list are cleared. */
532 /* Thus accidentally marking a free list is not a problem; only */
533 /* objects on the list itself will be marked, and that's fixed here. */
535 register word size
; /* current object size */
536 register ptr_t p
; /* pointer to current object */
537 register struct hblk
* h
; /* pointer to block containing *p */
539 register int word_no
; /* "index" of *p in *q */
542 for (kind
= 0; kind
< GC_n_kinds
; kind
++) {
543 for (size
= 1; size
<= MAXOBJSZ
; size
++) {
544 for (p
= GC_obj_kinds
[kind
].ok_freelist
[size
];
545 p
!= 0; p
=obj_link(p
)){
548 word_no
= (((word
*)p
) - ((word
*)h
));
549 clear_mark_bit_from_hdr(hhdr
, word_no
);
551 GC_mem_found
-= size
;
560 GC_printf1("Bytes recovered before sweep - f.l. count = %ld\n",
561 (long)WORDS_TO_BYTES(GC_mem_found
));
563 /* Reconstruct free lists to contain everything not marked */
564 GC_start_reclaim(FALSE
);
566 GC_used_heap_size_after_full
= USED_HEAP_SIZE
;
567 GC_need_full_gc
= FALSE
;
570 BYTES_TO_WORDS(USED_HEAP_SIZE
- GC_used_heap_size_after_full
)
571 > min_words_allocd();
576 "Immediately reclaimed %ld bytes in heap of size %lu bytes",
577 (long)WORDS_TO_BYTES(GC_mem_found
),
578 (unsigned long)GC_heapsize
);
580 GC_printf1("(%lu unmapped)", GC_unmapped_bytes
);
583 "\n%lu (atomic) + %lu (composite) collectable bytes in use\n",
584 (unsigned long)WORDS_TO_BYTES(GC_atomic_in_use
),
585 (unsigned long)WORDS_TO_BYTES(GC_composite_in_use
));
589 GC_is_full_gc
= FALSE
;
590 /* Reset or increment counters for next cycle */
591 GC_words_allocd_before_gc
+= GC_words_allocd
;
592 GC_non_gc_bytes_at_gc
= GC_non_gc_bytes
;
602 GC_printf2("Finalize + initiate sweep took %lu + %lu msecs\n",
603 MS_TIME_DIFF(finalize_time
,start_time
),
604 MS_TIME_DIFF(done_time
,finalize_time
));
608 /* Externally callable routine to invoke full, stop-world collection */
609 # if defined(__STDC__) || defined(__cplusplus)
610 int GC_try_to_collect(GC_stop_func stop_func
)
612 int GC_try_to_collect(stop_func
)
613 GC_stop_func stop_func
;
619 GC_INVOKE_FINALIZERS();
623 if (!GC_is_initialized
) GC_init_inner();
624 /* Minimize junk left in my registers */
625 GC_noop(0,0,0,0,0,0);
626 result
= (int)GC_try_to_collect_inner(stop_func
);
630 if(result
) GC_INVOKE_FINALIZERS();
634 void GC_gcollect
GC_PROTO(())
637 (void)GC_try_to_collect(GC_never_stop_func
);
640 word GC_n_heap_sects
= 0; /* Number of sections currently in heap. */
643 * Use the chunk of memory starting at p of size bytes as part of the heap.
644 * Assumes p is HBLKSIZE aligned, and bytes is a multiple of HBLKSIZE.
646 void GC_add_to_heap(p
, bytes
)
653 if (GC_n_heap_sects
>= MAX_HEAP_SECTS
) {
654 ABORT("Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS");
656 phdr
= GC_install_header(p
);
658 /* This is extremely unlikely. Can't add it. This will */
659 /* almost certainly result in a 0 return from the allocator, */
660 /* which is entirely appropriate. */
663 GC_heap_sects
[GC_n_heap_sects
].hs_start
= (ptr_t
)p
;
664 GC_heap_sects
[GC_n_heap_sects
].hs_bytes
= bytes
;
666 words
= BYTES_TO_WORDS(bytes
- HDR_BYTES
);
667 phdr
-> hb_sz
= words
;
668 phdr
-> hb_map
= (char *)1; /* A value != GC_invalid_map */
669 phdr
-> hb_flags
= 0;
671 GC_heapsize
+= bytes
;
672 if ((ptr_t
)p
<= GC_least_plausible_heap_addr
673 || GC_least_plausible_heap_addr
== 0) {
674 GC_least_plausible_heap_addr
= (ptr_t
)p
- sizeof(word
);
675 /* Making it a little smaller than necessary prevents */
676 /* us from getting a false hit from the variable */
677 /* itself. There's some unintentional reflection */
680 if ((ptr_t
)p
+ bytes
>= GC_greatest_plausible_heap_addr
) {
681 GC_greatest_plausible_heap_addr
= (ptr_t
)p
+ bytes
;
685 # if !defined(NO_DEBUGGING)
686 void GC_print_heap_sects()
690 GC_printf1("Total heap size: %lu\n", (unsigned long) GC_heapsize
);
691 for (i
= 0; i
< GC_n_heap_sects
; i
++) {
692 unsigned long start
= (unsigned long) GC_heap_sects
[i
].hs_start
;
693 unsigned long len
= (unsigned long) GC_heap_sects
[i
].hs_bytes
;
697 GC_printf3("Section %ld from 0x%lx to 0x%lx ", (unsigned long)i
,
698 start
, (unsigned long)(start
+ len
));
699 for (h
= (struct hblk
*)start
; h
< (struct hblk
*)(start
+ len
); h
++) {
700 if (GC_is_black_listed(h
, HBLKSIZE
)) nbl
++;
702 GC_printf2("%lu/%lu blacklisted\n", (unsigned long)nbl
,
703 (unsigned long)(len
/HBLKSIZE
));
708 ptr_t GC_least_plausible_heap_addr
= (ptr_t
)ONES
;
709 ptr_t GC_greatest_plausible_heap_addr
= 0;
714 return(x
> y
? x
: y
);
720 return(x
< y
? x
: y
);
723 # if defined(__STDC__) || defined(__cplusplus)
724 void GC_set_max_heap_size(GC_word n
)
726 void GC_set_max_heap_size(n
)
733 GC_word GC_max_retries
= 0;
736 * this explicitly increases the size of the heap. It is used
737 * internally, but may also be invoked from GC_expand_hp by the user.
738 * The argument is in units of HBLKSIZE.
739 * Tiny values of n are rounded up.
740 * Returns FALSE on failure.
742 GC_bool
GC_expand_hp_inner(n
)
747 word expansion_slop
; /* Number of bytes by which we expect the */
748 /* heap to expand soon. */
750 if (n
< MINHINCR
) n
= MINHINCR
;
751 bytes
= n
* HBLKSIZE
;
752 /* Make sure bytes is a multiple of GC_page_size */
754 word mask
= GC_page_size
- 1;
759 if (GC_max_heapsize
!= 0 && GC_heapsize
+ bytes
> GC_max_heapsize
) {
760 /* Exceeded self-imposed limit */
763 space
= GET_MEM(bytes
);
768 GC_printf2("Increasing heap size by %lu after %lu allocated bytes\n",
769 (unsigned long)bytes
,
770 (unsigned long)WORDS_TO_BYTES(GC_words_allocd
));
772 GC_printf1("Root size = %lu\n", GC_root_size
);
773 GC_print_block_list(); GC_print_hblkfreelist();
777 expansion_slop
= 8 * WORDS_TO_BYTES(min_words_allocd());
778 if (5 * HBLKSIZE
* MAXHINCR
> expansion_slop
) {
779 expansion_slop
= 5 * HBLKSIZE
* MAXHINCR
;
781 if (GC_last_heap_addr
== 0 && !((word
)space
& SIGNB
)
782 || GC_last_heap_addr
!= 0 && GC_last_heap_addr
< (ptr_t
)space
) {
783 /* Assume the heap is growing up */
784 GC_greatest_plausible_heap_addr
=
785 GC_max(GC_greatest_plausible_heap_addr
,
786 (ptr_t
)space
+ bytes
+ expansion_slop
);
788 /* Heap is growing down */
789 GC_least_plausible_heap_addr
=
790 GC_min(GC_least_plausible_heap_addr
,
791 (ptr_t
)space
- expansion_slop
);
793 GC_prev_heap_addr
= GC_last_heap_addr
;
794 GC_last_heap_addr
= (ptr_t
)space
;
795 GC_add_to_heap(space
, bytes
);
799 /* Really returns a bool, but it's externally visible, so that's clumsy. */
800 /* Arguments is in bytes. */
801 # if defined(__STDC__) || defined(__cplusplus)
802 int GC_expand_hp(size_t bytes
)
804 int GC_expand_hp(bytes
)
813 if (!GC_is_initialized
) GC_init_inner();
814 result
= (int)GC_expand_hp_inner(divHBLKSZ((word
)bytes
));
815 if (result
) GC_requested_heapsize
+= bytes
;
821 unsigned GC_fail_count
= 0;
822 /* How many consecutive GC/expansion failures? */
823 /* Reset by GC_allochblk. */
825 GC_bool
GC_collect_or_expand(needed_blocks
, ignore_off_page
)
827 GC_bool ignore_off_page
;
829 if (!GC_incremental
&& !GC_dont_gc
&&
830 (GC_dont_expand
&& GC_words_allocd
> 0 || GC_should_collect())) {
834 word blocks_to_get
= GC_heapsize
/(HBLKSIZE
*GC_free_space_divisor
)
837 if (blocks_to_get
> MAXHINCR
) {
840 if (ignore_off_page
) {
843 slop
= 2*divHBLKSZ(BL_LIMIT
);
844 if (slop
> needed_blocks
) slop
= needed_blocks
;
846 if (needed_blocks
+ slop
> MAXHINCR
) {
847 blocks_to_get
= needed_blocks
+ slop
;
849 blocks_to_get
= MAXHINCR
;
852 if (!GC_expand_hp_inner(blocks_to_get
)
853 && !GC_expand_hp_inner(needed_blocks
)) {
854 if (GC_fail_count
++ < GC_max_retries
) {
855 WARN("Out of Memory! Trying to continue ...\n", 0);
859 WARN("Out of Memory! Returning NIL!\n", 0);
865 GC_printf0("Memory available again ...\n");
874 * Make sure the object free list for sz is not empty.
875 * Return a pointer to the first object on the free list.
876 * The object MUST BE REMOVED FROM THE FREE LIST BY THE CALLER.
877 * Assumes we hold the allocator lock and signals are disabled.
880 ptr_t
GC_allocobj(sz
, kind
)
884 register ptr_t
* flh
= &(GC_obj_kinds
[kind
].ok_freelist
[sz
]);
886 if (sz
== 0) return(0);
890 /* Do our share of marking work */
891 if(GC_incremental
&& !GC_dont_gc
) GC_collect_a_little_inner(1);
892 /* Sweep blocks for objects of this size */
893 GC_continue_reclaim(sz
, kind
);
896 GC_new_hblk(sz
, kind
);
900 if (!GC_collect_or_expand((word
)1,FALSE
)) {