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