Path: blob/master/test/hotspot/jtreg/gc/g1/TestPLABSizeBounds.java
40942 views
/*1* Copyright (c) 2015, 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*/2223package gc.g1;2425/*26* @test TestPLABSizeBounds27* @bug 813485728* @summary Regression test to ensure that G1 supports PLAB sizes of half a region size.29* @requires vm.gc.G130* @library /test/lib31* @modules java.base/jdk.internal.misc32* java.management33* @run driver gc.g1.TestPLABSizeBounds34*/3536import java.util.ArrayList;3738import jdk.test.lib.Platform;39import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.process.ProcessTools;4142public class TestPLABSizeBounds {4344public static final int M = 1024 * 1024;4546/**47* Starts the VM with the given region size and the given PLAB size arguments. The VM start should48* succeed if shouldSucceed is true, otherwise it should fail.49*50* @param regionSize The region size the VM should be started with in bytes.51* @param plabSize The young and old gen PLAB sizes the VM should be started with in machine words.52* @param shouldSucceed The expected result of the VM invocation.53*/54public static void runTest(int regionSize, int plabSize, boolean shouldSucceed) throws Exception {55ArrayList<String> testArguments = new ArrayList<String>();5657testArguments.add("-XX:+UseG1GC");58testArguments.add("-Xmx256M");59testArguments.add("-XX:G1HeapRegionSize=" + regionSize);60testArguments.add("-XX:YoungPLABSize=" + plabSize);61testArguments.add("-XX:OldPLABSize=" + plabSize);62testArguments.add(GCTest.class.getName());6364ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(testArguments);65OutputAnalyzer output = new OutputAnalyzer(pb.start());6667if (shouldSucceed) {68output.shouldHaveExitValue(0);69} else {70output.shouldHaveExitValue(1);71}72}7374public static void runRegionTest(int regionSize) throws Exception {75final int regionSizeInBytes = regionSize * M;76final int wordSize = Platform.is32bit() ? 4 : 8;7778runTest(regionSizeInBytes, (regionSizeInBytes / wordSize) / 2 - 1, true);79runTest(regionSizeInBytes, (regionSizeInBytes / wordSize) / 2, true);80runTest(regionSizeInBytes, (regionSizeInBytes / wordSize) / 2 + 1, false);81}8283public static void main(String[] args) throws Exception {84runRegionTest(1);85runRegionTest(2);86runRegionTest(4);87runRegionTest(8);88runRegionTest(16);89runRegionTest(32);90}9192static class GCTest {93public static void main(String [] args) {94System.out.println("Test completed.");95}96}97}9899100101