3737#include " runtime/interfaceSupport.hpp"
3838#include " runtime/javaCalls.hpp"
3939#include " runtime/jniHandles.hpp"
40+ #include " runtime/mutexLocker.hpp"
4041#include " runtime/os.hpp"
4142#include " runtime/serviceThread.hpp"
4243#include " runtime/thread.inline.hpp"
@@ -428,8 +429,6 @@ static MemoryPool* get_memory_pool_from_jobject(jobject obj, TRAPS) {
428429 return MemoryService::get_memory_pool (ph);
429430}
430431
431- #endif // INCLUDE_MANAGEMENT
432-
433432static void validate_thread_id_array (typeArrayHandle ids_ah, TRAPS) {
434433 int num_threads = ids_ah->length ();
435434
@@ -445,8 +444,6 @@ static void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) {
445444 }
446445}
447446
448- #if INCLUDE_MANAGEMENT
449-
450447static void validate_thread_info_array (objArrayHandle infoArray_h, TRAPS) {
451448 // check if the element of infoArray is of type ThreadInfo class
452449 Klass* threadinfo_klass = Management::java_lang_management_ThreadInfo_klass (CHECK);
@@ -2230,7 +2227,39 @@ jlong Management::ticks_to_ms(jlong ticks) {
22302227 return (jlong)(((double )ticks / (double )os::elapsed_frequency ())
22312228 * (double )1000.0 );
22322229}
2233- #endif // INCLUDE_MANAGEMENT
2230+
2231+ // Gets the amount of memory allocated on the Java heap since JVM launch.
2232+ JVM_ENTRY (jlong, jmm_GetTotalThreadAllocatedMemory(JNIEnv *env))
2233+ // We keep a high water mark to ensure monotonicity
2234+ static jlong high_water_result = 0;
2235+ static jlong prev_result = 0 ;
2236+
2237+ jlong result;
2238+ if (Threads_lock->try_lock ()) {
2239+ result = ThreadService::exited_allocated_bytes ();
2240+ for (JavaThread* tp = Threads::first (); tp != NULL ; tp = tp->next ()) {
2241+ jlong size = thread->cooked_allocated_bytes ();
2242+ result += size;
2243+ }
2244+ Threads_lock->unlock ();
2245+ } else {
2246+ // Return the previous result if Threads_lock is locked
2247+ result = prev_result;
2248+ }
2249+
2250+ {
2251+ MutexLockerEx ml (MonitoringSupport_lock, Mutex::_no_safepoint_check_flag);
2252+ if (result < high_water_result) {
2253+ // Result wrapped to a negative value, in which case it's
2254+ // pegged at the last positive value.
2255+ result = high_water_result;
2256+ } else {
2257+ high_water_result = result;
2258+ }
2259+ prev_result = result;
2260+ }
2261+ return result;
2262+ JVM_END
22342263
22352264// Gets the amount of memory allocated on the Java heap for a single thread.
22362265// Returns -1 if the thread does not exist or has terminated.
@@ -2368,11 +2397,8 @@ JVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids,
23682397 }
23692398JVM_END
23702399
2371-
2372-
2373- #if INCLUDE_MANAGEMENT
23742400const struct jmmInterface_1_ jmm_interface = {
2375- NULL ,
2401+ jmm_GetTotalThreadAllocatedMemory ,
23762402 jmm_GetOneThreadAllocatedMemory,
23772403 jmm_GetVersion,
23782404 jmm_GetOptionalSupport,
0 commit comments