RFR: 8369449: Spec: introduce new JVMTI function GetTotalGCCpuTime [v3]

Ivan Walulya iwalulya at openjdk.org
Mon Oct 20 10:29:04 UTC 2025


On Sun, 19 Oct 2025 18:41:56 GMT, Jonas Norlinder <duke at openjdk.org> wrote:

> There may be two issues with the patch as is:
> 
> Calling `GetTotalGCCpuTime` in `Agent_OnLoad` can cause crash (since `CollectedHeap::gc_threads_do` do not protect against races on VM startup/shutdown).
> 
> If `GetTotalGCCpuTime` is invoked in a callback for GC start/end, this will cause a deadlock as the `Heap_lock` is already held. The `MutexLocker hl(Heap_lock)` pattern was introduced to avoid races that could happen from internal usage in G1 of `CPUTimeUsage::GC::total()` during shutdown. I could recall this wrong but I think the usage `Heap_lock` (which evidently has uses in other places) is an optimization to avoid having to create a new mutex shutdown variable. I could be wrong but it is maybe possible that this deadlock would be resolved by introducing a new mutex only used for syncing on the state of `Universe::_is_shutting_down`. I will ask @walulyai for his thoughts.

Right, there will be a deadlock if `GetTotalGCCpuTime` is called in the callbacks for events `GarbageCollectionStart`, `GarbageCollectionFinish`

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

PR Comment: https://git.openjdk.org/jdk/pull/27879#issuecomment-3421476400


More information about the serviceability-dev mailing list