Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/loopopts/TestLoopUnswitchingLostCastDependency.java
41149 views
1
/*
2
* Copyright (c) 2020, 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
/*
25
* @test
26
* @key stress randomness
27
* @bug 8241900
28
* @summary Loop unswitching may cause dependence on null check to be lost
29
*
30
* @requires vm.compiler2.enabled
31
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:+StressGCM -XX:+StressLCM TestLoopUnswitchingLostCastDependency
32
*/
33
34
import java.util.Arrays;
35
36
public class TestLoopUnswitchingLostCastDependency {
37
private static Object objectField;
38
39
public static void main(String[] args) {
40
Object[] array = new Object[100];
41
Arrays.fill(array, new Object());
42
for (int i = 0; i < 20_000; i++) {
43
array[1] = null;
44
test(array);
45
array[1] = new Object();
46
objectField = null;
47
test(array);
48
array[1] = new Object();
49
objectField = new Object();
50
test(array);
51
}
52
}
53
54
private static void test(Object[] array) {
55
Object o = objectField;
56
Object o3 = array[1];
57
int j = 0;
58
for (int i = 1; i < 100; i *= 2) {
59
Object o2 = array[i];
60
// Both branches taken: loop is unswitched.
61
if (o3 != null) {
62
if (o2 == null) {
63
}
64
// Both branches taken: loop is unswitched next.
65
if (o != null) {
66
// CastPP here becomes control dependent on o2 ==
67
// null check above.
68
if (o.getClass() == Object.class) {
69
}
70
// This causes partial peeling. When that happens,
71
// the o2 == null check becomes redundant with the
72
// o3 != null check in the peeled iteration. The
73
// CastPP with o as input that was control
74
// dependent on the o2 == null check becomes
75
// control dependent on the o3 != null check,
76
// above the o != null check.
77
if (j > 7) {
78
79
}
80
j++;
81
}
82
}
83
}
84
}
85
}
86
87