Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/IsMatureVsReprofileTest.java
41153 views
/*1* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813642126* @requires vm.jvmci & (vm.opt.TieredStopAtLevel == null | vm.opt.TieredStopAtLevel == 4)27* @library / /test/lib28* ../common/patches29* @modules java.base/jdk.internal.misc30* java.base/jdk.internal.org.objectweb.asm31* java.base/jdk.internal.org.objectweb.asm.tree32* jdk.internal.vm.ci/jdk.vm.ci.hotspot33* jdk.internal.vm.ci/jdk.vm.ci.code34* jdk.internal.vm.ci/jdk.vm.ci.meta35* jdk.internal.vm.ci/jdk.vm.ci.runtime36*37* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper38* sun.hotspot.WhiteBox39* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox40* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions41* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -Xbatch -XX:CompileThresholdScaling=1.042* compiler.jvmci.compilerToVM.IsMatureVsReprofileTest43*/4445package compiler.jvmci.compilerToVM;4647import compiler.jvmci.common.CTVMUtilities;48import compiler.jvmci.common.testcases.SimpleClass;49import jdk.vm.ci.hotspot.CompilerToVMHelper;50import jdk.test.lib.Asserts;51import sun.hotspot.WhiteBox;52import compiler.whitebox.CompilerWhiteBoxTest;53import java.lang.reflect.Executable;54import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;55import jdk.test.lib.Platform;5657public class IsMatureVsReprofileTest {58private static final WhiteBox WB = WhiteBox.getWhiteBox();59private static final boolean TIERED = WB.getBooleanVMFlag("TieredCompilation");60private static final boolean IS_XCOMP = Platform.isComp();6162public static void main(String[] args) throws Exception {63new IsMatureVsReprofileTest().test();64}6566public void test() throws Exception {67SimpleClass sclass = new SimpleClass();68Executable method = SimpleClass.class.getDeclaredMethod("testMethod");69long metaspaceMethodData = WB.getMethodData(method);70Asserts.assertEQ(metaspaceMethodData, 0L, "MDO should be null for a "71+ "never invoked method");72boolean isMature = CompilerToVMHelper.isMature(metaspaceMethodData);73Asserts.assertFalse(isMature, "null MDO can't be mature");74for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {75sclass.testMethod();76}77Asserts.assertTrue(WB.isMethodCompiled(method),78"Method should be compiled");79metaspaceMethodData = WB.getMethodData(method);80Asserts.assertNE(metaspaceMethodData, 0L,81"Multiple times invoked method should have MDO");82isMature = CompilerToVMHelper.isMature(metaspaceMethodData);83/* a method is not mature for -Xcomp and -Tiered,84see NonTieredCompPolicy::is_mature */85Asserts.assertEQ(!IS_XCOMP || TIERED, isMature,86"Unexpected isMature state for compiled method");87HotSpotResolvedJavaMethod resolvedMethod88= CTVMUtilities.getResolvedMethod(method);89CompilerToVMHelper.reprofile(resolvedMethod);90Asserts.assertFalse(WB.isMethodCompiled(method),91"Unexpected method compilation state after reprofile");92metaspaceMethodData = WB.getMethodData(method);93isMature = CompilerToVMHelper.isMature(metaspaceMethodData);94Asserts.assertNE(metaspaceMethodData, 0L,95"Got null MDO after reprofile");96Asserts.assertEQ(TIERED && IS_XCOMP, isMature,97"Got unexpected isMature state after reprofiling");98}99}100101102