Removing intrinsic of Thread.isInterrupted()

Yumin Qi yumin.qi at oracle.com
Mon Feb 24 17:46:37 PST 2014


Hi, Compiler team

   I worked on this bug: 6498581:ThreadInterruptTest3 produces wrong 
output on Windows.  This is a problem thread sleep wakes up spuriously 
due to a race condition between os::interrupt and os::is_interruped. 
Detail please see bug comments.

  https://bugs.openjdk.java.net/browse/JDK-6498581

   The fix is (without removing intrinsic, but intend to remove it) :
   http://cr.openjdk.java.net/~minqi/6498581/webrev00/

   One problem is that Thread.isInterrupted() is intrinsic and there is 
chance that code like

   boolean a = Thread.currentThread().isInterrupted();
   boolean b = Thread.interrupted();

   Will get different value. (fast/slow path)
   I tried to remove the intrinsic code and done a test using following 
code. The result showed there is no difference by removing the intrinsic 
of Thread.isInterrupted().

// test performance of removing Thread.isInterrupted() inlining
public class TestThreadInterrupted {
     public static void main(String... args) {
         Thread t = new Thread () {
             public void run() {
                 boolean isInt = false;
                 while (!isInt) {
                     try {
                         Thread.sleep(30);
                     } catch (InterruptedException ie) {
                         isInt = true;
                     }
                 }
             }
         };

         t.start();
         // run
         long start, finish, isum = 0L, osum = 0L;
         int  NUM = 20000;
         for (int j = 0; j < 100; j++) {
         isum = 0L;
         for (int i = 0; i < NUM; i++) {
             start = System.currentTimeMillis();
             t.isInterrupted();
             finish = System.currentTimeMillis();
             isum += (finish - start);
         }

         System.out.println("Total cost of " + NUM + " calls is " + isum 
+ " ms");
         osum += isum;
         }
         System.out.println("Average " + osum/100 + " ms");
         t.interrupt();
         try {
             t.join();
         } catch (InterruptedException e) {}
     }
}

And found there is no difference on Solaris-x64/sparcv9, Windows(32/64), 
linux(32/64) before and after the removing of intrinsic 
Thread.isInterrupted().

Should I remove the intrinsic?

Data (no major difference  for both with/without intrinsic):

1)windows :
....
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 1 ms
Total cost of 20000 calls is 1 ms
Total cost of 20000 calls is 1 ms
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 1 ms
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 0 ms
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 2 ms
Average 1 ms

2) Solaris-x64
....
Total cost of 20000 calls is 3 ms
Total cost of 20000 calls is 1 ms
Total cost of 20000 calls is 4 ms
Total cost of 20000 calls is 6 ms
Total cost of 20000 calls is 6 ms
Total cost of 20000 calls is 5 ms
Total cost of 20000 calls is 7 ms
Total cost of 20000 calls is 5 ms
Total cost of 20000 calls is 5 ms
Total cost of 20000 calls is 1 ms
Total cost of 20000 calls is 3 ms
Total cost of 20000 calls is 2 ms
Total cost of 20000 calls is 3 ms
Total cost of 20000 calls is 3 ms
Total cost of 20000 calls is 5 ms
Total cost of 20000 calls is 4 ms
Total cost of 20000 calls is 4 ms
Total cost of 20000 calls is 7 ms
Average 4 ms

3) Linux:

....
Total cost of 20000 calls is 30 ms
Total cost of 20000 calls is 29 ms
Total cost of 20000 calls is 26 ms
Total cost of 20000 calls is 26 ms
Total cost of 20000 calls is 26 ms
Total cost of 20000 calls is 24 ms
Total cost of 20000 calls is 29 ms
Total cost of 20000 calls is 25 ms
Total cost of 20000 calls is 20 ms
Average 24 ms


Thanks
Yumin


More information about the hotspot-compiler-dev mailing list