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