diff --git a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp index 00ec522bf..a45483686 100644 --- a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp +++ b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp @@ -52,3 +52,10 @@ CodeBlob* JitCodeCache::findRuntimeStub(const void *address) { _stubs_lock.unlockShared(); return stub; } + +long long JitCodeCache::runtimeStubsMemoryUsage() { + _stubs_lock.lockShared(); + long long usage = _runtime_stubs.memoryUsage(); + _stubs_lock.unlockShared(); + return usage; +} diff --git a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h index 005223384..8d369fe87 100644 --- a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h +++ b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h @@ -38,6 +38,12 @@ class JitCodeCache { } static CodeBlob* findRuntimeStub(const void *address); + + // Approximate heap usage of the runtime-stubs code cache, via + // CodeCache::memoryUsage() (a capacity/count-based estimate today; #677 + // makes it exact). Read under the shared stubs lock because + // DynamicCodeGenerated() mutates _runtime_stubs (add()/expand()) concurrently. + static long long runtimeStubsMemoryUsage(); static bool isJitCode(const void* pc) { return CodeHeap::contains(pc); } diff --git a/ddprof-lib/src/main/cpp/profiler.cpp b/ddprof-lib/src/main/cpp/profiler.cpp index 2820ee8c6..07b15a812 100644 --- a/ddprof-lib/src/main/cpp/profiler.cpp +++ b/ddprof-lib/src/main/cpp/profiler.cpp @@ -21,6 +21,7 @@ #include "itimer.h" #include "hotspot/vmStructs.inline.h" #include "hotspot/hotspotSupport.h" +#include "hotspot/jitCodeCache.h" #include "j9/j9Support.h" #include "j9/j9WallClock.h" #include "jvmSupport.h" @@ -1737,8 +1738,11 @@ Error Profiler::dump(const char *path, const int length) { const CodeCacheArray& native_libs = _libs->native_libs(); Counters::set(CODECACHE_NATIVE_COUNT, native_libs.count()); Counters::set(CODECACHE_NATIVE_SIZE_BYTES, native_libs.memoryUsage()); + // The runtime-stubs counter reflects the JIT runtime-stubs code cache, a + // separate cache from the native libraries (it previously duplicated + // native_libs.memoryUsage() by copy-paste). Read under its shared lock. Counters::set(CODECACHE_RUNTIME_STUBS_SIZE_BYTES, - native_libs.memoryUsage()); + JitCodeCache::runtimeStubsMemoryUsage()); Error err = Error::OK; // rotateDictsAndRun rotates the dictionaries, takes lockAll() around the