Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/7100935/TestShortArraycopy.java
32284 views
1
/*
2
* Copyright 2011 SAP AG. 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 TestShortArraycopy
26
* @bug 7100935
27
* @summary verify that shorts are copied element-wise atomic.
28
* @run main/othervm -Xint TestShortArraycopy
29
* @run main/othervm -Xcomp -Xbatch TestShortArraycopy
30
* @author [email protected]
31
*/
32
33
public class TestShortArraycopy {
34
35
static short[] a1 = new short[8];
36
static short[] a2 = new short[8];
37
static short[] a3 = new short[8];
38
39
static volatile boolean keepRunning = true;
40
41
public static void main(String[] args) throws InterruptedException {
42
43
for (int i = 0; i < a1.length ; i++) {
44
a1[i] = (short)0xffff;
45
a2[i] = (short)0xffff;
46
a3[i] = (short)0x0000;
47
}
48
Thread reader = new Thread() {
49
public void run() {
50
while (keepRunning) {
51
for (int j = 0; j < a1.length; j++) {
52
short s = a1[j];
53
if (s != (short)0xffff && s != (short)0x0000) {
54
System.out.println("Error: s = " + s);
55
throw new RuntimeException("wrong result");
56
57
}
58
}
59
}
60
}
61
};
62
Thread writer = new Thread() {
63
public void run() {
64
for (int i = 0; i < 1000000; i++) {
65
System.arraycopy(a2, 5, a1, 3, 3);
66
System.arraycopy(a3, 5, a1, 3, 3);
67
}
68
}
69
};
70
keepRunning = true;
71
reader.start();
72
writer.start();
73
writer.join();
74
keepRunning = false;
75
reader.join();
76
}
77
}
78
79