RFR: 8303242: ThreadMXBean issues with virtual threads [v2]
Alan Bateman
alanb at openjdk.org
Wed Mar 1 11:43:07 UTC 2023
On Tue, 28 Feb 2023 21:06:19 GMT, Mandy Chung <mchung at openjdk.org> wrote:
>> Alan Bateman has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
>>
>> - Clarify Thread CPU time seciton of spec
>> - Merge
>> - Fix minimal build
>> - Fix minimal build
>> - Initial commit
>
> test/jdk/java/lang/management/ThreadMXBean/VirtualThreads.java line 258:
>
>> 256: long tid = Thread.currentThread().threadId();
>> 257: long cpuTime = bean.getThreadCpuTime(tid);
>> 258: assertEquals(-1L, cpuTime);
>
> Am I correct that `getThreadCpuTime(tid)` returns -1 for the current thread is a virtual thread whereas `getCurrentThreadCpuTime` throws UOE in the current implementation?
>
> `getCurrentThreadCpuTime` is specified to be equivalent to calling `getThreadCpuTime(Thread.currentThread().threadId()`.
We didn't get this quite right in JDK 19 but I think I've fixed all those issues now. So assuming the VM supports CPU time for all platform threads, it means:
- isThreadCpuTimeEnabled and isCurrentThreadCpuTimeSupported will return true.
- If getThreadCpuTime(long) is called with the thread ID of a virtual thread then -1 will be returned.
- If getCurrentThreadCpuTime() is called from a virtual thread then -1 will be returned.
I did another pass over the API docs, update the "Thread CPU time" section, so I hope it is clearer now.
-------------
PR: https://git.openjdk.org/jdk/pull/12762
More information about the serviceability-dev
mailing list