--- old/src/share/vm/services/management.cpp 2014-09-04 08:39:59.857913190 +0200 +++ new/src/share/vm/services/management.cpp 2014-09-04 08:39:59.737913992 +0200 @@ -389,23 +389,6 @@ return (instanceOop) element(); } -// Helper functions -static JavaThread* find_java_thread_from_id(jlong thread_id) { - assert(Threads_lock->owned_by_self(), "Must hold Threads_lock"); - - JavaThread* java_thread = NULL; - // Sequential search for now. Need to do better optimization later. - for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) { - oop tobj = thread->threadObj(); - if (!thread->is_exiting() && - tobj != NULL && - thread_id == java_lang_Thread::thread_id(tobj)) { - java_thread = thread; - break; - } - } - return java_thread; -} static GCMemoryManager* get_gc_memory_manager_from_jobject(jobject mgr, TRAPS) { if (mgr == NULL) { @@ -442,6 +425,8 @@ return MemoryService::get_memory_pool(ph); } +#endif // INCLUDE_MANAGEMENT + static void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) { int num_threads = ids_ah->length(); @@ -457,6 +442,8 @@ } } +#if INCLUDE_MANAGEMENT + static void validate_thread_info_array(objArrayHandle infoArray_h, TRAPS) { // check if the element of infoArray is of type ThreadInfo class Klass* threadinfo_klass = Management::java_lang_management_ThreadInfo_klass(CHECK); @@ -820,45 +807,6 @@ return prev; JVM_END -// Gets an array containing the amount of memory allocated on the Java -// heap for a set of threads (in bytes). Each element of the array is -// the amount of memory allocated for the thread ID specified in the -// corresponding entry in the given array of thread IDs; or -1 if the -// thread does not exist or has terminated. -JVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids, - jlongArray sizeArray)) - // Check if threads is null - if (ids == NULL || sizeArray == NULL) { - THROW(vmSymbols::java_lang_NullPointerException()); - } - - ResourceMark rm(THREAD); - typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); - typeArrayHandle ids_ah(THREAD, ta); - - typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray)); - typeArrayHandle sizeArray_h(THREAD, sa); - - // validate the thread id array - validate_thread_id_array(ids_ah, CHECK); - - // sizeArray must be of the same length as the given array of thread IDs - int num_threads = ids_ah->length(); - if (num_threads != sizeArray_h->length()) { - THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), - "The length of the given long array does not match the length of " - "the given array of thread IDs"); - } - - MutexLockerEx ml(Threads_lock); - for (int i = 0; i < num_threads; i++) { - JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i)); - if (java_thread != NULL) { - sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes()); - } - } -JVM_END - // Returns a java/lang/management/MemoryUsage object representing // the memory usage for the heap or non-heap memory. JVM_ENTRY(jobject, jmm_GetMemoryUsage(JNIEnv* env, jboolean heap)) @@ -1164,7 +1112,7 @@ MutexLockerEx ml(Threads_lock); for (int i = 0; i < num_threads; i++) { jlong tid = ids_ah->long_at(i); - JavaThread* jt = find_java_thread_from_id(tid); + JavaThread* jt = Threads::find_java_thread_from_java_tid(tid); oop thread_obj = (jt != NULL ? jt->threadObj() : (oop)NULL); instanceHandle threadObj_h(THREAD, (instanceOop) thread_obj); thread_handle_array->append(threadObj_h); @@ -1243,7 +1191,7 @@ MutexLockerEx ml(Threads_lock); for (int i = 0; i < num_threads; i++) { jlong tid = ids_ah->long_at(i); - JavaThread* jt = find_java_thread_from_id(tid); + JavaThread* jt = Threads::find_java_thread_from_java_tid(tid); ThreadSnapshot* ts; if (jt == NULL) { // if the thread does not exist or now it is terminated, @@ -1489,7 +1437,7 @@ } } else { // reset contention statistics for a given thread - JavaThread* java_thread = find_java_thread_from_id(tid); + JavaThread* java_thread = Threads::find_java_thread_from_java_tid(tid); if (java_thread == NULL) { return false; } @@ -1558,7 +1506,7 @@ return os::current_thread_cpu_time(); } else { MutexLockerEx ml(Threads_lock); - java_thread = find_java_thread_from_id(thread_id); + java_thread = Threads::find_java_thread_from_java_tid(thread_id); if (java_thread != NULL) { return os::thread_cpu_time((Thread*) java_thread); } @@ -1566,78 +1514,6 @@ return -1; JVM_END -// Returns the CPU time consumed by a given thread (in nanoseconds). -// If thread_id == 0, CPU time for the current thread is returned. -// If user_sys_cpu_time = true, user level and system CPU time of -// a given thread is returned; otherwise, only user level CPU time -// is returned. -JVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time)) - if (!os::is_thread_cpu_time_supported()) { - return -1; - } - - if (thread_id < 0) { - THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), - "Invalid thread ID", -1); - } - - JavaThread* java_thread = NULL; - if (thread_id == 0) { - // current thread - return os::current_thread_cpu_time(user_sys_cpu_time != 0); - } else { - MutexLockerEx ml(Threads_lock); - java_thread = find_java_thread_from_id(thread_id); - if (java_thread != NULL) { - return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0); - } - } - return -1; -JVM_END - -// Gets an array containing the CPU times consumed by a set of threads -// (in nanoseconds). Each element of the array is the CPU time for the -// thread ID specified in the corresponding entry in the given array -// of thread IDs; or -1 if the thread does not exist or has terminated. -// If user_sys_cpu_time = true, the sum of user level and system CPU time -// for the given thread is returned; otherwise, only user level CPU time -// is returned. -JVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids, - jlongArray timeArray, - jboolean user_sys_cpu_time)) - // Check if threads is null - if (ids == NULL || timeArray == NULL) { - THROW(vmSymbols::java_lang_NullPointerException()); - } - - ResourceMark rm(THREAD); - typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); - typeArrayHandle ids_ah(THREAD, ta); - - typeArrayOop tia = typeArrayOop(JNIHandles::resolve_non_null(timeArray)); - typeArrayHandle timeArray_h(THREAD, tia); - - // validate the thread id array - validate_thread_id_array(ids_ah, CHECK); - - // timeArray must be of the same length as the given array of thread IDs - int num_threads = ids_ah->length(); - if (num_threads != timeArray_h->length()) { - THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), - "The length of the given long array does not match the length of " - "the given array of thread IDs"); - } - - MutexLockerEx ml(Threads_lock); - for (int i = 0; i < num_threads; i++) { - JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i)); - if (java_thread != NULL) { - timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread, - user_sys_cpu_time != 0)); - } - } -JVM_END - // Returns a String array of all VM global flag names JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env)) // last flag entry is always NULL, so subtract 1 @@ -2323,7 +2199,122 @@ return (jlong)(((double)ticks / (double)os::elapsed_frequency()) * (double)1000.0); } +#endif // INCLUDE_MANAGEMENT + +// Gets an array containing the amount of memory allocated on the Java +// heap for a set of threads (in bytes). Each element of the array is +// the amount of memory allocated for the thread ID specified in the +// corresponding entry in the given array of thread IDs; or -1 if the +// thread does not exist or has terminated. +JVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids, + jlongArray sizeArray)) + // Check if threads is null + if (ids == NULL || sizeArray == NULL) { + THROW(vmSymbols::java_lang_NullPointerException()); + } + + ResourceMark rm(THREAD); + typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); + typeArrayHandle ids_ah(THREAD, ta); + + typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray)); + typeArrayHandle sizeArray_h(THREAD, sa); + + // validate the thread id array + validate_thread_id_array(ids_ah, CHECK); + + // sizeArray must be of the same length as the given array of thread IDs + int num_threads = ids_ah->length(); + if (num_threads != sizeArray_h->length()) { + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), + "The length of the given long array does not match the length of " + "the given array of thread IDs"); + } + + MutexLockerEx ml(Threads_lock); + for (int i = 0; i < num_threads; i++) { + JavaThread* java_thread = Threads::find_java_thread_from_java_tid(ids_ah->long_at(i)); + if (java_thread != NULL) { + sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes()); + } + } +JVM_END + +// Returns the CPU time consumed by a given thread (in nanoseconds). +// If thread_id == 0, CPU time for the current thread is returned. +// If user_sys_cpu_time = true, user level and system CPU time of +// a given thread is returned; otherwise, only user level CPU time +// is returned. +JVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time)) + if (!os::is_thread_cpu_time_supported()) { + return -1; + } + + if (thread_id < 0) { + THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), + "Invalid thread ID", -1); + } + + JavaThread* java_thread = NULL; + if (thread_id == 0) { + // current thread + return os::current_thread_cpu_time(user_sys_cpu_time != 0); + } else { + MutexLockerEx ml(Threads_lock); + java_thread = Threads::find_java_thread_from_java_tid(thread_id); + if (java_thread != NULL) { + return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0); + } + } + return -1; +JVM_END + +// Gets an array containing the CPU times consumed by a set of threads +// (in nanoseconds). Each element of the array is the CPU time for the +// thread ID specified in the corresponding entry in the given array +// of thread IDs; or -1 if the thread does not exist or has terminated. +// If user_sys_cpu_time = true, the sum of user level and system CPU time +// for the given thread is returned; otherwise, only user level CPU time +// is returned. +JVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids, + jlongArray timeArray, + jboolean user_sys_cpu_time)) + // Check if threads is null + if (ids == NULL || timeArray == NULL) { + THROW(vmSymbols::java_lang_NullPointerException()); + } + + ResourceMark rm(THREAD); + typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); + typeArrayHandle ids_ah(THREAD, ta); + + typeArrayOop tia = typeArrayOop(JNIHandles::resolve_non_null(timeArray)); + typeArrayHandle timeArray_h(THREAD, tia); + + // validate the thread id array + validate_thread_id_array(ids_ah, CHECK); + + // timeArray must be of the same length as the given array of thread IDs + int num_threads = ids_ah->length(); + if (num_threads != timeArray_h->length()) { + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), + "The length of the given long array does not match the length of " + "the given array of thread IDs"); + } + + MutexLockerEx ml(Threads_lock); + for (int i = 0; i < num_threads; i++) { + JavaThread* java_thread = Threads::find_java_thread_from_java_tid(ids_ah->long_at(i)); + if (java_thread != NULL) { + timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread, + user_sys_cpu_time != 0)); + } + } +JVM_END + + +#if INCLUDE_MANAGEMENT const struct jmmInterface_1_ jmm_interface = { NULL, NULL,