1 /* 2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 6589834 27 * @summary Safepoint placed between stack pointer increment and decrement leads 28 * to interpreter's stack corruption after deoptimization. 29 * @library /test/lib / 30 * @modules java.base/jdk.internal.misc 31 * java.compiler 32 * java.management 33 * jdk.jvmstat/sun.jvmstat.monitor 34 * 35 * @build sun.hotspot.WhiteBox 36 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 37 * sun.hotspot.WhiteBox$WhiteBoxPermission 38 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 39 * -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack 40 * -XX:CompileCommand=compileonly,compiler.c2.cr6589834.InlinedArrayCloneTestCase::* 41 * -XX:CompileCommand=dontinline,compiler.c2.cr6589834.InlinedArrayCloneTestCase::invokeArrayClone 42 * -XX:CompileCommand=inline,compiler.c2.cr6589834.InlinedArrayCloneTestCase::verifyArguments 43 * compiler.c2.cr6589834.Test_ia32 44 */ 45 46 package compiler.c2.cr6589834; 47 48 import jdk.test.lib.Asserts; 49 import sun.hotspot.WhiteBox; 50 51 import java.lang.reflect.Method; 52 53 public class Test_ia32 { 54 private static final int NUM_THREADS 55 = Math.min(100, 2 * Runtime.getRuntime().availableProcessors()); 56 private static final int CLONE_LENGTH = 1000; 57 58 private static WhiteBox wb = WhiteBox.getWhiteBox(); 59 60 private final LoadedClass[] ARRAY = new LoadedClass[Test_ia32.CLONE_LENGTH]; 61 private volatile boolean doSpin = true; 62 private volatile boolean testFailed = false; 63 64 public boolean continueExecution() { 65 return doSpin; 66 } 67 68 public void stopExecution() { 69 doSpin = false; 70 } 71 72 public boolean isTestFailed() { 73 return testFailed; 74 } 75 76 public void setTestFailed() { 77 this.testFailed = true; 78 stopExecution(); 79 } 80 81 public LoadedClass[] getArray() { 82 return ARRAY; 83 } 84 85 public void runTest() { 86 Thread[] threads = new Thread[Test_ia32.NUM_THREADS]; 87 Method method; 88 89 try { 90 method = InlinedArrayCloneTestCase.class.getDeclaredMethod( 91 "invokeArrayClone", LoadedClass[].class); 92 } catch (NoSuchMethodException e) { 93 throw new Error("Tested method not found", e); 94 } 95 96 Asserts.assertTrue(wb.isMethodCompilable(method), 97 "Method " + method.getName() + " should be compilable."); 98 99 for (int i = 0; i < threads.length; i++) { 100 threads[i] = new Thread(new InlinedArrayCloneTestCase(this)); 101 threads[i].start(); 102 } 103 104 /* 105 * Wait until InlinedArrayCloneTestCase::invokeArrayClone is compiled. 106 */ 107 while (!wb.isMethodCompiled(method)) { 108 Thread.yield(); 109 } 110 111 /* 112 * Load NotLoadedClass to cause deoptimization of 113 * InlinedArrayCloneTestCase::invokeArrayClone due to invalidated 114 * dependency. 115 */ 116 try { 117 Class.forName(Test_ia32.class.getPackage().getName() + ".NotLoadedClass"); 118 } catch (ClassNotFoundException e) { 119 throw new Error("Unable to load class that invalidates " 120 + "CHA-dependency for method " + method.getName(), e); 121 } 122 123 stopExecution(); 124 125 for (Thread thread : threads) { 126 try { 127 thread.join(); 128 } catch (InterruptedException e) { 129 throw new Error("Fail to join thread " + thread, e); 130 } 131 } 132 133 Asserts.assertFalse(isTestFailed(), "Test failed."); 134 } 135 136 public static void main(String[] args) { 137 new Test_ia32().runTest(); 138 } 139 } 140 141 class LoadedClass { 142 } 143 144 @SuppressWarnings("unused") 145 class NotLoadedClass extends LoadedClass { 146 }