Skip to content

Commit b0983df

Browse files
committedSep 27, 2021
8274074: SIGFPE with C2 compiled code with -XX:+StressGCM
Reviewed-by: roland, thartmann
1 parent 7436a77 commit b0983df

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
 

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

+10
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,16 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
14481448
n->Opcode() != Op_Opaque4) {
14491449
Node *n_ctrl = get_ctrl(n);
14501450
IdealLoopTree *n_loop = get_loop(n_ctrl);
1451+
1452+
if (n->in(0) != NULL) {
1453+
IdealLoopTree* loop_ctrl = get_loop(n->in(0));
1454+
if (n_loop != loop_ctrl && n_loop->is_member(loop_ctrl)) {
1455+
// n has a control input inside a loop but get_ctrl() is member of an outer loop. This could happen, for example,
1456+
// for Div nodes inside a loop (control input inside loop) without a use except for an UCT (outside the loop).
1457+
// Rewire control of n to get_ctrl(n) to move it out of the loop, regardless if its input(s) are later sunk or not.
1458+
_igvn.replace_input_of(n, 0, n_ctrl);
1459+
}
1460+
}
14511461
if (n_loop != _ltree_root && n->outcnt() > 1) {
14521462
// Compute early control: needed for anti-dependence analysis. It's also possible that as a result of
14531463
// previous transformations in this loop opts round, the node can be hoisted now: early control will tell us.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
/*
25+
* @test
26+
* @key stress randomness
27+
* @bug 8274074
28+
* @requires vm.compiler2.enabled
29+
* @summary Sinking a data node used as divisor of a DivI node into a zero check UCT loses its pin outside the loop due to
30+
* optimizing the CastII node away, resulting in a div by zero crash (SIGFPE) due to letting the DivI node floating
31+
* back inside the loop.
32+
* @run main/othervm -Xcomp -XX:CompileCommand=compileonly,compiler.loopopts.TestSinkingDivisorLostPin -XX:-TieredCompilation
33+
* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:StressSeed=4177789702 compiler.loopopts.TestSinkingDivisorLostPin
34+
* @run main/othervm -Xcomp -XX:CompileCommand=compileonly,compiler.loopopts.TestSinkingDivisorLostPin -XX:-TieredCompilation
35+
* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM compiler.loopopts.TestSinkingDivisorLostPin
36+
*/
37+
38+
package compiler.loopopts;
39+
40+
public class TestSinkingDivisorLostPin {
41+
static int iFld = 1;
42+
static int x = 1;
43+
static int q = 0;
44+
static int iArrFld[] = new int[100];
45+
46+
public static void main(String[] strArr) {
47+
test();
48+
}
49+
50+
static void test() {
51+
int y = 1;
52+
int i = 1;
53+
do {
54+
int j;
55+
for (j = 1; j < 88; j++) {
56+
iArrFld[1] = x;
57+
}
58+
try {
59+
y = iFld - q; // y = 1 - 0
60+
y = (iArrFld[2] / y); // y = iArrFld[2] / 1
61+
// Zero check Z1 with UCT
62+
// DivI node D on IfTrue path of zero check
63+
y = (5 / iFld); // y = 5 / 1
64+
// Zero check Z2 with UCT
65+
// DivI node D is only used on IfFalse path of zero check Z2 into UCT (on IfTrue path, the result is not used anywhere
66+
// because we directly overwrite it again with "y = (5 / iFld)). The IfFalse path of the zero check, however, is never
67+
// taken because iFld = 1. But before applying the sinking algorithm, the DivI node D could be executed during the
68+
// loop, as the zero check Z1 succeeds. Only after sinking the SubI node for "iFld - q" into the IfFalse path of Z2
69+
// and optimizing it accordingly (iFld is found to be zero because the zero check Z2 failed, i.e. iFld is zero which is
70+
// propagated into the CastII node whose type is improved to [0,0] and the node is replaced by constant zero), the
71+
// DivI node must NOT be executed inside the loop anymore. But the DivI node is executed in the loop because of losing
72+
// the CastII pin. The fix is to update the control input of the DivI node to the get_ctrl() input outside the loop
73+
// (IfFalse of zero check Z2).
74+
} catch (ArithmeticException a_e) {
75+
}
76+
77+
iFld -= 8;
78+
if (y == 3) {
79+
}
80+
i++;
81+
} while (i < 10);
82+
}
83+
84+
}
85+

0 commit comments

Comments
 (0)
Please sign in to comment.