Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestCloneAccessStressGCM.java
64474 views
1
/*
2
* Copyright (c) 2020, 2021, 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 stress randomness
27
* @bug 8235332 8248226
28
* @summary Test cloning with more than 8 (=ArrayCopyLoadStoreMaxElem) fields with StressGCM
29
* @library /
30
* @requires vm.compiler2.enabled | vm.graal.enabled
31
*
32
* @run main/othervm -Xbatch
33
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test
34
* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks
35
* compiler.arraycopy.TestCloneAccessStressGCM
36
* @run main/othervm -Xbatch
37
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test
38
* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks
39
* -XX:-ReduceBulkZeroing
40
* compiler.arraycopy.TestCloneAccessStressGCM
41
*/
42
43
package compiler.arraycopy;
44
45
public class TestCloneAccessStressGCM {
46
47
static int test(E src) throws CloneNotSupportedException {
48
// ArrayCopyNode for this clone is not inlined since there are more than 8 (=ArrayCopyLoadStoreMaxElem) fields
49
E dest = (E)src.clone();
50
51
// The ArrayCopyNode initialization for the clone is executed after the LoadI nodes for 'dest' due to a
52
// memory input from the uninitialized new object instead of the ArrayCopyNode. As a result, uninitialized
53
// memory is read for each field and added together.
54
return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 +
55
dest.i6 + dest.i7 + dest.i8 + dest.i9;
56
}
57
58
public static void main(String[] args) throws Exception {
59
TestCloneAccessStressGCM test = new TestCloneAccessStressGCM();
60
int result = 0;
61
E e = new E();
62
for (int i = 0; i < 20000; i++) {
63
result = test(e);
64
if (result != 36) {
65
throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum());
66
}
67
}
68
69
if (result != 36) {
70
throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum());
71
}
72
}
73
}
74
75
class E implements Cloneable {
76
/*
77
* Need more than 8 (=ArrayCopyLoadStoreMaxElem) fields
78
*/
79
int i1;
80
int i2;
81
int i3;
82
int i4;
83
int i5;
84
int i6;
85
int i7;
86
int i8;
87
int i9;
88
89
E() {
90
i1 = 0;
91
i2 = 1;
92
i3 = 2;
93
i4 = 3;
94
i5 = 4;
95
i6 = 5;
96
i7 = 6;
97
i8 = 7;
98
i9 = 8;
99
}
100
101
public Object clone() throws CloneNotSupportedException {
102
return super.clone();
103
}
104
105
public int sum() {
106
return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9;
107
}
108
}
109
110
111