RFR: 8303242: ThreadMXBean issues with virtual threads [v3]
Mandy Chung
mchung at openjdk.org
Wed Mar 1 21:41:07 UTC 2023
On Wed, 1 Mar 2023 11:40:26 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> 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.
This looks better. I see `testGetCurrentThreadCpuTime` and `testGetCurrentThreadUserTime` test cases fixed.
-------------
PR: https://git.openjdk.org/jdk/pull/12762
More information about the hotspot-runtime-dev
mailing list