Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6723458

Microbenchmark: Jit missing optimisation of some methods

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE REQUEST :
      the compiled code running with the serveroption should be able to optimise and inline call to virtual mthods across class boundaries

      In particular where the class that is being executed is a final class, then all of the methods can be resolved

      JUSTIFICATION :
      this can improve performance

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      more methods are precisely resolved and inlined.

      It seem to me that some more optimisation is possible

      class b2f is final so the methods that it calls are resolvable and inlineable

      similarly for b2f2 as this is a final extension to a class which does not override he methods concerned

      similarly for the other classeswhere the methods are not overridden

      -------
      It also seems strange to me that the compiler or JIT does not optimise away
                  for (int i = 0; i < count; i++) {
                      dummy = -1;
                      dummy = -2;
                  }
      to (this seems to be done)

                  for (int i = 0; i < count; i++) {
                      dummy = -2;
                  }

      to

                  for (int i = 0; i < count; i++) {
                  }
                  dummy = -2;

      and eventually to

                  dummy = -2;
              }

      ACTUAL -
      the performance of the test application is below

      the application is running on java 5 u6, and running with the -server option

      -----------------------------------------------------
      b1.bottom: 331 ms b2.bottom: 320 ms b1f.bottom: 321 ms b2f.bottom: 310 ms b2f2.bottom: 301 ms extra.bottom: 30 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 360 ms b2.bottom: 331 ms b1f.bottom: 310 ms b2f.bottom: 291 ms b2f2.bottom: 310 ms extra.bottom: 30 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 301 ms b2.bottom: 290 ms b1f.bottom: 321 ms b2f.bottom: 310 ms b2f2.bottom: 360 ms extra.bottom: 31 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 330 ms b2.bottom: 301 ms b1f.bottom: 360 ms b2f.bottom: 300 ms b2f2.bottom: 301 ms extra.bottom: 30 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 300 ms b2.bottom: 331 ms b1f.bottom: 310 ms b2f.bottom: 311 ms b2f2.bottom: 300 ms extra.bottom: 30 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 301 ms b2.bottom: 330 ms b1f.bottom: 311 ms b2f.bottom: 300 ms b2f2.bottom: 291 ms extra.bottom: 80 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 310 ms b2.bottom: 311 ms b1f.bottom: 330 ms b2f.bottom: 371 ms b2f2.bottom: 360 ms extra.bottom: 20 ms extra.bottom2: 30 ms extraf.bottom: 30 ms
      b1.bottom: 331 ms b2.bottom: 340 ms b1f.bottom: 321 ms b2f.bottom: 340 ms b2f2.bottom: 311 ms extra.bottom: 30 ms extra.bottom2: 20 ms extraf.bottom: 30 ms
      b1.bottom: 320 ms b2.bottom: 421 ms b1f.bottom: 491 ms b2f.bottom: 300 ms b2f2.bottom: 310 ms extra.bottom: 30 ms extra.bottom2: 20 ms extraf.bottom: 31 ms
      b1.bottom: 330 ms b2.bottom: 310 ms b1f.bottom: 321 ms b2f.bottom: 300 ms b2f2.bottom: 321 ms extra.bottom: 20 ms extra.bottom2: 30 ms extraf.bottom: 20 ms

      ---------- BEGIN SOURCE ----------
      import java.util.List;

      public class test11 {
          
          
          private final static int count = 100000000;
          
          long dummy = 0;
          extra xx = new extra();
          void run() {
              b1 b1 = new b1();
              b1f b1f = new b1f();
              b2 b2 = new b2();
              b2f b2f = new b2f();
              b2f2 b2f2 = new b2f2();
              extra extra = new extra();
              extraf extraf = new extraf();
              
              for (int i = 0; i < 10; i++) {
                  b1.bottom();
                  b1f.bottom();
                  b2.bottom();
                  b2f.bottom();
                  b2f2.bottom();
                  extra.bottom();
                  extra.bottom2();
                  extraf.bottom();
              }
              long time = System.currentTimeMillis();
              for (int i = 0; i < 10; i++) {
                  b1.bottom();
                  time = timer(time,"b1.bottom");
                  b2.bottom();
                  time = timer(time,"b2.bottom");
                  b1f.bottom();
                  time = timer(time,"b1f.bottom");
                  b2f.bottom();
                  time = timer(time,"b2f.bottom");
                  b2f2.bottom();
                  time = timer(time,"b2f2.bottom");
                  extra.bottom();
                  time = timer(time,"extra.bottom");
                  extra.bottom2();
                  time = timer(time,"extra.bottom2");
                  extraf.bottom();
                  time = timer(time,"extraf.bottom");
                  
                  
                  
                  System.out.println();
              }
              xx.middle();
          }
          
          long timer(long start, String msg) {
              long end = System.currentTimeMillis();
              System.out.print(msg+": "+(end-start)+" ms ");
              return end;
          }
          
          
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              new test11().run();
          }
          
          class top {
              void top() {
                  dummy = 1;
              }
          }
          class m1 extends top {
              void middle() {
                  dummy = 2;
              }
          }
          class m2 extends top {
              void middle() {
                  dummy = 3;
              }
          }
          class extra {
              private final void top() {
                  dummy = -1;
              }
              private final void middle() {
                  dummy = -2;
              }
              final void bottom() {
                  for (int i = 0; i < count; i++) {
                      top();
                      middle();
                  }
              }
              final void bottom2() {
                  for (int i = 0; i < count; i++) {
                      dummy = -1;
                      dummy = -2;
                  }
              }
              
          }
          final class extraf extends m1 {
              void top() {
                  dummy = -1;
              }
              void middle() {
                  dummy = -2;
              }
              void bottom() {
                  for (int i = 0; i < count; i++) {
                      top();
                      middle();
                  }
              }
              
          }
          class b1 extends m1 {
              void bottom() {
                  for (int i = 0; i < count; i++) {
                      top();
                      middle();
                  }
              }
          }
          class b1f extends m1 {
              void bottom() {
                  for (int i = 0; i < count; i++) {
                      top();
                      middle();
                  }
              }
          }
          class b2 extends m2 {
              void bottom() {
                  for (int i = 0; i < count; i++) {
                      top();
                      middle();
                  }
              }
          }
          final class b2f2 extends b2{
          }
          final class b2f extends m2 {
              void bottom() {
                  for (int i = 0; i < count; i++) {
                      top();
                      middle();
                  }
              }
          }
      }

      ---------- END SOURCE ----------

            chagedorn Christian Hagedorn
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: