jmx-dev RFR: 8304074: [JMX] Add an approximation of total bytes allocated on the Java heap by the JVM
Volker Simonis
simonis at openjdk.org
Fri May 5 17:16:19 UTC 2023
On Fri, 5 May 2023 06:45:10 GMT, David Holmes <dholmes at 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.
>
> src/hotspot/share/services/management.cpp line 2102:
>
>> 2100: JVM_ENTRY(jlong, jmm_GetAllThreadAllocatedMemory(JNIEnv *env))
>> 2101: // There is a race between threads that exit during the loop and calling
>> 2102: // exited_allocated_bytes. If the result is initialized with exited_allocated_bytes,
>
> If you want a stable and accurate value did you consider holding the Threads_lock while you iterate the threads? Or do it as a safepoint VMop?
The API specification clearly states that this method returns "*an approximation of the total amount of memory allocated in heap*" so in my opinion it is OK to keep it simple here and don't start messing with looks and safepoints.
But can't we make this a little more accurate by only adding a threads allocated bytes if it is not `thread->is_terminated()`? Wouldn't that prevent double counting most of the time?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13814#discussion_r1186246289
More information about the jmx-dev
mailing list