This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH] Fix some JVMTI thinkos
- From: Keith Seitz <keiths at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: Tue, 19 Sep 2006 16:14:45 -0700
- Subject: [PATCH] Fix some JVMTI thinkos
Hi,
I am going to commit this as kind of obvious (now that it has been
found). This patch fixes two bugs in jvmti.cc. [Okay, that and I'd like
to prune the number of jvmti.cc patches I'm hanging on to and revising.]
First, we were passing an incorrect (albeit not illegal) parameter
THREAD_CHECK_VALID, which needs a java::lang::Thread* not a
java::lang::Object* (which is what jthread is defined as).
Second we were dereferencing a pointer that was just freed. Ouch.
If there are any problems, please don't hesitate to email me (and/or
YELL, SCREAM, flame, etc).
Keith
ChangeLog
2006-09-19 Keith Seitz <keiths@redhat.com>
* jvmti.cc (THREAD_DEFAULT_TO_CURRENT): Clarify parameter list.
(THREAD_CHECK_VALID): Likewise.
(THREAD_CHECK_ALIVE): Likewise.
(_Jv_JVMTI_SuspendThread): Call THREAD_CHECK_VALID on a Thread not
jthread.
(_Jv_JVMTI_ResumeThread): Likewise.
(_Jv_JVMTI_InterruptThread): Likewise.
(_Jv_JVMTI_DisposeEnvironment): Probably unwise to dereference
an object
that was just freed.
Index: jvmti.cc
===================================================================
--- jvmti.cc (revision 116636)
+++ jvmti.cc (working copy)
@@ -56,26 +56,26 @@
// Some commonly-used checks
-#define THREAD_DEFAULT_TO_CURRENT(jthread) \
+#define THREAD_DEFAULT_TO_CURRENT(Ajthread) \
do \
{ \
- if (jthread == NULL) \
- jthread = java::lang::Thread::currentThread (); \
+ if (Ajthread == NULL) \
+ Ajthread = java::lang::Thread::currentThread (); \
} \
while (0)
-#define THREAD_CHECK_VALID(jthread) \
+#define THREAD_CHECK_VALID(Athread) \
do \
{ \
- if (!java::lang::Thread::class$.isAssignableFrom (&(jthread->class$))) \
+ if (!java::lang::Thread::class$.isAssignableFrom (&(Athread->class$))) \
return JVMTI_ERROR_INVALID_THREAD; \
} \
while (0)
-#define THREAD_CHECK_IS_ALIVE(thread) \
+#define THREAD_CHECK_IS_ALIVE(Athread) \
do \
{ \
- if (!thread->isAlive ()) \
+ if (!Athread->isAlive ()) \
return JVMTI_ERROR_THREAD_NOT_ALIVE; \
} \
while (0)
@@ -106,9 +106,9 @@
using namespace java::lang;
THREAD_DEFAULT_TO_CURRENT (thread);
- THREAD_CHECK_VALID (thread);
-
+
Thread *t = reinterpret_cast<Thread *> (thread);
+ THREAD_CHECK_VALID (t);
THREAD_CHECK_IS_ALIVE (t);
_Jv_Thread_t *data = _Jv_ThreadGetData (t);
@@ -122,9 +122,9 @@
using namespace java::lang;
THREAD_DEFAULT_TO_CURRENT (thread);
- THREAD_CHECK_VALID (thread);
Thread *t = reinterpret_cast<Thread *> (thread);
+ THREAD_CHECK_VALID (t);
THREAD_CHECK_IS_ALIVE (t);
_Jv_Thread_t *data = _Jv_ThreadGetData (t);
@@ -141,8 +141,9 @@
// FIXME: capability handling? 'can_signal_thread'
if (thread == NULL)
return JVMTI_ERROR_INVALID_THREAD;
- THREAD_CHECK_VALID (thread);
+
Thread *real_thread = reinterpret_cast<Thread *> (thread);
+ THREAD_CHECK_VALID (real_thread);
THREAD_CHECK_IS_ALIVE (real_thread);
real_thread->interrupt();
return JVMTI_ERROR_NONE;
@@ -487,8 +488,9 @@
JvSynchronize dummy (_envListLock);
if (_jvmtiEnvironments->env == env)
{
+ struct jvmti_env_list *next = _jvmtiEnvironments->next;
_Jv_Free (_jvmtiEnvironments);
- _jvmtiEnvironments = _jvmtiEnvironments->next;
+ _jvmtiEnvironments = next;
}
else
{