Skip to content

Commit f56d1f6

Browse files
committed
8266480: Implicit null check optimization does not update control of hoisted memory operation
Backport-of: c2b50f9
1 parent 2c2cc74 commit f56d1f6

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/hotspot/share/opto/lcm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ void PhaseCFG::implicit_null_check(Block* block, Node *proj, Node *val, int allo
413413

414414
// Move the control dependence if it is pinned to not-null block.
415415
// Don't change it in other cases: NULL or dominating control.
416-
if (best->in(0) == not_null_block->head()) {
416+
Node* ctrl = best->in(0);
417+
if (get_block_for_node(ctrl) == not_null_block) {
417418
// Set it to control edge of null check.
418419
best->set_req(0, proj->in(0)->in(0));
419420
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
package compiler.c2;
25+
26+
/**
27+
* @test
28+
* @bug 8266480
29+
* @summary Check correct re-wiring of control edge when hoisting a memory
30+
* operation for an implicit null check.
31+
* @run main/othervm -Xbatch
32+
* compiler.c2.TestImplicitNullCheckDominance
33+
*/
34+
public class TestImplicitNullCheckDominance {
35+
36+
double dFld;
37+
int iFld;
38+
39+
static void test1(TestImplicitNullCheckDominance t, double d) {
40+
for (int i = 0; i < 100; i++) {
41+
t.dFld = d % 42;
42+
t.iFld = 43;
43+
}
44+
}
45+
46+
static void test2(TestImplicitNullCheckDominance t) {
47+
for (int i = 0; i < 10; i++) {
48+
for (int j = 0; j < 100; j++) {
49+
t.dFld %= 42;
50+
t.iFld = 43;
51+
}
52+
}
53+
}
54+
55+
public static void main(String[] args) {
56+
TestImplicitNullCheckDominance t = new TestImplicitNullCheckDominance();
57+
for (int i = 0; i < 50_000; ++i) {
58+
test1(t, i);
59+
test2(t);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)