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