Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/TestArrayCopy.java
41149 views
1
/*
2
* Copyright (c) 2016 SAP SE 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 8159611
27
* @summary The elimination of System.arraycopy by EscapeAnalysis prevents
28
* an IndexOutOfBoundsException from being thrown if the arraycopy
29
* is called with a negative length argument.
30
* @modules java.base/jdk.internal.misc
31
* @library /testlibrary /test/lib
32
* @build sun.hotspot.WhiteBox
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
*
35
* @run main/othervm/timeout=300
36
* -Xbootclasspath/a:.
37
* -XX:+UnlockDiagnosticVMOptions
38
* -XX:+WhiteBoxAPI
39
* -XX:-UseOnStackReplacement
40
* compiler.escapeAnalysis.TestArrayCopy
41
*
42
* @author Volker Simonis
43
*/
44
45
package compiler.escapeAnalysis;
46
47
import sun.hotspot.WhiteBox;
48
import java.lang.reflect.Method;
49
50
public class TestArrayCopy {
51
52
private static final WhiteBox WB = WhiteBox.getWhiteBox();
53
// DST_LEN Must be const, otherwise EliminateAllocations won't work
54
static final int DST_LEN = 4;
55
static final int SRC_LEN = 8;
56
57
public static boolean do_test1(Object src, int src_pos, int dst_pos, int cpy_len) {
58
try {
59
System.arraycopy(src, src_pos, new Object[DST_LEN], dst_pos, cpy_len);
60
return false;
61
} catch (IndexOutOfBoundsException e) {
62
return true;
63
}
64
}
65
66
public static int do_test2(Object src, int src_pos, int dst_pos, int cpy_len) {
67
try {
68
System.arraycopy(src, src_pos, new Object[DST_LEN], dst_pos, cpy_len);
69
return 0;
70
} catch (IndexOutOfBoundsException e) {
71
return 1;
72
} catch (ArrayStoreException e) {
73
return 2;
74
}
75
}
76
77
static final int COUNT = 100_000;
78
static final int[] src_pos = { 0, -1, -1, 0, 0, 0, 1, 1, 1, 1, 1 };
79
static final int[] dst_pos = { 0, -1, 0, -1, 0, 1, 0, 1, 1, 1, 1 };
80
static final int[] cpy_len = { 0, 0, 0, 0, -1, -1, -1, -1, 8, 4, 2 };
81
82
public static void main(String args[]) throws Exception {
83
int length = args.length > 0 ? Integer.parseInt(args[0]) : -1;
84
int[] int_arr = new int[SRC_LEN];
85
Object[] obj_arr = new Object[SRC_LEN];
86
87
Method test1 = TestArrayCopy.class.getMethod("do_test1", Object.class, int.class, int.class, int.class);
88
Method test2 = TestArrayCopy.class.getMethod("do_test2", Object.class, int.class, int.class, int.class);
89
90
for (int i = 0; i < src_pos.length; i++) {
91
int sp = src_pos[i];
92
int dp = dst_pos[i];
93
int cl = cpy_len[i];
94
String version1 = String.format("System.arraycopy(Object[8], %d, new Object[%d], %d, %d)", sp, DST_LEN, dp, cl);
95
String version2 = String.format("System.arraycopy(int[8], %d, new Object[%d], %d, %d)", sp, DST_LEN, dp, cl);
96
System.out.format("Testing " + version1 + "\nand " + version2).flush();
97
for (int x = 0; x < COUNT; x++) {
98
if (!do_test1(obj_arr, sp, dp, cl) &&
99
(sp < 0 || dp < 0 || cl < 0 || (sp + cl >= SRC_LEN) || (dp + cl >= DST_LEN))) {
100
throw new RuntimeException("Expected IndexOutOfBoundsException for " + version1);
101
}
102
int res = do_test2(int_arr, sp, dp, cl);
103
if (res == 0 || res == 1) {
104
throw new RuntimeException("Expected ArrayStoreException for " + version2);
105
}
106
}
107
WB.deoptimizeMethod(test1);
108
WB.clearMethodState(test1);
109
WB.deoptimizeMethod(test2);
110
WB.clearMethodState(test2);
111
}
112
113
}
114
}
115
116