gc stack moved to unlimited main stack
authorcacao <none@none>
Sun, 4 Oct 1998 19:22:06 +0000 (19:22 +0000)
committercacao <none@none>
Sun, 4 Oct 1998 19:22:06 +0000 (19:22 +0000)
alpha/asmpart.c
alpha/threads.h
headers.c
src/cacaoh/headers.c
src/threads/green/threads.c
src/threads/green/threads.h
src/vm/tables.c
tables.c
threads/thread.c
threads/thread.h

index bd565a46f11c0f6b2a5af981e63d88a3ca93252b..50ba080da136aafeb467380692e106213c340987 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: asm; tab-width: 4 -*- */
 /****************************** asmpart.c **************************************
 *                                                                              *
 *   is an assembly language file, but called .c to fake the preprocessor.      *
        .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
index c2b8e86a0f48c322d239b3640e6e7d09567eadcf..52ad08b7b6383c0fa2b95700fc7e804b2ab4d314 100644 (file)
 
 #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;                 \
index dce631e1a85c9f1771013601efc199bc4cf6e348..6b8ee37ba18f528cb2546633b3735c2c723620e7 100644 (file)
--- 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; }
 
index dce631e1a85c9f1771013601efc199bc4cf6e348..6b8ee37ba18f528cb2546633b3735c2c723620e7 100644 (file)
@@ -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; }
 
index 89dde1d28b0404a0b46cb67853400301a8d41143..fe8ca4c434213cd3727d36d9451f57b59db27183 100644 (file)
@@ -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];
index 1f72d9e9e01db8738e14274090916f9bb82f71ab..f71cd06c1ef6256e3d4041920eb051c09a2db2ca 100644 (file)
@@ -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;
 
index fd979fd6dd8dba8deb960a37f400b7323095cf94..cddc2dafdcedcd4b18ae06ae9b33a7d589f627ca 100644 (file)
@@ -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);
index fd979fd6dd8dba8deb960a37f400b7323095cf94..cddc2dafdcedcd4b18ae06ae9b33a7d589f627ca 100644 (file)
--- 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);
index 89dde1d28b0404a0b46cb67853400301a8d41143..fe8ca4c434213cd3727d36d9451f57b59db27183 100644 (file)
@@ -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];
index 1f72d9e9e01db8738e14274090916f9bb82f71ab..f71cd06c1ef6256e3d4041920eb051c09a2db2ca 100644 (file)
@@ -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;