X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libjava%2Fjvmti.cc;h=7c7923b2e8d81cf9189dadbf436a4c40b1a32681;hb=2c622b2eac33e9946e2ad459663f7c993d043e2a;hp=c13bb5aa3970b029bbb19edaaedd056431d10cf5;hpb=ca42112c32f3a96e8ef382fdfac01aae8f9a102e;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/jvmti.cc b/libjava/jvmti.cc index c13bb5aa397..7c7923b2e8d 100644 --- a/libjava/jvmti.cc +++ b/libjava/jvmti.cc @@ -1,6 +1,6 @@ // jvmti.cc - JVMTI implementation -/* Copyright (C) 2006, 2007 Free Software Foundation +/* Copyright (C) 2006, 2007, 2010 Free Software Foundation This file is part of libgcj. @@ -30,6 +30,7 @@ details. */ #include #include #include +#include #include #include #include @@ -521,6 +522,66 @@ _Jv_JVMTI_GetFrameCount (MAYBE_UNUSED jvmtiEnv *env, jthread thread, } static jvmtiError JNICALL +_Jv_JVMTI_GetThreadState (MAYBE_UNUSED jvmtiEnv *env, jthread thread, + jint *thread_state_ptr) +{ + REQUIRE_PHASE (env, JVMTI_PHASE_LIVE); + + THREAD_DEFAULT_TO_CURRENT (thread); + THREAD_CHECK_VALID (thread); + NULL_CHECK (thread_state_ptr); + + jint state = 0; + if (thread->isAlive ()) + { + state |= JVMTI_THREAD_STATE_ALIVE; + + _Jv_Thread_t *data = _Jv_ThreadGetData (thread); + if (_Jv_IsThreadSuspended (data)) + state |= JVMTI_THREAD_STATE_SUSPENDED; + + if (thread->isInterrupted ()) + state |= JVMTI_THREAD_STATE_INTERRUPTED; + + _Jv_Frame *frame = reinterpret_cast<_Jv_Frame *> (thread->frame); + if (frame != NULL && frame->frame_type == frame_native) + state |= JVMTI_THREAD_STATE_IN_NATIVE; + + using namespace java::lang; + Thread$State *ts = thread->getState (); + if (ts == Thread$State::RUNNABLE) + state |= JVMTI_THREAD_STATE_RUNNABLE; + else if (ts == Thread$State::BLOCKED) + state |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER; + else if (ts == Thread$State::TIMED_WAITING + || ts == Thread$State::WAITING) + { + state |= JVMTI_THREAD_STATE_WAITING; + state |= ((ts == Thread$State::WAITING) + ? JVMTI_THREAD_STATE_WAITING_INDEFINITELY + : JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT); + + /* FIXME: We don't have a way to tell + the caller why the thread is suspended, + i.e., JVMTI_THREAD_STATE_SLEEPING, + JVMTI_THREAD_STATE_PARKED, and + JVMTI_THREAD_STATE_IN_OBJECT_WAIT + are never set. */ + } + } + else + { + using namespace java::lang; + Thread$State *ts = thread->getState (); + if (ts == Thread$State::TERMINATED) + state |= JVMTI_THREAD_STATE_TERMINATED; + } + + *thread_state_ptr = state; + return JVMTI_ERROR_NONE; +} + +static jvmtiError JNICALL _Jv_JVMTI_CreateRawMonitor (MAYBE_UNUSED jvmtiEnv *env, const char *name, jrawMonitorID *result) { @@ -2004,7 +2065,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface = UNIMPLEMENTED, // GetThreadGroupInfo UNIMPLEMENTED, // GetThreadGroupChildren _Jv_JVMTI_GetFrameCount, // GetFrameCount - UNIMPLEMENTED, // GetThreadState + _Jv_JVMTI_GetThreadState, // GetThreadState RESERVED, // reserved18 UNIMPLEMENTED, // GetFrameLocation UNIMPLEMENTED, // NotifyPopFrame @@ -2149,6 +2210,7 @@ _Jv_GetJVMTIEnv (void) { _Jv_JVMTIEnv *env = (_Jv_JVMTIEnv *) _Jv_MallocUnchecked (sizeof (_Jv_JVMTIEnv)); + memset (env, 0, sizeof (_Jv_JVMTIEnv)); env->p = &_Jv_JVMTI_Interface; struct jvmti_env_list *element = (struct jvmti_env_list *) _Jv_MallocUnchecked (sizeof (struct jvmti_env_list));