From bb2147f6f015d3c14f0ac95055ba9cd8078637d6 Mon Sep 17 00:00:00 2001 From: Roman Kennke Date: Wed, 22 Jul 2026 15:35:04 +0200 Subject: [PATCH 1/2] fix(codecache): report the real runtime-stubs cache size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CODECACHE_RUNTIME_STUBS_SIZE_BYTES was set to native_libs.memoryUsage() — the same value as CODECACHE_NATIVE_SIZE_BYTES — a copy-paste since the counter was introduced (d0b0d1e44). It never reflected the runtime-stubs cache. The runtime stubs live in JitCodeCache::_runtime_stubs (populated by DynamicCodeGenerated as the JVM emits stubs), a different cache from the native libraries. Add JitCodeCache::runtimeStubsMemoryUsage(), which reads that cache's size under its shared _stubs_lock (the cache is mutated concurrently by the JVMTI callback), and set the counter from it. Co-Authored-By: Claude Opus 4.8 (1M context) --- ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp | 7 +++++++ ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h | 5 +++++ ddprof-lib/src/main/cpp/profiler.cpp | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.cpp index 00ec522bfe..a45483686d 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 005223384f..88c66be015 100644 --- a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h +++ b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h @@ -38,6 +38,11 @@ class JitCodeCache { } static CodeBlob* findRuntimeStub(const void *address); + + // Live heap footprint of the runtime-stubs code cache. 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 2820ee8c6f..07b15a812e 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 From 2886d411b833bf8b8e12ed533ac8b62139ea982b Mon Sep 17 00:00:00 2001 From: Roman Kennke Date: Wed, 22 Jul 2026 17:15:14 +0200 Subject: [PATCH 2/2] docs(codecache): word runtime-stubs usage as approximate, not "live footprint" CodeCache::memoryUsage() is a capacity/count-based estimate on main, so "live heap footprint" overstated it. Reword to "approximate heap usage" and note #677 makes memoryUsage() exact. Co-Authored-By: Claude Opus 4.8 (1M context) --- ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h index 88c66be015..8d369fe87c 100644 --- a/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h +++ b/ddprof-lib/src/main/cpp/hotspot/jitCodeCache.h @@ -39,9 +39,10 @@ class JitCodeCache { static CodeBlob* findRuntimeStub(const void *address); - // Live heap footprint of the runtime-stubs code cache. Read under the - // shared stubs lock because DynamicCodeGenerated() mutates _runtime_stubs - // (add()/expand()) concurrently. + // 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);