1 /* 2 * Copyright (c) 2016, 2020, 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 * @requires vm.aot 27 * @library /test/lib /testlibrary / 28 * @modules java.base/jdk.internal.misc 29 * @build compiler.aot.RecompilationTest 30 * sun.hotspot.WhiteBox 31 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 32 * @run driver compiler.aot.AotCompiler -libname libRecompilationTest1.so 33 * -class compiler.whitebox.SimpleTestCaseHelper 34 * -extraopt -Dgraal.TieredAOT=true -extraopt -Dgraal.ProfileSimpleMethods=true 35 * -extraopt -Dgraal.ProbabilisticProfiling=false 36 * -extraopt -XX:+UnlockDiagnosticVMOptions -extraopt -XX:+WhiteBoxAPI -extraopt -Xbootclasspath/a:. 37 * -extraopt -XX:-UseCompressedOops 38 * -extraopt -XX:CompileCommand=dontinline,compiler.whitebox.SimpleTestCaseHelper::* 39 * @run driver compiler.aot.AotCompiler -libname libRecompilationTest2.so 40 * -class compiler.whitebox.SimpleTestCaseHelper 41 * -extraopt -Dgraal.TieredAOT=false 42 * -extraopt -XX:+UnlockDiagnosticVMOptions -extraopt -XX:+WhiteBoxAPI -extraopt -Xbootclasspath/a:. 43 * -extraopt -XX:-UseCompressedOops 44 * -extraopt -XX:CompileCommand=dontinline,compiler.whitebox.SimpleTestCaseHelper::* 45 * @run main/othervm -Xmixed -Xbatch -XX:+UnlockExperimentalVMOptions -XX:+UseAOT -XX:-TieredCompilation 46 * -XX:-UseCounterDecay -XX:-UseCompressedOops 47 * -XX:-Inline 48 * -XX:AOTLibrary=./libRecompilationTest2.so -Xbootclasspath/a:. 49 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 50 * -Dcompiler.aot.RecompilationTest.check_level=-1 51 * compiler.aot.RecompilationTest 52 * @summary check if recompilation after aot goes fine 53 */ 54 55 /* having whitebox-related options for aot compiler is a temporary solution, 56 because of JDK-8146201 57 */ 58 59 package compiler.aot; 60 61 import compiler.whitebox.CompilerWhiteBoxTest; 62 import java.lang.reflect.Executable; 63 import jdk.test.lib.Asserts; 64 65 public final class RecompilationTest extends CompilerWhiteBoxTest { 66 private static final int CHECK_LEVEL = Integer.getInteger( 67 "compiler.aot.RecompilationTest.check_level"); 68 main(String args[])69 public static void main(String args[]) { 70 CompilerWhiteBoxTest.main(RecompilationTest::new, args); 71 } 72 RecompilationTest(TestCase testCase)73 private RecompilationTest(TestCase testCase) { 74 super(testCase); 75 } 76 77 @Override test()78 protected void test() throws Exception { 79 if (testCase.isOsr()) { 80 /* aot compiler is not using osr compilation */ 81 System.out.println("Skipping OSR case"); 82 return; 83 } 84 Executable e = testCase.getExecutable(); 85 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(e), 86 testCase.name() + ": an executable expected to be compiled"); 87 Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(e), 88 COMP_LEVEL_AOT, 89 String.format("%s: unexpected compilation level at start", 90 testCase.name())); 91 compile(); 92 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(e), testCase.name() 93 + ": method expected to be compiled"); 94 /* a case with AOT'ed code checks exact compilation level equality 95 while another case checks minimum level and if method compiled 96 because there might be different compilation level transitions */ 97 if (CHECK_LEVEL != COMP_LEVEL_AOT) { 98 Asserts.assertGTE(WHITE_BOX.getMethodCompilationLevel(e), 99 CHECK_LEVEL, 100 String.format("%s: expected compilation level" 101 + " after compilation to be no less than %d for %s", 102 testCase.name(), CHECK_LEVEL, testCase.name())); 103 } else { 104 Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(e), 105 COMP_LEVEL_AOT, String.format("%s: expected compilation" 106 + " level after compilation to be equal to %d for %s", 107 testCase.name(), COMP_LEVEL_AOT, testCase.name())); 108 } 109 } 110 } 111