On Fri, 5 May 2023 21:38:47 GMT, Paul Hohensee <p...@openjdk.org> wrote:
>> Please review this addition to com.sun.management.ThreadMXBean that returns >> the total number of bytes allocated on the Java heap since JVM launch by >> both terminated and live threads. >> >> Because this PR adds a new interface method, I've updated the JMM_VERSION to >> 4, but would be happy to update it to 3_1 instead. > > Paul Hohensee has updated the pull request incrementally with one additional > commit since the last revision: > > 8304074: [JMX] Add an approximation of total bytes allocated on the Java > heap by the JVM src/hotspot/share/services/management.cpp line 2107: > 2105: // when result is initialized. > 2106: jlong result = ThreadService::exited_allocated_bytes(); > 2107: for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = > jtiwh.next();) { If you call `exited_allocated_bytes` whilst you have an active `ThreadsListHandle` then you at least ensure you don't miss accounting for threads that are just about to terminate. src/hotspot/share/services/threadService.cpp line 173: > 171: // was not called, e.g., > JavaThread::cleanup_failed_attach_current_thread(). > 172: decrement_thread_counts(thread, daemon); > 173: > ThreadService::incr_exited_allocated_bytes(thread->cooked_allocated_bytes()); By doing this here you increase the likelihood of double-accounting for this thread. If you do this after the thread is no longer on any threads-list you may miss its contribution entirely, but you won't double-count it. src/jdk.management/share/classes/com/sun/management/ThreadMXBean.java line 111: > 109: * Returns an approximation of the total amount of memory, in bytes, > 110: * allocated in heap memory since the Java virtual machine was > launched, > 111: * including the amount allocated by terminated threads. This "including ..." part seems redundant - it is the value allocated since JVM launch. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/13814#discussion_r1186967565 PR Review Comment: https://git.openjdk.org/jdk/pull/13814#discussion_r1186968365 PR Review Comment: https://git.openjdk.org/jdk/pull/13814#discussion_r1186968949