--- old/src/hotspot/share/services/management.cpp 2019-09-19 06:08:27.000000000 -0700 +++ new/src/hotspot/share/services/management.cpp 2019-09-19 06:08:27.000000000 -0700 @@ -2068,6 +2068,31 @@ } #endif // INCLUDE_MANAGEMENT +// Gets the amount of memory allocated on the Java heap for a single thread. +// Returns -1 if the thread does not exist or has terminated. +JVM_ENTRY(jlong, jmm_GetOneThreadAllocatedMemory(JNIEnv *env, jlong thread_id)) + if (thread_id < 0) { + THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), + "Invalid thread ID", -1); + } + + if (thread_id == 0) { + // current thread + if (THREAD->is_Java_thread()) { + return ((JavaThread*)THREAD)->cooked_allocated_bytes(); + } + return -1; + } + + ThreadsListHandle tlh; + JavaThread* java_thread = tlh.list()->find_JavaThread_from_java_tid(thread_id); + + if (java_thread != NULL) { + return java_thread->cooked_allocated_bytes(); + } + return -1; +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 @@ -2192,6 +2217,7 @@ jmm_GetMemoryManagers, jmm_GetMemoryPoolUsage, jmm_GetPeakMemoryPoolUsage, + jmm_GetOneThreadAllocatedMemory, jmm_GetThreadAllocatedMemory, jmm_GetMemoryUsage, jmm_GetLongAttribute,