Skip to content

Commit af0c1c5

Browse files
author
duke
committed
Backport 624d714
1 parent aae9f92 commit af0c1c5

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

src/hotspot/share/opto/escape.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1058,6 +1058,39 @@ void ConnectionGraph::updates_after_load_split(Node* data_phi, Node* previous_lo
10581058
// "new_load" might actually be a constant, parameter, etc.
10591059
if (new_load->is_Load()) {
10601060
Node* new_addp = new_load->in(MemNode::Address);
1061+
1062+
// If new_load is a Load but not from an AddP, it means that the load is folded into another
1063+
// load. And since this load is not from a field, we cannot create a unique type for it.
1064+
// For example:
1065+
//
1066+
// if (b) {
1067+
// Holder h1 = new Holder();
1068+
// Object o = ...;
1069+
// h.o = o.getClass();
1070+
// } else {
1071+
// Holder h2 = ...;
1072+
// }
1073+
// Holder h = Phi(h1, h2);
1074+
// Object r = h.o;
1075+
//
1076+
// Then, splitting r through the merge point results in:
1077+
//
1078+
// if (b) {
1079+
// Holder h1 = new Holder();
1080+
// Object o = ...;
1081+
// h.o = o.getClass();
1082+
// Object o1 = h.o;
1083+
// } else {
1084+
// Holder h2 = ...;
1085+
// Object o2 = h2.o;
1086+
// }
1087+
// Object r = Phi(o1, o2);
1088+
//
1089+
// In this case, o1 is folded to o.getClass() which is a Load but not from an AddP, but from
1090+
// an OopHandle that is loaded from the Klass of o.
1091+
if (!new_addp->is_AddP()) {
1092+
continue;
1093+
}
10611094
Node* base = get_addp_base(new_addp);
10621095

10631096
// The base might not be something that we can create an unique
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2026, 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+
package compiler.escapeAnalysis;
24+
25+
import java.util.Objects;
26+
27+
/*
28+
* @test
29+
* @bug 8374435
30+
* @summary assert during escape analysis when splitting a Load through a Phi because the input of
31+
* the result Phi is a Load not from an AddP
32+
* @run main/othervm -XX:-UseOnStackReplacement -XX:-UseCompressedOops ${test.main.class}
33+
*/
34+
public class TestSplitLoadThroughPhiDuringEA {
35+
static class Holder {
36+
Object o;
37+
}
38+
39+
public static void main(String[] args) {
40+
Object o = new Object();
41+
Holder h = new Holder();
42+
for (int i = 0; i < 20000; i++) {
43+
test(true, h, o);
44+
test(false, h, o);
45+
}
46+
}
47+
48+
private static Object test(boolean b, Holder h, Object o) {
49+
h = Objects.requireNonNull(h);
50+
if (b) {
51+
h = new Holder();
52+
// This access has the pattern LoadP -> LoadP, which upsets the compiler because the
53+
// pointer input of a LoadP is not an AddP
54+
h.o = o.getClass();
55+
}
56+
return h.o;
57+
}
58+
}

0 commit comments

Comments
 (0)