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 /testlibrary /test/lib 30 * @modules java.base/jdk.internal.misc 31 * java.compiler 32 * java.management 33 * jdk.jvmstat/sun.jvmstat.monitor 34 * @build ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.* 35 * Test_ia32 InlinedArrayCloneTestCase 36 * @run main ClassFileInstaller sun.hotspot.WhiteBox 37 * sun.hotspot.WhiteBox$WhiteBoxPermission 38 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 39 * -XX:+WhiteBoxAPI -XX:CompileOnly=InlinedArrayCloneTestCase 40 * -XX:CompileCommand=dontinline,InlinedArrayCloneTestCase.invokeArrayClone 41 * -XX:CompileCommand=inline,InlinedArrayCloneTestCase.verifyArguments 42 * -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack Test_ia32 43 */ 44 45 import java.lang.reflect.Method; 46 47 import jdk.test.lib.Asserts; 48 import sun.hotspot.WhiteBox; 49 50 public class Test_ia32 { 51 private static final int NUM_THREADS 52 = Math.min(100, 2 * Runtime.getRuntime().availableProcessors()); 53 private static final int CLONE_LENGTH = 1000; 54 55 private static WhiteBox wb = WhiteBox.getWhiteBox(); 56 57 private final LoadedClass[] ARRAY = new LoadedClass[Test_ia32.CLONE_LENGTH]; 58 private volatile boolean doSpin = true; 59 private volatile boolean testFailed = false; 60 61 public boolean continueExecution() { 62 return doSpin; 63 } 64 65 public void stopExecution() { 66 doSpin = false; 67 } 68 69 public boolean isTestFailed() { 70 return testFailed; 71 } 72 73 public void setTestFailed() { 74 this.testFailed = true; 75 stopExecution(); 76 } 77 78 public LoadedClass[] getArray() { 79 return ARRAY; 80 } 81 82 public void runTest() { 83 Thread[] threads = new Thread[Test_ia32.NUM_THREADS]; 84 Method method; 85 86 try { 87 method = InlinedArrayCloneTestCase.class.getDeclaredMethod( 88 "invokeArrayClone", LoadedClass[].class); 89 } catch (NoSuchMethodException e) { 90 throw new Error("Tested method not found", e); 91 } 92 93 Asserts.assertTrue(wb.isMethodCompilable(method), 94 "Method " + method.getName() + " should be compilable."); 95 96 for (int i = 0; i < threads.length; i++) { 97 threads[i] = new Thread(new InlinedArrayCloneTestCase(this)); 98 threads[i].start(); 99 } 100 101 /* 102 * Wait until InlinedArrayCloneTestCase::invokeArrayClone is compiled. 103 */ 104 while (!wb.isMethodCompiled(method)) { 105 Thread.yield(); 106 } 107 108 /* 109 * Load NotLoadedClass to cause deoptimization of 110 * InlinedArrayCloneTestCase::invokeArrayClone due to invalidated 111 * dependency. 112 */ 113 try { 114 Class.forName("NotLoadedClass"); 115 } catch (ClassNotFoundException e) { 116 throw new Error("Unable to load class that invalidates " 117 + "CHA-dependency for method " + method.getName(), e); 118 } 119 120 stopExecution(); 121 122 for (Thread thread : threads) { 123 try { 124 thread.join(); 125 } catch (InterruptedException e) { 126 throw new Error("Fail to join thread " + thread, e); 127 } 128 } 129 130 Asserts.assertFalse(isTestFailed(), "Test failed."); 131 } 132 133 public static void main(String[] args) { 134 new Test_ia32().runTest(); 135 } 136 } 137 138 class LoadedClass { 139 } 140 141 @SuppressWarnings("unused") 142 class NotLoadedClass extends LoadedClass { 143 }