MaterializeVirtualObjectTest.java revision 12592:ab3d4589f4d8
1/* 2 * Copyright (c) 2015, 2016, 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 * @bug 8136421 27 * @requires vm.jvmci 28 * & (vm.compMode != "Xcomp" | vm.opt.TieredCompilation == null | vm.opt.TieredCompilation == true) 29 * @summary no "-Xcomp -XX:-TieredCompilation" combination allowed until JDK-8140018 is resolved 30 * @library / /test/lib 31 * @library ../common/patches 32 * @modules java.base/jdk.internal.misc 33 * @modules java.base/jdk.internal.org.objectweb.asm 34 * java.base/jdk.internal.org.objectweb.asm.tree 35 * jdk.vm.ci/jdk.vm.ci.hotspot 36 * jdk.vm.ci/jdk.vm.ci.code 37 * jdk.vm.ci/jdk.vm.ci.meta 38 * 39 * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox 40 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 41 * sun.hotspot.WhiteBox$WhiteBoxPermission 42 * @run main/othervm -Xmixed -Xbootclasspath/a:. 43 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 44 * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 45 * -XX:CompileCommand=exclude,*::check 46 * -XX:+DoEscapeAnalysis -XX:-UseCounterDecay 47 * -XX:CompileCommand=dontinline,compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest,testFrame 48 * -XX:CompileCommand=inline,compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest,recurse 49 * -Xbatch 50 * -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false 51 * compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest 52 * @run main/othervm -Xmixed -Xbootclasspath/a:. 53 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 54 * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 55 * -XX:CompileCommand=exclude,*::check 56 * -XX:+DoEscapeAnalysis -XX:-UseCounterDecay 57 * -Xbatch 58 * -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true 59 * compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest 60 */ 61 62package compiler.jvmci.compilerToVM; 63 64import compiler.jvmci.common.CTVMUtilities; 65import compiler.testlibrary.CompilerUtils; 66import compiler.whitebox.CompilerWhiteBoxTest; 67import jdk.test.lib.Asserts; 68import jdk.vm.ci.hotspot.CompilerToVMHelper; 69import jdk.vm.ci.hotspot.HotSpotStackFrameReference; 70import jdk.vm.ci.meta.ResolvedJavaMethod; 71import sun.hotspot.WhiteBox; 72 73import java.lang.reflect.Method; 74 75public class MaterializeVirtualObjectTest { 76 private static final WhiteBox WB; 77 private static final Method METHOD; 78 private static final ResolvedJavaMethod RESOLVED_METHOD; 79 private static final boolean INVALIDATE; 80 private static final int COMPILE_THRESHOLD; 81 82 static { 83 WB = WhiteBox.getWhiteBox(); 84 try { 85 METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod( 86 "testFrame", String.class, int.class); 87 } catch (NoSuchMethodException e) { 88 throw new Error("Can't get executable for test method", e); 89 } 90 RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD); 91 INVALIDATE = Boolean.getBoolean( 92 "compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate"); 93 COMPILE_THRESHOLD = WB.getBooleanVMFlag("TieredCompilation") 94 ? CompilerWhiteBoxTest.THRESHOLD 95 : CompilerWhiteBoxTest.THRESHOLD * 2; 96 } 97 98 public static void main(String[] args) { 99 int levels[] = CompilerUtils.getAvailableCompilationLevels(); 100 // we need compilation level 4 to use EscapeAnalysis 101 if (levels.length < 1 || levels[levels.length - 1] != 4) { 102 System.out.println("INFO: Test needs compilation level 4 to" 103 + " be available. Skipping."); 104 } else { 105 new MaterializeVirtualObjectTest().test(); 106 } 107 } 108 109 private static String getName() { 110 return "CASE: invalidate=" + INVALIDATE; 111 } 112 113 private void test() { 114 System.out.println(getName()); 115 Asserts.assertFalse(WB.isMethodCompiled(METHOD), getName() 116 + " : method unexpectedly compiled"); 117 /* need to trigger compilation by multiple method invocations 118 in order to have method profile data to be gathered */ 119 for (int i = 0; i < COMPILE_THRESHOLD; i++) { 120 testFrame("someString", i); 121 } 122 Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName() 123 + "Method unexpectedly not compiled"); 124 Asserts.assertTrue(WB.getMethodCompilationLevel(METHOD) == 4, getName() 125 + "Method not compiled at level 4"); 126 testFrame("someString", COMPILE_THRESHOLD); 127 } 128 129 private void testFrame(String str, int iteration) { 130 Helper helper = new Helper(str); 131 recurse(2, iteration); 132 Asserts.assertTrue((helper.string != null) && (this != null) 133 && (helper != null), String.format("%s : some locals are null", getName())); 134 } 135 private void recurse(int depth, int iteration) { 136 if (depth == 0) { 137 check(iteration); 138 } else { 139 Integer s = new Integer(depth); 140 recurse(depth - 1, iteration); 141 Asserts.assertEQ(s.intValue(), depth, String.format("different values: %s != %s", s.intValue(), depth)); 142 } 143 } 144 145 private void check(int iteration) { 146 // Materialize virtual objects on last invocation 147 if (iteration == COMPILE_THRESHOLD) { 148 HotSpotStackFrameReference hsFrame = CompilerToVMHelper 149 .getNextStackFrame(/* topmost frame */ null, 150 new ResolvedJavaMethod[]{ 151 RESOLVED_METHOD}, /* don't skip any */ 0); 152 Asserts.assertNotNull(hsFrame, getName() + " : got null frame"); 153 Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName() 154 + "Test method should be compiled"); 155 Asserts.assertTrue(hsFrame.hasVirtualObjects(), getName() 156 + ": has no virtual object before materialization"); 157 CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE); 158 Asserts.assertFalse(hsFrame.hasVirtualObjects(), getName() 159 + " : has virtual object after materialization"); 160 Asserts.assertEQ(WB.isMethodCompiled(METHOD), !INVALIDATE, getName() 161 + " : unexpected compiled status"); 162 } 163 } 164 165 private class Helper { 166 public String string; 167 168 public Helper(String s) { 169 this.string = s; 170 } 171 } 172} 173