1 /* 2 * Copyright (c) 2017, 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 * @library / /test/lib 29 * ../common/patches 30 * @modules java.base/jdk.internal.misc 31 * java.base/jdk.internal.org.objectweb.asm 32 * java.base/jdk.internal.org.objectweb.asm.tree 33 * jdk.internal.vm.ci/jdk.vm.ci.hotspot 34 * jdk.internal.vm.ci/jdk.vm.ci.code 35 * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper 36 * sun.hotspot.WhiteBox 37 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 38 * sun.hotspot.WhiteBox$WhiteBoxPermission 39 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 40 * -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -Xbatch 41 * compiler.jvmci.compilerToVM.IsMatureVsReprofileTest 42 */ 43 44 package compiler.jvmci.compilerToVM; 45 46 import compiler.jvmci.common.CTVMUtilities; 47 import compiler.jvmci.common.testcases.SimpleClass; 48 import jdk.vm.ci.hotspot.CompilerToVMHelper; 49 import jdk.test.lib.Asserts; 50 import sun.hotspot.WhiteBox; 51 import compiler.whitebox.CompilerWhiteBoxTest; 52 import java.lang.reflect.Executable; 53 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 54 import jdk.test.lib.Platform; 55 56 public class IsMatureVsReprofileTest { 57 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 58 private static final boolean TIERED = WB.getBooleanVMFlag("TieredCompilation"); 59 private static final boolean IS_XCOMP = Platform.isComp(); 60 61 public static void main(String[] args) throws Exception { 62 new IsMatureVsReprofileTest().test(); 63 } 64 65 public void test() throws Exception { 66 SimpleClass sclass = new SimpleClass(); 67 Executable method = SimpleClass.class.getDeclaredMethod("testMethod"); 68 long metaspaceMethodData = WB.getMethodData(method); 69 Asserts.assertEQ(metaspaceMethodData, 0L, "MDO should be null for a " 70 + "never invoked method"); 71 boolean isMature = CompilerToVMHelper.isMature(metaspaceMethodData); 72 Asserts.assertFalse(isMature, "null MDO can't be mature"); 73 for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) { 74 sclass.testMethod(); 75 } 76 Asserts.assertTrue(WB.isMethodCompiled(method), 77 "Method should be compiled"); 78 metaspaceMethodData = WB.getMethodData(method); 79 Asserts.assertNE(metaspaceMethodData, 0L, 80 "Multiple times invoked method should have MDO"); 81 isMature = CompilerToVMHelper.isMature(metaspaceMethodData); 82 /* a method is not mature for -Xcomp and -Tiered, 83 see NonTieredCompPolicy::is_mature */ 84 Asserts.assertEQ(!IS_XCOMP || TIERED, isMature, 85 "Unexpected isMature state for compiled method"); 86 HotSpotResolvedJavaMethod resolvedMethod 87 = CTVMUtilities.getResolvedMethod(method); 88 CompilerToVMHelper.reprofile(resolvedMethod); 89 Asserts.assertFalse(WB.isMethodCompiled(method), 90 "Unexpected method compilation state after reprofile"); 91 metaspaceMethodData = WB.getMethodData(method); 92 isMature = CompilerToVMHelper.isMature(metaspaceMethodData); 93 Asserts.assertNE(metaspaceMethodData, 0L, 94 "Got null MDO after reprofile"); 95 Asserts.assertEQ(TIERED && IS_XCOMP, isMature, 96 "Got unexpected isMature state after reprofiling"); 97 } 98 }