On Wed, 1 Mar 2023 11:40:26 GMT, Alan Bateman <al...@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

Reply via email to