Path: blob/master/test/hotspot/jtreg/gc/arguments/TestSmallInitialHeapWithLargePageAndNUMA.java
40948 views
/*1* Copyright (c) 2016, 2021, 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.arguments;2425/*26* @test TestSmallInitialHeapWithLargePageAndNUMA27* @bug 802390528* @requires os.family == "linux"29* @requires vm.gc.Parallel30* @summary Check large pages and NUMA are working together via the output message.31* @library /test/lib32* @library /33* @modules java.base/jdk.internal.misc34* @modules java.management/sun.management35* @build TestSmallInitialHeapWithLargePageAndNUMA36* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox37* @run main/othervm -Xbootclasspath/a:. -XX:+UseHugeTLBFS -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI gc.arguments.TestSmallInitialHeapWithLargePageAndNUMA38*/3940import jdk.test.lib.process.ProcessTools;41import jdk.test.lib.process.OutputAnalyzer;42import sun.hotspot.WhiteBox;43import jtreg.SkippedException;4445public class TestSmallInitialHeapWithLargePageAndNUMA {4647private static final String MSG_EXIT_TOO_SMALL_HEAP = "Failed initializing NUMA with large pages. Too small heap size";48private static final String MSG_GC_TRIGGERED_BEFORE_INIT = "GC triggered before VM initialization completed.";4950public static void main(String[] args) throws Exception {5152WhiteBox wb = WhiteBox.getWhiteBox();53long heapAlignment = wb.getHeapAlignment();5455// When using large pages, Linux does not support freeing parts of reserved and committed memory.56// And current Linux implementation uses page size as a condition to actually freeing memory.57// If we allocate pages less than NUMA node, NUMA will try to use default page size and58// this will free the memory which Linux does not support.59// Assume the minimum NUMA node as 2.60long initHeap = heapAlignment;61long maxHeap = heapAlignment * 2;6263ProcessBuilder pb_enabled = GCArguments.createJavaProcessBuilder(64"-XX:+UseParallelGC",65"-Xms" + String.valueOf(initHeap),66"-Xmx" + String.valueOf(maxHeap),67"-XX:+UseNUMA",68"-XX:+UseHugeTLBFS",69"-XX:+PrintFlagsFinal",70"-version");71OutputAnalyzer analyzer = new OutputAnalyzer(pb_enabled.start());7273if (largePageOrNumaEnabled(analyzer)) {74// We reach here, if both NUMA and HugeTLB are supported.75// However final flags will not be printed as NUMA initialization will be failed.76checkAnalyzerValues(analyzer, 1, MSG_EXIT_TOO_SMALL_HEAP);77} else {78throw new SkippedException("either NUMA or HugeTLB is not supported");79}80}8182// If both NUMA and large pages are enabled, VM will exit during NUMA initialization83// under the small heap configuration. So final flags will not be printed.84private static boolean largePageOrNumaEnabled(OutputAnalyzer analyzer) {85String output = analyzer.getOutput();8687return !output.contains("[Global flags]");88}8990// We need to test with small heap but fastdebug binary fails to initialize because of the small heap.91// So skip that case.92private static void checkAnalyzerValues(OutputAnalyzer analyzer, int expectedExitValue, String expectedMessage) {93String output = analyzer.getOutput();9495// If the VM exits because of the small heap, skip checking the exit value.96if (!output.contains(MSG_GC_TRIGGERED_BEFORE_INIT)) {97analyzer.shouldHaveExitValue(expectedExitValue);98}99if (expectedMessage != null) {100analyzer.shouldContain(expectedMessage);101}102}103}104105106