This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [RFA/JVMTI] SuspendThread and ResumeThread
- From: Keith Seitz <keiths at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: Fri, 21 Jul 2006 15:59:31 -0700
- Subject: Re: [RFA/JVMTI] SuspendThread and ResumeThread
- References: <44C125C8.4080607@redhat.com>
Keith Seitz wrote:
As requested here are the JVMTI functions SuspendThread and
ResumeThread. They're very basic. They don't check for some error
conditions (like checking whether the thread to be suspended is already
suspended). I have them working in my sandbox breakpoint-enabled gij.
Actually, I'd like to submit this alternative version for the two JVMTI
functions, which now do at least some validity checking.
I've attached the patch in its entirety for completeness.
Keith
Index: boehm.cc
===================================================================
--- boehm.cc (revision 115627)
+++ boehm.cc (working copy)
@@ -678,19 +678,20 @@
#endif
}
-#if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
- && !defined(GC_WIN32_THREADS) && !defined(GC_DARWIN_THREADS)
-
void
_Jv_SuspendThread (_Jv_Thread_t *thread)
{
+#if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
+ && !defined(GC_WIN32_THREADS) && !defined(GC_DARWIN_THREADS)
GC_suspend_thread (_Jv_GetPlatformThreadID (thread));
+#endif
}
void
_Jv_ResumeThread (_Jv_Thread_t *thread)
{
+#if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
+ && !defined(GC_WIN32_THREADS) && !defined(GC_DARWIN_THREADS)
GC_resume_thread (_Jv_GetPlatformThreadID (thread));
+#endif
}
-
-#endif
Index: posix-threads.cc
===================================================================
--- posix-threads.cc (revision 115627)
+++ posix-threads.cc (working copy)
@@ -505,22 +505,6 @@
pthread_mutex_unlock (&daemon_mutex);
}
-void
-_Jv_ThreadDebugSuspend (_Jv_Thread_t *data)
-{
-}
-
-void
-_Jv_ThreadDebugResume (_Jv_Thread_t *data)
-{
-}
-
-jint
-_Jv_ThreadDebugSuspendCount (_Jv_Thread_t *data)
-{
- return -1;
-}
-
#if defined(SLOW_PTHREAD_SELF)
#include "sysdep/locks.h"
Index: jvmti.cc
===================================================================
--- jvmti.cc (revision 115631)
+++ jvmti.cc (working copy)
@@ -11,8 +11,56 @@
#include <config.h>
#include <jvm.h>
+#include <java-threads.h>
+#include <java-gc.h>
#include <jvmti.h>
+#include <java/lang/Thread.h>
+
+// Some commonly-used checks
+
+#define THREAD_DEFAULT_TO_CURRENT(jthread) \
+ if (jthread == NULL) jthread = java::lang::Thread::currentThread ();
+
+#define THREAD_CHECK_VALID(jthread) \
+ if (!java::lang::Thread::class$.isAssignableFrom (&(jthread->class$))) \
+ return JVMTI_ERROR_INVALID_THREAD;
+
+#define THREAD_CHECK_IS_ALIVE(thread) \
+ if (!thread->isAlive ()) return JVMTI_ERROR_THREAD_NOT_ALIVE;
+
+static jvmtiError
+_Jv_JVMTI_SuspendThread (MAYBE_UNUSED jvmtiEnv *env, jthread thread)
+{
+ using namespace java::lang;
+
+ THREAD_DEFAULT_TO_CURRENT (thread);
+ THREAD_CHECK_VALID (thread);
+
+ Thread *t = reinterpret_cast<Thread *> (thread);
+ THREAD_CHECK_IS_ALIVE (t);
+
+ _Jv_Thread_t *data = _Jv_ThreadGetData (t);
+ _Jv_SuspendThread (data);
+ return JVMTI_ERROR_NONE;
+}
+
+static jvmtiError
+_Jv_JVMTI_ResumeThread (MAYBE_UNUSED jvmtiEnv *env, jthread thread)
+{
+ using namespace java::lang;
+
+ THREAD_DEFAULT_TO_CURRENT (thread);
+ THREAD_CHECK_VALID (thread);
+
+ Thread *t = reinterpret_cast<Thread *> (thread);
+ THREAD_CHECK_IS_ALIVE (t);
+
+ _Jv_Thread_t *data = _Jv_ThreadGetData (t);
+ _Jv_ResumeThread (data);
+ return JVMTI_ERROR_NONE;
+}
+
#define RESERVED NULL
#define UNIMPLEMENTED NULL
@@ -30,8 +78,8 @@
UNIMPLEMENTED, // SetEventNotification
RESERVED, // reserved3
UNIMPLEMENTED, // GetAllThreads
- UNIMPLEMENTED, // SuspendThread
- UNIMPLEMENTED, // ResumeThread
+ _Jv_JVMTI_SuspendThread, // SuspendThread
+ _Jv_JVMTI_ResumeThread, // ResumeThread
UNIMPLEMENTED, // StopThread
UNIMPLEMENTED, // InterruptThread
UNIMPLEMENTED, // GetThreadInfo