Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/oom/TestAllocLargeObj.java
32285 views
/*1* Copyright (c) 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/**24* @test TestAllocLargeObj25* @summary Test allocation of small object to result OOM, but not to crash JVM26* @key gc27* @library /testlibrary28*29* @run main TestAllocLargeObj30*/3132import com.oracle.java.testlibrary.*;3334public class TestAllocLargeObj {3536static final int SIZE = 1 * 1024 * 1024;37static final int COUNT = 16;3839static volatile Object sink;4041public static void work() throws Exception {42Object[] root = new Object[COUNT];43sink = root;44for (int c = 0; c < COUNT; c++) {45root[c] = new Object[SIZE];46}47}4849public static void main(String[] args) throws Exception {50if (args.length > 0) {51work();52return;53}5455{56ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(57"-Xmx16m",58"-XX:+UnlockExperimentalVMOptions",59"-XX:+UseShenandoahGC",60TestAllocLargeObj.class.getName(),61"test");6263OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());64analyzer.shouldHaveExitValue(1);65analyzer.shouldContain("java.lang.OutOfMemoryError: Java heap space");66}6768{69ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(70"-Xmx1g",71"-XX:+UnlockExperimentalVMOptions",72"-XX:+UseShenandoahGC",73TestAllocLargeObj.class.getName(),74"test");7576OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());77analyzer.shouldHaveExitValue(0);78analyzer.shouldNotContain("java.lang.OutOfMemoryError: Java heap space");79}80}81}828384