Skip to content

Commit 0955aca

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

File tree

3 files changed

+109
-3
lines changed

3 files changed

+109
-3
lines changed

src/hotspot/share/ci/ciMethod.cpp

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

103+
// Check for blackhole intrinsic and then populate the intrinsic ID.
104+
CompilerOracle::tag_blackhole_if_possible(h_m);
105+
_intrinsic_id = h_m->intrinsic_id();
106+
104107
ciEnv *env = CURRENT_ENV;
105108
if (env->jvmti_can_hotswap_or_post_breakpoint()) {
106109
// 6328518 check hotswap conditions under the right lock.
@@ -154,8 +157,6 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
154157
ciReplay::initialize(this);
155158
}
156159
#endif
157-
158-
CompilerOracle::tag_blackhole_if_possible(h_m);
159160
}
160161

161162

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public class IRNode {
134134
public static final String SCOPE_OBJECT = "(.*# ScObj.*" + END;
135135
public static final String MEMBAR = START + "MemBar" + MID + END;
136136
public static final String SAFEPOINT = START + "SafePoint" + MID + END;
137+
138+
public static final String MUL_L = START + "MulL" + MID + END;
137139
public static final String POPCOUNT_L = START + "PopCountL" + MID + END;
138140

139141
/**

0 commit comments

Comments
 (0)