Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestLargePageUseForAuxMemory.java
32284 views
/*1* Copyright (c) 2015, 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* @test TestLargePageUseForAuxMemory.java25* @bug 805835426* @key gc27* @library /testlibrary /testlibrary/whitebox28* @requires (vm.gc=="G1" | vm.gc=="null")29* @build TestLargePageUseForAuxMemory30* @run main ClassFileInstaller sun.hotspot.WhiteBox31* sun.hotspot.WhiteBox$WhiteBoxPermission32* @summary Test that auxiliary data structures are allocated using large pages if available.33* @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages TestLargePageUseForAuxMemory34*/3536import com.oracle.java.testlibrary.*;37import sun.hotspot.WhiteBox;3839public class TestLargePageUseForAuxMemory {40static final int HEAP_REGION_SIZE = 4 * 1024 * 1024;41static long largePageSize;42static long smallPageSize;4344static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception {45output.shouldContain("G1 'Block offset table': pg_sz=" + expectedPageSize);46output.shouldContain("G1 'Card counts table': pg_sz=" + expectedPageSize);47}4849static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception {50output.shouldContain("G1 'Prev Bitmap': pg_sz=" + expectedPageSize);51output.shouldContain("G1 'Next Bitmap': pg_sz=" + expectedPageSize);52}5354static void testVM(long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception {55ProcessBuilder pb;56// Test with large page enabled.57pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",58"-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,59"-Xms" + 10 * HEAP_REGION_SIZE,60"-Xmx" + heapsize,61"-XX:+TracePageSizes",62"-XX:+UseLargePages",63"-XX:+IgnoreUnrecognizedVMOptions", // there is on ObjectAlignmentInBytes in 32 bit builds64"-XX:ObjectAlignmentInBytes=8",65"-version");6667OutputAnalyzer output = new OutputAnalyzer(pb.start());68checkSmallTables(output, (cardsShouldUseLargePages ? largePageSize : smallPageSize));69checkBitmaps(output, (bitmapShouldUseLargePages ? largePageSize : smallPageSize));70output.shouldHaveExitValue(0);7172// Test with large page disabled.73pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",74"-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,75"-Xms" + 10 * HEAP_REGION_SIZE,76"-Xmx" + heapsize,77"-XX:+TracePageSizes",78"-XX:-UseLargePages",79"-XX:+IgnoreUnrecognizedVMOptions", // there is on ObjectAlignmentInBytes in 32 bit builds80"-XX:ObjectAlignmentInBytes=8",81"-version");8283output = new OutputAnalyzer(pb.start());84checkSmallTables(output, smallPageSize);85checkBitmaps(output, smallPageSize);86output.shouldHaveExitValue(0);87}8889public static void main(String[] args) throws Exception {90if (!Platform.isDebugBuild()) {91System.out.println("Skip tests on non-debug builds because the required option TracePageSizes is a debug-only option.");92return;93}9495WhiteBox wb = WhiteBox.getWhiteBox();96smallPageSize = wb.getVMPageSize();97largePageSize = wb.getVMLargePageSize();9899if (largePageSize == 0) {100System.out.println("Skip tests because large page support does not seem to be available on this platform.");101return;102}103104// To get large pages for the card table etc. we need at least a 1G heap (with 4k page size).105// 32 bit systems will have problems reserving such an amount of contiguous space, so skip the106// test there.107if (!Platform.is32bit()) {108// Size that a single card covers.109final int cardSize = 512;110111final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize;112113testVM(heapSizeForCardTableUsingLargePages, true, true);114testVM(heapSizeForCardTableUsingLargePages + HEAP_REGION_SIZE, true, true);115testVM(heapSizeForCardTableUsingLargePages - HEAP_REGION_SIZE, false, true);116}117118// Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test119// everywhere.120final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte121final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor;122123testVM(heapSizeForBitmapUsingLargePages, false, true);124testVM(heapSizeForBitmapUsingLargePages + HEAP_REGION_SIZE, false, true);125testVM(heapSizeForBitmapUsingLargePages - HEAP_REGION_SIZE, false, false);126}127}128129130131