1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test TestLargePageUseForAuxMemory.java 26 * @bug 8058354 27 * @key gc 28 * @library /testlibrary /../../test/lib 29 * @requires (vm.gc=="G1" | vm.gc=="null") 30 * @build TestLargePageUseForAuxMemory 31 * @run main ClassFileInstaller sun.hotspot.WhiteBox 32 * sun.hotspot.WhiteBox$WhiteBoxPermission 33 * @summary Test that auxiliary data structures are allocated using large pages if available. 34 * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages TestLargePageUseForAuxMemory 35 */ 36 37 import com.oracle.java.testlibrary.*; 38 import sun.hotspot.WhiteBox; 39 40 public class TestLargePageUseForAuxMemory { 41 static final int HEAP_REGION_SIZE = 4 * 1024 * 1024; 42 static long largePageSize; 43 static long smallPageSize; 44 45 static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception { 46 output.shouldContain("G1 'Block offset table': pg_sz=" + expectedPageSize); 47 output.shouldContain("G1 'Card counts table': pg_sz=" + expectedPageSize); 48 } 49 50 static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception { 51 output.shouldContain("G1 'Prev Bitmap': pg_sz=" + expectedPageSize); 52 output.shouldContain("G1 'Next Bitmap': pg_sz=" + expectedPageSize); 53 } 54 55 static void testVM(long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception { 56 ProcessBuilder pb; 57 // Test with large page enabled. 58 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 59 "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE, 60 "-Xms" + 10 * HEAP_REGION_SIZE, 61 "-Xmx" + heapsize, 62 "-XX:+TracePageSizes", 63 "-XX:+UseLargePages", 64 "-XX:+IgnoreUnrecognizedVMOptions", // there is on ObjectAlignmentInBytes in 32 bit builds 65 "-XX:ObjectAlignmentInBytes=8", 66 "-version"); 67 68 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 69 checkSmallTables(output, (cardsShouldUseLargePages ? largePageSize : smallPageSize)); 70 checkBitmaps(output, (bitmapShouldUseLargePages ? largePageSize : smallPageSize)); 71 output.shouldHaveExitValue(0); 72 73 // Test with large page disabled. 74 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 75 "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE, 76 "-Xms" + 10 * HEAP_REGION_SIZE, 77 "-Xmx" + heapsize, 78 "-XX:+TracePageSizes", 79 "-XX:-UseLargePages", 80 "-XX:+IgnoreUnrecognizedVMOptions", // there is on ObjectAlignmentInBytes in 32 bit builds 81 "-XX:ObjectAlignmentInBytes=8", 82 "-version"); 83 84 output = new OutputAnalyzer(pb.start()); 85 checkSmallTables(output, smallPageSize); 86 checkBitmaps(output, smallPageSize); 87 output.shouldHaveExitValue(0); 88 } 89 90 public static void main(String[] args) throws Exception { 91 if (!Platform.isDebugBuild()) { 92 System.out.println("Skip tests on non-debug builds because the required option TracePageSizes is a debug-only option."); 93 return; 94 } 95 96 WhiteBox wb = WhiteBox.getWhiteBox(); 97 smallPageSize = wb.getVMPageSize(); 98 largePageSize = wb.getVMLargePageSize(); 99 100 if (largePageSize == 0) { 101 System.out.println("Skip tests because large page support does not seem to be available on this platform."); 102 return; 103 } 104 105 // To get large pages for the card table etc. we need at least a 1G heap (with 4k page size). 106 // 32 bit systems will have problems reserving such an amount of contiguous space, so skip the 107 // test there. 108 if (!Platform.is32bit()) { 109 // Size that a single card covers. 110 final int cardSize = 512; 111 112 final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize; 113 114 testVM(heapSizeForCardTableUsingLargePages, true, true); 115 testVM(heapSizeForCardTableUsingLargePages + HEAP_REGION_SIZE, true, true); 116 testVM(heapSizeForCardTableUsingLargePages - HEAP_REGION_SIZE, false, true); 117 } 118 119 // Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test 120 // everywhere. 121 final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte 122 final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor; 123 124 testVM(heapSizeForBitmapUsingLargePages, false, true); 125 testVM(heapSizeForBitmapUsingLargePages + HEAP_REGION_SIZE, false, true); 126 testVM(heapSizeForBitmapUsingLargePages - HEAP_REGION_SIZE, false, false); 127 } 128 } 129