Skip to content

Commit 8e0d736

Browse files
committed
8373525: C2: assert(_base == Long) failed: Not a Long
Reviewed-by: chagedorn Backport-of: a61a1d3
1 parent 6d9e91f commit 8e0d736

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

src/hotspot/share/opto/addnode.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,10 @@ static Node* fold_subI_no_underflow_pattern(Node* n, PhaseGVN* phase) {
15981598
Node* x = add2->in(1);
15991599
Node* con2 = add2->in(2);
16001600
if (is_sub_con(con2)) {
1601+
// The graph could be dying (i.e. x is top) in which case type(x) is not a long.
1602+
const TypeLong* x_long = phase->type(x)->isa_long();
16011603
// Collapsed graph not equivalent if potential over/underflow -> bailing out (*)
1602-
if (can_overflow(phase->type(x)->is_long(), con1->get_long() + con2->get_long())) {
1604+
if (x_long == nullptr || can_overflow(x_long, con1->get_long() + con2->get_long())) {
16031605
return nullptr;
16041606
}
16051607
Node* new_con = phase->transform(new AddLNode(con1, con2));
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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

Comments
 (0)