1+ /*
2+ * Copyright (c) 2025, 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 8373525
27+ * @summary Test for the check of a valid type (long) for the input variable of overflow protection
28+ * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.loopopts.TestValidTypeInOverflowProtection::test
29+ * ${test.main.class}
30+ * @run main ${test.main.class}
31+ */
32+
33+ package compiler .loopopts ;
34+
35+ import java .util .Vector ;
36+
37+ class TestVector extends Vector {
38+ TestVector (int initialCapacity ) {
39+ super (initialCapacity );
40+ }
41+
42+ Object getElementData () {
43+ return elementData ;
44+ }
45+ }
46+
47+ public class TestValidTypeInOverflowProtection {
48+ int cntr ;
49+ int mode ;
50+ int value = 533 ;
51+ int one = 1 ;
52+
53+ public static void main (String [] args ) {
54+ TestValidTypeInOverflowProtection test = new TestValidTypeInOverflowProtection ();
55+ for (int i = 0 ; i < 1000 ; i ++) {
56+ test .test ();
57+ }
58+ }
59+
60+ TestVector nextVector () {
61+ if (cntr == one ) {
62+ return null ;
63+ }
64+ TestVector vect = new TestVector (value );
65+ if (mode == 2 ) {
66+ int cap = vect .capacity ();
67+ for (int i = 0 ; i < cap ; i ++) {
68+ vect .addElement (new Object ());
69+ }
70+ }
71+ if (++mode == 3 ) {
72+ mode = cntr ++;
73+ }
74+ return vect ;
75+ }
76+
77+ String test () {
78+ cntr = 0 ;
79+ TestVector vect = nextVector ();
80+ while (vect != null ) {
81+ Object backup_array = new Object [vect .size ()];
82+ System .arraycopy (vect .getElementData (), 0 , backup_array , 0 , vect .size ());
83+ int old_size = vect .size ();
84+ int old_cap = vect .capacity ();
85+ vect .setSize (vect .capacity () + 1 );
86+ for (int i = old_size ; i < old_cap ; i ++) {
87+ if (vect .elementAt (i ) != null ) {
88+ }
89+ }
90+ for (int i = 0 ; i < new MyInteger (old_size ).v ; i ++) {
91+ }
92+ vect = nextVector ();
93+ }
94+ return null ;
95+ }
96+
97+ class MyInteger {
98+ int v ;
99+
100+ MyInteger (int v ) {
101+ int M452 = 4 ;
102+ int N452 = 8 ;
103+ for (int i452 = 0 ; i452 < M452 ; i452 ++) {
104+ for (int j452 = 0 ; j452 < N452 ; j452 ++) {
105+ switch (i452 ) {
106+ case -2 :
107+ case 0 :
108+ this .v = v ;
109+ }
110+ }
111+ }
112+ }
113+ }
114+ }
0 commit comments