diff options
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 8584c33..b9646b7 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 |