Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit f142228

Browse files
committed
8285394: Compiler blackholes can be eliminated due to stale ciMethod::intrinsic_id()
Reviewed-by: kvn Backport-of: ce8db2c40378de01ce35ca37ec315af47974d6d6
1 parent 2447d2f commit f142228

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
lines changed

src/hotspot/share/ci/ciMethod.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
8282
_max_stack = h_m->max_stack();
8383
_max_locals = h_m->max_locals();
8484
_code_size = h_m->code_size();
85-
_intrinsic_id = h_m->intrinsic_id();
8685
_handler_count = h_m->exception_table_length();
8786
_size_of_parameters = h_m->size_of_parameters();
8887
_uses_monitors = h_m->access_flags().has_monitor_bytecodes();
@@ -102,6 +101,10 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
102101
_bcea = NULL;
103102
#endif // COMPILER2
104103

104+
// Check for blackhole intrinsic and then populate the intrinsic ID.
105+
CompilerOracle::tag_blackhole_if_possible(h_m);
106+
_intrinsic_id = h_m->intrinsic_id();
107+
105108
ciEnv *env = CURRENT_ENV;
106109
if (env->jvmti_can_hotswap_or_post_breakpoint()) {
107110
// 6328518 check hotswap conditions under the right lock.
@@ -157,8 +160,6 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
157160
ciReplay::initialize(this);
158161
}
159162
#endif
160-
161-
CompilerOracle::tag_blackhole_if_possible(h_m);
162163
}
163164

164165

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
}

test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public class IRNode {
141141
public static final String LSHIFT_L = START + "LShiftL" + MID + END;
142142
public static final String ADD_I = START + "AddI" + MID + END;
143143
public static final String ADD_L = START + "AddL" + MID + END;
144+
public static final String MUL_L = START + "MulL" + MID + END;
144145
public static final String CONV_I2L = START + "ConvI2L" + MID + END;
145146
public static final String POPCOUNT_L = START + "PopCountL" + MID + END;
146147

0 commit comments

Comments
 (0)