Skip to content

Commit 31eefe5

Browse files
committed
8284848: C2: Compiler blackhole arguments should be treated as globally escaping
Reviewed-by: kvn Backport-of: 5629c7555f9bb779c57f45dfb071abbb1d87bb7d
1 parent c735f55 commit 31eefe5

File tree

6 files changed

+258
-0
lines changed

6 files changed

+258
-0
lines changed

src/hotspot/share/opto/escape.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,24 @@ void ConnectionGraph::add_node_to_connection_graph(Node *n, Unique_Node_List *de
618618
add_java_object(n, PointsToNode::ArgEscape);
619619
break;
620620
}
621+
case Op_Blackhole: {
622+
// All blackhole pointer arguments are globally escaping.
623+
// Only do this if there is at least one pointer argument.
624+
// Do not add edges during first iteration because some could be
625+
// not defined yet, defer to final step.
626+
for (uint i = 0; i < n->req(); i++) {
627+
Node* in = n->in(i);
628+
if (in != nullptr) {
629+
const Type* at = _igvn->type(in);
630+
if (!at->isa_ptr()) continue;
631+
632+
add_local_var(n, PointsToNode::GlobalEscape);
633+
delayed_worklist->push(n);
634+
break;
635+
}
636+
}
637+
break;
638+
}
621639
default:
622640
; // Do nothing for nodes not related to EA.
623641
}
@@ -789,6 +807,26 @@ void ConnectionGraph::add_final_edges(Node *n) {
789807
}
790808
break;
791809
}
810+
case Op_Blackhole: {
811+
// All blackhole pointer arguments are globally escaping.
812+
for (uint i = 0; i < n->req(); i++) {
813+
Node* in = n->in(i);
814+
if (in != nullptr) {
815+
const Type* at = _igvn->type(in);
816+
if (!at->isa_ptr()) continue;
817+
818+
if (in->is_AddP()) {
819+
in = get_addp_base(in);
820+
}
821+
822+
PointsToNode* ptn = ptnode_adr(in->_idx);
823+
assert(ptn != nullptr, "should be defined already");
824+
set_escape_state(ptn, PointsToNode::GlobalEscape);
825+
add_edge(n_ptn, ptn);
826+
}
827+
}
828+
break;
829+
}
792830
default: {
793831
// This method should be called only for EA specific nodes which may
794832
// miss some edges when they were created.

test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public class BlackholeIntrinsicTest {
7777
TESTS.put("bh_s_long_2", BlackholeIntrinsicTest::test_long_2);
7878
TESTS.put("bh_s_double_2", BlackholeIntrinsicTest::test_double_2);
7979
TESTS.put("bh_s_Object_2", BlackholeIntrinsicTest::test_Object_2);
80+
81+
// Test calling static methods through instance method to exercise
82+
// unusual intrinsic shapes.
83+
TESTS.put("bh_is_int_0", BlackholeIntrinsicTest::test_is_int_0);
84+
TESTS.put("bh_is_Object_0", BlackholeIntrinsicTest::test_is_Object_0);
85+
TESTS.put("bh_is_int_1", BlackholeIntrinsicTest::test_is_int_1);
86+
TESTS.put("bh_is_Object_1", BlackholeIntrinsicTest::test_is_Object_1);
87+
TESTS.put("bh_is_int_2", BlackholeIntrinsicTest::test_is_int_2);
88+
TESTS.put("bh_is_Object_2", BlackholeIntrinsicTest::test_is_Object_2);
8089
}
8190

8291
private static final int CYCLES = 100_000;
@@ -162,6 +171,13 @@ private static void test_int_0() {
162171
}
163172
}
164173

174+
private static void test_is_int_0() {
175+
BlackholeTarget t = new BlackholeTarget();
176+
for (int c = 0; c < CYCLES; c++) {
177+
t.bh_is_int_0();
178+
}
179+
}
180+
165181
private static void test_float_0() {
166182
for (int c = 0; c < CYCLES; c++) {
167183
BlackholeTarget.bh_s_float_0();
@@ -186,6 +202,13 @@ private static void test_Object_0() {
186202
}
187203
}
188204

205+
private static void test_is_Object_0() {
206+
BlackholeTarget t = new BlackholeTarget();
207+
for (int c = 0; c < CYCLES; c++) {
208+
t.bh_is_Object_0();
209+
}
210+
}
211+
189212
private static void test_boolean_1() {
190213
for (int c = 0; c < CYCLES; c++) {
191214
BlackholeTarget.bh_s_boolean_1((c & 0x1) == 0);
@@ -216,6 +239,13 @@ private static void test_int_1() {
216239
}
217240
}
218241

242+
private static void test_is_int_1() {
243+
BlackholeTarget t = new BlackholeTarget();
244+
for (int c = 0; c < CYCLES; c++) {
245+
t.bh_is_int_1(c);
246+
}
247+
}
248+
219249
private static void test_float_1() {
220250
for (int c = 0; c < CYCLES; c++) {
221251
BlackholeTarget.bh_s_float_1(c);
@@ -241,6 +271,14 @@ private static void test_Object_1() {
241271
}
242272
}
243273

274+
private static void test_is_Object_1() {
275+
BlackholeTarget t = new BlackholeTarget();
276+
for (int c = 0; c < CYCLES; c++) {
277+
Object o = new Object();
278+
t.bh_is_Object_1(o);
279+
}
280+
}
281+
244282
private static void test_boolean_2() {
245283
for (int c = 0; c < CYCLES; c++) {
246284
BlackholeTarget.bh_s_boolean_2((c & 0x1) == 0, (c & 0x2) == 0);
@@ -271,6 +309,13 @@ private static void test_int_2() {
271309
}
272310
}
273311

312+
private static void test_is_int_2() {
313+
BlackholeTarget t = new BlackholeTarget();
314+
for (int c = 0; c < CYCLES; c++) {
315+
t.bh_is_int_2(c, c + 1);
316+
}
317+
}
318+
274319
private static void test_float_2() {
275320
for (int c = 0; c < CYCLES; c++) {
276321
BlackholeTarget.bh_s_float_2(c, c + 1);
@@ -296,4 +341,13 @@ private static void test_Object_2() {
296341
BlackholeTarget.bh_s_Object_2(o1, o2);
297342
}
298343
}
344+
345+
private static void test_is_Object_2() {
346+
BlackholeTarget t = new BlackholeTarget();
347+
for (int c = 0; c < CYCLES; c++) {
348+
Object o1 = new Object();
349+
Object o2 = new Object();
350+
t.bh_is_Object_2(o1, o2);
351+
}
352+
}
299353
}

test/hotspot/jtreg/compiler/blackhole/BlackholeTarget.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static void bh_s_long_0() {}
4848
public static void bh_s_double_0() {}
4949
public static void bh_s_Object_0() {}
5050

51+
public static void bh_is_int_0() {}
52+
public static void bh_is_Object_0() {}
53+
5154
public static void bh_s_boolean_1(boolean v) {}
5255
public static void bh_s_byte_1(byte v) {}
5356
public static void bh_s_short_1(short v) {}
@@ -58,6 +61,9 @@ public static void bh_s_long_1(long v) {}
5861
public static void bh_s_double_1(double v) {}
5962
public static void bh_s_Object_1(Object v) {}
6063

64+
public static void bh_is_int_1(int v) {}
65+
public static void bh_is_Object_1(Object v) {}
66+
6167
public static void bh_s_boolean_1_delegate(boolean v) { bh_s_boolean_1(v); }
6268
public static void bh_s_byte_1_delegate(byte v) { bh_s_byte_1(v); }
6369
public static void bh_s_short_1_delegate(short v) { bh_s_short_1(v); }
@@ -78,6 +84,9 @@ public static void bh_s_long_2(long v1, long v2) {}
7884
public static void bh_s_double_2(double v1, double v2) {}
7985
public static void bh_s_Object_2(Object v1, Object v2) {}
8086

87+
public static void bh_is_int_2(int v1, int v2) {}
88+
public static void bh_is_Object_2(Object v1, Object v2) {}
89+
8190
public static boolean bh_sr_boolean(boolean v) { return false; }
8291
public static byte bh_sr_byte(byte v) { return 0; }
8392
public static short bh_sr_short(short v) { return 0; }
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 8284848
27+
* @requires vm.compiler2.enabled
28+
* @summary Blackhole arguments are globally escaping, thus preventing advanced EA optimizations
29+
* @library /test/lib /
30+
* @run driver compiler.c2.irTests.blackhole.BlackholeStoreStoreEATest
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 BlackholeStoreStoreEATest {
39+
40+
public static void main(String[] args) {
41+
TestFramework.runWithFlags(
42+
"-XX:+UnlockExperimentalVMOptions",
43+
"-XX:CompileCommand=blackhole,compiler.c2.irTests.blackhole.BlackholeStoreStoreEATest::blackhole"
44+
);
45+
}
46+
47+
/*
48+
* Negative test is not possible: the StoreStore barrier is still in, even if we just do dontinline.
49+
* Positive test: check that blackhole keeps the StoreStore barrier in.
50+
*/
51+
52+
@Test
53+
@IR(counts = {IRNode.MEMBAR_STORESTORE, "1"})
54+
static void testBlackholed() {
55+
Object o = new Object();
56+
blackhole(o);
57+
}
58+
59+
static void blackhole(Object o) {}
60+
61+
@Run(test = "testBlackholed")
62+
static void runBlackholed() {
63+
testBlackholed();
64+
}
65+
66+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 8284848
27+
* @requires vm.compiler2.enabled
28+
* @summary Blackhole arguments are globally escaping, thus preventing advanced EA optimizations
29+
* @library /test/lib /
30+
* @run driver compiler.c2.irTests.blackhole.BlackholeSyncEATest
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 BlackholeSyncEATest {
39+
40+
public static void main(String[] args) {
41+
TestFramework.runWithFlags(
42+
"-XX:+UnlockExperimentalVMOptions",
43+
"-XX:CompileCommand=blackhole,compiler.c2.irTests.blackhole.BlackholeSyncEATest::blackhole",
44+
"-XX:CompileCommand=dontinline,compiler.c2.irTests.blackhole.BlackholeSyncEATest::dontinline"
45+
);
46+
}
47+
48+
/*
49+
* Negative test: check that dontinline method still allows EA to eliminate the synchronization.
50+
*/
51+
52+
@Test
53+
@IR(failOn = {IRNode.FAST_LOCK, IRNode.FAST_UNLOCK})
54+
static void testDontline() {
55+
Object o = new Object();
56+
synchronized (o) {}
57+
dontinline(o);
58+
}
59+
60+
static void dontinline(Object o) {}
61+
62+
@Run(test = "testDontline")
63+
static void runDontinline() {
64+
testDontline();
65+
}
66+
67+
/*
68+
* Positive test: check that blackhole keeps the synchronization in.
69+
*/
70+
71+
@Test
72+
@IR(counts = {IRNode.FAST_LOCK, "1"})
73+
@IR(counts = {IRNode.FAST_UNLOCK, "1"})
74+
static void testBlackholed() {
75+
Object o = new Object();
76+
synchronized (o) {}
77+
blackhole(o);
78+
}
79+
80+
static void blackhole(Object o) {}
81+
82+
@Run(test = "testBlackholed")
83+
static void runBlackholed() {
84+
testBlackholed();
85+
}
86+
87+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ public class IRNode {
133133

134134
public static final String SCOPE_OBJECT = "(.*# ScObj.*" + END;
135135
public static final String MEMBAR = START + "MemBar" + MID + END;
136+
public static final String MEMBAR_STORESTORE = START + "MemBarStoreStore" + MID + END;
136137
public static final String SAFEPOINT = START + "SafePoint" + MID + END;
137138

138139
public static final String MUL_L = START + "MulL" + MID + END;
139140
public static final String POPCOUNT_L = START + "PopCountL" + MID + END;
140141

142+
public static final String FAST_LOCK = START + "FastLock" + MID + END;
143+
public static final String FAST_UNLOCK = START + "FastUnlock" + MID + END;
144+
141145
/**
142146
* Called by {@link IRMatcher} to merge special composite nodes together with additional user-defined input.
143147
*/

0 commit comments

Comments
 (0)