1 /*
2 * Copyright (c) 2013, 2014, 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 MakeMethodNotCompilableTest
26 * @bug 8012322 8006683 8007288 8022832
27 * @library /testlibrary /testlibrary/whitebox
28 * @build MakeMethodNotCompilableTest
29 * @run main ClassFileInstaller sun.hotspot.WhiteBox
30 * sun.hotspot.WhiteBox$WhiteBoxPermission
31 * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* MakeMethodNotCompilableTest
32 * @summary testing of WB::makeMethodNotCompilable()
33 * @author igor.ignatyev@oracle.com
34 */
35 public class MakeMethodNotCompilableTest extends CompilerWhiteBoxTest {
36 private int bci;
37 public static void main(String[] args) throws Exception {
38 CompilerWhiteBoxTest.main(MakeMethodNotCompilableTest::new, args);
39 }
40
41 private MakeMethodNotCompilableTest(TestCase testCase) {
42 super(testCase);
43 // to prevent inlining of #method
44 WHITE_BOX.testSetDontInlineMethod(method, true);
45 }
46
47 /**
48 * Tests {@code WB::makeMethodNotCompilable()} by calling it before
49 * compilation and checking that method isn't compiled. Also
50 * checks that WB::clearMethodState() clears no-compilable flags. For
51 * tiered, additional checks for all available levels are conducted.
52 *
53 * @throws Exception if one of the checks fails.
54 */
55 @Override
56 protected void test() throws Exception {
57 if (skipXcompOSR()) {
58 return;
59 }
60 checkNotCompiled();
61 if (!isCompilable()) {
62 throw new RuntimeException(method + " must be compilable");
63 }
64
65 bci = getBci();
66
67 if (TIERED_COMPILATION) {
68 final int tierLimit = TIERED_STOP_AT_LEVEL + 1;
69 for (int testedTier = 1; testedTier < tierLimit; ++testedTier) {
70 testTier(testedTier);
71 }
72 for (int testedTier = 1; testedTier < tierLimit; ++testedTier) {
73 makeNotCompilable(testedTier);
74 if (isCompilable(testedTier)) {
75 throw new RuntimeException(method
76 + " must be not compilable at level" + testedTier);
77 }
78 WHITE_BOX.enqueueMethodForCompilation(method, testedTier, bci);
79 checkNotCompiled();
80
81 if (!isCompilable()) {
82 System.out.println(method
83 + " is not compilable after level " + testedTier);
84 }
85 }
86 } else {
87 compile();
88 checkCompiled();
89 int compLevel = getCompLevel();
90 deoptimize();
91 makeNotCompilable(compLevel);
92 if (isCompilable(COMP_LEVEL_ANY)) {
93 throw new RuntimeException(method
94 + " must be not compilable at CompLevel::CompLevel_any,"
95 + " after it is not compilable at " + compLevel);
96 }
97
98 WHITE_BOX.clearMethodState(method);
99 if (!isCompilable()) {
100 throw new RuntimeException(method
101 + " is not compilable after clearMethodState()");
102 }
103
104 // nocompilable at opposite level must make no sense
105 int oppositeLevel;
106 if (isC1Compile(compLevel)) {
107 oppositeLevel = COMP_LEVEL_FULL_OPTIMIZATION;
108 } else {
109 oppositeLevel = COMP_LEVEL_SIMPLE;
110 }
111 makeNotCompilable(oppositeLevel);
112
113 if (!isCompilable(COMP_LEVEL_ANY)) {
114 throw new RuntimeException(method
115 + " must be compilable at CompLevel::CompLevel_any,"
116 + " even it is not compilable at opposite level ["
117 + compLevel + "]");
118 }
119
120 if (!isCompilable(compLevel)) {
121 throw new RuntimeException(method
122 + " must be compilable at level " + compLevel
123 + ", even it is not compilable at opposite level ["
124 + compLevel + "]");
125 }
126 }
127
128 // clearing after tiered/non-tiered tests
129 // WB.clearMethodState() must reset no-compilable flags
130 WHITE_BOX.clearMethodState(method);
131 if (!isCompilable()) {
132 throw new RuntimeException(method
133 + " is not compilable after clearMethodState()");
134 }
135
136 makeNotCompilable();
137 if (isCompilable()) {
138 throw new RuntimeException(method + " must be not compilable");
139 }
140
141 compile();
142 checkNotOsrCompiled();
143 if (isCompilable()) {
144 throw new RuntimeException(method + " must be not compilable");
145 }
146 // WB.clearMethodState() must reset no-compilable flags
147 WHITE_BOX.clearMethodState(method);
148 if (!isCompilable()) {
149 throw new RuntimeException(method
150 + " is not compilable after clearMethodState()");
151 }
152 compile();
153 checkCompiled();
154 }
155
156 // separately tests each tier
157 private void testTier(int testedTier) {
158 if (!isCompilable(testedTier)) {
159 throw new RuntimeException(method
160 + " is not compilable on start");
161 }
162 makeNotCompilable(testedTier);
163
164 // tests for all other tiers
165 for (int anotherTier = 1, tierLimit = TIERED_STOP_AT_LEVEL + 1;
166 anotherTier < tierLimit; ++anotherTier) {
167 boolean isCompilable = isCompilable(anotherTier);
168 if (sameCompile(testedTier, anotherTier)) {
169 if (isCompilable) {
170 throw new RuntimeException(method
171 + " must be not compilable at level " + anotherTier
172 + ", if it is not compilable at " + testedTier);
173 }
174 WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci);
175 checkNotCompiled();
176 } else {
177 if (!isCompilable) {
178 throw new RuntimeException(method
179 + " must be compilable at level " + anotherTier
180 + ", even if it is not compilable at "
181 + testedTier);
182 }
183 WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci);
184 checkCompiled();
185 deoptimize();
186 }
187
188 if (!isCompilable(COMP_LEVEL_ANY)) {
189 throw new RuntimeException(method
190 + " must be compilable at 'CompLevel::CompLevel_any'"
191 + ", if it is not compilable only at " + testedTier);
192 }
193 }
194
195 // clear state after test
196 WHITE_BOX.clearMethodState(method);
197 if (!isCompilable(testedTier)) {
198 throw new RuntimeException(method
199 + " is not compilable after clearMethodState()");
200 }
201 }
202
203 private boolean sameCompile(int level1, int level2) {
204 if (level1 == level2) {
205 return true;
206 }
207 if (isC1Compile(level1) && isC1Compile(level2)) {
208 return true;
209 }
210 if (isC2Compile(level1) && isC2Compile(level2)) {
211 return true;
212 }
213 return false;
214 }
215
216 private int getBci() {
217 compile();
218 checkCompiled();
219 int result = WHITE_BOX.getMethodEntryBci(method);
220 deoptimize();
221 WHITE_BOX.clearMethodState(method);
222 return result;
223 }
224 }
--- EOF ---