test/compiler/6880034/Test6880034.java

Thu, 17 Apr 2014 16:09:08 -0700

author
amurillo
date
Thu, 17 Apr 2014 16:09:08 -0700
changeset 6635
49b5160951dd
parent 1907
c18cbe5936b8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag hs25.20-b11 for changeset b6a2ba7d3ea7

kvn@1442 1 /*
kvn@1442 2 * Copyright 2009 SAP AG. All Rights Reserved.
kvn@1442 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kvn@1442 4 *
kvn@1442 5 * This code is free software; you can redistribute it and/or modify it
kvn@1442 6 * under the terms of the GNU General Public License version 2 only, as
kvn@1442 7 * published by the Free Software Foundation.
kvn@1442 8 *
kvn@1442 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kvn@1442 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kvn@1442 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kvn@1442 12 * version 2 for more details (a copy is included in the LICENSE file that
kvn@1442 13 * accompanied this code).
kvn@1442 14 *
kvn@1442 15 * You should have received a copy of the GNU General Public License version
kvn@1442 16 * 2 along with this work; if not, write to the Free Software Foundation,
kvn@1442 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kvn@1442 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
kvn@1442 22 */
kvn@1442 23
kvn@1442 24 /**
kvn@1442 25 * @test
kvn@1442 26 * @bug 6880034
kvn@1442 27 * @summary SIGBUS during deoptimisation at a safepoint on 64bit-SPARC
kvn@1442 28 *
kvn@1442 29 * @run main/othervm -Xcomp -Xbatch -XX:CompileCommand=compileonly,Test6880034,deopt_compiledframe_at_safepoint -XX:+PrintCompilation Test6880034
kvn@1442 30 */
kvn@1442 31
kvn@1442 32
kvn@1442 33
kvn@1442 34 // This test provokes a deoptimisation at a safepoint.
kvn@1442 35 //
kvn@1442 36 // It achieves this by compiling the method 'deopt_compiledframe_at_safepoint'
kvn@1442 37 // before its first usage at a point in time when a call to the virtual method
kvn@1442 38 // A::doSomething() from within 'deopt_compiledframe_at_safepoint' can be
kvn@1442 39 // optimised to a static call because class A has no descendants.
kvn@1442 40 //
kvn@1442 41 // Later, when deopt_compiledframe_at_safepoint() is running, class B which
kvn@1442 42 // extends A and overrides the virtual method "doSomething()", is loaded
kvn@1442 43 // asynchronously in another thread. This makes the compiled code of
kvn@1442 44 // 'deopt_compiledframe_at_safepoint' invalid and triggers a deoptimisation of
kvn@1442 45 // the frame where 'deopt_compiledframe_at_safepoint' is running in a
kvn@1442 46 // loop.
kvn@1442 47 //
kvn@1442 48 // The deoptimisation leads to a SIGBUS on 64-bit server VMs on SPARC and to
kvn@1442 49 // an incorrect result on 32-bit server VMs on SPARC due to a regression
kvn@1442 50 // introduced by the change: "6420645: Create a vm that uses compressed oops
kvn@1442 51 // for up to 32gb heapsizes"
kvn@1442 52 // (http://hg.openjdk.java.net/jdk7/jdk7/hotspot/rev/ba764ed4b6f2). Further
kvn@1442 53 // investigation showed that change 6420645 is not really the root cause of
kvn@1442 54 // this error but only reveals a problem with the float register encodings in
kvn@1442 55 // sparc.ad which was hidden until now.
kvn@1442 56 //
kvn@1442 57 // Notice that for this test to fail in jtreg it is crucial that
kvn@1442 58 // deopt_compiledframe_at_safepoint() runs in the main thread. Otherwise a
kvn@1442 59 // crash in deopt_compiledframe_at_safepoint() will not be detected as a test
kvn@1442 60 // failure by jtreg.
kvn@1442 61 //
kvn@1442 62 // Author: Volker H. Simonis
kvn@1442 63
kvn@1442 64 class A {
kvn@1442 65 public int doSomething() {
kvn@1442 66 return 0;
kvn@1442 67 }
kvn@1442 68 }
kvn@1442 69
kvn@1442 70 class B extends A {
kvn@1442 71 public B() {}
kvn@1442 72 // override 'A::doSomething()'
kvn@1442 73 public int doSomething() {
kvn@1442 74 return 1;
kvn@1442 75 }
kvn@1442 76 }
kvn@1442 77
kvn@1442 78 class G {
kvn@1442 79 public static volatile A a = new A();
kvn@1442 80
kvn@1442 81 // Change 'a' to point to a 'B' object
kvn@1442 82 public static void setAtoB() {
kvn@1442 83 try {
kvn@1442 84 a = (A) ClassLoader.
kvn@1442 85 getSystemClassLoader().
kvn@1442 86 loadClass("B").
kvn@1442 87 getConstructor(new Class[] {}).
kvn@1442 88 newInstance(new Object[] {});
kvn@1442 89 }
kvn@1442 90 catch (Exception e) {
kvn@1442 91 System.out.println(e);
kvn@1442 92 }
kvn@1442 93 }
kvn@1442 94 }
kvn@1442 95
kvn@1442 96 public class Test6880034 {
kvn@1442 97
kvn@1442 98 public static volatile boolean is_in_loop = false;
kvn@1442 99 public static volatile boolean stop_while_loop = false;
kvn@1442 100
kvn@1442 101 public static double deopt_compiledframe_at_safepoint() {
kvn@1442 102 // This will be an optimised static call to A::doSomething() until we load "B"
kvn@1442 103 int i = G.a.doSomething();
kvn@1442 104
kvn@1442 105 // Need more than 16 'double' locals in this frame
kvn@1442 106 double local1 = 1;
kvn@1442 107 double local2 = 2;
kvn@1442 108 double local3 = 3;
kvn@1442 109 double local4 = 4;
kvn@1442 110 double local5 = 5;
kvn@1442 111 double local6 = 6;
kvn@1442 112 double local7 = 7;
kvn@1442 113 double local8 = 8;
kvn@1442 114
kvn@1442 115 long k = 0;
kvn@1442 116 // Once we load "B", this method will be made 'not entrant' and deoptimised
kvn@1442 117 // at the safepoint which is at the end of this loop.
kvn@1442 118 while (!stop_while_loop) {
kvn@1442 119 if (k == 1) local1 += i;
kvn@1442 120 if (k == 2) local2 += i;
kvn@1442 121 if (k == 3) local3 += i;
kvn@1442 122 if (k == 4) local4 += i;
kvn@1442 123 if (k == 5) local5 += i;
kvn@1442 124 if (k == 6) local6 += i;
kvn@1442 125 if (k == 7) local7 += i;
kvn@1442 126 if (k == 8) local8 += i;
kvn@1442 127
kvn@1442 128 // Tell the world that we're now running wild in the loop
kvn@1442 129 if (k++ == 20000) is_in_loop = true;
kvn@1442 130 }
kvn@1442 131
kvn@1442 132 return
kvn@1442 133 local1 + local2 + local3 + local4 +
kvn@1442 134 local5 + local6 + local7 + local8 + i;
kvn@1442 135 }
kvn@1442 136
kvn@1442 137 public static void main(String[] args) {
kvn@1442 138
kvn@1442 139 // Just to resolve G before we compile deopt_compiledframe_at_safepoint()
kvn@1442 140 G g = new G();
kvn@1442 141
kvn@1442 142 // Asynchronous thread which will eventually invalidate the code for
kvn@1442 143 // deopt_compiledframe_at_safepoint() and therefore triggering a
kvn@1442 144 // deoptimisation of that method.
kvn@1442 145 new Thread() {
kvn@1442 146 public void run() {
kvn@1442 147 while (!is_in_loop) {
kvn@1442 148 // Wait until the loop is running
kvn@1442 149 }
kvn@1442 150 // Load class 'B' asynchronously..
kvn@1442 151 G.setAtoB();
kvn@1442 152 // ..and stop the loop
kvn@1442 153 stop_while_loop = true;
kvn@1442 154 }
kvn@1442 155 }.start();
kvn@1442 156
kvn@1442 157 // Run the loop in deopt_compiledframe_at_safepoint()
kvn@1442 158 double retVal = deopt_compiledframe_at_safepoint();
kvn@1442 159
kvn@1442 160 System.out.println(retVal == 36 ? "OK" : "ERROR : " + retVal);
kvn@1442 161 if (retVal != 36) throw new RuntimeException();
kvn@1442 162 }
kvn@1442 163 }

mercurial