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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*
* Copyright (c) 2015, 2019, 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
* @bug 8136421
*
* @requires vm.jvmci & vm.compMode == "Xmixed"
* @requires vm.opt.final.EliminateAllocations == true
*
* @comment no "-Xcomp -XX:-TieredCompilation" combination allowed until JDK-8140018 is resolved
* @requires vm.opt.TieredCompilation == null | vm.opt.TieredCompilation == true
*
* @library / /test/lib
* @library ../common/patches
* @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.org.objectweb.asm
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.code.stack
* jdk.internal.vm.ci/jdk.vm.ci.meta
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbatch -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=true
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
* @run main/othervm -Xbatch -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=false
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
* @run main/othervm -Xbatch -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=true
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
* @run main/othervm -Xbatch -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=false
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
*/
package compiler.jvmci.compilerToVM;
import compiler.jvmci.common.CTVMUtilities;
import compiler.testlibrary.CompilerUtils;
import compiler.whitebox.CompilerWhiteBoxTest;
import jdk.test.lib.Asserts;
import jdk.vm.ci.code.stack.InspectedFrame;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotStackFrameReference;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jtreg.SkippedException;
import sun.hotspot.WhiteBox;
import java.lang.reflect.Method;
public class MaterializeVirtualObjectTest {
private static final WhiteBox WB;
private static final boolean INVALIDATE;
private static final int COMPILE_THRESHOLD;
private static final Method MATERIALIZED_METHOD;
private static final Method NOT_MATERIALIZED_METHOD;
private static final ResolvedJavaMethod MATERIALIZED_RESOLVED;
private static final ResolvedJavaMethod NOT_MATERIALIZED_RESOLVED;
private static final boolean MATERIALIZE_FIRST;
static {
Method method1;
Method method2;
WB = WhiteBox.getWhiteBox();
try {
method1 = MaterializeVirtualObjectTest.class.getDeclaredMethod("testFrame",
String.class, int.class);
method2 = MaterializeVirtualObjectTest.class.getDeclaredMethod("testFrame2",
String.class, int.class);
} catch (NoSuchMethodException e) {
throw new Error("Can't get executable for test method", e);
}
ResolvedJavaMethod resolved1;
ResolvedJavaMethod resolved2;
resolved1 = CTVMUtilities.getResolvedMethod(method1);
resolved2 = CTVMUtilities.getResolvedMethod(method2);
INVALIDATE = Boolean.getBoolean(
"compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate");
COMPILE_THRESHOLD = WB.getBooleanVMFlag("TieredCompilation")
? CompilerWhiteBoxTest.THRESHOLD
: CompilerWhiteBoxTest.THRESHOLD * 2;
MATERIALIZE_FIRST = Boolean.getBoolean(
"compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst");
MATERIALIZED_RESOLVED = MATERIALIZE_FIRST ? resolved1 : resolved2;
NOT_MATERIALIZED_RESOLVED = MATERIALIZE_FIRST ? resolved2 : resolved1;
MATERIALIZED_METHOD = MATERIALIZE_FIRST ? method1 : method2;
NOT_MATERIALIZED_METHOD = MATERIALIZE_FIRST ? method2 : method1;
}
public static void main(String[] args) {
int levels[] = CompilerUtils.getAvailableCompilationLevels();
// we need compilation level 4 to use EscapeAnalysis
if (levels.length < 1 || levels[levels.length - 1] != 4) {
throw new SkippedException("Test needs compilation level 4");
}
new MaterializeVirtualObjectTest().test();
}
private static String getName() {
return "CASE: invalidate=" + INVALIDATE + ", materializedMethod="
+ (MATERIALIZE_FIRST ? "testFrame" : "testFrame2")
+ ", notMaterializedMethod="
+ (MATERIALIZE_FIRST ? "testFrame2" : "testFrame");
}
private void test() {
System.out.println(getName());
Asserts.assertFalse(WB.isMethodCompiled(MATERIALIZED_METHOD),
getName() + " : materialized method is compiled");
Asserts.assertFalse(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
getName() + " : not materialized method is compiled");
for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {
testFrame("someString", i);
}
Asserts.assertTrue(WB.isMethodCompiled(MATERIALIZED_METHOD), getName()
+ " : materialized method not compiled");
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
getName() + " : not materialized method not compiled");
testFrame("someString", /* materialize */ CompilerWhiteBoxTest.THRESHOLD);
}
private void testFrame(String str, int iteration) {
Helper helper = new Helper(str);
testFrame2(str, iteration);
Asserts.assertTrue((helper.string != null) && (this != null)
&& (helper != null), String.format("%s : some locals are null", getName()));
}
private void testFrame2(String str, int iteration) {
Helper helper = new Helper(str);
recurse(2, iteration);
Asserts.assertTrue((helper.string != null) && (this != null)
&& (helper != null), String.format("%s : some locals are null", getName()));
}
private void recurse(int depth, int iteration) {
if (depth == 0) {
check(iteration);
} else {
Integer s = new Integer(depth);
recurse(depth - 1, iteration);
Asserts.assertEQ(s.intValue(), depth,
String.format("different values: %s != %s", s.intValue(), depth));
}
}
private void check(int iteration) {
// Materialize virtual objects on last invocation
if (iteration == COMPILE_THRESHOLD) {
// get frames and check not-null
HotSpotStackFrameReference materialized = CompilerToVMHelper.iterateFrames(
new ResolvedJavaMethod[] {MATERIALIZED_RESOLVED},
null /* any */,
0,
f -> (HotSpotStackFrameReference) f);
Asserts.assertNotNull(materialized, getName()
+ " : got null frame for materialized method");
Asserts.assertTrue(materialized.isMethod(MATERIALIZED_RESOLVED),
"Expected materialized method but got " + materialized);
InspectedFrame notMaterialized = CompilerToVMHelper.iterateFrames(
new ResolvedJavaMethod[] {NOT_MATERIALIZED_RESOLVED},
null /* any */,
0,
f -> f);
Asserts.assertNE(materialized, notMaterialized,
"Got same frame pointer for both tested frames");
Asserts.assertTrue(notMaterialized.isMethod(NOT_MATERIALIZED_RESOLVED),
"Expected notMaterialized method but got " + notMaterialized);
Asserts.assertNotNull(notMaterialized, getName()
+ " : got null frame for not materialized method");
Asserts.assertTrue(WB.isMethodCompiled(MATERIALIZED_METHOD), getName()
+ " : materialized method not compiled");
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
getName() + " : not materialized method not compiled");
// check that frames has virtual objects before materialization stage
Asserts.assertTrue(materialized.hasVirtualObjects(), getName()
+ ": materialized frame has no virtual object before materialization");
Asserts.assertTrue(notMaterialized.hasVirtualObjects(), getName()
+ ": notMaterialized frame has no virtual object before materialization");
// materialize
CompilerToVMHelper.materializeVirtualObjects(materialized, INVALIDATE);
// check that only not materialized frame has virtual objects
Asserts.assertFalse(materialized.hasVirtualObjects(), getName()
+ " : materialized has virtual object after materialization");
Asserts.assertTrue(notMaterialized.hasVirtualObjects(), getName()
+ " : notMaterialized has no virtual object after materialization");
// check that materialized frame was deoptimized in case invalidate=true
Asserts.assertEQ(WB.isMethodCompiled(MATERIALIZED_METHOD), !INVALIDATE, getName()
+ " : materialized method has unexpected compiled status");
// check that not materialized frame wasn't deoptimized
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD), getName()
+ " : not materialized method has unexpected compiled status");
}
}
private class Helper {
public String string;
public Helper(String s) {
this.string = s;
}
}
}
|