DoNotInlineOrCompileTest.java revision 12772:fbb9c8026495
1170753Skevlo/*
2170753Skevlo * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3170753Skevlo * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4170753Skevlo *
5170753Skevlo * This code is free software; you can redistribute it and/or modify it
6170753Skevlo * under the terms of the GNU General Public License version 2 only, as
7170753Skevlo * published by the Free Software Foundation.
8170753Skevlo *
9170753Skevlo * This code is distributed in the hope that it will be useful, but WITHOUT
10170753Skevlo * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11170753Skevlo * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12170753Skevlo * version 2 for more details (a copy is included in the LICENSE file that
13170753Skevlo * accompanied this code).
14170753Skevlo *
15170753Skevlo * You should have received a copy of the GNU General Public License version
16170753Skevlo * 2 along with this work; if not, write to the Free Software Foundation,
17170753Skevlo * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18170753Skevlo *
19170753Skevlo * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20170753Skevlo * or visit www.oracle.com if you need additional information or have any
21170753Skevlo * questions.
22170753Skevlo */
23170753Skevlo
24170753Skevlo/**
25170753Skevlo * @test
26170753Skevlo * @bug 8136421
27170753Skevlo * @requires vm.jvmci
28178354Ssam * @library /test/lib /
29170753Skevlo * @library ../common/patches
30170753Skevlo * @modules java.base/jdk.internal.misc
31170753Skevlo * @modules java.base/jdk.internal.org.objectweb.asm
32170753Skevlo *          java.base/jdk.internal.org.objectweb.asm.tree
33170753Skevlo *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
34170753Skevlo *          jdk.internal.vm.ci/jdk.vm.ci.code
35170753Skevlo *
36170753Skevlo * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
37170753Skevlo * @run driver ClassFileInstaller sun.hotspot.WhiteBox
38170753Skevlo *                                sun.hotspot.WhiteBox$WhiteBoxPermission
39172131Sbrueffer * @run main/othervm -Xbootclasspath/a:.
40178354Ssam *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
41170753Skevlo *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
42178354Ssam *                   -Djvmci.Compiler=null
43178354Ssam *                   compiler.jvmci.compilerToVM.DoNotInlineOrCompileTest
44178354Ssam */
45170753Skevlo
46170753Skevlopackage compiler.jvmci.compilerToVM;
47172131Sbrueffer
48178354Ssamimport compiler.jvmci.common.CTVMUtilities;
49172131Sbruefferimport jdk.test.lib.Asserts;
50170753Skevloimport jdk.vm.ci.hotspot.CompilerToVMHelper;
51233648Seadlerimport jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
52170753Skevloimport sun.hotspot.WhiteBox;
53170753Skevlo
54170753Skevloimport java.lang.reflect.Executable;
55170753Skevloimport java.util.ArrayList;
56170753Skevloimport java.util.Arrays;
57170753Skevloimport java.util.List;
58170753Skevlo
59170753Skevlopublic class DoNotInlineOrCompileTest {
60
61    private static final WhiteBox WB = WhiteBox.getWhiteBox();
62
63    public static void main(String[] args) {
64        List<Executable> testCases = createTestCases();
65        testCases.forEach(DoNotInlineOrCompileTest::runSanityTest);
66    }
67
68    private static void runSanityTest(Executable aMethod) {
69        HotSpotResolvedJavaMethod method = CTVMUtilities
70                .getResolvedMethod(aMethod);
71        boolean hasNeverInlineDirective = CompilerToVMHelper.hasNeverInlineDirective(method);
72        Asserts.assertFalse(hasNeverInlineDirective, "Unexpected initial " +
73                "value of property 'hasNeverInlineDirective'");
74        CompilerToVMHelper.doNotInlineOrCompile(method);
75        hasNeverInlineDirective = CompilerToVMHelper.hasNeverInlineDirective(method);
76        Asserts.assertTrue(hasNeverInlineDirective, aMethod
77                + " : hasNeverInlineDirective is false even after doNotInlineOrCompile'");
78    }
79
80    private static List<Executable> createTestCases() {
81        List<Executable> testCases = new ArrayList<>();
82
83        Class<?> aClass = DummyClass.class;
84        testCases.addAll(Arrays.asList(aClass.getDeclaredMethods()));
85        testCases.addAll(Arrays.asList(aClass.getDeclaredConstructors()));
86        return testCases;
87    }
88}
89