Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/TestEliminateAllocation.java
41152 views
1
/*
2
* Copyright (c) 2019, 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 8231412
27
* @summary The enhancement eliminates all allocations in the loop body of test() due to an improved field zeroing elimination dominance check.
28
* @run main/othervm -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestEliminateAllocation::test
29
* compiler.escapeAnalysis.TestEliminateAllocation
30
*/
31
32
package compiler.escapeAnalysis;
33
34
public class TestEliminateAllocation {
35
36
public static int a = 20;
37
public static int b = 30;
38
public static int c = 40;
39
40
public void test() {
41
int i = 0;
42
43
/*
44
* The resulting IR for the loop body contains 2 allocations, one Wrapper and an int array
45
* The array field store in the Wrapper object 'wrapper.arr = arr' cannot be capturued due to an early bail out.
46
* Therefore, the initial value of wrapper.arr is null.
47
* As a result, the escape analysis marks the array allocation as not scalar replaceable:
48
* 'wrapper.arr' which is null is merged with the int array object in the assignment 'wrapper.arr = arr'.
49
* Both null and the int array are treated as different objects. As a result the array allocation cannot be eliminated.
50
*
51
* The new enhancement does not bail out early anymore and therefore escape analysis does not mark it as
52
* not scalar replaceable. This results in elimination of all allocations in this method.
53
*/
54
do {
55
int[] arr = new int[] { a / b / c };
56
Wrapper wrapper = new Wrapper();
57
wrapper.setArr(arr);
58
i++;
59
}
60
while (i < 10);
61
}
62
63
public static void main(String[] strArr) {
64
TestEliminateAllocation _instance = new TestEliminateAllocation();
65
for (int i = 0; i < 10_000; i++ ) {
66
_instance.test();
67
}
68
}
69
}
70
71
class Wrapper {
72
int[] arr;
73
void setArr(int... many) { arr = many; }
74
}
75
76