test/gc/g1/TestLargePageUseForAuxMemory.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 7786
0956bdcc671e
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

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

mercurial