* src/threads/posix/thread-posix.cpp: Implemented thread suspension mechanism.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Thu, 29 Oct 2009 14:00:36 +0000 (15:00 +0100)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Thu, 29 Oct 2009 14:00:36 +0000 (15:00 +0100)
* src/threads/posix/thread-posix.hpp: Likewise.
* src/threads/threadlist.cpp (ThreadList::dump_threads): Use above mechanism.
* src/native/vm/openjdk/jvm.cpp (JVM_SuspendThread, JVM_ResumeThread): Likewise.

* src/vm/signal.cpp (signal_handler_sigusr1): Added generic suspension handler.
* src/vm/signallocal.hpp (md_signal_handler_sigusr1): Removed prototype.
* src/vm/jit/alpha/linux/md-os.c: Removed implementation of above function.
* src/vm/jit/arm/linux/md-os.c: Likewise.
* src/vm/jit/i386/freebsd/md-os.c: Likewise.
* src/vm/jit/i386/linux/md-os.c: Likewise.
* src/vm/jit/i386/solaris/md-os.c: Likewise.
* src/vm/jit/m68k/linux/md-os.c: Likewise.
* src/vm/jit/powerpc/linux/md-os.c: Likewise.
* src/vm/jit/x86_64/linux/md-os.c: Likewise.
* src/vm/jit/x86_64/solaris/md-os.c: Likewise.

15 files changed:
src/native/vm/openjdk/jvm.cpp
src/threads/posix/thread-posix.cpp
src/threads/posix/thread-posix.hpp
src/threads/threadlist.cpp
src/vm/jit/alpha/linux/md-os.c
src/vm/jit/arm/linux/md-os.c
src/vm/jit/i386/freebsd/md-os.c
src/vm/jit/i386/linux/md-os.c
src/vm/jit/i386/solaris/md-os.c
src/vm/jit/m68k/linux/md-os.c
src/vm/jit/powerpc/linux/md-os.c
src/vm/jit/x86_64/linux/md-os.c
src/vm/jit/x86_64/solaris/md-os.c
src/vm/signal.cpp
src/vm/signallocal.hpp

index 6c12ba268455f620590a2788c41571fc241e85db..58229157aa7a3adb4d0f1522aaf04c96d93afccb 100644 (file)
@@ -2147,7 +2147,23 @@ jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
 
 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
 {
-       log_println("JVM_SuspendThread: Deprecated.  Not implemented.");
+       java_handle_t *h;
+       threadobject  *t;
+
+       TRACEJVMCALLS(("JVM_SuspendThread(env=%p, jthread=%p)", env, jthread));
+
+       if (opt_PrintWarnings)
+               log_println("JVM_SuspendThread: Deprecated, do not use!");
+
+       h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
+
+       /* The threadobject is null when a thread is created in Java. */
+
+       if (t == NULL)
+               return;
+
+       threads_suspend_thread(t, SUSPEND_REASON_JAVA);
 }
 
 
@@ -2155,7 +2171,23 @@ void JVM_SuspendThread(JNIEnv* env, jobject jthread)
 
 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
 {
-       log_println("JVM_ResumeThread: Deprecated.  Not implemented.");
+       java_handle_t *h;
+       threadobject  *t;
+
+       TRACEJVMCALLS(("JVM_ResumeThread(env=%p, jthread=%p)", env, jthread));
+
+       if (opt_PrintWarnings)
+               log_println("JVM_ResumeThread: Deprecated, do not use!");
+
+       h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
+
+       /* The threadobject is null when a thread is created in Java. */
+
+       if (t == NULL)
+               return;
+
+       threads_resume_thread(t, SUSPEND_REASON_JAVA);
 }
 
 
index 636638628eafc07bd51e8ff80ffe9aeb6604496e..6a0e54adce134c6c7828b12e4a4797b93288f34e 100644 (file)
@@ -1101,134 +1101,146 @@ bool thread_detach_current_thread(void)
 }
 
 
-/* threads_suspend_thread ******************************************************
-
-   Suspend the passed thread. Execution stops until the thread
-   is explicitly resumend again.
-
-   IN:
-     reason.....Reason for suspending this thread.
-
-*******************************************************************************/
-
-bool threads_suspend_thread(threadobject *thread, s4 reason)
+/**
+ * Internal helper function which suspends the current thread. This is
+ * the core method of the suspension mechanism actually blocking the
+ * execution until the suspension reason is cleared again. Note that
+ * the current thread needs to hold the suspension mutex while calling
+ * this function.
+ */
+static void threads_suspend_self()
 {
-       /* acquire the suspendmutex */
-       thread->suspendmutex->lock();
-
-       if (thread->suspended) {
-               thread->suspendmutex->unlock();
-               return false;
-       }
+       threadobject* thread = THREADOBJECT;
 
-       /* set the reason for the suspension */
-       thread->suspend_reason = reason;
+       DEBUGTHREADS("suspending", thread);
 
-       /* send the suspend signal to the thread */
-       assert(thread != THREADOBJECT);
-       if (pthread_kill(thread->tid, SIGUSR1) != 0)
-               vm_abort("threads_suspend_thread: pthread_kill failed: %s",
-                                strerror(errno));
+       // Mark thread as suspended.
+       assert(!thread->suspended);
+       assert(thread->suspend_reason != SUSPEND_REASON_NONE);
+       thread->suspended = true;
 
-       /* REMEMBER: do not release the suspendmutex, this is done
-          by the thread itself in threads_suspend_ack().  */
+       // Acknowledge the suspension.
+       thread->suspendcond->broadcast();
 
-       return true;
-}
+#if defined(ENABLE_GC_CACAO)
+       // If we are stopping the world, we should send a global ack.
+       if (thread->suspend_reason == SUSPEND_REASON_STOPWORLD)
+               threads_sem_post(&suspend_ack);
+#endif
 
+       // Release the suspension mutex and wait till we are resumed.
+       thread->suspendcond->wait(thread->suspendmutex);
 
-/* threads_suspend_ack *********************************************************
+#if defined(ENABLE_GC_CACAO)
+       // XXX This is propably not ok!
+       // If we are starting the world, we should send a global ack.
+       if (thread->suspend_reason == SUSPEND_REASON_STOPWORLD)
+               threads_sem_post(&suspend_ack);
+#endif
 
-   Acknowledges the suspension of the current thread.
+       // Mark thread as not suspended.
+       assert(thread->suspended);
+       assert(thread->suspend_reason == SUSPEND_REASON_NONE);
+       thread->suspended = false;
 
-   IN:
-     pc.....The PC where the thread suspended its execution.
-     sp.....The SP before the thread suspended its execution.
+       DEBUGTHREADS("resuming", thread);
+}
 
-*******************************************************************************/
 
-#if defined(ENABLE_GC_CACAO)
-void threads_suspend_ack(u1* pc, u1* sp)
+/**
+ * Suspend the passed thread. Execution of that thread stops until the thread
+ * is explicitly resumend again.
+ *
+ * @param thread The thread to be suspended.
+ * @param reason Reason for suspending the given thread.
+ * @return True of operation was successful, false otherwise.
+ */
+bool threads_suspend_thread(threadobject *thread, int32_t reason)
 {
-       threadobject *thread;
-
-       thread = THREADOBJECT;
+       // Sanity check.
+       assert(reason != SUSPEND_REASON_NONE);
 
-       assert(thread->suspend_reason != 0);
+       // Guard this with the suspension mutex.
+       MutexLocker ml(*thread->suspendmutex);
 
-       /* TODO: remember dump memory size */
-
-       /* inform the GC about the suspension */
-       if (thread->suspend_reason == SUSPEND_REASON_STOPWORLD && gc_pending) {
+       // Check if thread is already suspended.
+       if (thread->suspended)
+               return false;
 
-               /* check if the GC wants to leave the thread running */
-               if (!gc_suspend(thread, pc, sp)) {
+       // Check if thread is in the process of suspending.
+       if (thread->suspend_reason != SUSPEND_REASON_NONE)
+               return false;
 
-                       /* REMEMBER: we do not unlock the suspendmutex because the thread
-                          will suspend itself again at a later time */
-                       return;
+       // Set the reason for suspending the thread.
+       thread->suspend_reason = reason;
 
-               }
+       if (thread == THREADOBJECT) {
+               // We already hold the suspension mutex and can suspend ourselves
+               // immediately without using signals at all.
+               threads_suspend_self();
        }
-
-       /* mark this thread as suspended and remember the PC */
-       thread->pc        = pc;
-       thread->suspended = true;
-
-       /* if we are stopping the world, we should send a global ack */
-       if (thread->suspend_reason == SUSPEND_REASON_STOPWORLD) {
-               threads_sem_post(&suspend_ack);
+       else {
+               // Send the suspend signal to the other thread.
+               if (pthread_kill(thread->tid, SIGUSR1) != 0)
+                       os::abort_errno("threads_suspend_thread: pthread_kill failed");
+
+               // Wait for the thread to acknowledge the suspension.
+               // XXX A possible optimization would be to not wait here, but you
+               //     better think this through twice before trying it!
+               thread->suspendcond->wait(thread->suspendmutex);
        }
 
-       DEBUGTHREADS("suspending", thread);
+       return true;
+}
 
-       /* release the suspension mutex and wait till we are resumed */
-       thread->suspendcond->wait(thread->suspendmutex);
 
-       DEBUGTHREADS("resuming", thread);
+/**
+ * Resumes execution of the passed thread.
+ *
+ * @param thread The thread to be resumed.
+ * @param reason Reason for suspending the given thread.
+ * @return True of operation was successful, false otherwise.
+ */
+bool threads_resume_thread(threadobject *thread, int32_t reason)
+{
+       // Sanity check.
+       assert(thread != THREADOBJECT);
+       assert(reason != SUSPEND_REASON_NONE);
 
-       /* if we are stopping the world, we should send a global ack */
-       if (thread->suspend_reason == SUSPEND_REASON_STOPWORLD) {
-               threads_sem_post(&suspend_ack);
-       }
+       // Guard this with the suspension mutex.
+       MutexLocker ml(*thread->suspendmutex);
 
-       /* TODO: free dump memory */
+       // Check if thread really is suspended.
+       if (!thread->suspended)
+               return false;
 
-       /* release the suspendmutex */
-       thread->suspendmutex->unlock();
-}
-#endif
+       // Threads can only be resumed for the same reason they were suspended.
+       if (thread->suspend_reason != reason)
+               return false;
 
+       // Clear the reason for suspending the thread.
+       thread->suspend_reason = SUSPEND_REASON_NONE;
 
-/* threads_resume_thread *******************************************************
+       // Tell everyone that the thread should resume.
+       thread->suspendcond->broadcast();
 
-   Resumes the execution of the passed thread.
+       return true;
+}
 
-*******************************************************************************/
 
-#if defined(ENABLE_GC_CACAO)
-bool threads_resume_thread(threadobject *thread)
+/**
+ * Acknowledges the suspension of the current thread.
+ */
+void threads_suspend_ack()
 {
-       /* acquire the suspendmutex */
-       thread->suspendmutex->lock();
+       threadobject* thread = THREADOBJECT;
 
-       if (!thread->suspended) {
-               thread->suspendmutex->unlock();
-               return false;
-       }
-
-       thread->suspended = false;
+       // Guard this with the suspension mutex.
+       MutexLocker ml(*thread->suspendmutex);
 
-       /* tell everyone that the thread should resume */
-       assert(thread != THREADOBJECT);
-       thread->suspendcond->broadcast();
-
-       /* release the suspendmutex */
-       thread->suspendmutex->unlock();
-
-       return true;
+       // Suspend ourselves while holding the suspension mutex.
+       threads_suspend_self();
 }
-#endif
 
 
 /* threads_join_all_threads ****************************************************
index 7dafeae304d82d8c1c0a4f6ecabc181e920b26b9..9257ce8131db2e1bedea4e3d865da2c2092e2795 100644 (file)
 #define THREAD_FLAG_DAEMON      0x04    /* daemon thread                      */
 #define THREAD_FLAG_IN_NATIVE   0x08    /* currently executing native code    */
 
-#define SUSPEND_REASON_JNI       1      /* suspended from JNI                 */
-#define SUSPEND_REASON_STOPWORLD 2      /* suspended from stop-thw-world      */
+#define SUSPEND_REASON_NONE      0      /* no reason to suspend               */
+#define SUSPEND_REASON_JAVA      1      /* suspended from java.lang.Thread    */
+#define SUSPEND_REASON_STOPWORLD 2      /* suspended from stop-the-world      */
+#define SUSPEND_REASON_DUMP      3      /* suspended from threadlist dumping  */
+#define SUSPEND_REASON_JVMTI     4      /* suspended from JVMTI agent         */
 
 
 typedef struct threadobject threadobject;
@@ -294,11 +297,9 @@ void threads_start_thread(threadobject *thread, functionptr function);
 
 void threads_set_thread_priority(pthread_t tid, int priority);
 
-#if defined(ENABLE_GC_CACAO)
-bool threads_suspend_thread(threadobject *thread, s4 reason);
-void threads_suspend_ack(u1* pc, u1* sp);
-bool threads_resume_thread(threadobject *thread);
-#endif
+bool threads_suspend_thread(threadobject *thread, int32_t reason);
+bool threads_resume_thread(threadobject *thread, int32_t reason);
+void threads_suspend_ack();
 
 void threads_join_all_threads(void);
 
index e6dd58371dc9c869a9358bad2b55ead53e7e4f99..70ad276835fb61cb07e10f95bf53e122172faa53 100644 (file)
@@ -59,13 +59,15 @@ int32_t             ThreadList::_number_of_non_daemon_threads;
  */
 void ThreadList::dump_threads()
 {
-       // XXX we should stop the world here
+       // XXX we should stop the world here and remove explicit
+       //     thread suspension from the loop below.
        // Lock the thread lists.
        lock();
 
        printf("Full thread dump CACAO "VERSION":\n");
 
        // Iterate over all started threads.
+       threadobject* self = THREADOBJECT;
        for (List<threadobject*>::iterator it = _active_thread_list.begin(); it != _active_thread_list.end(); it++) {
                threadobject* t = *it;
 
@@ -73,13 +75,10 @@ void ThreadList::dump_threads()
                if (t->state == THREAD_STATE_NEW)
                        continue;
 
-#if defined(ENABLE_GC_CACAO)
-               /* Suspend the thread. */
-               /* XXX Is the suspend reason correct? */
+               /* Suspend the thread (and ignore return value). */
 
-               if (threads_suspend_thread(t, SUSPEND_REASON_JNI) == false)
-                       vm_abort("threads_dump: threads_suspend_thread failed");
-#endif
+               if (t != self)
+                       (void) threads_suspend_thread(t, SUSPEND_REASON_DUMP);
 
                /* Print thread info. */
 
@@ -91,12 +90,10 @@ void ThreadList::dump_threads()
 
                stacktrace_print_of_thread(t);
 
-#if defined(ENABLE_GC_CACAO)
-               /* Resume the thread. */
+               /* Resume the thread (and ignore return value). */
 
-               if (threads_resume_thread(t) == false)
-                       vm_abort("threads_dump: threads_resume_thread failed");
-#endif
+               if (t != self)
+                       (void) threads_resume_thread(t, SUSPEND_REASON_DUMP);
        }
 
        // Unlock the thread lists.
index c6eb6b1287c335d294206761d3e7d5fd6e0ff38e..2d02d8c48c261cade25bbcff46aa138540a95e3c 100644 (file)
@@ -77,33 +77,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->sc_pc;
-       sp = (u1 *) _mc->sc_regs[REG_SP];
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index f8d29c56757faf36fa79ee8932f71249d67c794e..bd1475985669790e6c93e192877a40644fd284c3 100644 (file)
@@ -94,33 +94,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       scontext_t *_sc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _sc = &_uc->uc_mcontext;
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _sc->arm_pc;
-       sp = (u1 *) _sc->arm_sp;
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index b6a4c482807b606d8fef3d2b346db4ada2de6e6f..a65dd4a2c894f609c51f2c658479019c247688de 100644 (file)
@@ -250,33 +250,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->mc_eip;
-       sp = (u1 *) _mc->mc_esp;
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index 1417ec01a073347972182d543c5e6f1ac661c1bb..15320a670002ea998c9ad4c813d07e305d88f715 100644 (file)
@@ -90,33 +90,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->gregs[REG_EIP];
-       sp = (u1 *) _mc->gregs[REG_ESP];
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index 2fb36877828935d981cc999b2361c8553eb494a6..1cc718e87d2b4e0d9f2f1547848ad23733fc8fe8 100644 (file)
@@ -90,33 +90,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->gregs[EIP];
-       sp = (u1 *) _mc->gregs[UESP];
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index 45e1a34ffde91dd53740b1483c8d95782fd42d83..359541fb2e34cb922e21b769a2962a1f6a4facd7 100644 (file)
@@ -253,33 +253,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->gregs[R_PC];
-       sp = (u1 *) _mc->gregs[R_SP];
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
index 2a6899381867ef9aef8817eccefd3ea169243b91..d0f378dcc392fd0c1044cfd69aca51b39c70893f 100644 (file)
@@ -117,43 +117,6 @@ void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t    *_uc;
-       mcontext_t    *_mc;
-       unsigned long *_gregs;
-       u1            *pc;
-       u1            *sp;
-
-       _uc = (ucontext_t *) _p;
-
-#if defined(__UCLIBC__)
-       _mc    = &(_uc->uc_mcontext);
-       _gregs = _mc->regs->gpr;
-#else
-       _mc    = _uc->uc_mcontext.uc_regs;
-       _gregs = _mc->gregs;
-#endif
-
-       /* get the PC and SP for this thread */
-
-       pc = (u1 *) _gregs[PT_NIP];
-       sp = (u1 *) _gregs[REG_SP];
-
-       /* now suspend the current thread */
-
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index ad8fbd9fdbbe56596bf8ee76789aa97cf90946cf..6f3d2ce2d8785d46d300b0be5d2ab4f0fff352b1 100644 (file)
@@ -101,36 +101,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
-          different to the ones in <ucontext.h>. */
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->gregs[REG_RIP];
-       sp = (u1 *) _mc->gregs[REG_RSP];
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index 96f22f04080ee426f3df9859bd262e2da0ba00df..6f97d8831e58cf3699419b636676c2b7ff3ec7d6 100644 (file)
@@ -99,36 +99,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
-/* md_signal_handler_sigusr1 ***************************************************
-
-   Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t *_uc;
-       mcontext_t *_mc;
-       u1         *pc;
-       u1         *sp;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
-          different to the ones in <ucontext.h>. */
-
-       /* get the PC and SP for this thread */
-       pc = (u1 *) _mc->gregs[REG_RIP];
-       sp = (u1 *) _mc->gregs[REG_RSP];
-
-       /* now suspend the current thread */
-       threads_suspend_ack(pc, sp);
-}
-#endif
-
-
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.
index 9bfe3da3de9a83abfa6f80b206bd960e0a2adc39..57d422d1df1d08370b478e9000359c2616b34fe5 100644 (file)
@@ -62,6 +62,7 @@
 /* function prototypes ********************************************************/
 
 void signal_handler_sighup(int sig, siginfo_t *siginfo, void *_p);
+void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p);
 
 
 /* signal_init *****************************************************************
@@ -195,10 +196,10 @@ bool signal_init(void)
        signal_register_signal(Signal_INTERRUPT_SYSTEM_CALL, (functionptr) signal_handler_sighup, 0);
 #endif
 
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-       /* SIGUSR1 handler for the exact GC to suspend threads */
+#if defined(ENABLE_THREADS)
+       /* SIGUSR1 handler for thread suspension */
 
-       signal_register_signal(SIGUSR1, (functionptr) md_signal_handler_sigusr1,
+       signal_register_signal(SIGUSR1, (functionptr) signal_handler_sigusr1,
                                                   SA_SIGINFO);
 #endif
 
@@ -388,6 +389,21 @@ void signal_handler_sighup(int sig, siginfo_t *siginfo, void *_p)
 #endif
 
 
+/* signal_handler_sigusr1 ******************************************************
+
+   Signal handler for suspending threads.
+
+*******************************************************************************/
+
+#if defined(ENABLE_THREADS)
+void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
+{
+       // Really suspend ourselves by acknowledging the suspension.
+       threads_suspend_ack();
+}
+#endif
+
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
index 94d1727cc3872913eda662260964f4678bdba88f..29a75cf4b9aadd36038d05d84d8e7e2e17911d3d 100644 (file)
@@ -74,8 +74,6 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p);
 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p);
 #endif
 
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p);
-
 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p);
 
 #ifdef __cplusplus