On Sat, 18 Oct 2025 00:56:25 GMT, Serguei Spitsyn <[email protected]> wrote:

>> With [JDK-8359110](https://bugs.openjdk.org/browse/JDK-8359110) a framework 
>> to measure GC CPU time was introduced.
>> It will be exposed in JMX as `MemoryMXBean.getTotalGcCpuTime()`. There is 
>> also interest to get the same performance data from JVMTI.
>> The following API's are being added with this enhancement:
>> 
>> Introduce:
>>  - new capability: `can_get_gc_cpu_time`
>>  - new JVMTI functions:
>>     - `jvmtiError GetGCCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr)`
>>     - `jvmtiError GetTotalGCCpuTime(jvmtiEnv* env, jlong* nanos_ptr)`
>> 
>> **CSR**: [8370159](https://bugs.openjdk.org/browse/JDK-8370159): Spec: 
>> introduce new JVMTI function GetTotalGCCpuTime
>> 
>> Testing:
>>  - TBD: Mach5 tiers 1-6
>
> Serguei Spitsyn has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   fix a typo in GetGCCpuTimerInfo: long => jlong

src/hotspot/share/prims/jvmtiManageCapabilities.cpp line 95:

> 93:     jc.can_get_current_thread_cpu_time = 1;
> 94:     jc.can_get_thread_cpu_time = 1;
> 95:     jc.can_get_gc_cpu_time = 1;

I'm wondering, would a user trying to call `GetTotalGCCpuTime` if 
`can_get_gc_cpu_time` is not successfully set to 1 be undefined behavior? The 
specs say "To possess a capability, the agent must add the capability 
(https://docs.oracle.com/en/java/javase/25/docs/specs/jvmti.html#capability). 
If yes maybe we can discard the extra call to 
`os::is_thread_cpu_time_supported` in `JvmtiEnv::GetTotalGCCpuTime`? That seems 
to align with the pattern to not have that check in the other methods as you 
pointed out.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27879#discussion_r2443399514

Reply via email to