2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #define AO_SCHEME_CONST_BITS
17 #include "ao_scheme.h"
21 #ifdef AO_SCHEME_MAKE_CONST
24 * When building the constant table, it is the
25 * pool for allocations.
29 uint8_t ao_scheme_const[AO_SCHEME_POOL_CONST] __attribute__((aligned(4)));
30 #define ao_scheme_pool ao_scheme_const
32 #define AO_SCHEME_POOL AO_SCHEME_POOL_CONST
36 uint8_t ao_scheme_pool[AO_SCHEME_POOL + AO_SCHEME_POOL_EXTRA] __attribute__((aligned(4)));
41 #define DBG_MEM_STATS DBG_MEM
44 #define DBG_MEM_STACK 0
46 char *mem_collect_stack;
47 int64_t mem_collect_max_depth;
50 ao_scheme_check_stack(void)
55 depth = mem_collect_stack - &x;
56 if (depth > mem_collect_max_depth)
57 mem_collect_max_depth = depth;
61 _ao_scheme_reset_stack(char *x)
63 mem_collect_stack = x;
64 // mem_collect_max_depth = 0;
66 #define ao_scheme_declare_stack char x;
67 #define ao_scheme_reset_stack() _ao_scheme_reset_stack(&x)
69 #define ao_scheme_check_stack()
70 #define ao_scheme_declare_stack
71 #define ao_scheme_reset_stack()
75 #define DBG_MEM_RECORD 1
80 int dbg_mem = DBG_MEM_START;
85 struct ao_scheme_record {
86 struct ao_scheme_record *next;
87 const struct ao_scheme_type *type;
92 static struct ao_scheme_record *record_head, **record_tail;
95 ao_scheme_record_free(struct ao_scheme_record *record)
98 struct ao_scheme_record *next = record->next;
105 ao_scheme_record_reset(void)
107 ao_scheme_record_free(record_head);
109 record_tail = &record_head;
113 ao_scheme_record(const struct ao_scheme_type *type,
117 struct ao_scheme_record *r = malloc(sizeof (struct ao_scheme_record));
124 record_tail = &r->next;
127 static struct ao_scheme_record *
128 ao_scheme_record_save(void)
130 struct ao_scheme_record *r = record_head;
133 record_tail = &record_head;
138 ao_scheme_record_compare(const char *where,
139 struct ao_scheme_record *a,
140 struct ao_scheme_record *b)
143 if (a->type != b->type || a->size != b->size) {
144 printf("%s record difers %d %s %d -> %d %s %d\n",
146 MDBG_OFFSET(a->addr),
149 MDBG_OFFSET(b->addr),
158 printf("%s record differs %d %s %d -> NULL\n",
160 MDBG_OFFSET(a->addr),
166 printf("%s record differs NULL -> %d %s %d\n",
168 MDBG_OFFSET(b->addr),
176 #define ao_scheme_record_reset()
177 #define ao_scheme_record(t,a,s)
180 uint8_t ao_scheme_exception;
182 struct ao_scheme_root {
183 const struct ao_scheme_type *type;
187 #define AO_SCHEME_NUM_STASH 6
188 static ao_poly stash_poly[AO_SCHEME_NUM_STASH];
189 static int stash_poly_ptr;
191 static const struct ao_scheme_root ao_scheme_root[] = {
194 .addr = (void **) (void *) &stash_poly[0]
198 .addr = (void **) (void *) &stash_poly[1]
202 .addr = (void **) (void *) &stash_poly[2]
206 .addr = (void **) (void *) &stash_poly[3]
210 .addr = (void **) (void *) &stash_poly[4]
214 .addr = (void **) (void *) &stash_poly[5]
217 .type = &ao_scheme_atom_type,
218 .addr = (void **) &ao_scheme_atoms
221 .type = &ao_scheme_frame_type,
222 .addr = (void **) &ao_scheme_frame_global,
225 .type = &ao_scheme_frame_type,
226 .addr = (void **) &ao_scheme_frame_current,
229 .type = &ao_scheme_stack_type,
230 .addr = (void **) &ao_scheme_stack,
234 .addr = (void **) (void *) &ao_scheme_v,
237 .type = &ao_scheme_cons_type,
238 .addr = (void **) &ao_scheme_read_cons,
241 .type = &ao_scheme_cons_type,
242 .addr = (void **) &ao_scheme_read_cons_tail,
245 .type = &ao_scheme_cons_type,
246 .addr = (void **) &ao_scheme_read_stack,
248 #ifdef AO_SCHEME_MAKE_CONST
250 .type = &ao_scheme_bool_type,
251 .addr = (void **) &ao_scheme_false,
254 .type = &ao_scheme_bool_type,
255 .addr = (void **) &ao_scheme_true,
260 #define AO_SCHEME_ROOT (sizeof (ao_scheme_root) / sizeof (ao_scheme_root[0]))
262 static const void ** const ao_scheme_cache[] = {
263 (const void **) &ao_scheme_cons_free_list,
264 (const void **) &ao_scheme_stack_free_list,
265 (const void **) &ao_scheme_frame_free_list[0],
266 (const void **) &ao_scheme_frame_free_list[1],
267 (const void **) &ao_scheme_frame_free_list[2],
268 (const void **) &ao_scheme_frame_free_list[3],
269 (const void **) &ao_scheme_frame_free_list[4],
270 (const void **) &ao_scheme_frame_free_list[5],
273 #if AO_SCHEME_FRAME_FREE != 6
274 #error Unexpected AO_SCHEME_FRAME_FREE value
277 #define AO_SCHEME_CACHE (sizeof (ao_scheme_cache) / sizeof (ao_scheme_cache[0]))
279 #define AO_SCHEME_BUSY_SIZE ((AO_SCHEME_POOL + 31) / 32)
281 static int ao_scheme_printing, ao_scheme_print_cleared;
283 static int ao_scheme_collecting;
285 static uint8_t ao_scheme_busy[AO_SCHEME_BUSY_SIZE];
286 static uint8_t ao_scheme_cons_note[AO_SCHEME_BUSY_SIZE];
287 static uint8_t ao_scheme_cons_last[AO_SCHEME_BUSY_SIZE];
288 static uint8_t ao_scheme_cons_noted;
290 uint16_t ao_scheme_top;
292 struct ao_scheme_chunk {
300 #define AO_SCHEME_NCHUNK 64
302 static struct ao_scheme_chunk ao_scheme_chunk[AO_SCHEME_NCHUNK];
304 /* Offset of an address within the pool. */
305 static inline uint16_t pool_offset(void *addr) {
307 if (!ao_scheme_is_pool_addr(addr))
310 return ((uint8_t *) addr) - ao_scheme_pool;
313 static inline void mark(uint8_t *tag, int offset) {
314 int byte = offset >> 5;
315 int bit = (offset >> 2) & 7;
316 ao_scheme_check_stack();
317 tag[byte] |= (1 << bit);
320 static inline void clear(uint8_t *tag, int offset) {
321 int byte = offset >> 5;
322 int bit = (offset >> 2) & 7;
323 tag[byte] &= ~(1 << bit);
326 static inline int busy(uint8_t *tag, int offset) {
327 int byte = offset >> 5;
328 int bit = (offset >> 2) & 7;
329 return (tag[byte] >> bit) & 1;
332 static inline int min(int a, int b) { return a < b ? a : b; }
333 static inline int max(int a, int b) { return a > b ? a : b; }
335 static inline int limit(int offset) {
336 return min(AO_SCHEME_POOL, max(offset, 0));
340 note_cons(uint16_t offset)
342 MDBG_MOVE("note cons %d\n", offset);
343 ao_scheme_cons_noted = 1;
344 mark(ao_scheme_cons_note, offset);
347 static uint16_t chunk_low, chunk_high;
348 static uint16_t chunk_first, chunk_last;
351 find_chunk(uint16_t offset)
354 /* Binary search for the location */
358 int m = (l + r) >> 1;
359 if (ao_scheme_chunk[m].old_offset < offset)
368 note_chunk(uint16_t offset, uint16_t size)
373 if (offset < chunk_low || chunk_high <= offset)
376 l = find_chunk(offset);
379 * The correct location is always in 'l', with r = l-1 being
380 * the entry before the right one
384 /* Off the right side */
385 if (l >= AO_SCHEME_NCHUNK)
388 /* Off the left side */
389 if (l == 0 && chunk_last && offset > ao_scheme_chunk[0].old_offset)
392 if (l < chunk_last && ao_scheme_chunk[l].old_offset == offset)
396 /* Shuffle existing entries right */
397 end = min(AO_SCHEME_NCHUNK, chunk_last + 1);
399 memmove(&ao_scheme_chunk[l+1],
401 (end - (l+1)) * sizeof (struct ao_scheme_chunk));
404 ao_scheme_chunk[l].old_offset = offset;
405 ao_scheme_chunk[l].size = size;
407 /* Increment the number of elements up to the size of the array */
408 if (chunk_last < AO_SCHEME_NCHUNK)
411 /* Set the top address if the array is full */
412 if (chunk_last == AO_SCHEME_NCHUNK)
413 chunk_high = ao_scheme_chunk[AO_SCHEME_NCHUNK-1].old_offset +
414 ao_scheme_chunk[AO_SCHEME_NCHUNK-1].size;
420 chunk_high = ao_scheme_top;
426 * Walk all referenced objects calling functions on each one
430 walk(int (*visit_addr)(const struct ao_scheme_type *type, void **addr),
431 int (*visit_poly)(ao_poly *p, uint8_t do_note_cons))
435 ao_scheme_record_reset();
436 memset(ao_scheme_busy, '\0', sizeof (ao_scheme_busy));
437 memset(ao_scheme_cons_note, '\0', sizeof (ao_scheme_cons_note));
438 ao_scheme_cons_noted = 0;
439 for (i = 0; i < (int) AO_SCHEME_ROOT; i++) {
440 if (ao_scheme_root[i].type) {
441 void **a = ao_scheme_root[i].addr, *v;
443 MDBG_MOVE("root ptr %d\n", MDBG_OFFSET(v));
444 visit_addr(ao_scheme_root[i].type, a);
447 ao_poly *a = (ao_poly *) ao_scheme_root[i].addr, p;
449 MDBG_MOVE("root poly %d\n", MDBG_OFFSET(ao_scheme_ref(p)));
454 while (ao_scheme_cons_noted) {
455 memcpy(ao_scheme_cons_last, ao_scheme_cons_note, sizeof (ao_scheme_cons_note));
456 memset(ao_scheme_cons_note, '\0', sizeof (ao_scheme_cons_note));
457 ao_scheme_cons_noted = 0;
458 for (i = 0; i < AO_SCHEME_POOL; i += 4) {
459 if (busy(ao_scheme_cons_last, i)) {
460 void *v = ao_scheme_pool + i;
461 MDBG_MOVE("root cons %d\n", MDBG_OFFSET(v));
462 visit_addr(&ao_scheme_cons_type, &v);
474 for (i = 0; i < ao_scheme_top; i += 4) {
475 if ((i & 0xff) == 0) {
478 else if ((i & 0x1f) == 0)
480 if (busy(ao_scheme_busy, i))
487 #define DUMP_BUSY() dump_busy()
492 static const struct ao_scheme_type * const ao_scheme_types[AO_SCHEME_NUM_TYPE] = {
493 [AO_SCHEME_CONS] = &ao_scheme_cons_type,
494 [AO_SCHEME_INT] = NULL,
495 #ifdef AO_SCHEME_FEATURE_BIGINT
496 [AO_SCHEME_BIGINT] = &ao_scheme_bigint_type,
498 [AO_SCHEME_OTHER] = (void *) 0x1,
499 [AO_SCHEME_ATOM] = &ao_scheme_atom_type,
500 [AO_SCHEME_BUILTIN] = &ao_scheme_builtin_type,
501 [AO_SCHEME_FRAME] = &ao_scheme_frame_type,
502 [AO_SCHEME_FRAME_VALS] = &ao_scheme_frame_vals_type,
503 [AO_SCHEME_LAMBDA] = &ao_scheme_lambda_type,
504 [AO_SCHEME_STACK] = &ao_scheme_stack_type,
505 [AO_SCHEME_BOOL] = &ao_scheme_bool_type,
506 [AO_SCHEME_STRING] = &ao_scheme_string_type,
507 #ifdef AO_SCHEME_FEATURE_FLOAT
508 [AO_SCHEME_FLOAT] = &ao_scheme_float_type,
510 #ifdef AO_SCHEME_FEATURE_VECTOR
511 [AO_SCHEME_VECTOR] = &ao_scheme_vector_type,
516 ao_scheme_mark(const struct ao_scheme_type *type, void *addr);
519 ao_scheme_move(const struct ao_scheme_type *type, void **ref);
522 ao_scheme_mark_ref(const struct ao_scheme_type *type, void **ref)
524 return ao_scheme_mark(type, *ref);
528 ao_scheme_poly_mark_ref(ao_poly *p, uint8_t do_note_cons)
530 return ao_scheme_poly_mark(*p, do_note_cons);
534 uint64_t ao_scheme_collects[2];
535 uint64_t ao_scheme_freed[2];
536 uint64_t ao_scheme_loops[2];
539 int ao_scheme_last_top;
540 int ao_scheme_collect_counts;
543 ao_scheme_collect(uint8_t style)
545 ao_scheme_declare_stack
552 struct ao_scheme_record *mark_record = NULL, *move_record = NULL;
554 MDBG_MOVE("collect %lu\n", ao_scheme_collects[style]);
556 MDBG_DO(ao_scheme_frame_write(ao_scheme_frame_poly(ao_scheme_frame_global)));
557 MDBG_DO(++ao_scheme_collecting);
559 ao_scheme_reset_stack();
561 /* The first time through, we're doing a full collect */
562 if (ao_scheme_last_top == 0)
563 style = AO_SCHEME_COLLECT_FULL;
565 /* One in a while, just do a full collect */
567 if (ao_scheme_collect_counts >= 128)
568 style = AO_SCHEME_COLLECT_FULL;
570 if (style == AO_SCHEME_COLLECT_FULL)
571 ao_scheme_collect_counts = 0;
573 /* Clear references to all caches */
574 for (i = 0; i < (int) AO_SCHEME_CACHE; i++)
575 *ao_scheme_cache[i] = NULL;
576 if (style == AO_SCHEME_COLLECT_FULL) {
579 chunk_low = top = ao_scheme_last_top;
582 MDBG_MOVE("move chunks from %d to %d\n", chunk_low, top);
583 /* Find the sizes of the first chunk of objects to move */
585 walk(ao_scheme_mark_ref, ao_scheme_poly_mark_ref);
588 ao_scheme_record_free(mark_record);
589 mark_record = ao_scheme_record_save();
590 if (mark_record && move_record)
591 ao_scheme_record_compare("mark", move_record, mark_record);
596 /* Find the first moving object */
597 for (i = 0; i < chunk_last; i++) {
598 uint16_t size = ao_scheme_chunk[i].size;
604 if (ao_scheme_chunk[i].old_offset > top)
607 MDBG_MOVE("chunk %d %d not moving\n",
608 ao_scheme_chunk[i].old_offset,
609 ao_scheme_chunk[i].size);
611 if (ao_scheme_chunk[i].old_offset != top)
617 /* Short-circuit the rest of the loop when all of the
618 * found objects aren't moving. This isn't strictly
619 * necessary as the rest of the loop is structured to
620 * work in this case, but GCC 7.2.0 with optimization
621 * greater than 2 generates incorrect code for this...
623 if (i == AO_SCHEME_NCHUNK) {
624 chunk_low = chunk_high;
632 * Limit amount of chunk array used in mapping moves
633 * to the active region
636 chunk_low = ao_scheme_chunk[i].old_offset;
638 /* Copy all of the objects */
639 for (; i < chunk_last; i++) {
640 uint16_t size = ao_scheme_chunk[i].size;
647 MDBG_MOVE("chunk %d %d -> %d\n",
648 ao_scheme_chunk[i].old_offset,
651 ao_scheme_chunk[i].new_offset = top;
653 memmove(&ao_scheme_pool[top],
654 &ao_scheme_pool[ao_scheme_chunk[i].old_offset],
660 if (chunk_first < chunk_last) {
661 /* Relocate all references to the objects */
662 walk(ao_scheme_move, ao_scheme_poly_move);
665 ao_scheme_record_free(move_record);
666 move_record = ao_scheme_record_save();
667 if (mark_record && move_record)
668 ao_scheme_record_compare("move", mark_record, move_record);
675 /* If we ran into the end of the heap, then
676 * there's no need to keep walking
678 if (chunk_last != AO_SCHEME_NCHUNK)
681 /* Next loop starts right above this loop */
682 chunk_low = chunk_high;
687 ++ao_scheme_collects[style];
688 ao_scheme_freed[style] += ao_scheme_top - top;
689 ao_scheme_loops[style] += loops;
693 if (style == AO_SCHEME_COLLECT_FULL)
694 ao_scheme_last_top = top;
696 MDBG_DO(memset(ao_scheme_chunk, '\0', sizeof (ao_scheme_chunk));
697 walk(ao_scheme_mark_ref, ao_scheme_poly_mark_ref));
700 fprintf(stderr, "max collect stack depth %lu\n", mem_collect_max_depth);
702 MDBG_DO(--ao_scheme_collecting);
703 return AO_SCHEME_POOL - ao_scheme_top;
708 ao_scheme_cons_check(struct ao_scheme_cons *cons)
715 walk(ao_scheme_mark_ref, ao_scheme_poly_mark_ref);
717 if (!ao_scheme_is_pool_addr(cons))
719 offset = pool_offset(cons);
720 if (busy(ao_scheme_busy, offset)) {
721 ao_scheme_printf("cons at %p offset %d poly %d is busy\n\t%v\n", cons, offset, ao_scheme_cons_poly(cons), ao_scheme_cons_poly(cons));
725 if (!ao_scheme_is_pair(cdr))
727 cons = ao_scheme_poly_cons(cdr);
733 * Mark interfaces for objects
738 * Note a reference to memory and collect information about a few
739 * object sizes at a time
743 ao_scheme_mark_memory(const struct ao_scheme_type *type, void *addr)
746 if (!ao_scheme_is_pool_addr(addr))
749 offset = pool_offset(addr);
750 MDBG_MOVE("mark memory %d\n", MDBG_OFFSET(addr));
751 if (busy(ao_scheme_busy, offset)) {
752 MDBG_MOVE("already marked\n");
755 mark(ao_scheme_busy, offset);
756 note_chunk(offset, ao_scheme_size(type, addr));
761 * Mark an object and all that it refereces
764 ao_scheme_mark(const struct ao_scheme_type *type, void *addr)
767 MDBG_MOVE("mark %d\n", MDBG_OFFSET(addr));
769 ret = ao_scheme_mark_memory(type, addr);
771 MDBG_MOVE("mark recurse\n");
779 * Mark an object, unless it is a cons cell and
780 * do_note_cons is set. In that case, just
781 * set a bit in the cons note array; those
782 * will be marked in a separate pass to avoid
783 * deep recursion in the collector
786 ao_scheme_poly_mark(ao_poly p, uint8_t do_note_cons)
792 type = ao_scheme_poly_base_type(p);
794 if (type == AO_SCHEME_INT)
797 addr = ao_scheme_ref(p);
798 if (!ao_scheme_is_pool_addr(addr))
801 if (type == AO_SCHEME_CONS && do_note_cons) {
802 note_cons(pool_offset(addr));
805 const struct ao_scheme_type *lisp_type;
807 if (type == AO_SCHEME_OTHER)
808 type = ao_scheme_other_type(addr);
810 lisp_type = ao_scheme_types[type];
816 MDBG_MOVE("mark %d\n", MDBG_OFFSET(addr));
818 ret = ao_scheme_mark_memory(lisp_type, addr);
820 MDBG_MOVE("mark recurse\n");
821 lisp_type->mark(addr);
829 * Find the current location of an object
830 * based on the original location. For unmoved
831 * objects, this is simple. For moved objects,
836 move_map(uint16_t offset)
840 if (offset < chunk_low || chunk_high <= offset)
843 l = find_chunk(offset);
846 if (ao_scheme_chunk[l].old_offset != offset)
849 return ao_scheme_chunk[l].new_offset;
853 ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref)
856 uint16_t offset, orig_offset;
858 if (!ao_scheme_is_pool_addr(addr))
863 MDBG_MOVE("move memory %d\n", MDBG_OFFSET(addr));
864 orig_offset = pool_offset(addr);
865 offset = move_map(orig_offset);
866 if (offset != orig_offset) {
867 MDBG_MOVE("update ref %d %d -> %d\n",
868 ao_scheme_is_pool_addr(ref) ? MDBG_OFFSET(ref) : -1,
869 orig_offset, offset);
870 *ref = ao_scheme_pool + offset;
872 if (busy(ao_scheme_busy, offset)) {
873 MDBG_MOVE("already moved\n");
876 mark(ao_scheme_busy, offset);
877 ao_scheme_record(type, addr, ao_scheme_size(type, addr));
882 ao_scheme_move(const struct ao_scheme_type *type, void **ref)
885 MDBG_MOVE("move object %d\n", MDBG_OFFSET(*ref));
887 ret = ao_scheme_move_memory(type, ref);
889 MDBG_MOVE("move recurse\n");
897 ao_scheme_poly_move(ao_poly *ref, uint8_t do_note_cons)
902 uint16_t offset, orig_offset;
904 if (ao_scheme_poly_base_type(p) == AO_SCHEME_INT)
907 addr = ao_scheme_ref(p);
908 if (!ao_scheme_is_pool_addr(addr))
911 orig_offset = pool_offset(addr);
912 offset = move_map(orig_offset);
914 if (ao_scheme_poly_base_type(p) == AO_SCHEME_CONS && do_note_cons) {
915 note_cons(orig_offset);
918 uint8_t type = ao_scheme_poly_base_type(p);
919 const struct ao_scheme_type *lisp_type;
921 if (type == AO_SCHEME_OTHER)
922 type = ao_scheme_other_type(ao_scheme_pool + offset);
924 lisp_type = ao_scheme_types[type];
929 /* inline ao_scheme_move to save stack space */
930 MDBG_MOVE("move object %d\n", MDBG_OFFSET(addr));
932 ret = ao_scheme_move_memory(lisp_type, &addr);
934 MDBG_MOVE("move recurse\n");
935 lisp_type->move(addr);
940 /* Re-write the poly value */
941 if (offset != orig_offset) {
942 ao_poly np = ao_scheme_poly(ao_scheme_pool + offset, ao_scheme_poly_base_type(p));
943 MDBG_MOVE("poly %d moved %d -> %d\n",
944 ao_scheme_poly_type(np), orig_offset, offset);
952 ao_scheme_validate(void)
955 memset(ao_scheme_chunk, '\0', sizeof (ao_scheme_chunk));
956 walk(ao_scheme_mark_ref, ao_scheme_poly_mark_ref);
964 ao_scheme_alloc(int size)
968 MDBG_DO(++dbg_allocs);
969 MDBG_DO(if (dbg_validate) ao_scheme_validate());
970 size = ao_scheme_size_round(size);
971 if (AO_SCHEME_POOL - ao_scheme_top < size &&
972 ao_scheme_collect(AO_SCHEME_COLLECT_INCREMENTAL) < size &&
973 ao_scheme_collect(AO_SCHEME_COLLECT_FULL) < size)
975 ao_scheme_error(AO_SCHEME_OOM, "out of memory");
978 addr = ao_scheme_pool + ao_scheme_top;
979 ao_scheme_top += size;
980 MDBG_MOVE("alloc %d size %d\n", MDBG_OFFSET(addr), size);
985 ao_scheme_poly_stash(ao_poly p)
987 assert(stash_poly_ptr < AO_SCHEME_NUM_STASH);
988 stash_poly[stash_poly_ptr++] = p;
992 ao_scheme_poly_fetch(void)
996 assert (stash_poly_ptr > 0);
997 p = stash_poly[--stash_poly_ptr];
998 stash_poly[stash_poly_ptr] = AO_SCHEME_NIL;
1003 ao_scheme_print_mark_addr(void *addr)
1008 if (ao_scheme_collecting)
1012 if (!ao_scheme_is_pool_addr(addr))
1015 if (!ao_scheme_print_cleared) {
1016 ao_scheme_print_cleared = 1;
1017 memset(ao_scheme_busy, '\0', sizeof (ao_scheme_busy));
1019 offset = pool_offset(addr);
1020 if (busy(ao_scheme_busy, offset))
1022 mark(ao_scheme_busy, offset);
1027 ao_scheme_print_clear_addr(void *addr)
1032 if (ao_scheme_collecting)
1036 if (!ao_scheme_is_pool_addr(addr))
1039 if (!ao_scheme_print_cleared)
1041 offset = pool_offset(addr);
1042 clear(ao_scheme_busy, offset);
1045 /* Notes that printing has started */
1047 ao_scheme_print_start(void)
1049 ao_scheme_printing++;
1052 /* Notes that printing has ended. Returns 1 if printing is still going on */
1054 ao_scheme_print_stop(void)
1056 ao_scheme_printing--;
1057 if (ao_scheme_printing != 0)
1059 ao_scheme_print_cleared = 0;