Skip to content

Commit 1cee3b9

Browse files
committedAug 23, 2023
8313262: C2: Sinking node may cause required cast to be dropped
Reviewed-by: chagedorn, thartmann
1 parent f8203cb commit 1cee3b9

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed
 

‎src/hotspot/share/opto/loopopts.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
16421642
// Find control for 'x' next to use but not inside inner loops.
16431643
x_ctrl = place_outside_loop(x_ctrl, n_loop);
16441644
// Replace all uses
1645-
if (u->is_ConstraintCast() && u->bottom_type()->higher_equal(_igvn.type(n)) && u->in(0) == x_ctrl) {
1645+
if (u->is_ConstraintCast() && _igvn.type(n)->higher_equal(u->bottom_type()) && u->in(0) == x_ctrl) {
16461646
// If we're sinking a chain of data nodes, we might have inserted a cast to pin the use which is not necessary
16471647
// anymore now that we're going to pin n as well
16481648
_igvn.replace_node(u, x);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2023, 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 8313262
27+
* @summary Sinking node may cause required cast to be dropped
28+
* @requires vm.gc.Shenandoah
29+
* @run main/othervm -XX:-BackgroundCompilation -XX:+UseShenandoahGC TestSinkingNodeDropsNotNullCast
30+
*/
31+
32+
import java.util.Arrays;
33+
34+
public class TestSinkingNodeDropsNotNullCast {
35+
public static void main(String[] args) {
36+
Object[] array1 = new Object[100];
37+
Object[] array2 = new Object[100];
38+
Arrays.fill(array2, new Object());
39+
for (int i = 0; i < 20_000; i++) {
40+
test(array1);
41+
test(array1);
42+
test(array2);
43+
}
44+
}
45+
46+
private static Object test(Object[] array) {
47+
Object o;
48+
int i = 1;
49+
do {
50+
synchronized (new Object()) {
51+
}
52+
o = array[i];
53+
if (o != null) {
54+
if (o instanceof A) {
55+
return ((A) o).field;
56+
} else {
57+
return o;
58+
}
59+
}
60+
i++;
61+
} while (i < 100);
62+
return o;
63+
}
64+
65+
private static class A {
66+
Object field;
67+
}
68+
}

0 commit comments

Comments
 (0)
Please sign in to comment.