2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
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
34
package compiler.allocation;
36
public class TestAllocation {
38
public static volatile int size = 128;
39
public static volatile int neg_size = -128;
41
public int testUnknownPositiveArrayLength() {
42
Payload w = new Payload(17, size);
43
return w.i + w.ba.length;
46
public int testStoreCapture() {
47
byte[] bs = new byte[1];
52
public int testUnknownNegativeArrayLength() {
53
boolean success = false;
55
Payload w = new Payload(17, neg_size);
56
return w.i + w.ba.length;
57
} catch (NegativeArraySizeException e) {
61
throw new RuntimeException("Should have thrown NegativeArraySizeException");
67
public int testConstantPositiveArrayLength() {
68
Payload w = new Payload(173, 10);
69
return w.i + w.ba.length;
72
public int testConstantPositiveArrayLength2() {
73
Payload w = new Payload(173, 10);
76
return w.i + w.ba.length;
79
public int testConstantNegativeArrayLength() {
80
boolean success = false;
82
Payload w = new Payload(173, -10);
83
return w.i + w.ba.length;
84
} catch (NegativeArraySizeException e) {
88
throw new RuntimeException("Should have thrown NegativeArraySizeException");
93
public static class Payload {
97
public Payload(int i, int size) {
99
this.ba = new byte[size];
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();
118
void setArr(int... many) { arr = many; }