Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/allocation/TestAllocation.java
41152 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 8237581
27
* @summary Testing allocation expansion when there is no use of the allocation
28
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+PrintCompilation -XX:+PrintEliminateAllocations -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::test*
29
* compiler.allocation.TestAllocation
30
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+PrintCompilation -XX:+PrintEliminateAllocations -XX:-DoEscapeAnalysis -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::test*
31
* compiler.allocation.TestAllocation
32
*/
33
34
package compiler.allocation;
35
36
public class TestAllocation {
37
38
public static volatile int size = 128;
39
public static volatile int neg_size = -128;
40
41
public int testUnknownPositiveArrayLength() {
42
Payload w = new Payload(17, size);
43
return w.i + w.ba.length;
44
}
45
46
public int testStoreCapture() {
47
byte[] bs = new byte[1];
48
bs[0] = 1;
49
return bs.length;
50
}
51
52
public int testUnknownNegativeArrayLength() {
53
boolean success = false;
54
try {
55
Payload w = new Payload(17, neg_size);
56
return w.i + w.ba.length;
57
} catch (NegativeArraySizeException e) {
58
success = true;
59
}
60
if (!success) {
61
throw new RuntimeException("Should have thrown NegativeArraySizeException");
62
}
63
return 0;
64
65
}
66
67
public int testConstantPositiveArrayLength() {
68
Payload w = new Payload(173, 10);
69
return w.i + w.ba.length;
70
}
71
72
public int testConstantPositiveArrayLength2() {
73
Payload w = new Payload(173, 10);
74
w.i = 17;
75
w.ba = new byte[10];
76
return w.i + w.ba.length;
77
}
78
79
public int testConstantNegativeArrayLength() {
80
boolean success = false;
81
try {
82
Payload w = new Payload(173, -10);
83
return w.i + w.ba.length;
84
} catch (NegativeArraySizeException e) {
85
success = true;
86
}
87
if (!success) {
88
throw new RuntimeException("Should have thrown NegativeArraySizeException");
89
}
90
return 0;
91
}
92
93
public static class Payload {
94
public int i;
95
public byte ba[];
96
97
public Payload(int i, int size) {
98
this.i = i;
99
this.ba = new byte[size];
100
}
101
}
102
103
public static void main(String[] strArr) {
104
TestAllocation test = new TestAllocation();
105
for (int i = 0; i < 10_000; i++ ) {
106
test.testUnknownPositiveArrayLength();
107
test.testUnknownNegativeArrayLength();
108
test.testConstantPositiveArrayLength();
109
test.testConstantPositiveArrayLength2();
110
test.testConstantNegativeArrayLength();
111
test.testStoreCapture();
112
}
113
}
114
}
115
116
class Wrapper {
117
int[] arr;
118
void setArr(int... many) { arr = many; }
119
}
120
121