save a few instructions on mark-stack operations

svn: r12716
This commit is contained in:
Matthew Flatt 2008-12-06 17:31:18 +00:00
parent bf8816007a
commit 014bd392da

View File

@ -1244,35 +1244,37 @@ typedef struct MarkSegment {
struct MarkSegment *prev; struct MarkSegment *prev;
struct MarkSegment *next; struct MarkSegment *next;
void **top; void **top;
void **end;
void *stop_here; /* this is only used for its address */
} MarkSegment; } MarkSegment;
#define MARK_STACK_START(ms) ((void **)(void *)&ms[1])
#define MARK_STACK_END(ms) ((void **)((char *)ms + STACK_PART_SIZE))
static THREAD_LOCAL MarkSegment *mark_stack = NULL; static THREAD_LOCAL MarkSegment *mark_stack = NULL;
inline static MarkSegment* mark_stack_create_frame() { inline static MarkSegment* mark_stack_create_frame() {
MarkSegment *mark_frame = (MarkSegment*)ofm_malloc(STACK_PART_SIZE); MarkSegment *mark_frame = (MarkSegment*)ofm_malloc(STACK_PART_SIZE);
mark_frame->next = NULL; mark_frame->next = NULL;
mark_frame->top = &(mark_frame->stop_here); mark_frame->top = MARK_STACK_START(mark_frame);
mark_frame->end = PPTR(NUM(mark_frame) + STACK_PART_SIZE);
return mark_frame; return mark_frame;
} }
inline static void push_ptr(void *ptr) inline static void init_mark_stack()
{ {
/* This happens at the very beginning */
if(!mark_stack) { if(!mark_stack) {
mark_stack = mark_stack_create_frame(); mark_stack = mark_stack_create_frame();
mark_stack->prev = NULL; mark_stack->prev = NULL;
} }
}
inline static void push_ptr(void *ptr)
{
/* This happens during propoagation if we go past the end of this MarkSegment*/ /* This happens during propoagation if we go past the end of this MarkSegment*/
if(mark_stack->top == mark_stack->end) { if(mark_stack->top == MARK_STACK_END(mark_stack)) {
/* test to see if we already have another stack page ready */ /* test to see if we already have another stack page ready */
if(mark_stack->next) { if(mark_stack->next) {
/* we do, so just use it */ /* we do, so just use it */
mark_stack = mark_stack->next; mark_stack = mark_stack->next;
mark_stack->top = &(mark_stack->stop_here); mark_stack->top = MARK_STACK_START(mark_stack);
} else { } else {
/* we don't, so we need to allocate one */ /* we don't, so we need to allocate one */
mark_stack->next = mark_stack_create_frame(); mark_stack->next = mark_stack_create_frame();
@ -1287,7 +1289,7 @@ inline static void push_ptr(void *ptr)
inline static int pop_ptr(void **ptr) inline static int pop_ptr(void **ptr)
{ {
if(mark_stack->top == &mark_stack->stop_here) { if(mark_stack->top == MARK_STACK_START(mark_stack)) {
if(mark_stack->prev) { if(mark_stack->prev) {
/* if there is a previous page, go to it */ /* if there is a previous page, go to it */
mark_stack = mark_stack->prev; mark_stack = mark_stack->prev;
@ -1323,7 +1325,7 @@ inline static void clear_stack_pages(void)
free(mark_stack); free(mark_stack);
} }
mark_stack = base; mark_stack = base;
mark_stack->top = PPTR(mark_stack) + 4; mark_stack->top = MARK_STACK_START(mark_stack);
} }
} }
@ -1332,7 +1334,7 @@ inline static void reset_pointer_stack(void)
/* go to the head of the list */ /* go to the head of the list */
for(; mark_stack->prev; mark_stack = mark_stack->prev) {} for(; mark_stack->prev; mark_stack = mark_stack->prev) {}
/* reset the stack */ /* reset the stack */
mark_stack->top = PPTR(mark_stack) + 4; mark_stack->top = MARK_STACK_START(mark_stack);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1424,6 +1426,8 @@ void NewGC_initialize(NewGC *newgc) {
newgc->generations_available = 1; newgc->generations_available = 1;
newgc->last_full_mem_use = (20 * 1024 * 1024); newgc->last_full_mem_use = (20 * 1024 * 1024);
newgc->new_btc_mark = 1; newgc->new_btc_mark = 1;
init_mark_stack();
} }
void GC_init_type_tags(int count, int pair, int mutable_pair, int weakbox, int ephemeron, int weakarray, int custbox) void GC_init_type_tags(int count, int pair, int mutable_pair, int weakbox, int ephemeron, int weakarray, int custbox)
@ -1655,11 +1659,11 @@ void GC_mark(const void *const_p)
work->has_new = 1; work->has_new = 1;
/* transfer the object */ /* transfer the object */
ohead->mark = 1; /* mark is copied to newplace, too */
memcpy(newplace, (const void *)ohead, size); memcpy(newplace, (const void *)ohead, size);
/* mark the old location as marked and moved, and the new location /* mark the old location as marked and moved, and the new location
as marked */ as marked */
ohead->mark = ohead->moved = 1; ohead->moved = 1;
((struct objhead *)newplace)->mark = 1;
/* if we're doing memory accounting, then we need the btc_mark /* if we're doing memory accounting, then we need the btc_mark
to be set properly */ to be set properly */
#ifdef NEWGC_BTC_ACCOUNT #ifdef NEWGC_BTC_ACCOUNT