Skip to content

Commit f33c874

Browse files
committed
8319764: C2 compilation asserts during incremental inlining because Phi input is out of bounds
Reviewed-by: thartmann, chagedorn
1 parent 6868b37 commit f33c874

File tree

2 files changed

+141
-6
lines changed

2 files changed

+141
-6
lines changed

src/hotspot/share/opto/replacednodes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ void ReplacedNodes::apply(Compile* C, Node* ctl) {
152152
} else if (n->outcnt() != 0 && n != improved) {
153153
if (n->is_Phi()) {
154154
Node* region = n->in(0);
155-
Node* prev = stack.node_at(stack.size() - 2);
156-
for (uint j = 1; j < region->req(); ++j) {
157-
if (n->in(j) == prev) {
158-
Node* in = region->in(j);
159-
if (in != nullptr && !in->is_top()) {
160-
if (is_dominator(ctl, in)) {
155+
if (n->req() == region->req()) { // ignore dead phis
156+
Node* prev = stack.node_at(stack.size() - 2);
157+
for (uint j = 1; j < region->req(); ++j) {
158+
if (n->in(j) == prev) {
159+
Node* in = region->in(j);
160+
if (in != nullptr && !in->is_top() && is_dominator(ctl, in)) {
161161
valid_control.set(in->_idx);
162162
collect_nodes_to_clone(stack, to_fix);
163163
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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 8319764
27+
* @summary C2 compilation asserts during incremental inlining because Phi input is out of bounds
28+
* @requires vm.compiler2.enabled
29+
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,TestLateInlineReplacedNodesExceptionPath::notInlined
30+
* -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -XX:StressSeed=1246687813 TestLateInlineReplacedNodesExceptionPath
31+
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,TestLateInlineReplacedNodesExceptionPath::notInlined
32+
* -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN TestLateInlineReplacedNodesExceptionPath
33+
*/
34+
35+
import java.lang.invoke.MethodHandle;
36+
import java.lang.invoke.MethodHandles;
37+
import java.lang.invoke.MethodType;
38+
39+
public class TestLateInlineReplacedNodesExceptionPath {
40+
private static A fieldA;
41+
private static C fieldC = new C();
42+
43+
public static void main(String[] args) throws Throwable {
44+
A a = new A();
45+
B b = new B();
46+
for (int i = 0; i < 20_000; i++) {
47+
fieldA = a;
48+
test1(true);
49+
fieldA = b;
50+
test1(true);
51+
inlined1(true);
52+
inlined1(false);
53+
inlined2(true);
54+
inlined2(false);
55+
}
56+
}
57+
58+
static final MethodHandle mh1;
59+
static MethodHandle mh2;
60+
static final MethodHandle mh3;
61+
static MethodHandle mh4;
62+
63+
static {
64+
try {
65+
MethodHandles.Lookup lookup = MethodHandles.lookup();
66+
mh1 = lookup.findStatic(TestLateInlineReplacedNodesExceptionPath.class, "lateInlined1", MethodType.methodType(void.class, C.class));
67+
mh2 = mh1;
68+
mh3 = lookup.findStatic(TestLateInlineReplacedNodesExceptionPath.class, "lateInlined2", MethodType.methodType(void.class, C.class));
69+
mh4 = mh3;
70+
} catch (NoSuchMethodException | IllegalAccessException e) {
71+
e.printStackTrace();
72+
throw new RuntimeException("Method handle lookup failed");
73+
}
74+
}
75+
76+
private static void lateInlined1(C c) {
77+
fieldA.m(c);
78+
c.field++;
79+
fieldA.m(c);
80+
}
81+
82+
private static void lateInlined2(C c) {
83+
c.field++;
84+
}
85+
86+
private static void test1(boolean flag) throws Throwable {
87+
final C c = fieldC;
88+
MethodHandle mh = null;
89+
if (flag) {
90+
mh = inlined1(flag);
91+
}
92+
mh.invokeExact(c);
93+
mh = null;
94+
if (flag) {
95+
mh = inlined2(flag);
96+
}
97+
mh.invokeExact(c);
98+
}
99+
100+
private static MethodHandle inlined1(boolean flag) {
101+
if (flag) {
102+
return mh1;
103+
}
104+
return mh2;
105+
}
106+
107+
private static MethodHandle inlined2(boolean flag) {
108+
if (flag) {
109+
return mh3;
110+
}
111+
return mh4;
112+
}
113+
114+
private static void notInlined() {
115+
}
116+
117+
private static class A {
118+
public void m(C c) {
119+
c.field++;
120+
notInlined();
121+
}
122+
123+
}
124+
125+
private static class B extends A {
126+
127+
public void m(C c) {
128+
notInlined();
129+
}
130+
}
131+
132+
private static class C {
133+
public int field;
134+
}
135+
}

0 commit comments

Comments
 (0)