Path: blob/master/test/hotspot/jtreg/compiler/allocation/TestFailedAllocationBadGraph.java
64474 views
/*1* Copyright (c) 2022, Red Hat, Inc. 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 827921926* @summary C2 crash when allocating array of size too large27* @requires vm.compiler2.enabled28* @library /test/lib /29* @build sun.hotspot.WhiteBox30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm -ea -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation TestFailedAllocationBadGraph32*/3334import sun.hotspot.WhiteBox;35import java.lang.reflect.Method;36import compiler.whitebox.CompilerWhiteBoxTest;3738public class TestFailedAllocationBadGraph {39private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();4041private static long[] array;42private static int field;43private static volatile int barrier;4445public static void main(String[] args) throws Exception {46run("test1");47run("test2");48}4950private static void run(String method) throws Exception {51Method m = TestFailedAllocationBadGraph.class.getDeclaredMethod(method);52WHITE_BOX.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);53if (!WHITE_BOX.isMethodCompiled(m) || WHITE_BOX.getMethodCompilationLevel(m) != CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION) {54throw new RuntimeException("should still be compiled");55}56}5758private static int test1() {59int length = Integer.MAX_VALUE;60try {61array = new long[length];62} catch (OutOfMemoryError outOfMemoryError) {63barrier = 0x42;64length = field;65}66return length;67}6869private static int test2() {70int length = -1;71try {72array = new long[length];73} catch (OutOfMemoryError outOfMemoryError) {74barrier = 0x42;75length = field;76}77return length;78}79}808182