8138799: improve tests for CompilerToVM::MaterializeVirtualObjectTest

Reviewed-by: kvn
This commit is contained in:
Dmitrij Pochepko 2017-02-15 17:40:44 +03:00
parent 54491302fe
commit 5c88e780c2

View File

@ -39,22 +39,48 @@
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xmixed -Xbootclasspath/a:.
* @run main/othervm -Xmixed -Xbatch -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,*::check
* -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
* -XX:CompileCommand=dontinline,compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest,testFrame
* -XX:CompileCommand=inline,compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest,recurse
* -Xbatch
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=true
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
* @run main/othervm -Xmixed -Xbootclasspath/a:.
* @run main/othervm -Xmixed -Xbatch -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,*::check
* -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
* -Xbatch
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=false
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
* @run main/othervm -Xmixed -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 -Xmixed -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
*/
@ -74,25 +100,41 @@ import java.lang.reflect.Method;
public class MaterializeVirtualObjectTest {
private static final WhiteBox WB;
private static final Method METHOD;
private static final ResolvedJavaMethod RESOLVED_METHOD;
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 {
METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod(
"testFrame", String.class, int.class);
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);
}
RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD);
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) {
@ -107,58 +149,87 @@ public class MaterializeVirtualObjectTest {
}
private static String getName() {
return "CASE: invalidate=" + INVALIDATE;
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(METHOD), getName()
+ " : method unexpectedly compiled");
/* need to trigger compilation by multiple method invocations
in order to have method profile data to be gathered */
for (int i = 0; i < COMPILE_THRESHOLD; i++) {
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(METHOD), getName()
+ "Method unexpectedly not compiled");
Asserts.assertTrue(WB.getMethodCompilationLevel(METHOD) == 4, getName()
+ "Method not compiled at level 4");
testFrame("someString", COMPILE_THRESHOLD);
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));
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) {
HotSpotStackFrameReference hsFrame = CompilerToVMHelper
.getNextStackFrame(/* topmost frame */ null,
new ResolvedJavaMethod[]{
RESOLVED_METHOD}, /* don't skip any */ 0);
Asserts.assertNotNull(hsFrame, getName() + " : got null frame");
Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
+ "Test method should be compiled");
Asserts.assertTrue(hsFrame.hasVirtualObjects(), getName()
+ ": has no virtual object before materialization");
CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE);
Asserts.assertFalse(hsFrame.hasVirtualObjects(), getName()
+ " : has virtual object after materialization");
Asserts.assertEQ(WB.isMethodCompiled(METHOD), !INVALIDATE, getName()
+ " : unexpected compiled status");
// get frames and check not-null
HotSpotStackFrameReference materialized = CompilerToVMHelper.getNextStackFrame(
/* topmost frame */ null, new ResolvedJavaMethod[]{MATERIALIZED_RESOLVED},
/* don't skip any */ 0);
Asserts.assertNotNull(materialized, getName()
+ " : got null frame for materialized method");
HotSpotStackFrameReference notMaterialized = CompilerToVMHelper.getNextStackFrame(
/* topmost frame */ null, new ResolvedJavaMethod[]{NOT_MATERIALIZED_RESOLVED},
/* don't skip any */ 0);
Asserts.assertNE(materialized, notMaterialized,
"Got same frame pointer for both tested frames");
Asserts.assertNotNull(notMaterialized, getName()
+ " : got null frame for not materialized method");
// 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");
}
}