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