1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/**
* @test id=C1
* @bug 8280481
* @summary Checks that stubs to the interpreter can be shared for static or final method.
* @library /test/lib
* @requires vm.opt.TieredStopAtLevel == null & vm.opt.TieredCompilation == null
* @requires vm.simpleArch == "x86" | vm.simpleArch == "x64" | vm.simpleArch == "aarch64" | vm.simpleArch == "riscv64"
* @requires vm.debug
* @run driver compiler.sharedstubs.SharedStubToInterpTest -XX:TieredStopAtLevel=1
*
* @test id=C2
* @requires vm.opt.TieredStopAtLevel == null & vm.opt.TieredCompilation == null
* @requires vm.simpleArch == "x86" | vm.simpleArch == "x64" | vm.simpleArch == "aarch64" | vm.simpleArch == "riscv64"
* @requires vm.debug
* @requires !vm.graal.enabled
* @run driver compiler.sharedstubs.SharedStubToInterpTest -XX:-TieredCompilation
*
*/
package compiler.sharedstubs;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class SharedStubToInterpTest {
private final static int ITERATIONS_TO_HEAT_LOOP = 20_000;
private static void runTest(String compiler, String test) throws Exception {
String testClassName = SharedStubToInterpTest.class.getName() + "$" + test;
ArrayList<String> command = new ArrayList<String>();
command.add(compiler);
command.add("-XX:+UnlockDiagnosticVMOptions");
command.add("-Xbatch");
command.add("-XX:+PrintRelocations");
command.add("-XX:CompileCommand=compileonly," + testClassName + "::" + "test");
command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "test");
command.add("-XX:CompileCommand=print," + testClassName + "::" + "test");
command.add("-XX:CompileCommand=exclude," + testClassName + "::" + "log01");
command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "log01");
command.add("-XX:CompileCommand=exclude," + testClassName + "::" + "log02");
command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "log02");
command.add(testClassName);
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(command);
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldHaveExitValue(0);
System.out.println(analyzer.getOutput());
checkOutput(analyzer);
}
public static void main(String[] args) throws Exception {
String[] methods = new String[] { "StaticMethodTest", "FinalClassTest", "FinalMethodTest"};
for (String methodName : methods) {
runTest(args[0], methodName);
}
}
private static void checkOutput(OutputAnalyzer output) {
List<String> addrs = Pattern.compile("\\(static_stub\\) addr=(\\w+) .*\\[static_call=")
.matcher(output.getStdout())
.results()
.map(m -> m.group(1))
.toList();
if (addrs.stream().distinct().count() >= addrs.size()) {
throw new RuntimeException("No static stubs reused: distinct " + addrs.stream().distinct().count() + ", in total " + addrs.size());
}
}
public static class StaticMethodTest {
static void log01(int i) {
}
static void log02(int i) {
}
static void test(int i) {
if (i % 3 == 0) {
log01(i);
log02(i);
} else {
log01(i);
log02(i);
}
}
public static void main(String[] args) {
for (int i = 1; i < ITERATIONS_TO_HEAT_LOOP; ++i) {
test(i);
}
}
}
public static final class FinalClassTest {
void log01(int i) {
}
void log02(int i) {
}
void test(int i) {
if (i % 3 == 0) {
log01(i);
log02(i);
} else {
log01(i);
log02(i);
}
}
public static void main(String[] args) {
FinalClassTest tFC = new FinalClassTest();
for (int i = 1; i < ITERATIONS_TO_HEAT_LOOP; ++i) {
tFC.test(i);
}
}
}
public static class FinalMethodTest {
final void log01(int i) {
}
final void log02(int i) {
}
void test(int i) {
if (i % 3 == 0) {
log01(i);
log02(i);
} else {
log01(i);
log02(i);
}
}
public static void main(String[] args) {
FinalMethodTest tFM = new FinalMethodTest();
for (int i = 1; i < ITERATIONS_TO_HEAT_LOOP; ++i) {
tFM.test(i);
}
}
}
}
|