Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/TestSelfArrayCopy.java
41152 views
1
/*
2
* Copyright (c) 2019, 2020, 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
* @key randomness
27
* @bug 8229016 8231055
28
* @summary Test correct elimination of array allocation with arraycopy to itself.
29
* @library /test/lib
30
* @run main/othervm -Xbatch -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestSelfArrayCopy::test*
31
* compiler.escapeAnalysis.TestSelfArrayCopy
32
*/
33
34
package compiler.escapeAnalysis;
35
36
import jdk.test.lib.Utils;
37
38
public class TestSelfArrayCopy {
39
private static boolean b = false;
40
private static final int rI1 = Utils.getRandomInstance().nextInt();
41
private static final int rI2 = Utils.getRandomInstance().nextInt();
42
43
private static int test1() {
44
// Non-escaping allocation
45
Integer[] array = {rI1, rI2};
46
// Arraycopy with src == dst
47
System.arraycopy(array, 0, array, 0, array.length - 1);
48
if (b) {
49
// Uncommon trap
50
System.out.println(array[0]);
51
}
52
return array[0] + array[1];
53
}
54
55
private static int test2() {
56
// Non-escaping allocation
57
Integer[] array = {rI1, rI2};
58
// Arraycopy with src == dst
59
System.arraycopy(array, 0, array, 1, 1);
60
if (b) {
61
// Uncommon trap
62
System.out.println(array[0]);
63
}
64
return array[0] + array[1];
65
}
66
67
public static void main(String[] args) {
68
int expected1 = rI1 + rI2;
69
int expected2 = rI1 + rI1;
70
// Trigger compilation
71
for (int i = 0; i < 20_000; ++i) {
72
int result = test1();
73
if (result != expected1) {
74
throw new RuntimeException("Incorrect result: " + result + " != " + expected1);
75
}
76
result = test2();
77
if (result != expected2) {
78
throw new RuntimeException("Incorrect result: " + result + " != " + expected2);
79
}
80
}
81
b = true;
82
int result = test1();
83
if (result != expected1) {
84
throw new RuntimeException("Incorrect result: " + result + " != " + expected1);
85
}
86
result = test2();
87
if (result != expected2) {
88
throw new RuntimeException("Incorrect result: " + result + " != " + expected2);
89
}
90
}
91
}
92
93