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 * -Djvmci.Compiler=null 42 * compiler.jvmci.compilerToVM.IsMatureVsReprofileTest 43 */ 44 45 package compiler.jvmci.compilerToVM; 46 47 import compiler.jvmci.common.CTVMUtilities; 48 import compiler.jvmci.common.testcases.SimpleClass; 49 import jdk.vm.ci.hotspot.CompilerToVMHelper; 50 import jdk.test.lib.Asserts; 51 import sun.hotspot.WhiteBox; 52 import compiler.whitebox.CompilerWhiteBoxTest; 53 import java.lang.reflect.Executable; 54 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 55 import jdk.test.lib.Platform; 56 57 public class IsMatureVsReprofileTest { 58 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 59 private static final boolean TIERED = WB.getBooleanVMFlag("TieredCompilation"); 60 private static final boolean IS_XCOMP = Platform.isComp(); 61 62 public static void main(String[] args) throws Exception { 63 new IsMatureVsReprofileTest().test(); 64 } 65 66 public void test() throws Exception { 67 SimpleClass sclass = new SimpleClass(); 68 Executable method = SimpleClass.class.getDeclaredMethod("testMethod"); 69 long metaspaceMethodData = WB.getMethodData(method); 70 Asserts.assertEQ(metaspaceMethodData, 0L, "MDO should be null for a " 71 + "never invoked method"); 72 boolean isMature = CompilerToVMHelper.isMature(metaspaceMethodData); 73 Asserts.assertFalse(isMature, "null MDO can't be mature"); 74 for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) { 75 sclass.testMethod(); 76 } 77 Asserts.assertTrue(WB.isMethodCompiled(method), 78 "Method should be compiled"); 79 metaspaceMethodData = WB.getMethodData(method); 80 Asserts.assertNE(metaspaceMethodData, 0L, 81 "Multiple times invoked method should have MDO"); 82 isMature = CompilerToVMHelper.isMature(metaspaceMethodData); 83 /* a method is not mature for -Xcomp and -Tiered, 84 see NonTieredCompPolicy::is_mature */ 85 Asserts.assertEQ(!IS_XCOMP || TIERED, isMature, 86 "Unexpected isMature state for compiled method"); 87 HotSpotResolvedJavaMethod resolvedMethod 88 = CTVMUtilities.getResolvedMethod(method); 89 CompilerToVMHelper.reprofile(resolvedMethod); 90 Asserts.assertFalse(WB.isMethodCompiled(method), 91 "Unexpected method compilation state after reprofile"); 92 metaspaceMethodData = WB.getMethodData(method); 93 isMature = CompilerToVMHelper.isMature(metaspaceMethodData); 94 Asserts.assertNE(metaspaceMethodData, 0L, 95 "Got null MDO after reprofile"); 96 Asserts.assertEQ(TIERED && IS_XCOMP, isMature, 97 "Got unexpected isMature state after reprofiling"); 98 } 99 }