Skip to content

Commit 78d3712

Browse files
committed
8287432: C2: assert(tn->in(0) != __null) failed: must have live top node
Reviewed-by: kvn, thartmann
1 parent f7791ad commit 78d3712

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/hotspot/share/opto/compile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3664,7 +3664,7 @@ void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& f
36643664
n->set_req(MemBarNode::Precedent, top());
36653665
while (wq.size() > 0) {
36663666
Node* m = wq.pop();
3667-
if (m->outcnt() == 0) {
3667+
if (m->outcnt() == 0 && m != top()) {
36683668
for (uint j = 0; j < m->req(); j++) {
36693669
Node* in = m->in(j);
36703670
if (in != NULL) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2022, 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+
/*
25+
* @test
26+
* @bug 8287432
27+
* @summary Test removal of precedence edge of MemBarAcquire together with other now dead input nodes which visits a
28+
* top node. This resulted in a crash before as it disconnected top from the graph which is unexpected.
29+
*
30+
* @run main/othervm -Xbatch compiler.c2.TestRemoveMemBarPrecEdge
31+
*/
32+
package compiler.c2;
33+
34+
public class TestRemoveMemBarPrecEdge {
35+
static boolean flag = false;
36+
37+
public static void main(String[] args) {
38+
for (int i = 0; i < 10000; i++) {
39+
test();
40+
flag = !flag;
41+
}
42+
}
43+
44+
public static void test() {
45+
// currentThread() is intrinsified and C2 emits a special AddP node with a base that is top.
46+
Thread t = Thread.currentThread();
47+
// getName() returns the volatile _name field. The method is inlined and we just emit a LoadN + DecodeN which
48+
// is a precedence edge input into both MemBarAcquire nodes below for the volatile field _name.
49+
if (flag) {
50+
t.getName();
51+
} else {
52+
t.getName();
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)