2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1996 by Xerox Corporation. All rights reserved.
4 * Copyright (c) 1996-1999 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.
18 #include "private/gc_priv.h"
20 signed_word GC_mem_found
= 0;
21 /* Number of words of memory reclaimed */
23 #if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
24 word GC_fl_builder_count
= 0;
25 /* Number of threads currently building free lists without */
26 /* holding GC lock. It is not safe to collect if this is */
28 #endif /* PARALLEL_MARK */
30 static void report_leak(p
, sz
)
34 if (HDR(p
) -> hb_obj_kind
== PTRFREE
) {
35 GC_err_printf0("Leaked atomic object at ");
37 GC_err_printf0("Leaked composite object at ");
43 # define FOUND_FREE(hblk, word_no) \
45 report_leak((ptr_t)hblk + WORDS_TO_BYTES(word_no), \
46 HDR(hblk) -> hb_sz); \
56 * Test whether a block is completely empty, i.e. contains no marked
57 * objects. This does not require the block to be in physical
61 GC_bool
GC_block_empty(hhdr
)
64 /* We treat hb_marks as an array of words here, even if it is */
65 /* actually an array of bytes. Since we only check for zero, there */
66 /* are no endian-ness issues. */
67 register word
*p
= (word
*)(&(hhdr
-> hb_marks
[0]));
68 register word
* plim
=
69 (word
*)(&(hhdr
-> hb_marks
[MARK_BITS_SZ
]));
71 if (*p
++) return(FALSE
);
76 /* The following functions sometimes return a DONT_KNOW value. */
80 # define GC_block_nearly_full1(hhdr, pat1) DONT_KNOW
81 # define GC_block_nearly_full3(hhdr, pat1, pat2) DONT_KNOW
82 # define GC_block_nearly_full(hhdr) DONT_KNOW
85 #if !defined(SMALL_CONFIG) && defined(USE_MARK_BYTES)
87 # define GC_block_nearly_full1(hhdr, pat1) GC_block_nearly_full(hhdr)
88 # define GC_block_nearly_full3(hhdr, pat1, pat2) GC_block_nearly_full(hhdr)
91 GC_bool
GC_block_nearly_full(hhdr
)
94 /* We again treat hb_marks as an array of words, even though it */
95 /* isn't. We first sum up all the words, resulting in a word */
96 /* containing 4 or 8 separate partial sums. */
97 /* We then sum the bytes in the word of partial sums. */
98 /* This is still endian independant. This fails if the partial */
99 /* sums can overflow. */
100 # if (BYTES_TO_WORDS(MARK_BITS_SZ)) >= 256
101 --> potential overflow
; fix the code
103 register word
*p
= (word
*)(&(hhdr
-> hb_marks
[0]));
104 register word
* plim
=
105 (word
*)(&(hhdr
-> hb_marks
[MARK_BITS_SZ
]));
113 while (sum_vector
> 0) {
114 sum
+= sum_vector
& 0xff;
117 return (sum
> BYTES_TO_WORDS(7*HBLKSIZE
/8)/(hhdr
-> hb_sz
));
119 #endif /* USE_MARK_BYTES */
121 #if !defined(SMALL_CONFIG) && !defined(USE_MARK_BYTES)
124 * Test whether nearly all of the mark words consist of the same
127 #define FULL_THRESHOLD (MARK_BITS_SZ/16)
129 GC_bool
GC_block_nearly_full1(hhdr
, pat1
)
135 GC_ASSERT((MARK_BITS_SZ
& 1) == 0);
136 for (i
= 0; i
< MARK_BITS_SZ
; ++i
) {
137 if ((hhdr
-> hb_marks
[i
] | ~pat1
) != ONES
) {
138 if (++misses
> FULL_THRESHOLD
) return FALSE
;
145 * Test whether the same repeating 3 word pattern occurs in nearly
146 * all the mark bit slots.
147 * This is used as a heuristic, so we're a bit sloppy and ignore
148 * the last one or two words.
150 GC_bool
GC_block_nearly_full3(hhdr
, pat1
, pat2
, pat3
)
152 word pat1
, pat2
, pat3
;
157 if (MARK_BITS_SZ
< 4) {
160 for (i
= 0; i
< MARK_BITS_SZ
- 2; i
+= 3) {
161 if ((hhdr
-> hb_marks
[i
] | ~pat1
) != ONES
) {
162 if (++misses
> FULL_THRESHOLD
) return FALSE
;
164 if ((hhdr
-> hb_marks
[i
+1] | ~pat2
) != ONES
) {
165 if (++misses
> FULL_THRESHOLD
) return FALSE
;
167 if ((hhdr
-> hb_marks
[i
+2] | ~pat3
) != ONES
) {
168 if (++misses
> FULL_THRESHOLD
) return FALSE
;
174 /* Check whether a small object block is nearly full by looking at only */
176 /* We manually precomputed the mark bit patterns that need to be */
177 /* checked for, and we give up on the ones that are unlikely to occur, */
178 /* or have period > 3. */
179 /* This would be a lot easier with a mark bit per object instead of per */
180 /* word, but that would rewuire computing object numbers in the mark */
181 /* loop, which would require different data structures ... */
182 GC_bool
GC_block_nearly_full(hhdr
)
185 int sz
= hhdr
-> hb_sz
;
187 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
188 return DONT_KNOW
; /* Shouldn't be used in any standard config. */
190 # if CPP_WORDSZ == 32
193 return GC_block_nearly_full1(hhdr
, 0xffffffffl
);
195 return GC_block_nearly_full1(hhdr
, 0x55555555l
);
197 return GC_block_nearly_full1(hhdr
, 0x11111111l
);
199 return GC_block_nearly_full3(hhdr
, 0x41041041l
,
203 return GC_block_nearly_full1(hhdr
, 0x01010101l
);
205 return GC_block_nearly_full3(hhdr
, 0x01001001l
,
209 return GC_block_nearly_full1(hhdr
, 0x00010001l
);
211 return GC_block_nearly_full1(hhdr
, 0x00000001l
);
216 # if CPP_WORDSZ == 64
219 return GC_block_nearly_full1(hhdr
, 0xffffffffffffffffl
);
221 return GC_block_nearly_full1(hhdr
, 0x5555555555555555l
);
223 return GC_block_nearly_full1(hhdr
, 0x1111111111111111l
);
225 return GC_block_nearly_full3(hhdr
, 0x1041041041041041l
,
227 0x0410410410410410l
);
229 return GC_block_nearly_full1(hhdr
, 0x0101010101010101l
);
231 return GC_block_nearly_full3(hhdr
, 0x1001001001001001l
,
233 0x0010010010010010l
);
235 return GC_block_nearly_full1(hhdr
, 0x0001000100010001l
);
237 return GC_block_nearly_full1(hhdr
, 0x0000000100000001l
);
243 #endif /* !SMALL_CONFIG && !USE_MARK_BYTES */
245 /* We keep track of reclaimed memory if we are either asked to, or */
246 /* we are using the parallel marker. In the latter case, we assume */
247 /* that most allocation goes through GC_malloc_many for scalability. */
248 /* GC_malloc_many needs the count anyway. */
249 # if defined(GATHERSTATS) || defined(PARALLEL_MARK)
250 # define INCR_WORDS(sz) n_words_found += (sz)
251 # define COUNT_PARAM , count
252 # define COUNT_ARG , count
253 # define COUNT_DECL signed_word * count;
254 # define NWORDS_DECL signed_word n_words_found = 0;
255 # define COUNT_UPDATE *count += n_words_found;
256 # define MEM_FOUND_ADDR , &GC_mem_found
258 # define INCR_WORDS(sz)
263 # define COUNT_UPDATE
264 # define MEM_FOUND_ADDR
267 * Restore unmarked small objects in h of size sz to the object
268 * free list. Returns the new list.
269 * Clears unmarked objects.
272 ptr_t
GC_reclaim_clear(hbp
, hhdr
, sz
, list COUNT_PARAM
)
273 register struct hblk
*hbp
; /* ptr to current heap block */
279 register int word_no
;
280 register word
*p
, *q
, *plim
;
283 GC_ASSERT(hhdr
== GC_find_header((ptr_t
)hbp
));
284 p
= (word
*)(hbp
->hb_body
);
286 plim
= (word
*)((((word
)hbp
) + HBLKSIZE
)
287 - WORDS_TO_BYTES(sz
));
289 /* go through all words in block */
291 if( mark_bit_from_hdr(hhdr
, word_no
) ) {
295 /* object is available - put on list */
298 /* Clear object, advance p to next object in the process */
300 # ifdef USE_MARK_BYTES
302 && !((word
)p
& (2 * sizeof(word
) - 1)));
310 p
++; /* Skip link field */
322 #if !defined(SMALL_CONFIG) && !defined(USE_MARK_BYTES)
325 * A special case for 2 word composite objects (e.g. cons cells):
328 ptr_t
GC_reclaim_clear2(hbp
, hhdr
, list COUNT_PARAM
)
329 register struct hblk
*hbp
; /* ptr to current heap block */
334 register word
* mark_word_addr
= &(hhdr
->hb_marks
[0]);
335 register word
*p
, *plim
;
336 register word mark_word
;
339 # define DO_OBJ(start_displ) \
340 if (!(mark_word & ((word)1 << start_displ))) { \
341 p[start_displ] = (word)list; \
342 list = (ptr_t)(p+start_displ); \
343 p[start_displ+1] = 0; \
347 p
= (word
*)(hbp
->hb_body
);
348 plim
= (word
*)(((word
)hbp
) + HBLKSIZE
);
350 /* go through all words in block */
352 mark_word
= *mark_word_addr
++;
353 for (i
= 0; i
< WORDSZ
; i
+= 8) {
368 * Another special case for 4 word composite objects:
371 ptr_t
GC_reclaim_clear4(hbp
, hhdr
, list COUNT_PARAM
)
372 register struct hblk
*hbp
; /* ptr to current heap block */
377 register word
* mark_word_addr
= &(hhdr
->hb_marks
[0]);
378 register word
*p
, *plim
;
379 register word mark_word
;
381 # define DO_OBJ(start_displ) \
382 if (!(mark_word & ((word)1 << start_displ))) { \
383 p[start_displ] = (word)list; \
384 list = (ptr_t)(p+start_displ); \
385 p[start_displ+1] = 0; \
386 CLEAR_DOUBLE(p + start_displ + 2); \
390 p
= (word
*)(hbp
->hb_body
);
391 plim
= (word
*)(((word
)hbp
) + HBLKSIZE
);
393 /* go through all words in block */
395 mark_word
= *mark_word_addr
++;
404 # if CPP_WORDSZ == 64
421 #endif /* !SMALL_CONFIG && !USE_MARK_BYTES */
423 /* The same thing, but don't clear objects: */
425 ptr_t
GC_reclaim_uninit(hbp
, hhdr
, sz
, list COUNT_PARAM
)
426 register struct hblk
*hbp
; /* ptr to current heap block */
432 register int word_no
= 0;
433 register word
*p
, *plim
;
436 p
= (word
*)(hbp
->hb_body
);
437 plim
= (word
*)((((word
)hbp
) + HBLKSIZE
)
438 - WORDS_TO_BYTES(sz
));
440 /* go through all words in block */
442 if( !mark_bit_from_hdr(hhdr
, word_no
) ) {
444 /* object is available - put on list */
455 /* Don't really reclaim objects, just check for unmarked ones: */
457 void GC_reclaim_check(hbp
, hhdr
, sz
)
458 register struct hblk
*hbp
; /* ptr to current heap block */
462 register int word_no
= 0;
463 register word
*p
, *plim
;
465 register int n_words_found
= 0;
468 p
= (word
*)(hbp
->hb_body
);
469 plim
= (word
*)((((word
)hbp
) + HBLKSIZE
)
470 - WORDS_TO_BYTES(sz
));
472 /* go through all words in block */
474 if( !mark_bit_from_hdr(hhdr
, word_no
) ) {
475 FOUND_FREE(hbp
, word_no
);
482 #if !defined(SMALL_CONFIG) && !defined(USE_MARK_BYTES)
484 * Another special case for 2 word atomic objects:
487 ptr_t
GC_reclaim_uninit2(hbp
, hhdr
, list COUNT_PARAM
)
488 register struct hblk
*hbp
; /* ptr to current heap block */
493 register word
* mark_word_addr
= &(hhdr
->hb_marks
[0]);
494 register word
*p
, *plim
;
495 register word mark_word
;
498 # define DO_OBJ(start_displ) \
499 if (!(mark_word & ((word)1 << start_displ))) { \
500 p[start_displ] = (word)list; \
501 list = (ptr_t)(p+start_displ); \
505 p
= (word
*)(hbp
->hb_body
);
506 plim
= (word
*)(((word
)hbp
) + HBLKSIZE
);
508 /* go through all words in block */
510 mark_word
= *mark_word_addr
++;
511 for (i
= 0; i
< WORDSZ
; i
+= 8) {
526 * Another special case for 4 word atomic objects:
529 ptr_t
GC_reclaim_uninit4(hbp
, hhdr
, list COUNT_PARAM
)
530 register struct hblk
*hbp
; /* ptr to current heap block */
535 register word
* mark_word_addr
= &(hhdr
->hb_marks
[0]);
536 register word
*p
, *plim
;
537 register word mark_word
;
539 # define DO_OBJ(start_displ) \
540 if (!(mark_word & ((word)1 << start_displ))) { \
541 p[start_displ] = (word)list; \
542 list = (ptr_t)(p+start_displ); \
546 p
= (word
*)(hbp
->hb_body
);
547 plim
= (word
*)(((word
)hbp
) + HBLKSIZE
);
549 /* go through all words in block */
551 mark_word
= *mark_word_addr
++;
560 # if CPP_WORDSZ == 64
577 /* Finally the one word case, which never requires any clearing: */
579 ptr_t
GC_reclaim1(hbp
, hhdr
, list COUNT_PARAM
)
580 register struct hblk
*hbp
; /* ptr to current heap block */
585 register word
* mark_word_addr
= &(hhdr
->hb_marks
[0]);
586 register word
*p
, *plim
;
587 register word mark_word
;
590 # define DO_OBJ(start_displ) \
591 if (!(mark_word & ((word)1 << start_displ))) { \
592 p[start_displ] = (word)list; \
593 list = (ptr_t)(p+start_displ); \
597 p
= (word
*)(hbp
->hb_body
);
598 plim
= (word
*)(((word
)hbp
) + HBLKSIZE
);
600 /* go through all words in block */
602 mark_word
= *mark_word_addr
++;
603 for (i
= 0; i
< WORDSZ
; i
+= 4) {
617 #endif /* !SMALL_CONFIG && !USE_MARK_BYTES */
620 * Generic procedure to rebuild a free list in hbp.
621 * Also called directly from GC_malloc_many.
623 ptr_t
GC_reclaim_generic(hbp
, hhdr
, sz
, init
, list COUNT_PARAM
)
624 struct hblk
*hbp
; /* ptr to current heap block */
633 GC_ASSERT(GC_find_header((ptr_t
)hbp
) == hhdr
);
636 # if !defined(SMALL_CONFIG) && !defined(USE_MARK_BYTES)
638 /* We now issue the hint even if GC_nearly_full returned */
641 result
= GC_reclaim1(hbp
, hhdr
, list COUNT_ARG
);
645 result
= GC_reclaim_clear2(hbp
, hhdr
, list COUNT_ARG
);
649 result
= GC_reclaim_clear4(hbp
, hhdr
, list COUNT_ARG
);
651 # endif /* !SMALL_CONFIG && !USE_MARK_BYTES */
654 result
= GC_reclaim_clear(hbp
, hhdr
, sz
, list COUNT_ARG
);
659 # if !defined(SMALL_CONFIG) && !defined(USE_MARK_BYTES)
662 result
= GC_reclaim1(hbp
, hhdr
, list COUNT_ARG
);
666 result
= GC_reclaim_uninit2(hbp
, hhdr
, list COUNT_ARG
);
670 result
= GC_reclaim_uninit4(hbp
, hhdr
, list COUNT_ARG
);
672 # endif /* !SMALL_CONFIG && !USE_MARK_BYTES */
675 result
= GC_reclaim_uninit(hbp
, hhdr
, sz
, list COUNT_ARG
);
679 if (IS_UNCOLLECTABLE(hhdr
-> hb_obj_kind
)) GC_set_hdr_marks(hhdr
);
684 * Restore unmarked small objects in the block pointed to by hbp
685 * to the appropriate object free list.
686 * If entirely empty blocks are to be completely deallocated, then
687 * caller should perform that check.
689 void GC_reclaim_small_nonempty_block(hbp
, report_if_found COUNT_PARAM
)
690 register struct hblk
*hbp
; /* ptr to current heap block */
691 int report_if_found
; /* Abort if a reclaimable object is found */
694 hdr
*hhdr
= HDR(hbp
);
695 word sz
= hhdr
-> hb_sz
;
696 int kind
= hhdr
-> hb_obj_kind
;
697 struct obj_kind
* ok
= &GC_obj_kinds
[kind
];
698 ptr_t
* flh
= &(ok
-> ok_freelist
[sz
]);
700 hhdr
-> hb_last_reclaimed
= (unsigned short) GC_gc_no
;
702 if (report_if_found
) {
703 GC_reclaim_check(hbp
, hhdr
, sz
);
705 *flh
= GC_reclaim_generic(hbp
, hhdr
, sz
,
706 (ok
-> ok_init
|| GC_debugging_started
),
707 *flh MEM_FOUND_ADDR
);
712 * Restore an unmarked large object or an entirely empty blocks of small objects
713 * to the heap block free list.
714 * Otherwise enqueue the block for later processing
715 * by GC_reclaim_small_nonempty_block.
716 * If report_if_found is TRUE, then process any block immediately, and
717 * simply report free objects; do not actually reclaim them.
719 # if defined(__STDC__) || defined(__cplusplus)
720 void GC_reclaim_block(register struct hblk
*hbp
, word report_if_found
)
722 void GC_reclaim_block(hbp
, report_if_found
)
723 register struct hblk
*hbp
; /* ptr to current heap block */
724 word report_if_found
; /* Abort if a reclaimable object is found */
728 register word sz
; /* size of objects in current block */
729 register struct obj_kind
* ok
;
734 ok
= &GC_obj_kinds
[hhdr
-> hb_obj_kind
];
736 if( sz
> MAXOBJSZ
) { /* 1 big object */
737 if( !mark_bit_from_hdr(hhdr
, 0) ) {
738 if (report_if_found
) {
741 word blocks
= OBJ_SZ_TO_BLOCKS(sz
);
743 GC_large_allocd_bytes
-= blocks
* HBLKSIZE
;
752 GC_bool empty
= GC_block_empty(hhdr
);
753 if (report_if_found
) {
754 GC_reclaim_small_nonempty_block(hbp
, (int)report_if_found
758 GC_mem_found
+= BYTES_TO_WORDS(HBLKSIZE
);
761 } else if (TRUE
!= GC_block_nearly_full(hhdr
)){
762 /* group of smaller objects, enqueue the real work */
763 rlh
= &(ok
-> ok_reclaim_list
[sz
]);
764 hhdr
-> hb_next
= *rlh
;
766 } /* else not worth salvaging. */
767 /* We used to do the nearly_full check later, but we */
768 /* already have the right cache context here. Also */
769 /* doing it here avoids some silly lock contention in */
770 /* GC_malloc_many. */
774 #if !defined(NO_DEBUGGING)
775 /* Routines to gather and print heap block info */
776 /* intended for debugging. Otherwise should be called */
781 size_t number_of_blocks
;
785 #ifdef USE_MARK_BYTES
787 /* Return the number of set mark bits in the given header */
788 int GC_n_set_marks(hhdr
)
791 register int result
= 0;
794 for (i
= 0; i
< MARK_BITS_SZ
; i
++) {
795 result
+= hhdr
-> hb_marks
[i
];
802 /* Number of set bits in a word. Not performance critical. */
803 static int set_bits(n
)
807 register int result
= 0;
816 /* Return the number of set mark bits in the given header */
817 int GC_n_set_marks(hhdr
)
820 register int result
= 0;
823 for (i
= 0; i
< MARK_BITS_SZ
; i
++) {
824 result
+= set_bits(hhdr
-> hb_marks
[i
]);
829 #endif /* !USE_MARK_BYTES */
832 # if defined(__STDC__) || defined(__cplusplus)
833 void GC_print_block_descr(struct hblk
*h
, word dummy
)
835 void GC_print_block_descr(h
, dummy
)
840 register hdr
* hhdr
= HDR(h
);
841 register size_t bytes
= WORDS_TO_BYTES(hhdr
-> hb_sz
);
842 struct Print_stats
*ps
;
844 GC_printf3("(%lu:%lu,%lu)", (unsigned long)(hhdr
-> hb_obj_kind
),
845 (unsigned long)bytes
,
846 (unsigned long)(GC_n_set_marks(hhdr
)));
848 bytes
&= ~(HBLKSIZE
-1);
850 ps
= (struct Print_stats
*)dummy
;
851 ps
->total_bytes
+= bytes
;
852 ps
->number_of_blocks
++;
855 void GC_print_block_list()
857 struct Print_stats pstats
;
859 GC_printf0("(kind(0=ptrfree,1=normal,2=unc.,3=stubborn):size_in_bytes, #_marks_set)\n");
860 pstats
.number_of_blocks
= 0;
861 pstats
.total_bytes
= 0;
862 GC_apply_to_all_blocks(GC_print_block_descr
, (word
)&pstats
);
863 GC_printf2("\nblocks = %lu, bytes = %lu\n",
864 (unsigned long)pstats
.number_of_blocks
,
865 (unsigned long)pstats
.total_bytes
);
868 #endif /* NO_DEBUGGING */
871 * Perform GC_reclaim_block on the entire heap, after first clearing
872 * small object free lists (if we are not just looking for leaks).
874 void GC_start_reclaim(report_if_found
)
875 int report_if_found
; /* Abort if a GC_reclaimable object is found */
879 # if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
880 GC_ASSERT(0 == GC_fl_builder_count
);
882 /* Clear reclaim- and free-lists */
883 for (kind
= 0; kind
< GC_n_kinds
; kind
++) {
886 register struct hblk
** rlp
;
887 register struct hblk
** rlim
;
888 register struct hblk
** rlist
= GC_obj_kinds
[kind
].ok_reclaim_list
;
890 if (rlist
== 0) continue; /* This kind not used. */
891 if (!report_if_found
) {
892 lim
= &(GC_obj_kinds
[kind
].ok_freelist
[MAXOBJSZ
+1]);
893 for( fop
= GC_obj_kinds
[kind
].ok_freelist
; fop
< lim
; fop
++ ) {
896 } /* otherwise free list objects are marked, */
897 /* and its safe to leave them */
898 rlim
= rlist
+ MAXOBJSZ
+1;
899 for( rlp
= rlist
; rlp
< rlim
; rlp
++ ) {
905 GC_printf0("GC_reclaim: current block sizes:\n");
906 GC_print_block_list();
909 /* Go through all heap blocks (in hblklist) and reclaim unmarked objects */
910 /* or enqueue the block for later processing. */
911 GC_apply_to_all_blocks(GC_reclaim_block
, (word
)report_if_found
);
914 /* This is a very stupid thing to do. We make it possible anyway, */
915 /* so that you can convince yourself that it really is very stupid. */
916 GC_reclaim_all((GC_stop_func
)0, FALSE
);
918 # if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
919 GC_ASSERT(0 == GC_fl_builder_count
);
925 * Sweep blocks of the indicated object size and kind until either the
926 * appropriate free list is nonempty, or there are no more blocks to
929 void GC_continue_reclaim(sz
, kind
)
934 register struct hblk
* hbp
;
935 register struct obj_kind
* ok
= &(GC_obj_kinds
[kind
]);
936 struct hblk
** rlh
= ok
-> ok_reclaim_list
;
937 ptr_t
*flh
= &(ok
-> ok_freelist
[sz
]);
939 if (rlh
== 0) return; /* No blocks of this kind. */
941 while ((hbp
= *rlh
) != 0) {
943 *rlh
= hhdr
-> hb_next
;
944 GC_reclaim_small_nonempty_block(hbp
, FALSE MEM_FOUND_ADDR
);
945 if (*flh
!= 0) break;
950 * Reclaim all small blocks waiting to be reclaimed.
951 * Abort and return FALSE when/if (*stop_func)() returns TRUE.
952 * If this returns TRUE, then it's safe to restart the world
953 * with incorrectly cleared mark bits.
954 * If ignore_old is TRUE, then reclaim only blocks that have been
955 * recently reclaimed, and discard the rest.
956 * Stop_func may be 0.
958 GC_bool
GC_reclaim_all(stop_func
, ignore_old
)
959 GC_stop_func stop_func
;
965 register struct hblk
* hbp
;
966 register struct obj_kind
* ok
;
970 CLOCK_TYPE start_time
;
971 CLOCK_TYPE done_time
;
973 GET_TIME(start_time
);
976 for (kind
= 0; kind
< GC_n_kinds
; kind
++) {
977 ok
= &(GC_obj_kinds
[kind
]);
978 rlp
= ok
-> ok_reclaim_list
;
979 if (rlp
== 0) continue;
980 for (sz
= 1; sz
<= MAXOBJSZ
; sz
++) {
982 while ((hbp
= *rlh
) != 0) {
983 if (stop_func
!= (GC_stop_func
)0 && (*stop_func
)()) {
987 *rlh
= hhdr
-> hb_next
;
988 if (!ignore_old
|| hhdr
-> hb_last_reclaimed
== GC_gc_no
- 1) {
989 /* It's likely we'll need it this time, too */
990 /* It's been touched recently, so this */
991 /* shouldn't trigger paging. */
992 GC_reclaim_small_nonempty_block(hbp
, FALSE MEM_FOUND_ADDR
);
999 GC_printf1("Disposing of reclaim lists took %lu msecs\n",
1000 MS_TIME_DIFF(done_time
,start_time
));