Removing intrinsic of Thread.isInterrupted()

Yumin Qi yumin.qi at oracle.com
Tue Feb 25 09:25:35 PST 2014


Aleksey,

   Thanks for the info, I modified as

         final int  NUM = 20000;
         boolean interrupts[] = new boolean[NUM];
         start = System.currentTimeMillis();
         for (int j = 0; j < 100; j++) {
             for (int i = 0; i < NUM; i++) {
                 interrupts[i] = t.isInterrupted();
             }
         }
         finish = System.currentTimeMillis();
         osum = finish - start;
         System.out.println(NUM + " calls cost: " + osum  + " ms");

The result showed no difference (even a little better without intrinsic).
I think I can remove it from hotspot.

Thanks
Yumin

On 2/25/2014 12:36 AM, Aleksey Shipilev wrote:
> On 02/25/2014 12:31 PM, Florian Weimer wrote:
>> On 02/25/2014 02:46 AM, Yumin Qi wrote:
>>>           isum = 0L;
>>>           for (int i = 0; i < NUM; i++) {
>>>               start = System.currentTimeMillis();
>>>               t.isInterrupted();
>>>               finish = System.currentTimeMillis();
>>>               isum += (finish - start);
>>>           }
>> This benchmark loop looks invalid to me.  I think you have to store the
>> result of t.isInterrupted(), perhaps to an array of booleans, and time
>> the entire thing, not just the call itself.
> Indeed. That's how you do it with JMH:
>   https://github.com/shipilev/benchmarks-scratch/blob/master/src/main/java/org/sample/ThreadIsInterrupted.java
>
> On my Linux x86_64, JDK 8b129 the difference is minuscule.
>
> -Aleksey



More information about the hotspot-compiler-dev mailing list