< prev index next >

test/compiler/c2/Test6880034.java

Print this page
rev 11557 : 8132919: use package in compiler tests
Reviewed-by: duke


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 6880034
  27  * @summary SIGBUS during deoptimisation at a safepoint on 64bit-SPARC
  28  *
  29  * @run main/othervm -Xcomp -Xbatch -XX:CompileCommand=compileonly,Test6880034,deopt_compiledframe_at_safepoint -XX:+PrintCompilation Test6880034



  30  */
  31 

  32 
  33 
  34 // This test provokes a deoptimisation at a safepoint.
  35 //
  36 // It achieves this by compiling the method 'deopt_compiledframe_at_safepoint'
  37 // before its first usage at a point in time when a call to the virtual method
  38 // A::doSomething() from within 'deopt_compiledframe_at_safepoint' can be
  39 // optimised to a static call because class A has no descendants.
  40 //
  41 // Later, when deopt_compiledframe_at_safepoint() is running, class B which
  42 // extends A and overrides the virtual method "doSomething()", is loaded
  43 // asynchronously in another thread.  This makes the compiled code of
  44 // 'deopt_compiledframe_at_safepoint' invalid and triggers a deoptimisation of
  45 // the frame where 'deopt_compiledframe_at_safepoint' is running in a
  46 // loop.
  47 //
  48 // The deoptimisation leads to a SIGBUS on 64-bit server VMs on SPARC and to
  49 // an incorrect result on 32-bit server VMs on SPARC due to a regression
  50 // introduced by the change: "6420645: Create a vm that uses compressed oops
  51 // for up to 32gb heapsizes"
  52 // (http://hg.openjdk.java.net/jdk7/jdk7/hotspot/rev/ba764ed4b6f2).  Further
  53 // investigation showed that change 6420645 is not really the root cause of
  54 // this error but only reveals a problem with the float register encodings in
  55 // sparc.ad which was hidden until now.
  56 //
  57 // Notice that for this test to fail in jtreg it is crucial that
  58 // deopt_compiledframe_at_safepoint() runs in the main thread. Otherwise a
  59 // crash in deopt_compiledframe_at_safepoint() will not be detected as a test
  60 // failure by jtreg.
  61 //
  62 // Author: Volker H. Simonis
  63 
  64 class A {

  65   public int doSomething() {
  66     return 0;
  67   }
  68 }
  69 
  70 class B extends A {
  71   public B() {}
  72   // override 'A::doSomething()'
  73   public int doSomething() {
  74     return 1;
  75   }
  76 }
  77 
  78 class G {
  79   public static volatile A a = new A();
  80 
  81   // Change 'a' to point to a 'B' object
  82   public static void setAtoB() {
  83     try {
  84       a =  (A) ClassLoader.
  85         getSystemClassLoader().
  86         loadClass("B").
  87         getConstructor(new Class[] {}).
  88         newInstance(new Object[] {});
  89     }
  90     catch (Exception e) {
  91       System.out.println(e);
  92     }
  93   }
  94 }
  95 
  96 public class Test6880034 {
  97 
  98   public static volatile boolean is_in_loop = false;
  99   public static volatile boolean stop_while_loop = false;
 100 
 101   public static double deopt_compiledframe_at_safepoint() {
 102     // This will be an optimised static call to A::doSomething() until we load "B"
 103     int i = G.a.doSomething();
 104 
 105     // Need more than 16 'double' locals in this frame
 106     double local1 = 1;
 107     double local2 = 2;
 108     double local3 = 3;
 109     double local4 = 4;
 110     double local5 = 5;
 111     double local6 = 6;
 112     double local7 = 7;
 113     double local8 = 8;
 114 
 115     long k = 0;
 116     // Once we load "B", this method will be made 'not entrant' and deoptimised
 117     // at the safepoint which is at the end of this loop.




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 6880034
  27  * @summary SIGBUS during deoptimisation at a safepoint on 64bit-SPARC
  28  *
  29  * @run main/othervm -Xcomp -Xbatch
  30  *    -XX:+PrintCompilation
  31  *    -XX:CompileCommand=compileonly,compiler.c2.Test6880034::deopt_compiledframe_at_safepoint
  32  *    compiler.c2.Test6880034
  33  */
  34 
  35 package compiler.c2;
  36 

  37 // This test provokes a deoptimisation at a safepoint.
  38 //
  39 // It achieves this by compiling the method 'deopt_compiledframe_at_safepoint'
  40 // before its first usage at a point in time when a call to the virtual method
  41 // A::doSomething() from within 'deopt_compiledframe_at_safepoint' can be
  42 // optimised to a static call because class A has no descendants.
  43 //
  44 // Later, when deopt_compiledframe_at_safepoint() is running, class B which
  45 // extends A and overrides the virtual method "doSomething()", is loaded
  46 // asynchronously in another thread.  This makes the compiled code of
  47 // 'deopt_compiledframe_at_safepoint' invalid and triggers a deoptimisation of
  48 // the frame where 'deopt_compiledframe_at_safepoint' is running in a
  49 // loop.
  50 //
  51 // The deoptimisation leads to a SIGBUS on 64-bit server VMs on SPARC and to
  52 // an incorrect result on 32-bit server VMs on SPARC due to a regression
  53 // introduced by the change: "6420645: Create a vm that uses compressed oops
  54 // for up to 32gb heapsizes"
  55 // (http://hg.openjdk.java.net/jdk7/jdk7/hotspot/rev/ba764ed4b6f2).  Further
  56 // investigation showed that change 6420645 is not really the root cause of
  57 // this error but only reveals a problem with the float register encodings in
  58 // sparc.ad which was hidden until now.
  59 //
  60 // Notice that for this test to fail in jtreg it is crucial that
  61 // deopt_compiledframe_at_safepoint() runs in the main thread. Otherwise a
  62 // crash in deopt_compiledframe_at_safepoint() will not be detected as a test
  63 // failure by jtreg.
  64 //
  65 // Author: Volker H. Simonis
  66 
  67 public class Test6880034 {
  68   static class A {
  69     public int doSomething() {
  70       return 0;
  71     }
  72   }
  73 
  74   static class B extends A {
  75     public B() {}
  76     // override 'A::doSomething()'
  77     public int doSomething() {
  78       return 1;
  79     }
  80   }
  81 
  82   static class G {
  83     public static volatile A a = new A();
  84 
  85     // Change 'a' to point to a 'B' object
  86     public static void setAtoB() {
  87       try {
  88         a =  (A) ClassLoader.
  89                 getSystemClassLoader().
  90                 loadClass("B").
  91                 getConstructor(new Class[] {}).
  92                 newInstance(new Object[] {});
  93       }
  94       catch (Exception e) {
  95         System.out.println(e);
  96       }
  97     }
  98   }
  99 


 100   public static volatile boolean is_in_loop = false;
 101   public static volatile boolean stop_while_loop = false;
 102 
 103   public static double deopt_compiledframe_at_safepoint() {
 104     // This will be an optimised static call to A::doSomething() until we load "B"
 105     int i = G.a.doSomething();
 106 
 107     // Need more than 16 'double' locals in this frame
 108     double local1 = 1;
 109     double local2 = 2;
 110     double local3 = 3;
 111     double local4 = 4;
 112     double local5 = 5;
 113     double local6 = 6;
 114     double local7 = 7;
 115     double local8 = 8;
 116 
 117     long k = 0;
 118     // Once we load "B", this method will be made 'not entrant' and deoptimised
 119     // at the safepoint which is at the end of this loop.


< prev index next >