/* * Get Thread CPU Time * * Return the CPU time utilized by the specified thread. * * OPTIONAL Functionality. */ jvmtiError JNICALL jvmtiGetThreadCpuTime(jvmtiEnv* env, jthread thread, jlong* nanos_ptr) { TRACE2("jvmti.timer", "GetThreadCpuTime called"); IDATA status; SuspendEnabledChecker sec; /* * Check given env & current phase. */ jvmtiPhase phases[] = {JVMTI_PHASE_LIVE}; CHECK_EVERYTHING(); CHECK_CAPABILITY(can_get_thread_cpu_time); if (NULL == nanos_ptr) return JVMTI_ERROR_NULL_POINTER; if (NULL == thread) { status = jthread_get_thread_cpu_time(NULL, nanos_ptr); } else { if (! is_valid_thread_object(thread)) return JVMTI_ERROR_INVALID_THREAD; // lock thread manager to avoid occasional change of thread state hythread_global_lock(); int state;// =thread_get_thread_state(thread); jvmtiError err = jvmtiGetThreadState(env, thread, &state); if (err != JVMTI_ERROR_NONE){ return err; } switch (state) { case JVMTI_THREAD_STATE_TERMINATED: // thread is terminated case JVMTI_JAVA_LANG_THREAD_STATE_NEW: // thread is new hythread_global_unlock(); return JVMTI_ERROR_THREAD_NOT_ALIVE; default: // thread is alive status = jthread_get_thread_cpu_time(thread, nanos_ptr); break; } hythread_global_unlock(); } if (status != TM_ERROR_NONE) return JVMTI_ERROR_INTERNAL; return JVMTI_ERROR_NONE; }
static jvmtiError GetLocal_checkArgs(jvmtiEnv* env, jthread *thread, jint depth, jint UNREF slot, void* value_ptr) { jint state; jvmtiError err; // TODO: check error condition: JVMTI_ERROR_MUST_POSSESS_CAPABILITY if (*thread == 0) { *thread = getCurrentThread(); } // check error condition: JVMTI_ERROR_INVALID_THREAD err = jvmtiGetThreadState(env, *thread, &state); if (err != JVMTI_ERROR_NONE) { return err; } // check error condition: JVMTI_ERROR_THREAD_NOT_ALIVE if ((state & JVMTI_THREAD_STATE_ALIVE) == 0) { return JVMTI_ERROR_THREAD_NOT_ALIVE; } // check error condition: JVMTI_ERROR_ILLEGAL_ARGUMENT if (depth < 0) { return JVMTI_ERROR_ILLEGAL_ARGUMENT; } // check error condition: JVMTI_ERROR_NULL_POINTER if (value_ptr == 0) { return JVMTI_ERROR_NULL_POINTER; } return JVMTI_ERROR_NONE; }