Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/ReprofileTest.java
41153 views
/*1* Copyright (c) 2015, 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/lib /28* @library ../common/patches29* @modules java.base/jdk.internal.misc30* @modules 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*36* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox37* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox38* @run main/othervm -Xbootclasspath/a:.39* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI40* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI41* -Xmixed -Xbatch42* compiler.jvmci.compilerToVM.ReprofileTest43*/4445package compiler.jvmci.compilerToVM;4647import compiler.jvmci.common.CTVMUtilities;48import compiler.whitebox.CompilerWhiteBoxTest;49import jdk.test.lib.Asserts;50import jdk.vm.ci.hotspot.CompilerToVMHelper;51import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;52import jdk.vm.ci.meta.ProfilingInfo;5354import java.lang.reflect.Method;55import java.util.ArrayList;56import java.util.List;5758public class ReprofileTest {5960public static void main(String[] args) {61List<Method> testCases = createTestCases();62testCases.forEach(ReprofileTest::runSanityTest);63}6465private static List<Method> createTestCases() {66List<Method> testCases = new ArrayList<>();67try {6869Class<?> aClass = DummyClass.class;70testCases.add(aClass.getMethod("dummyInstanceFunction"));7172aClass = DummyClass.class;73testCases.add(aClass.getMethod("dummyFunction"));74} catch (NoSuchMethodException e) {75throw new Error("TEST BUG " + e.getMessage(), e);76}77return testCases;78}7980private static void runSanityTest(Method aMethod) {81System.out.println(aMethod);82HotSpotResolvedJavaMethod method = CTVMUtilities83.getResolvedMethod(aMethod);84ProfilingInfo startProfile = method.getProfilingInfo();85Asserts.assertFalse(startProfile.isMature(), aMethod86+ " : profiling info is mature in the beginning");8788// make interpreter to profile this method89try {90Object obj = aMethod.getDeclaringClass().newInstance();91for (long i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {92aMethod.invoke(obj);93}94} catch (ReflectiveOperationException e) {95throw new Error("TEST BUG : " + e.getMessage(), e);96}97ProfilingInfo compProfile = method.getProfilingInfo();9899Asserts.assertNE(startProfile.toString(), compProfile.toString(),100String.format("%s : profiling info wasn't changed after "101+ "%d invocations",102aMethod, CompilerWhiteBoxTest.THRESHOLD));103Asserts.assertTrue(compProfile.isMature(),104String.format("%s is not mature after %d invocations",105aMethod, CompilerWhiteBoxTest.THRESHOLD));106107CompilerToVMHelper.reprofile(method);108ProfilingInfo reprofiledProfile = method.getProfilingInfo();109110Asserts.assertNE(startProfile.toString(), reprofiledProfile.toString(),111aMethod + " : profiling info wasn't changed after reprofiling");112Asserts.assertNE(compProfile.toString(), reprofiledProfile.toString(),113aMethod + " : profiling info didn't change after reprofile");114Asserts.assertFalse(reprofiledProfile.isMature(), aMethod115+ " : profiling info is mature after reprofiling");116}117}118119120