Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestCloneAccess.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
* @bug 8248791
27
* @summary Test cloning with more than 8 (=ArrayCopyLoadStoreMaxElem) where loads are wrongly replaced by zero.
28
* @requires vm.compiler2.enabled | vm.graal.enabled
29
*
30
* @run main/othervm -XX:-ReduceBulkZeroing
31
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccess::*
32
* compiler.arraycopy.TestCloneAccess
33
* @run main/othervm -XX:-ReduceBulkZeroing -XX:-ReduceInitialCardMarks
34
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccess::*
35
* compiler.arraycopy.TestCloneAccess
36
*/
37
package compiler.arraycopy;
38
39
public class TestCloneAccess {
40
static int test(E src) throws CloneNotSupportedException {
41
// ArrayCopyNode for this clone is not inlined since there are more than 8 (=ArrayCopyLoadStoreMaxElem) fields
42
src.i1 = 3;
43
E dest = (E)src.clone();
44
dontInline(dest.i1, dest.i2);
45
46
// Both loads are wrongly optimized and replaced by a constant zero. LoadNode::Value() tries to find out if a load
47
// is done from a freshly-allocated object. If that is the case, the load can be replaced by the default value zero.
48
// However, in this case, the Allocation node belongs to an ArrayCopyNode which is responsible for initializing 'dest'.
49
// If -XX:-ReduceBulkZeroing is set, the InitializationNode of the allocation does not bail out of this optimization
50
// which results in a replacement of both loads by zero. This is addressed by this fix. If -XX:+ReduceBulkZeroing is
51
// set, then we already bail out and perform the load correctly.
52
return dest.i1 + dest.i2;
53
}
54
55
public static void main(String[] args) throws Exception {
56
E e = new E();
57
e.i2 = 4;
58
int res = 0;
59
for (int i = 0; i < 20000; i++) {
60
res = test(e);
61
if (res != 7 || e.i1 != 3 || e.i2 != 4) {
62
throw new RuntimeException("Wrong result! Expected: res = 7, e.i1 = 3, e.i2 = 4 "
63
+ "but got: res = " + res + ", e.i1 = " + e.i1 + ", e.i2 = " + e.i2);
64
}
65
}
66
}
67
68
// Dont inline this method
69
public static void dontInline(int i1, int i2) {
70
}
71
}
72
73
class E implements Cloneable {
74
/*
75
* Need more than 8 (=ArrayCopyLoadStoreMaxElem) fields
76
*/
77
int i1;
78
int i2;
79
int i3;
80
int i4;
81
int i5;
82
int i6;
83
int i7;
84
int i8;
85
int i9;
86
87
E() {
88
i1 = 0;
89
i2 = 1;
90
i3 = 2;
91
i4 = 3;
92
i5 = 4;
93
i6 = 5;
94
i7 = 6;
95
i8 = 7;
96
i9 = 8;
97
}
98
99
public Object clone() throws CloneNotSupportedException {
100
return super.clone();
101
}
102
}
103
104
105