Skip to content

Commit 2cdf617

Browse files
hgqxjjmerykitty
authored andcommitted
8372649: C2 compilation fails with "there should be an oop in OopMap instead of a live raw oop at safepoint"
Reviewed-by: qamai, chagedorn
1 parent 9a3b850 commit 2cdf617

File tree

2 files changed

+122
-6
lines changed

2 files changed

+122
-6
lines changed

src/hotspot/share/opto/output.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 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
@@ -2914,17 +2914,30 @@ void Scheduling::ComputeRegisterAntidependencies(Block *b) {
29142914

29152915
Node *m = b->get_node(i);
29162916

2917-
// Add precedence edge from following safepoint to use of derived pointer
2918-
if( last_safept_node != end_node &&
2917+
if (last_safept_node != end_node &&
29192918
m != last_safept_node) {
2919+
bool need_safept_prec = false;
2920+
// Add precedence edge from following safepoint to use of derived pointer
29202921
for (uint k = 1; k < m->req(); k++) {
29212922
const Type *t = m->in(k)->bottom_type();
2922-
if( t->isa_oop_ptr() &&
2923-
t->is_ptr()->offset() != 0 ) {
2924-
last_safept_node->add_prec( m );
2923+
if (t->isa_oop_ptr() &&
2924+
t->is_ptr()->offset() != 0) {
2925+
need_safept_prec = true;
29252926
break;
29262927
}
29272928
}
2929+
// A CheckCastPP whose input is still RawPtr must stay above the following safepoint.
2930+
// Otherwise post-regalloc block-local scheduling can leave a live raw oop at the safepoint.
2931+
if (!need_safept_prec && m->is_Mach() &&
2932+
m->as_Mach()->ideal_Opcode() == Op_CheckCastPP) {
2933+
Node* def = m->in(1);
2934+
if (def != nullptr && def->bottom_type()->base() == Type::RawPtr) {
2935+
need_safept_prec = true;
2936+
}
2937+
}
2938+
if (need_safept_prec) {
2939+
last_safept_node->add_prec(m);
2940+
}
29282941
}
29292942

29302943
if( n->jvms() ) { // Precedence edge from derived to safept
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
24+
/*
25+
* @test
26+
* @bug 8372649 8376189
27+
* @summary CheckCastPP with RawPtr input can be scheduled below a safepoint during C2
28+
* post-regalloc block-local scheduling, causing a live raw oop at the safepoint
29+
* instead of a corresponding oop in the OopMap.
30+
* @library /test/lib
31+
* @modules jdk.incubator.vector
32+
* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:TrackedInitializationLimit=0
33+
* -XX:CompileCommand=compileonly,${test.main.class}::test8372649
34+
* -XX:+OptoScheduling ${test.main.class} 8372649
35+
* @run main/othervm --add-modules=jdk.incubator.vector
36+
* -XX:+OptoScheduling ${test.main.class} 8376189
37+
*/
38+
39+
package compiler.codegen;
40+
41+
import jdk.incubator.vector.*;
42+
import jdk.test.lib.Asserts;
43+
44+
public class TestCheckCastPPRawOopSchedulingAtSafepoint {
45+
private static final VectorSpecies<Integer> SPECIES_I = IntVector.SPECIES_64;
46+
47+
static public void main(String[] args) {
48+
String mode = args[0];
49+
if ("8372649".equals(mode)) {
50+
run8372649();
51+
} else if ("8376189".equals(mode)) {
52+
run8376189();
53+
}
54+
}
55+
56+
// JDK-8372649
57+
static void run8372649(){
58+
for (int j = 6; 116 > j; ++j) {
59+
test8372649();
60+
}
61+
Asserts.assertEQ(Test.c, 43560L);
62+
}
63+
64+
static class Test {
65+
static int a = 256;
66+
float[] b = new float[256];
67+
static long c;
68+
}
69+
70+
static void test8372649() {
71+
float[][] g = new float[Test.a][Test.a];
72+
for (int d = 7; d < 16; d++) {
73+
long e = 1;
74+
do {
75+
g[d][(int) e] = d;
76+
synchronized (new Test()) {}
77+
} while (++e < 5);
78+
}
79+
for (int i = 0; i < Test.a; ++i) {
80+
for (int j = 0; j < Test.a ; ++j) {
81+
Test.c += g[i][j];
82+
}
83+
}
84+
}
85+
86+
// JDK-8376189
87+
static void run8376189(){
88+
int[] a = new int[10_000];
89+
int r = 0;
90+
for (int i = 0; i < 10_000; i++) {
91+
r = test8376189(a);
92+
}
93+
Asserts.assertEQ(r, 0);
94+
}
95+
96+
public static int test8376189(int[] a) {
97+
var mins = IntVector.broadcast(SPECIES_I, a[0]);
98+
for (int i = 0; i < SPECIES_I.loopBound(a.length); i += SPECIES_I.length()) {
99+
mins = IntVector.fromArray(SPECIES_I, a, 0);
100+
}
101+
return mins.reduceLanes(VectorOperators.MIN);
102+
}
103+
}

0 commit comments

Comments
 (0)