Path: blob/master/test/hotspot/jtreg/compiler/allocation/TestAllocation.java
41152 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 823758126* @summary Testing allocation expansion when there is no use of the allocation27* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+PrintCompilation -XX:+PrintEliminateAllocations -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::test*28* compiler.allocation.TestAllocation29* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+PrintCompilation -XX:+PrintEliminateAllocations -XX:-DoEscapeAnalysis -XX:CompileCommand=compileonly,compiler.allocation.TestAllocation::test*30* compiler.allocation.TestAllocation31*/3233package compiler.allocation;3435public class TestAllocation {3637public static volatile int size = 128;38public static volatile int neg_size = -128;3940public int testUnknownPositiveArrayLength() {41Payload w = new Payload(17, size);42return w.i + w.ba.length;43}4445public int testStoreCapture() {46byte[] bs = new byte[1];47bs[0] = 1;48return bs.length;49}5051public int testUnknownNegativeArrayLength() {52boolean success = false;53try {54Payload w = new Payload(17, neg_size);55return w.i + w.ba.length;56} catch (NegativeArraySizeException e) {57success = true;58}59if (!success) {60throw new RuntimeException("Should have thrown NegativeArraySizeException");61}62return 0;6364}6566public int testConstantPositiveArrayLength() {67Payload w = new Payload(173, 10);68return w.i + w.ba.length;69}7071public int testConstantPositiveArrayLength2() {72Payload w = new Payload(173, 10);73w.i = 17;74w.ba = new byte[10];75return w.i + w.ba.length;76}7778public int testConstantNegativeArrayLength() {79boolean success = false;80try {81Payload w = new Payload(173, -10);82return w.i + w.ba.length;83} catch (NegativeArraySizeException e) {84success = true;85}86if (!success) {87throw new RuntimeException("Should have thrown NegativeArraySizeException");88}89return 0;90}9192public static class Payload {93public int i;94public byte ba[];9596public Payload(int i, int size) {97this.i = i;98this.ba = new byte[size];99}100}101102public static void main(String[] strArr) {103TestAllocation test = new TestAllocation();104for (int i = 0; i < 10_000; i++ ) {105test.testUnknownPositiveArrayLength();106test.testUnknownNegativeArrayLength();107test.testConstantPositiveArrayLength();108test.testConstantPositiveArrayLength2();109test.testConstantNegativeArrayLength();110test.testStoreCapture();111}112}113}114115class Wrapper {116int[] arr;117void setArr(int... many) { arr = many; }118}119120121