Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyMemoryChain.java
41149 views
1
/*
2
* Copyright (c) 2019, 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 8233164
27
* @summary Test correct wiring of load/store memory for arraycopy ideal transformation.
28
* @run main/othervm -XX:CompileCommand=dontinline,compiler.arraycopy.TestArrayCopyMemoryChain::test* -Xbatch
29
* compiler.arraycopy.TestArrayCopyMemoryChain
30
*/
31
32
package compiler.arraycopy;
33
34
public class TestArrayCopyMemoryChain {
35
36
private String mySweetEscape1 = null;
37
38
private String getString(int i) {
39
return "A" + i + "B";
40
}
41
42
// Original test depending on Indify String Concat
43
public void test1(int i) {
44
mySweetEscape1 = getString(i) + "CD";
45
}
46
47
private byte[] mySweetEscape2;
48
49
class Wrapper {
50
public final byte[] array;
51
public Wrapper(byte[] array) {
52
this.array = array;
53
}
54
}
55
56
// Simplified test independent of Strings
57
public void test2(int idx, int size) {
58
// Create destination array with unknown size and let it escape.
59
byte[] dst = new byte[size];
60
mySweetEscape2 = dst;
61
// Create constant src1 array.
62
byte[] src1 = {43, 44};
63
// Wrap src2 into an Object such that it's only available after
64
// Escape Analys determined that the Object is non-escaping.
65
byte[] array = {42};
66
Wrapper wrapper = new Wrapper(array);
67
byte[] src2 = wrapper.array;
68
// Copy src1 and scr2 into destination array.
69
System.arraycopy(src1, 0, dst, idx, src1.length);
70
System.arraycopy(src2, 0, dst, 0, src2.length);
71
}
72
73
public static void main(String[] args) {
74
TestArrayCopyMemoryChain t = new TestArrayCopyMemoryChain();
75
for (int i = 0; i < 100_000; ++i) {
76
t.test1(0);
77
if (!t.mySweetEscape1.equals("A0BCD")) {
78
throw new RuntimeException("Test1 failed");
79
}
80
t.test2(1, 3);
81
if (t.mySweetEscape2[0] != 42 || t.mySweetEscape2[1] != 43 || t.mySweetEscape2[2] != 44) {
82
throw new RuntimeException("Test2 failed");
83
}
84
}
85
}
86
}
87
88