os_windows.cpp : simplify is_thread_cpu_time_supported ?

David Holmes david.holmes at oracle.com
Fri Mar 26 02:28:26 UTC 2021


Sorry, correction ...

On 26/03/2021 8:30 am, David Holmes wrote:
> Hi Matthias,
> 
> On 25/03/2021 11:49 pm, Baesken, Matthias wrote:
>> Hello,  I wonder , should we just return  true  in  
>> os::is_thread_cpu_time_supported()   on Windows  ?
>>
>> See
>>
>> https://github.com/openjdk/jdk/blob/master/src/hotspot/os/windows/os_windows.cpp#L4588 
>>
>> According to  MSDN
>> https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreadtimes 
>>
>> GetThreadTimes is supported  on Win2003/XP and higher . This should be 
>> fine for OpenJDK .
> 
> Yes it should be fine. There may be other Windows archaisms in the code 
> that could be cleaned up now.

The issue was not API availability (we got rid of that check a long time 
ago) but security permissions. We actually just returned "true" prior to 
JDK 5 but that was changed by JDK-4884677 when the JVM TI support was added.

It is a bit messy. We use the result of 
os::is_thread_cpu_time_supported() at initialization time, on the main 
thread to then decide the global availability of this feature. And via 
the normal launcher that thread will have all access bits set and so we 
will flag thread_cpu_time as being available. At runtime we might 
encounter a thread for which the access bits are not present and so the 
actual get_thread_cpu_time call may return -1. In theory the JVM could 
be loaded on a thread without full permissions and so we would then 
globally disable thread_cpu_time.

So I think this code has to stay.

David
-----

> Cheers,
> David
> 
>> Best regards, Matthias
>>


More information about the hotspot-dev mailing list