1 /*
2  * Copyright (c) 2015, 2020, 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 & vm.compMode == "Xmixed"
28  * @library /test/lib /
29  * @library ../common/patches
30  * @modules jdk.internal.vm.compiler
31  * @modules java.base/jdk.internal.misc
32  * @modules java.base/jdk.internal.org.objectweb.asm
33  *          java.base/jdk.internal.org.objectweb.asm.tree
34  *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
35  *          jdk.internal.vm.ci/jdk.vm.ci.code
36  *          jdk.internal.vm.ci/jdk.vm.ci.meta
37  *          jdk.internal.vm.ci/jdk.vm.ci.runtime
38  *
39  * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
40  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
41  * @run main/othervm -Xbootclasspath/a:.
42  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
43  *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler
44  *                   compiler.jvmci.compilerToVM.IsCompilableTest
45  */
46 
47 /**
48  * @test
49  * @requires vm.jvmci & vm.compMode == "Xmixed"
50  * @library /test/lib /
51  * @library ../common/patches
52  * @modules java.base/jdk.internal.misc
53  * @modules java.base/jdk.internal.org.objectweb.asm
54  *          java.base/jdk.internal.org.objectweb.asm.tree
55  *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
56  *          jdk.internal.vm.ci/jdk.vm.ci.code
57  *          jdk.internal.vm.ci/jdk.vm.ci.meta
58  *          jdk.internal.vm.ci/jdk.vm.ci.runtime
59  *
60  * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
61  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
62  * @run main/othervm -Xbootclasspath/a:.
63  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
64  *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler
65  *                   compiler.jvmci.compilerToVM.IsCompilableTest
66  */
67 
68 package compiler.jvmci.compilerToVM;
69 
70 import compiler.jvmci.common.CTVMUtilities;
71 import jdk.test.lib.Asserts;
72 import jdk.vm.ci.hotspot.CompilerToVMHelper;
73 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
74 import sun.hotspot.WhiteBox;
75 
76 import java.lang.reflect.Executable;
77 import java.util.ArrayList;
78 import java.util.Arrays;
79 import java.util.List;
80 
81 public class IsCompilableTest {
82 
83     private static final WhiteBox WB = WhiteBox.getWhiteBox();
84 
main(String[] args)85     public static void main(String[] args) {
86         List<Executable> testCases = createTestCases();
87         testCases.forEach(IsCompilableTest::runSanityTest);
88     }
89 
runSanityTest(Executable aMethod)90     private static void runSanityTest(Executable aMethod) {
91         HotSpotResolvedJavaMethod method = CTVMUtilities
92                 .getResolvedMethod(aMethod);
93         boolean isCompilable = CompilerToVMHelper.isCompilable(method);
94         boolean expected = WB.isMethodCompilable(aMethod);
95         Asserts.assertEQ(isCompilable, expected, "Unexpected initial " +
96                 "value of property 'compilable'");
97 
98         WB.makeMethodNotCompilable(aMethod);
99         isCompilable = CompilerToVMHelper.isCompilable(method);
100         Asserts.assertFalse(isCompilable, aMethod + "Unexpected value of " +
101             "property 'isCompilable' after setting 'compilable' to false");
102     }
103 
createTestCases()104     private static List<Executable> createTestCases() {
105         List<Executable> testCases = new ArrayList<>();
106 
107         Class<?> aClass = DummyClass.class;
108         testCases.addAll(Arrays.asList(aClass.getDeclaredMethods()));
109         testCases.addAll(Arrays.asList(aClass.getDeclaredConstructors()));
110         return testCases;
111     }
112 }
113