| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| #ifndef GC_PMARK_H |
| # define GC_PMARK_H |
|
|
| # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST) |
| # include "dbg_mlc.h" |
| # endif |
| # ifndef GC_MARK_H |
| # include "../gc_mark.h" |
| # endif |
| # ifndef GC_PRIVATE_H |
| # include "gc_priv.h" |
| # endif |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| # define BITMAP_BITS (WORDSZ - GC_DS_TAG_BITS) |
| # define PROC(descr) \ |
| (GC_mark_procs[((descr) >> GC_DS_TAG_BITS) & (GC_MAX_MARK_PROCS-1)]) |
| # define ENV(descr) \ |
| ((descr) >> (GC_DS_TAG_BITS + GC_LOG_MAX_MARK_PROCS)) |
| # define MAX_ENV \ |
| (((word)1 << (WORDSZ - GC_DS_TAG_BITS - GC_LOG_MAX_MARK_PROCS)) - 1) |
|
|
|
|
| extern unsigned GC_n_mark_procs; |
|
|
| |
| #define GC_MARK_STACK_DISCARDS (INITIAL_MARK_STACK_SIZE/8) |
|
|
| typedef struct GC_ms_entry { |
| ptr_t mse_start; |
| GC_word mse_descr; |
| |
| |
| } mse; |
|
|
| extern size_t GC_mark_stack_size; |
|
|
| extern mse * GC_mark_stack_limit; |
|
|
| #ifdef PARALLEL_MARK |
| extern mse * volatile GC_mark_stack_top; |
| #else |
| extern mse * GC_mark_stack_top; |
| #endif |
|
|
| extern mse * GC_mark_stack; |
|
|
| #ifdef PARALLEL_MARK |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void GC_do_parallel_mark(); |
| |
|
|
| extern GC_bool GC_help_wanted; |
| extern unsigned GC_helper_count; |
| |
| extern unsigned GC_active_count; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #endif |
|
|
| |
| |
| ptr_t GC_find_start(ptr_t current, hdr *hhdr, hdr **new_hdr_p); |
|
|
| mse * GC_signal_mark_stack_overflow(mse *msp); |
|
|
| |
| |
| # define PUSH_OBJ(obj, hhdr, mark_stack_top, mark_stack_limit) \ |
| { \ |
| register word _descr = (hhdr) -> hb_descr; \ |
| \ |
| if (_descr != 0) { \ |
| mark_stack_top++; \ |
| if (mark_stack_top >= mark_stack_limit) { \ |
| mark_stack_top = GC_signal_mark_stack_overflow(mark_stack_top); \ |
| } \ |
| mark_stack_top -> mse_start = (obj); \ |
| mark_stack_top -> mse_descr = _descr; \ |
| } \ |
| } |
|
|
| |
| |
| |
| |
| # define PUSH_CONTENTS(current, mark_stack_top, mark_stack_limit, \ |
| source, exit_label) \ |
| { \ |
| hdr * my_hhdr; \ |
| \ |
| HC_GET_HDR(current, my_hhdr, source, exit_label); \ |
| PUSH_CONTENTS_HDR(current, mark_stack_top, mark_stack_limit, \ |
| source, exit_label, my_hhdr, TRUE); \ |
| exit_label: ; \ |
| } |
|
|
| |
|
|
| # ifdef USE_MARK_BITS |
| # ifdef PARALLEL_MARK |
| |
| |
| # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \ |
| { \ |
| if (!(*(addr) & (mask))) { \ |
| AO_or((AO_t *)(addr), (mask); \ |
| } else { \ |
| goto label; \ |
| } \ |
| } |
| # else |
| # define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \ |
| { \ |
| word old = *(addr); \ |
| word my_bits = (bits); \ |
| if (old & my_bits) goto exit_label; \ |
| *(addr) = (old | my_bits); \ |
| } |
| # endif |
| # define SET_MARK_BIT_EXIT_IF_SET(hhdr,bit_no,exit_label) \ |
| { \ |
| word * mark_word_addr = hhdr -> hb_marks + divWORDSZ(bit_no); \ |
| \ |
| OR_WORD_EXIT_IF_SET(mark_word_addr, (word)1 << modWORDSZ(bit_no), \ |
| exit_label); \ |
| } |
| # endif |
|
|
|
|
| #ifdef USE_MARK_BYTES |
| # if defined(I386) && defined(__GNUC__) |
| # define LONG_MULT(hprod, lprod, x, y) { \ |
| asm("mull %2" : "=a"(lprod), "=d"(hprod) : "g"(y), "0"(x)); \ |
| } |
| # else |
| # define LONG_MULT(hprod, lprod, x, y) { \ |
| unsigned long long prod = (unsigned long long)x \ |
| * (unsigned long long)y; \ |
| hprod = prod >> 32; \ |
| lprod = (unsigned32)prod; \ |
| } |
| # endif |
|
|
| |
| |
| |
| # define SET_MARK_BIT_EXIT_IF_SET(hhdr,bit_no,exit_label) \ |
| { \ |
| char * mark_byte_addr = (char *)hhdr -> hb_marks + (bit_no); \ |
| char mark_byte = *mark_byte_addr; \ |
| \ |
| if (mark_byte) goto exit_label; \ |
| *mark_byte_addr = 1; \ |
| } |
| #endif |
|
|
| #ifdef PARALLEL_MARK |
| # define INCR_MARKS(hhdr) \ |
| AO_store(&(hhdr -> hb_n_marks), AO_load(&(hhdr -> hb_n_marks))+1); |
| #else |
| # define INCR_MARKS(hhdr) ++(hhdr -> hb_n_marks) |
| #endif |
|
|
| #ifdef ENABLE_TRACE |
| # define TRACE(source, cmd) \ |
| if (GC_trace_addr != 0 && (ptr_t)(source) == GC_trace_addr) cmd |
| # define TRACE_TARGET(target, cmd) \ |
| if (GC_trace_addr != 0 && (target) == *(ptr_t *)GC_trace_addr) cmd |
| #else |
| # define TRACE(source, cmd) |
| # define TRACE_TARGET(source, cmd) |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifdef MARK_BIT_PER_GRANULE |
| # define PUSH_CONTENTS_HDR(current, mark_stack_top, mark_stack_limit, \ |
| source, exit_label, hhdr, do_offset_check) \ |
| { \ |
| size_t displ = HBLKDISPL(current); \ |
| \ |
| \ |
| \ |
| size_t gran_displ = BYTES_TO_GRANULES(displ); \ |
| size_t gran_offset = hhdr -> hb_map[gran_displ]; \ |
| size_t byte_offset = displ & (GRANULE_BYTES - 1); \ |
| ptr_t base = current; \ |
| \ |
| if (EXPECT((gran_offset | byte_offset) != 0, FALSE)) { \ |
| if (hhdr -> hb_large_block) { \ |
| \ |
| size_t obj_displ; \ |
| base = (ptr_t)(hhdr -> hb_block); \ |
| obj_displ = (ptr_t)(current) - base; \ |
| if (obj_displ != displ) { \ |
| GC_ASSERT(obj_displ < hhdr -> hb_sz); \ |
| \ |
| \ |
| ; \ |
| } else { \ |
| if (do_offset_check && !GC_valid_offsets[obj_displ]) { \ |
| GC_ADD_TO_BLACK_LIST_NORMAL(current, source); \ |
| goto exit_label; \ |
| } \ |
| } \ |
| gran_displ = 0; \ |
| GC_ASSERT(hhdr -> hb_sz > HBLKSIZE || \ |
| hhdr -> hb_block == HBLKPTR(current)); \ |
| GC_ASSERT((ptr_t)(hhdr -> hb_block) <= (ptr_t) current); \ |
| } else { \ |
| size_t obj_displ = GRANULES_TO_BYTES(gran_offset) \ |
| + byte_offset; \ |
| if (do_offset_check && !GC_valid_offsets[obj_displ]) { \ |
| GC_ADD_TO_BLACK_LIST_NORMAL(current, source); \ |
| goto exit_label; \ |
| } \ |
| gran_displ -= gran_offset; \ |
| base -= obj_displ; \ |
| } \ |
| } \ |
| GC_ASSERT(hhdr == GC_find_header(base)); \ |
| GC_ASSERT(gran_displ % BYTES_TO_GRANULES(hhdr -> hb_sz) == 0); \ |
| TRACE(source, GC_log_printf("GC:%d: passed validity tests\n",GC_gc_no)); \ |
| SET_MARK_BIT_EXIT_IF_SET(hhdr, gran_displ, exit_label); \ |
| TRACE(source, GC_log_printf("GC:%d: previously unmarked\n",GC_gc_no)); \ |
| TRACE_TARGET(base, \ |
| GC_log_printf("GC:%d: marking %p from %p instead\n", GC_gc_no, \ |
| base, source)); \ |
| INCR_MARKS(hhdr); \ |
| GC_STORE_BACK_PTR((ptr_t)source, base); \ |
| PUSH_OBJ(base, hhdr, mark_stack_top, mark_stack_limit); \ |
| } |
| #endif |
|
|
| #ifdef MARK_BIT_PER_OBJ |
| # define PUSH_CONTENTS_HDR(current, mark_stack_top, mark_stack_limit, \ |
| source, exit_label, hhdr, do_offset_check) \ |
| { \ |
| size_t displ = HBLKDISPL(current); \ |
| unsigned32 low_prod, high_prod, offset_fraction; \ |
| unsigned32 inv_sz = hhdr -> hb_inv_sz; \ |
| ptr_t base = current; \ |
| LONG_MULT(high_prod, low_prod, displ, inv_sz); \ |
| \ |
| if (EXPECT(low_prod >> 16 != 0, FALSE)) { \ |
| FIXME: fails if offset is a multiple of HBLKSIZE which becomes 0 \ |
| if (inv_sz == LARGE_INV_SZ) { \ |
| size_t obj_displ; \ |
| base = (ptr_t)(hhdr -> hb_block); \ |
| obj_displ = (ptr_t)(current) - base; \ |
| if (obj_displ != displ) { \ |
| GC_ASSERT(obj_displ < hhdr -> hb_sz); \ |
| \ |
| \ |
| ; \ |
| } else { \ |
| if (do_offset_check && !GC_valid_offsets[obj_displ]) { \ |
| GC_ADD_TO_BLACK_LIST_NORMAL(current, source); \ |
| goto exit_label; \ |
| } \ |
| } \ |
| GC_ASSERT(hhdr -> hb_sz > HBLKSIZE || \ |
| hhdr -> hb_block == HBLKPTR(current)); \ |
| GC_ASSERT((ptr_t)(hhdr -> hb_block) < (ptr_t) current); \ |
| } else { \ |
| \ |
| GC_ASSERT(HBLKSIZE <= (1 << 15)); \ |
| size_t obj_displ = (((low_prod >> 16) + 1) * (hhdr -> hb_sz)) >> 16; \ |
| if (do_offset_check && !GC_valid_offsets[obj_displ]) { \ |
| GC_ADD_TO_BLACK_LIST_NORMAL(current, source); \ |
| goto exit_label; \ |
| } \ |
| base -= obj_displ; \ |
| } \ |
| } \ |
| \ |
| \ |
| GC_ASSERT(high_prod >= 0 && high_prod <= HBLK_OBJS(hhdr -> hb_sz)); \ |
| TRACE(source, GC_log_printf("GC:%d: passed validity tests\n",GC_gc_no)); \ |
| SET_MARK_BIT_EXIT_IF_SET(hhdr, high_prod, exit_label); \ |
| TRACE(source, GC_log_printf("GC:%d: previously unmarked\n",GC_gc_no)); \ |
| TRACE_TARGET(base, \ |
| GC_log_printf("GC:%d: marking %p from %p instead\n", GC_gc_no, \ |
| base, source)); \ |
| INCR_MARKS(hhdr); \ |
| GC_STORE_BACK_PTR((ptr_t)source, base); \ |
| PUSH_OBJ(base, hhdr, mark_stack_top, mark_stack_limit); \ |
| } |
| #endif |
|
|
| #if defined(PRINT_BLACK_LIST) || defined(KEEP_BACK_PTRS) |
| # define PUSH_ONE_CHECKED_STACK(p, source) \ |
| GC_mark_and_push_stack(p, (ptr_t)(source)) |
| #else |
| # define PUSH_ONE_CHECKED_STACK(p, source) \ |
| GC_mark_and_push_stack(p) |
| #endif |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| # if NEED_FIXUP_POINTER |
| |
| # define GC_PUSH_ONE_STACK(p, source) \ |
| if ((p) >= (ptr_t)GC_least_plausible_heap_addr \ |
| && (p) < (ptr_t)GC_greatest_plausible_heap_addr) { \ |
| PUSH_ONE_CHECKED_STACK(p, source); \ |
| } \ |
| FIXUP_POINTER(p); \ |
| if ((p) >= (ptr_t)GC_least_plausible_heap_addr \ |
| && (p) < (ptr_t)GC_greatest_plausible_heap_addr) { \ |
| PUSH_ONE_CHECKED_STACK(p, source); \ |
| } |
| # else |
| # define GC_PUSH_ONE_STACK(p, source) \ |
| if ((ptr_t)(p) >= (ptr_t)GC_least_plausible_heap_addr \ |
| && (ptr_t)(p) < (ptr_t)GC_greatest_plausible_heap_addr) { \ |
| PUSH_ONE_CHECKED_STACK(p, source); \ |
| } |
| # endif |
|
|
|
|
| |
| |
| |
| |
| # define GC_PUSH_ONE_HEAP(p,source) \ |
| FIXUP_POINTER(p); \ |
| if ((p) >= (ptr_t)GC_least_plausible_heap_addr \ |
| && (p) < (ptr_t)GC_greatest_plausible_heap_addr) { \ |
| GC_mark_stack_top = GC_mark_and_push( \ |
| (void *)(p), GC_mark_stack_top, \ |
| GC_mark_stack_limit, (void * *)(source)); \ |
| } |
|
|
| |
| |
| |
| |
| mse * GC_mark_from(mse * top, mse * bottom, mse *limit); |
|
|
| #define MARK_FROM_MARK_STACK() \ |
| GC_mark_stack_top = GC_mark_from(GC_mark_stack_top, \ |
| GC_mark_stack, \ |
| GC_mark_stack + GC_mark_stack_size); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| # define GC_MARK_FO(real_ptr, mark_proc) \ |
| { \ |
| (*(mark_proc))(real_ptr); \ |
| while (!GC_mark_stack_empty()) MARK_FROM_MARK_STACK(); \ |
| if (GC_mark_state != MS_NONE) { \ |
| GC_set_mark_bit(real_ptr); \ |
| while (!GC_mark_some((ptr_t)0)) {} \ |
| } \ |
| } |
|
|
| extern GC_bool GC_mark_stack_too_small; |
| |
| |
|
|
| typedef int mark_state_t; |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| # define MS_NONE 0 |
| |
|
|
| # define MS_PUSH_RESCUERS 1 |
| |
| |
| |
| |
|
|
| # define MS_PUSH_UNCOLLECTABLE 2 |
| |
| |
| |
| |
|
|
| # define MS_ROOTS_PUSHED 3 |
|
|
| # define MS_PARTIALLY_INVALID 4 |
| |
| |
| |
|
|
| # define MS_INVALID 5 |
|
|
| extern mark_state_t GC_mark_state; |
|
|
| #endif |
|
|
|
|