Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestNegArrayLengthAsIndex1.java
64474 views
1
/*
2
* Copyright (C) 2021 THL A29 Limited, a Tencent company. 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 8268362
27
* @requires vm.compiler2.enabled & vm.debug
28
* @summary C2 using negative array length as index, using a.length.
29
* AllocateArrayNode::make_ideal_length create CastIINode to not negative range.
30
* Apply transform in GraphKit::load_array_length will covert array load index type to top.
31
* This cause assert in Parse::array_addressing, it expect index type is int.
32
* @run main/othervm -XX:-PrintCompilation compiler.arraycopy.TestNegArrayLengthAsIndex1
33
*/
34
35
package compiler.arraycopy;
36
public class TestNegArrayLengthAsIndex1 {
37
38
public static void main(String[] args) throws Exception {
39
for (int i = 0; i < 10000; i++) {
40
foo();
41
}
42
}
43
44
static int foo() {
45
int minusOne = -1;
46
int[] a = null;
47
try {
48
a = new int[minusOne];
49
} catch (NegativeArraySizeException e) {
50
return 0;
51
}
52
return a[a.length - 1];
53
}
54
}
55
56