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 171 172 173 174 175 176 177 178
|
/*
* Copyright (c) 2016, 2023, Oracle and/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
* @library /test/lib /
*
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver/timeout=180 compiler.jsr292.ContinuousCallSiteTargetChange
*/
package compiler.jsr292;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import sun.hotspot.WhiteBox;
import java.lang.invoke.CallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MutableCallSite;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ContinuousCallSiteTargetChange {
static final int ITERATIONS = Integer.parseInt(System.getProperty("iterations", "50"));
static void runTest(Class<?> test, String... extraArgs) throws Exception {
List<String> argsList = new ArrayList<>(
List.of("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining"));
argsList.addAll(Arrays.asList(extraArgs));
argsList.add(test.getName());
argsList.add(Integer.toString(ITERATIONS));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(argsList);
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldHaveExitValue(0);
analyzer.shouldNotContain("made not compilable");
analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
}
static void testServer(Class<?> test, String... args) throws Exception {
List<String> extraArgsList = new ArrayList<>(
List.of("-server", "-XX:-TieredCompilation", "-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"));
extraArgsList.addAll(Arrays.asList(args));
runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
}
static void testClient(Class<?> test, String... args) throws Exception {
List<String> extraArgsList = new ArrayList<>(
List.of("-client", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1",
"-Xbootclasspath/a:.", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"));
extraArgsList.addAll(Arrays.asList(args));
runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
}
public static void main(String[] args) throws Exception {
testServer(RecompilationTest.class, "-Xbatch");
testClient(RecompilationTest.class, "-Xbatch");
testServer(PingPongTest.class);
testClient(PingPongTest.class);
}
static MethodHandle findStatic(Class<?> cls, String name, MethodType mt) {
try {
return MethodHandles.lookup().findStatic(cls, name, mt);
} catch (Exception e) {
throw new Error(e);
}
}
static class RecompilationTest {
static final MethodType mt = MethodType.methodType(void.class);
static final CallSite cs = new MutableCallSite(mt);
static final MethodHandle mh = cs.dynamicInvoker();
static void f() {
}
static void test1() throws Throwable {
mh.invokeExact();
}
static void test2() throws Throwable {
cs.getTarget().invokeExact();
}
static void iteration() throws Throwable {
MethodHandle mh1 = findStatic(RecompilationTest.class, "f", mt);
cs.setTarget(mh1);
for (int i = 0; i < 20_000; i++) {
test1();
test2();
}
}
public static void main(String[] args) throws Throwable {
int iterations = Integer.parseInt(args[0]);
for (int i = 0; i < iterations; i++) {
iteration();
}
}
}
static class PingPongTest {
static final MethodType mt = MethodType.methodType(void.class);
static final CallSite cs = new MutableCallSite(mt);
static final MethodHandle mh = cs.dynamicInvoker();
static final MethodHandle ping = findStatic(PingPongTest.class, "ping", mt);
static final MethodHandle pong = findStatic(PingPongTest.class, "pong", mt);
static void ping() {
Asserts.assertEQ(cs.getTarget(), ping, "wrong call site target");
cs.setTarget(pong);
}
static void pong() {
Asserts.assertEQ(cs.getTarget(), pong, "wrong call site target");
cs.setTarget(ping);
}
static void iteration() throws Throwable {
cs.setTarget(ping);
for (int i = 0; i < 20_000; i++) {
mh.invokeExact();
}
}
public static void main(String[] args) throws Throwable {
int iterations = Integer.parseInt(args[0]);
WhiteBox whiteBox = WhiteBox.getWhiteBox();
for (int i = 0; i < iterations; i++) {
iteration();
whiteBox.forceNMethodSweep();
}
}
}
}
|