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 * @summary Test that auxiliary data structures are allocated using large pages if available. 27 * @bug 8058354 8079208 28 * @key gc 29 * @library /testlibrary /../../test/lib 30 * @requires (vm.gc=="G1" | vm.gc=="null") 31 * @build jdk.test.lib.* sun.hotspot.WhiteBox 32 * @build TestLargePageUseForAuxMemory 33 * @run main ClassFileInstaller sun.hotspot.WhiteBox 34 * sun.hotspot.WhiteBox$WhiteBoxPermission 35 * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages TestLargePageUseForAuxMemory 36 */ 37 38 import java.lang.Math; 39 40 import jdk.test.lib.*; 41 import jdk.test.lib.Asserts; 42 import sun.hotspot.WhiteBox; 43 44 public class TestLargePageUseForAuxMemory { 45 static final long HEAP_REGION_SIZE = 1 * 1024 * 1024; 46 static long largePageSize; 47 static long smallPageSize; 48 static long allocGranularity; 49 50 static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception { 51 output.shouldContain("G1 'Block offset table': pg_sz=" + expectedPageSize); 52 output.shouldContain("G1 'Card counts table': pg_sz=" + expectedPageSize); 53 } 54 55 static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception { 56 output.shouldContain("G1 'Prev Bitmap': pg_sz=" + expectedPageSize); 57 output.shouldContain("G1 'Next Bitmap': pg_sz=" + expectedPageSize); 58 } 59 60 static void testVM(String what, long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception { 61 System.out.println(what + " heapsize " + heapsize + " card table should use large pages " + cardsShouldUseLargePages + " " + 62 "bitmaps should use large pages " + bitmapShouldUseLargePages); 63 ProcessBuilder pb; 64 // Test with large page enabled. 65 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 66 "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE, 67 "-Xms" + heapsize, 68 "-Xmx" + heapsize, 69 "-XX:+TracePageSizes", 70 "-XX:+UseLargePages", 71 "-XX:+IgnoreUnrecognizedVMOptions", // there is no ObjectAlignmentInBytes in 32 bit builds 72 "-XX:ObjectAlignmentInBytes=8", 73 "-version"); 74 75 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 76 checkSmallTables(output, (cardsShouldUseLargePages ? largePageSize : smallPageSize)); 77 checkBitmaps(output, (bitmapShouldUseLargePages ? largePageSize : smallPageSize)); 78 output.shouldHaveExitValue(0); 79 80 // Test with large page disabled. 81 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", 82 "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE, 83 "-Xms" + heapsize, 84 "-Xmx" + heapsize, 85 "-XX:+TracePageSizes", 86 "-XX:-UseLargePages", 87 "-XX:+IgnoreUnrecognizedVMOptions", // there is no ObjectAlignmentInBytes in 32 bit builds 88 "-XX:ObjectAlignmentInBytes=8", 89 "-version"); 90 91 output = new OutputAnalyzer(pb.start()); 92 checkSmallTables(output, smallPageSize); 93 checkBitmaps(output, smallPageSize); 94 output.shouldHaveExitValue(0); 95 } 96 97 public static void main(String[] args) throws Exception { 98 if (!Platform.isDebugBuild()) { 99 System.out.println("Skip tests on non-debug builds because the required option TracePageSizes is a debug-only option."); 100 return; 101 } 102 103 WhiteBox wb = WhiteBox.getWhiteBox(); 104 smallPageSize = wb.getVMPageSize(); 105 largePageSize = wb.getVMLargePageSize(); 106 allocGranularity = wb.getVMAllocationGranularity(); 107 108 if (largePageSize == 0) { 109 System.out.println("Skip tests because large page support does not seem to be available on this platform."); 110 return; 111 } 112 113 // To get large pages for the card table etc. we need at least a 1G heap (with 4k page size). 114 // 32 bit systems will have problems reserving such an amount of contiguous space, so skip the 115 // test there. 116 if (!Platform.is32bit()) { 117 // Size that a single card covers. 118 final int cardSize = 512; 119 120 final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize; 121 final long heapSizeDiffForCardTable = Math.max(Math.max(allocGranularity * cardSize, HEAP_REGION_SIZE), largePageSize); 122 123 Asserts.assertGT(heapSizeForCardTableUsingLargePages, heapSizeDiffForCardTable, 124 "To test we would require to use an invalid heap size"); 125 testVM("case1: card table and bitmap use large pages (barely)", heapSizeForCardTableUsingLargePages, true, true); 126 testVM("case2: card table and bitmap use large pages (extra slack)", heapSizeForCardTableUsingLargePages + heapSizeDiffForCardTable, true, true); 127 testVM("case3: only bitmap uses large pages (barely not)", heapSizeForCardTableUsingLargePages - heapSizeDiffForCardTable, false, true); 128 } 129 130 // Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test 131 // everywhere. 132 final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte 133 final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor; 134 final long heapSizeDiffForBitmap = Math.max(Math.max(allocGranularity * bitmapTranslationFactor, HEAP_REGION_SIZE), largePageSize); 135 136 Asserts.assertGT(heapSizeForBitmapUsingLargePages, heapSizeDiffForBitmap, 137 "To test we would require to use an invalid heap size"); 138 139 testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true); 140 testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true); 141 testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false); 142 } 143 }