Skip to content

Commit afa5d4c

Browse files
committedAug 30, 2022
8290451: Incorrect result when switching to C2 OSR compilation from C1
Reviewed-by: thartmann, kvn
1 parent bc6ac6f commit afa5d4c

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed
 

‎src/hotspot/share/c1/c1_Canonicalizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ void Canonicalizer::do_If(If* x) {
790790
else if (lss_sux == gtr_sux) { cond = If::neq; tsux = lss_sux; fsux = eql_sux; }
791791
else if (eql_sux == gtr_sux) { cond = If::geq; tsux = eql_sux; fsux = lss_sux; }
792792
else { ShouldNotReachHere(); }
793-
If* canon = new If(cmp->x(), cond, nan_sux == tsux, cmp->y(), tsux, fsux, cmp->state_before(), x->is_safepoint());
793+
If* canon = new If(cmp->x(), cond, nan_sux == tsux, cmp->y(), tsux, fsux, x->state_before(), x->is_safepoint());
794794
if (cmp->x() == cmp->y()) {
795795
do_If(canon);
796796
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2022, 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+
super public class BadStateAtLongCmp
25+
version 52:0
26+
{
27+
public static Field field:I;
28+
29+
public Method "<init>":"()V"
30+
stack 1 locals 1
31+
{
32+
aload_0;
33+
invokespecial Method java/lang/Object."<init>":"()V";
34+
return;
35+
}
36+
37+
/* Same as:
38+
public static void test() {
39+
long l = 0;
40+
do {
41+
l++;
42+
field++;
43+
} while (l < 1000);
44+
}
45+
but with field++ between the lcmp and iflt bytecodes.
46+
*/
47+
public static Method test:"()V"
48+
stack 4 locals 2
49+
{
50+
lconst_0;
51+
lstore_0;
52+
L2: stack_frame_type append;
53+
locals_map long;
54+
lload_0;
55+
lconst_1;
56+
ladd;
57+
lstore_0;
58+
lload_0;
59+
ldc2_w long 1000l;
60+
lcmp;
61+
getstatic Field field:"I";
62+
iconst_1;
63+
iadd;
64+
putstatic Field field:"I";
65+
iflt L2;
66+
return;
67+
}
68+
69+
} // end Class BadStateAtLongCmp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2022, 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 8290451
27+
* @summary Incorrect result when switching to C2 OSR compilation from C1
28+
* @compile BadStateAtLongCmp.jasm
29+
* @run main/othervm -Xbatch TestBadStateAtLongCmp
30+
*/
31+
32+
public class TestBadStateAtLongCmp {
33+
34+
public static void main(String[] args) {
35+
for (int i = 0; i < 20_000; i++) {
36+
BadStateAtLongCmp.test();
37+
}
38+
int expected = 20_000 * 1000;
39+
if (BadStateAtLongCmp.field != expected) {
40+
throw new RuntimeException("test failed: " + BadStateAtLongCmp.field + " != " + expected);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)
Please sign in to comment.