|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Red Hat, Inc. 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 8285394 |
| 27 | + * @requires vm.compiler2.enabled |
| 28 | + * @summary Blackholes should work when hot inlined |
| 29 | + * @library /test/lib / |
| 30 | + * @run driver compiler.c2.irTests.blackhole.BlackholeHotInlineTest |
| 31 | + */ |
| 32 | + |
| 33 | +package compiler.c2.irTests.blackhole; |
| 34 | + |
| 35 | +import compiler.lib.ir_framework.*; |
| 36 | +import jdk.test.lib.Asserts; |
| 37 | + |
| 38 | +public class BlackholeHotInlineTest { |
| 39 | + |
| 40 | + public static void main(String[] args) { |
| 41 | + TestFramework.runWithFlags( |
| 42 | + "-XX:+UnlockExperimentalVMOptions", |
| 43 | + "-XX:CompileThreshold=100", |
| 44 | + "-XX:-TieredCompilation", |
| 45 | + "-XX:CompileCommand=blackhole,compiler.c2.irTests.blackhole.BlackholeHotInlineTest::blackhole", |
| 46 | + "-XX:CompileCommand=dontinline,compiler.c2.irTests.blackhole.BlackholeHotInlineTest::dontinline" |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + static long x, y; |
| 51 | + |
| 52 | + /* |
| 53 | + * Negative test: check that dangling expression is eliminated |
| 54 | + */ |
| 55 | + |
| 56 | + @Test |
| 57 | + @IR(failOn = IRNode.MUL_L) |
| 58 | + static void testNothing() { |
| 59 | + long r = x * y; |
| 60 | + } |
| 61 | + |
| 62 | + @Run(test = "testNothing") |
| 63 | + static void runNothing() { |
| 64 | + testNothing(); |
| 65 | + } |
| 66 | + |
| 67 | + /* |
| 68 | + * Auxiliary test: check that dontinline method does not allow the elimination. |
| 69 | + */ |
| 70 | + |
| 71 | + @Test |
| 72 | + @IR(counts = {IRNode.MUL_L, "1"}) |
| 73 | + static void testDontline() { |
| 74 | + long r = x * y; |
| 75 | + dontinline(r); |
| 76 | + } |
| 77 | + |
| 78 | + static void dontinline(long x) {} |
| 79 | + |
| 80 | + @Run(test = "testDontline") |
| 81 | + static void runDontinline() { |
| 82 | + testDontline(); |
| 83 | + } |
| 84 | + |
| 85 | + /* |
| 86 | + * Positive test: check that blackhole method does not allow the elimination either. |
| 87 | + */ |
| 88 | + |
| 89 | + @Test |
| 90 | + @IR(counts = {IRNode.MUL_L, "1"}) |
| 91 | + static void testBlackholed() { |
| 92 | + long r = x * y; |
| 93 | + blackhole(r); |
| 94 | + } |
| 95 | + |
| 96 | + static void blackhole(long x) {} |
| 97 | + |
| 98 | + @Run(test = "testBlackholed") |
| 99 | + static void runBlackholed() { |
| 100 | + testBlackholed(); |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments