ReprofileTest.java revision 9814:22fd02fad88b
11590Srgrimes/*
21590Srgrimes * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
31590Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41590Srgrimes *
51590Srgrimes * This code is free software; you can redistribute it and/or modify it
61590Srgrimes * under the terms of the GNU General Public License version 2 only, as
71590Srgrimes * published by the Free Software Foundation.
81590Srgrimes *
91590Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101590Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111590Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121590Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131590Srgrimes * accompanied this code).
141590Srgrimes *
151590Srgrimes * You should have received a copy of the GNU General Public License version
161590Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171590Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181590Srgrimes *
191590Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201590Srgrimes * or visit www.oracle.com if you need additional information or have any
211590Srgrimes * questions.
221590Srgrimes *
231590Srgrimes */
241590Srgrimes
251590Srgrimes/**
261590Srgrimes * @test
271590Srgrimes * @bug 8136421
281590Srgrimes * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
291590Srgrimes * @library /testlibrary /test/lib /
301590Srgrimes * @compile ../common/CompilerToVMHelper.java
311590Srgrimes * @build sun.hotspot.WhiteBox
321590Srgrimes * @run main ClassFileInstaller
331590Srgrimes *      sun.hotspot.WhiteBox
341590Srgrimes *      sun.hotspot.WhiteBox$WhiteBoxPermission
351590Srgrimes *      jdk.vm.ci.hotspot.CompilerToVMHelper
361590Srgrimes * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
371590Srgrimes *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
381590Srgrimes *      -Xmixed
391590Srgrimes *      compiler.jvmci.compilerToVM.ReprofileTest
401590Srgrimes */
411590Srgrimes
421590Srgrimespackage compiler.jvmci.compilerToVM;
431590Srgrimes
441590Srgrimesimport compiler.jvmci.common.CTVMUtilities;
451590Srgrimesimport java.lang.reflect.Method;
461590Srgrimesimport java.util.ArrayList;
471590Srgrimesimport java.util.List;
481590Srgrimes
491590Srgrimesimport compiler.whitebox.CompilerWhiteBoxTest;
501590Srgrimesimport jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
511590Srgrimesimport jdk.vm.ci.hotspot.CompilerToVMHelper;
521590Srgrimesimport jdk.vm.ci.meta.ProfilingInfo;
531590Srgrimesimport jdk.test.lib.Asserts;
541590Srgrimes
551590Srgrimespublic class ReprofileTest {
5612804Speter
571590Srgrimes    public static void main(String[] args) {
581590Srgrimes        List<Method> testCases = createTestCases();
591590Srgrimes        testCases.forEach(ReprofileTest::runSanityTest);
601590Srgrimes    }
611590Srgrimes
621590Srgrimes    private static List<Method> createTestCases() {
631590Srgrimes        List<Method> testCases = new ArrayList<>();
641590Srgrimes        try {
651590Srgrimes
661590Srgrimes            Class<?> aClass = DummyClass.class;
671590Srgrimes            testCases.add(aClass.getMethod("dummyInstanceFunction"));
681590Srgrimes
691590Srgrimes            aClass = DummyClass.class;
701590Srgrimes            testCases.add(aClass.getMethod("dummyFunction"));
711590Srgrimes        } catch (NoSuchMethodException e) {
721590Srgrimes            throw new Error("TEST BUG " + e.getMessage(), e);
731590Srgrimes        }
741590Srgrimes        return testCases;
751590Srgrimes    }
761590Srgrimes
771590Srgrimes    private static void runSanityTest(Method aMethod) {
781590Srgrimes        System.out.println(aMethod);
791590Srgrimes        HotSpotResolvedJavaMethod method = CTVMUtilities
801590Srgrimes                .getResolvedMethod(aMethod);
811590Srgrimes        ProfilingInfo startProfile = method.getProfilingInfo();
821590Srgrimes        Asserts.assertFalse(startProfile.isMature(), aMethod
831590Srgrimes                + " : profiling info is mature in the beginning");
841590Srgrimes
851590Srgrimes        // make interpreter to profile this method
861590Srgrimes        try {
871590Srgrimes            Object obj = aMethod.getDeclaringClass().newInstance();
881590Srgrimes            for (long i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {
891590Srgrimes                aMethod.invoke(obj);
901590Srgrimes            }
911590Srgrimes        } catch (ReflectiveOperationException e) {
921590Srgrimes            throw new Error("TEST BUG : " + e.getMessage(), e);
931590Srgrimes        }
941590Srgrimes        ProfilingInfo compProfile = method.getProfilingInfo();
951590Srgrimes
961590Srgrimes        Asserts.assertNE(startProfile.toString(), compProfile.toString(),
971590Srgrimes                String.format("%s : profiling info wasn't changed after "
981590Srgrimes                                + "%d invocations",
991590Srgrimes                        aMethod, CompilerWhiteBoxTest.THRESHOLD));
1001590Srgrimes        Asserts.assertTrue(compProfile.isMature(),
1011590Srgrimes                String.format("%s is not mature after %d invocations",
1021590Srgrimes                        aMethod, CompilerWhiteBoxTest.THRESHOLD));
1031590Srgrimes
1041590Srgrimes        CompilerToVMHelper.reprofile(method);
1051590Srgrimes        ProfilingInfo reprofiledProfile = method.getProfilingInfo();
1061590Srgrimes
1071590Srgrimes        Asserts.assertNE(startProfile.toString(), reprofiledProfile.toString(),
1081590Srgrimes                aMethod + " : profiling info wasn't changed after reprofiling");
1091590Srgrimes        Asserts.assertNE(compProfile.toString(), reprofiledProfile.toString(),
1101620Srgrimes                aMethod + " : profiling info didn't change after reprofile");
1111590Srgrimes        Asserts.assertFalse(reprofiledProfile.isMature(), aMethod
1121590Srgrimes                + " : profiling info is mature after reprofiling");
1131590Srgrimes    }
1141590Srgrimes}
1151590Srgrimes