Thread.getState() very slow

Mandy Chung mandy.chung at oracle.com
Fri Aug 13 17:30:08 UTC 2010


Hi Doug,

Doug Lea wrote:
> Sorry for the long delay on this...
>
> On 07/15/10 23:43, Mandy Chung wrote:
>> I think making Thread.threadStatus a volatile field and using
>> JVMTI_JAVA_LANG_THREAD_STATE_MASK to convert Thread.threadStatus to 
>> Thread.State
>> enum would be a good solution.
>>
>>
>> It'd be great if Doug can do the experiment and evaluate the 
>> performance impact.
>> If you want me to prototype the jdk change, let me know and I should 
>> be able to
>> make some time to do it next week.
>>
>
> I did an equivalent experiment (of just directly accessing
> threadState via Unsafe.getIntVolatile and comparing it to
> cached values) and it was about 14X faster.  So anything
> along these lines would be grat. That said, I decided not
> to try to rely on getState in the near term. (Among other
> reasons, it does not usually reflect IO blockage.) So this
> is off the critical path for now. But someday someone is sure
> to run into similar performance issues unless implementation
> is improved.
>

Thanks for doing the experiment and the performance number which is 
great.  I file 2 CRs:

6977034: Thread.getState() very slow
6977039: Extend Thread.State.BLOCKED to reflect blocking on I/O state

Mandy



More information about the core-libs-dev mailing list