Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java
66644 views
1
/*
2
* Copyright (c) 2019, Red Hat, Inc. 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
package gc.epsilon;
25
26
/**
27
* @test TestArraycopyCheckcast
28
* @requires vm.gc.Epsilon
29
* @summary Epsilon is able to handle checkcasted array copies
30
* @library /test/lib
31
* @bug 8215724
32
*
33
* @run main/othervm -Xmx256m
34
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
35
* gc.epsilon.TestArraycopyCheckcast
36
*
37
* @run main/othervm -Xmx256m
38
* -Xint
39
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
40
* gc.epsilon.TestArraycopyCheckcast
41
*
42
* @run main/othervm -Xmx256m
43
* -Xbatch -Xcomp -XX:TieredStopAtLevel=1
44
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
45
* gc.epsilon.TestArraycopyCheckcast
46
*
47
* @run main/othervm -Xmx256m
48
* -Xbatch -Xcomp -XX:-TieredCompilation
49
* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
50
* gc.epsilon.TestArraycopyCheckcast
51
*/
52
53
public class TestArraycopyCheckcast {
54
55
static int COUNT = Integer.getInteger("count", 1000);
56
57
public static void main(String[] args) throws Exception {
58
Object[] src = new Object[COUNT];
59
Object[] dst = new B[COUNT];
60
61
// Test 1. Copy nulls, should succeed
62
try {
63
System.arraycopy(src, 0, dst, 0, COUNT);
64
} catch (ArrayStoreException e) {
65
throw new IllegalStateException("Should have completed");
66
}
67
68
// Test 2. Copying incompatible type, should fail
69
for (int c = 0; c < COUNT; c++) {
70
src[c] = new A();
71
}
72
73
try {
74
System.arraycopy(src, 0, dst, 0, COUNT);
75
throw new IllegalStateException("Should have failed with ArrayStoreException");
76
} catch (ArrayStoreException e) {
77
// Expected
78
}
79
80
// Test 3. Copying compatible type, should succeeded
81
for (int c = 0; c < COUNT; c++) {
82
src[c] = new C();
83
}
84
85
try {
86
System.arraycopy(src, 0, dst, 0, COUNT);
87
} catch (ArrayStoreException e) {
88
throw new IllegalStateException("Should have completed");
89
}
90
91
for (int c = 0; c < COUNT; c++) {
92
if (src[c] != dst[c]) {
93
throw new IllegalStateException("Copy failed at index " + c);
94
}
95
}
96
}
97
98
static class A {}
99
static class B extends A {}
100
static class C extends B {}
101
}
102
103