diff options
author | kgallowa <kgallowa@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-16 15:06:28 +0000 |
---|---|---|
committer | kgallowa <kgallowa@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-16 15:06:28 +0000 |
commit | 34b0e09cd2ed4f463f7168b8ca0fb8f15443d455 (patch) | |
tree | 8a3866653315bfe7be70d28bf9d7d4f62e0bdc88 /libjava/jvmti.cc | |
parent | 213448e9810276af654b401117bc42d2d43d447b (diff) | |
download | gcc-34b0e09cd2ed4f463f7168b8ca0fb8f15443d455.tar.gz |
2007-01-16 Kyle Galloway <kgallowa@redhat.com>
* jvmti.cc (_Jv_JVMTI_GetAllThreads): New function.
* testsuite/libjava.jvmti/getallthreads.java: New test.
* testsuite/libjava.jvmti/natgetallthreads.cc: Ditto.
* testsuite/libjava.jvmti/getallthreads.out: Ditto.
* testsuite/libjava.jvmti/getallthreads.h: Ditto.
* testsuite/libjava.jvmti/getallthreads.jar: Ditto.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120827 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/jvmti.cc')
-rw-r--r-- | libjava/jvmti.cc | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/libjava/jvmti.cc b/libjava/jvmti.cc index 8584c333d6d..b9646b7d101 100644 --- a/libjava/jvmti.cc +++ b/libjava/jvmti.cc @@ -28,7 +28,9 @@ details. */ #include <java/lang/Class.h> #include <java/lang/ClassLoader.h> #include <java/lang/Object.h> +#include <java/lang/OutOfMemoryError.h> #include <java/lang/Thread.h> +#include <java/lang/ThreadGroup.h> #include <java/lang/Throwable.h> #include <java/lang/VMClassLoader.h> #include <java/lang/reflect/Field.h> @@ -196,6 +198,51 @@ _Jv_JVMTI_InterruptThread (MAYBE_UNUSED jvmtiEnv *env, jthread thread) return JVMTI_ERROR_NONE; } +jvmtiError +_Jv_JVMTI_GetAllThreads(MAYBE_UNUSED jvmtiEnv *env, jint *thread_cnt, + jthread **threads) +{ + REQUIRE_PHASE (env, JVMTI_PHASE_LIVE); + NULL_CHECK (thread_cnt); + NULL_CHECK (threads); + + using namespace java::lang; + Thread *thr = Thread::currentThread (); + + ThreadGroup *root_grp = ThreadGroup::root; + jint estimate = root_grp->activeCount (); + + JArray<Thread *> *thr_arr; + + // Allocate some extra space since threads can be created between calls + try + { + thr_arr + = reinterpret_cast<JArray<Thread *> *> (JvNewObjectArray + ((estimate * 2), + &Thread::class$, NULL)); + } + catch (java::lang::OutOfMemoryError *err) + { + return JVMTI_ERROR_OUT_OF_MEMORY; + } + + *thread_cnt = root_grp->enumerate (thr_arr); + + jvmtiError jerr = env->Allocate ((jlong) ((*thread_cnt) * sizeof (jthread)), + (unsigned char **) threads); + + if (jerr != JVMTI_ERROR_NONE) + return jerr; + + // Transfer the threads to the result array + jthread *tmp_arr = reinterpret_cast<jthread *> (elements (thr_arr)); + + memcpy ((*threads), tmp_arr, (*thread_cnt)); + + return JVMTI_ERROR_NONE; +} + static jvmtiError JNICALL _Jv_JVMTI_CreateRawMonitor (MAYBE_UNUSED jvmtiEnv *env, const char *name, jrawMonitorID *result) @@ -1362,7 +1409,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface = RESERVED, // reserved1 _Jv_JVMTI_SetEventNotificationMode, // SetEventNotificationMode RESERVED, // reserved3 - UNIMPLEMENTED, // GetAllThreads + _Jv_JVMTI_GetAllThreads, // GetAllThreads _Jv_JVMTI_SuspendThread, // SuspendThread _Jv_JVMTI_ResumeThread, // ResumeThread UNIMPLEMENTED, // StopThread |