From: cacao Date: Sun, 4 Oct 1998 19:22:06 +0000 (+0000) Subject: gc stack moved to unlimited main stack X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=d552043fda3d6814dc9a51db3774d93040417bcb;p=cacao.git gc stack moved to unlimited main stack --- diff --git a/alpha/asmpart.c b/alpha/asmpart.c index bd565a46f..50ba080da 100644 --- a/alpha/asmpart.c +++ b/alpha/asmpart.c @@ -1,3 +1,4 @@ +/* -*- mode: asm; tab-width: 4 -*- */ /****************************** asmpart.c ************************************** * * * is an assembly language file, but called .c to fake the preprocessor. * @@ -104,7 +105,7 @@ .globl new_builtin_lrem .globl perform_alpha_threadswitch .globl initialize_thread_stack - .globl used_stack_top + .globl asm_switchstackandcall /*************************** imported variables *******************************/ @@ -332,9 +333,9 @@ noregchange: sra $22,48,$22 # isolate offset addq $22,$28,$22 # compute update address via method pointer - stq $0,0($22) # save new method address there + stq $0,0($22) # save new method address there - bis $0,$0,pv # load method address into pv + bis $0,$0,pv # load method address into pv jmp zero, (pv) # and call method. The method returns # directly to the caller (ra). @@ -1063,6 +1064,7 @@ initialize_thread_stack: /******************* function perform_alpha_threadswitch *********************** * * +* void perform_alpha_threadswitch (u1 **from, u1 **to, u1 **stackTop); * * performs a threadswitch * * * *******************************************************************************/ @@ -1088,6 +1090,7 @@ perform_alpha_threadswitch: stt sf7, 112(sp) stq ra, 120(sp) stq sp, 0(a0) + stq sp, 0(a2) ldq sp, 0(a1) ldq s0, 0(sp) ldq s1, 8(sp) @@ -1111,15 +1114,28 @@ perform_alpha_threadswitch: .end perform_alpha_threadswitch -/*********************** function used_stack_top ******************************* +/********************* function asm_switchstackandcall ************************* * * -* returns $sp * +* Switches to a new stack, calls a function and switches back. * +* a0 new stack pointer * +* a1 function pointer * * * *******************************************************************************/ - .ent used_stack_top -used_stack_top: - mov sp, v0 - jmp zero,(ra) - .end used_stack_top + .ent asm_switchstackandcall +asm_switchstackandcall: + lda a0,-2*8(a0) # allocate new stack + stq ra,0(a0) # save return address + stq sp,1*8(a0) # save old stack pointer + mov a0,sp # switch to new stack + + mov a1,pv # load function pointer + jmp ra,(pv) # and call funciton + + ldq ra,0(sp) # load return address + ldq sp,1*8(sp) # switch to old stack + + jmp zero,(ra) # return + + .end asm_switchstackandcall diff --git a/alpha/threads.h b/alpha/threads.h index c2b8e86a0..52ad08b7b 100644 --- a/alpha/threads.h +++ b/alpha/threads.h @@ -23,21 +23,19 @@ #include "../threads/thread.h" -void perform_alpha_threadswitch (u1 **from, u1 **to); +void perform_alpha_threadswitch (u1 **from, u1 **to, u1 **stackTop); u1* initialize_thread_stack (void *func, u1 *stack); -u1* used_stack_top (void); +void asm_switchstackandcall (void *stack, void *func); -#define THREADSTACKSIZE (64 * 1024) +#define THREADSTACKSIZE (32 * 1024) #define THREADSWITCH(to, from) perform_alpha_threadswitch(&(from)->restorePoint,\ - &(to)->restorePoint) + &(to)->restorePoint, &(from)->usedStackTop) #define THREADINIT(to, func) (to)->restorePoint = \ initialize_thread_stack((u1*)(func), \ (to)->stackEnd) -#define USEDSTACKTOP(top) (top) = used_stack_top() - #define THREADINFO(ee) \ do { \ (ee)->restorePoint = 0; \ diff --git a/headers.c b/headers.c index dce631e1a..6b8ee37ba 100644 --- a/headers.c +++ b/headers.c @@ -71,7 +71,7 @@ void removenativestub (u1 *stub) {} void perform_alpha_threadswitch (u1 **from, u1 **to) {} u1* initialize_thread_stack (void *func, u1 *stack) { return NULL; } -u1* used_stack_top (void) { return NULL; } +void asm_switchstackandcall () { } java_objectheader *native_new_and_init (void *p) { return NULL; } diff --git a/src/cacaoh/headers.c b/src/cacaoh/headers.c index dce631e1a..6b8ee37ba 100644 --- a/src/cacaoh/headers.c +++ b/src/cacaoh/headers.c @@ -71,7 +71,7 @@ void removenativestub (u1 *stub) {} void perform_alpha_threadswitch (u1 **from, u1 **to) {} u1* initialize_thread_stack (void *func, u1 *stack) { return NULL; } -u1* used_stack_top (void) { return NULL; } +void asm_switchstackandcall () { } java_objectheader *native_new_and_init (void *p) { return NULL; } diff --git a/src/threads/green/threads.c b/src/threads/green/threads.c index 89dde1d28..fe8ca4c43 100644 --- a/src/threads/green/threads.c +++ b/src/threads/green/threads.c @@ -41,6 +41,7 @@ static classinfo *class_java_lang_ThreadDeath; #if defined(USE_INTERNAL_THREADS) thread* currentThread; +thread* mainThread; thread* threadQhead[MAX_THREAD_PRIO + 1]; thread* threadQtail[MAX_THREAD_PRIO + 1]; @@ -132,7 +133,7 @@ initThreads(u1 *stackbottom) contexts[i].free = true; /* Allocate a thread to be the main thread */ - currentThread = (thread*)builtin_new(loader_load(unicode_new_char("java/lang/Thread"))); + mainThread = currentThread = (thread*)builtin_new(loader_load(unicode_new_char("java/lang/Thread"))); assert(currentThread != 0); currentThread->PrivateInfo = 1; @@ -172,7 +173,7 @@ initThreads(u1 *stackbottom) iresumeThread(currentThread); /* Start garbage collection thread */ - gcDaemonThread = startDaemon(gc_thread, "gc", 1024*512); + gcDaemonThread = startDaemon(gc_thread, "gc", 16384); iresumeThread(gcDaemonThread); heap_addreference((void**)&gcDaemonThread); @@ -633,7 +634,7 @@ reschedule(void) if (threadQhead[i] != currentThread) { - USEDSTACKTOP((CONTEXT(currentThread).usedStackTop)); + /* USEDSTACKTOP((CONTEXT(currentThread).usedStackTop)); */ lastThread = currentThread; currentThread = threadQhead[i]; diff --git a/src/threads/green/threads.h b/src/threads/green/threads.h index 1f72d9e9e..f71cd06c1 100644 --- a/src/threads/green/threads.h +++ b/src/threads/green/threads.h @@ -114,6 +114,7 @@ void checkEvents(bool block); extern int blockInts; extern bool needReschedule; extern thread *currentThread; +extern thread *mainThread; extern ctx contexts[]; extern int threadStackSize; diff --git a/src/vm/tables.c b/src/vm/tables.c index fd979fd6d..cddc2dafd 100644 --- a/src/vm/tables.c +++ b/src/vm/tables.c @@ -27,6 +27,7 @@ #include "asmpart.h" #include "callargs.h" +#include "sysdep/threads.h" #include "threads/thread.h" /* schani */ #include "threads/locks.h" @@ -1098,35 +1099,41 @@ static void markreferences (void **rstart, void **rend) static void markstack () /* schani */ { void *dummy; - void **top_of_stack = &dummy; #ifdef USE_THREADS - thread *aThread; + thread *aThread; - for (aThread = liveThreads; aThread != 0; aThread = CONTEXT(aThread).nextlive) { + for (aThread = liveThreads; aThread != 0; + aThread = CONTEXT(aThread).nextlive) { mark((heapblock*)aThread); if (aThread == currentThread) { - if (top_of_stack > (void**)CONTEXT(aThread).stackEnd) - markreferences ((void**)CONTEXT(aThread).stackEnd, top_of_stack); - else - markreferences (top_of_stack, (void**)CONTEXT(aThread).stackEnd); + void **top_of_stack = &dummy; + + if (top_of_stack > (void**)CONTEXT(aThread).stackEnd) + markreferences((void**)CONTEXT(aThread).stackEnd, top_of_stack); + else + markreferences(top_of_stack, (void**)CONTEXT(aThread).stackEnd); } else { - if (CONTEXT(aThread).usedStackTop > CONTEXT(aThread).stackEnd) - markreferences ((void**)CONTEXT(aThread).stackEnd, - (void**)CONTEXT(aThread).usedStackTop + 16); - else - markreferences ((void**)CONTEXT(aThread).usedStackTop - 16, - (void**)CONTEXT(aThread).stackEnd); + if (CONTEXT(aThread).usedStackTop > CONTEXT(aThread).stackEnd) + markreferences((void**)CONTEXT(aThread).stackEnd, + (void**)CONTEXT(aThread).usedStackTop); + else + markreferences((void**)CONTEXT(aThread).usedStackTop, + (void**)CONTEXT(aThread).stackEnd); } - } + } + + markreferences((void**)&threadQhead[0], + (void**)&threadQhead[MAX_THREAD_PRIO]); - markreferences((void**)&threadQhead[0], (void**)&threadQhead[MAX_THREAD_PRIO]); #else - if (top_of_stack > bottom_of_stack) - markreferences(bottom_of_stack, top_of_stack); - else - markreferences(top_of_stack, bottom_of_stack); + void **top_of_stack = &dummy; + + if (top_of_stack > bottom_of_stack) + markreferences(bottom_of_stack, top_of_stack); + else + markreferences(top_of_stack, bottom_of_stack); #endif } @@ -1356,7 +1363,8 @@ gc_thread (void) wait_cond(&gcThreadMutex, &gcConditionStart, 0); intsDisable(); - heap_docollect(); + assert(currentThread != mainThread); + asm_switchstackandcall(CONTEXT(mainThread).usedStackTop, heap_docollect); intsRestore(); signal_cond(&gcConditionDone); diff --git a/tables.c b/tables.c index fd979fd6d..cddc2dafd 100644 --- a/tables.c +++ b/tables.c @@ -27,6 +27,7 @@ #include "asmpart.h" #include "callargs.h" +#include "sysdep/threads.h" #include "threads/thread.h" /* schani */ #include "threads/locks.h" @@ -1098,35 +1099,41 @@ static void markreferences (void **rstart, void **rend) static void markstack () /* schani */ { void *dummy; - void **top_of_stack = &dummy; #ifdef USE_THREADS - thread *aThread; + thread *aThread; - for (aThread = liveThreads; aThread != 0; aThread = CONTEXT(aThread).nextlive) { + for (aThread = liveThreads; aThread != 0; + aThread = CONTEXT(aThread).nextlive) { mark((heapblock*)aThread); if (aThread == currentThread) { - if (top_of_stack > (void**)CONTEXT(aThread).stackEnd) - markreferences ((void**)CONTEXT(aThread).stackEnd, top_of_stack); - else - markreferences (top_of_stack, (void**)CONTEXT(aThread).stackEnd); + void **top_of_stack = &dummy; + + if (top_of_stack > (void**)CONTEXT(aThread).stackEnd) + markreferences((void**)CONTEXT(aThread).stackEnd, top_of_stack); + else + markreferences(top_of_stack, (void**)CONTEXT(aThread).stackEnd); } else { - if (CONTEXT(aThread).usedStackTop > CONTEXT(aThread).stackEnd) - markreferences ((void**)CONTEXT(aThread).stackEnd, - (void**)CONTEXT(aThread).usedStackTop + 16); - else - markreferences ((void**)CONTEXT(aThread).usedStackTop - 16, - (void**)CONTEXT(aThread).stackEnd); + if (CONTEXT(aThread).usedStackTop > CONTEXT(aThread).stackEnd) + markreferences((void**)CONTEXT(aThread).stackEnd, + (void**)CONTEXT(aThread).usedStackTop); + else + markreferences((void**)CONTEXT(aThread).usedStackTop, + (void**)CONTEXT(aThread).stackEnd); } - } + } + + markreferences((void**)&threadQhead[0], + (void**)&threadQhead[MAX_THREAD_PRIO]); - markreferences((void**)&threadQhead[0], (void**)&threadQhead[MAX_THREAD_PRIO]); #else - if (top_of_stack > bottom_of_stack) - markreferences(bottom_of_stack, top_of_stack); - else - markreferences(top_of_stack, bottom_of_stack); + void **top_of_stack = &dummy; + + if (top_of_stack > bottom_of_stack) + markreferences(bottom_of_stack, top_of_stack); + else + markreferences(top_of_stack, bottom_of_stack); #endif } @@ -1356,7 +1363,8 @@ gc_thread (void) wait_cond(&gcThreadMutex, &gcConditionStart, 0); intsDisable(); - heap_docollect(); + assert(currentThread != mainThread); + asm_switchstackandcall(CONTEXT(mainThread).usedStackTop, heap_docollect); intsRestore(); signal_cond(&gcConditionDone); diff --git a/threads/thread.c b/threads/thread.c index 89dde1d28..fe8ca4c43 100644 --- a/threads/thread.c +++ b/threads/thread.c @@ -41,6 +41,7 @@ static classinfo *class_java_lang_ThreadDeath; #if defined(USE_INTERNAL_THREADS) thread* currentThread; +thread* mainThread; thread* threadQhead[MAX_THREAD_PRIO + 1]; thread* threadQtail[MAX_THREAD_PRIO + 1]; @@ -132,7 +133,7 @@ initThreads(u1 *stackbottom) contexts[i].free = true; /* Allocate a thread to be the main thread */ - currentThread = (thread*)builtin_new(loader_load(unicode_new_char("java/lang/Thread"))); + mainThread = currentThread = (thread*)builtin_new(loader_load(unicode_new_char("java/lang/Thread"))); assert(currentThread != 0); currentThread->PrivateInfo = 1; @@ -172,7 +173,7 @@ initThreads(u1 *stackbottom) iresumeThread(currentThread); /* Start garbage collection thread */ - gcDaemonThread = startDaemon(gc_thread, "gc", 1024*512); + gcDaemonThread = startDaemon(gc_thread, "gc", 16384); iresumeThread(gcDaemonThread); heap_addreference((void**)&gcDaemonThread); @@ -633,7 +634,7 @@ reschedule(void) if (threadQhead[i] != currentThread) { - USEDSTACKTOP((CONTEXT(currentThread).usedStackTop)); + /* USEDSTACKTOP((CONTEXT(currentThread).usedStackTop)); */ lastThread = currentThread; currentThread = threadQhead[i]; diff --git a/threads/thread.h b/threads/thread.h index 1f72d9e9e..f71cd06c1 100644 --- a/threads/thread.h +++ b/threads/thread.h @@ -114,6 +114,7 @@ void checkEvents(bool block); extern int blockInts; extern bool needReschedule; extern thread *currentThread; +extern thread *mainThread; extern ctx contexts[]; extern int threadStackSize;