|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | + * @summary Tests WB::isMethodCompilable(m) in combination with compiler directives that prevent a compilation of m. |
| 27 | + * @bug 8263582 |
| 28 | + * @library /test/lib / |
| 29 | + * @build sun.hotspot.WhiteBox |
| 30 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox |
| 31 | + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
| 32 | + * -XX:CompileCommand=compileonly,compiler.whitebox.TestMethodCompilableCompilerDirectives::doesNotExist |
| 33 | + * compiler.whitebox.TestMethodCompilableCompilerDirectives |
| 34 | + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
| 35 | + * -XX:CompileCommand=exclude,compiler.whitebox.TestMethodCompilableCompilerDirectives::* |
| 36 | + * compiler.whitebox.TestMethodCompilableCompilerDirectives |
| 37 | + */ |
| 38 | + |
| 39 | +package compiler.whitebox; |
| 40 | + |
| 41 | +import jdk.test.lib.Asserts; |
| 42 | +import sun.hotspot.WhiteBox; |
| 43 | +import java.lang.reflect.Method; |
| 44 | + |
| 45 | +public class TestMethodCompilableCompilerDirectives { |
| 46 | + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
| 47 | + |
| 48 | + // Method too simple for C2 and only C1 compiled. |
| 49 | + public static int c1Compiled() { |
| 50 | + return 3; |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + // Method first C1 and then C2 compiled. |
| 55 | + public static int c2Compiled() { |
| 56 | + for (int i = 0; i < 100; i++); |
| 57 | + return 3; |
| 58 | + } |
| 59 | + |
| 60 | + // WB::isMethodCompilable(m) uses Method::is_not_compilable() to decide if m is compilable. Method::is_not_compilable(), however, |
| 61 | + // returns false regardless of any compiler directives if m was not yet tried to be compiled. The compiler directive ExcludeOption |
| 62 | + // to prevent a compilation is evaluated lazily and is only applied when a compilation for m is attempted. |
| 63 | + // Another problem is that Method::is_not_compilable() only returns true for CompLevel_any if C1 AND C2 cannot compile it. |
| 64 | + // This means that a compilation of m must have been attempted for C1 and C2 before WB::isMethodCompilable(m, CompLevel_any) will |
| 65 | + // ever return false. This disregards any compiler directives (e.g. compileonly, exclude) that prohibit a compilation of m completely. |
| 66 | + // WB::isMethodCompilable() should be aware of the ExcludeOption compiler directives at any point in time. |
| 67 | + public static void main(String[] args) throws NoSuchMethodException { |
| 68 | + Method c1CompiledMethod = TestMethodCompilableCompilerDirectives.class.getDeclaredMethod("c1Compiled"); |
| 69 | + Method c2CompiledMethod = TestMethodCompilableCompilerDirectives.class.getDeclaredMethod("c2Compiled"); |
| 70 | + |
| 71 | + boolean compilable = WhiteBox.getWhiteBox().isMethodCompilable(c1CompiledMethod); |
| 72 | + Asserts.assertFalse(compilable); |
| 73 | + for (int i = 0; i < 3000; i++) { |
| 74 | + c1Compiled(); |
| 75 | + } |
| 76 | + compilable = WhiteBox.getWhiteBox().isMethodCompilable(c1CompiledMethod); |
| 77 | + Asserts.assertFalse(compilable); |
| 78 | + |
| 79 | + |
| 80 | + compilable = WhiteBox.getWhiteBox().isMethodCompilable(c2CompiledMethod); |
| 81 | + Asserts.assertFalse(compilable); |
| 82 | + for (int i = 0; i < 3000; i++) { |
| 83 | + c2Compiled(); |
| 84 | + } |
| 85 | + compilable = WhiteBox.getWhiteBox().isMethodCompilable(c2CompiledMethod); |
| 86 | + Asserts.assertFalse(compilable); |
| 87 | + } |
| 88 | +} |
0 commit comments