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
39 import jdk.test.lib.*;
40 import sun.hotspot.WhiteBox;
41
42 public 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
|
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);
62 ProcessBuilder pb;
63 // Test with large page enabled.
64 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
65 "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
66 "-Xms" + heapsize,
67 "-Xmx" + heapsize,
68 "-XX:+TracePageSizes",
69 "-XX:+UseLargePages",
70 "-XX:+IgnoreUnrecognizedVMOptions", // there is no ObjectAlignmentInBytes in 32 bit builds
71 "-XX:ObjectAlignmentInBytes=8",
72 "-version");
73
74 OutputAnalyzer output = new OutputAnalyzer(pb.start());
75 checkSmallTables(output, (cardsShouldUseLargePages ? largePageSize : smallPageSize));
76 checkBitmaps(output, (bitmapShouldUseLargePages ? largePageSize : smallPageSize));
77 output.shouldHaveExitValue(0);
78
79 // Test with large page disabled.
80 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
81 "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
82 "-Xms" + heapsize,
83 "-Xmx" + heapsize,
84 "-XX:+TracePageSizes",
85 "-XX:-UseLargePages",
86 "-XX:+IgnoreUnrecognizedVMOptions", // there is no ObjectAlignmentInBytes in 32 bit builds
87 "-XX:ObjectAlignmentInBytes=8",
88 "-version");
89
90 output = new OutputAnalyzer(pb.start());
91 checkSmallTables(output, smallPageSize);
92 checkBitmaps(output, smallPageSize);
93 output.shouldHaveExitValue(0);
94 }
95
96 public static void main(String[] args) throws Exception {
97 if (!Platform.isDebugBuild()) {
98 System.out.println("Skip tests on non-debug builds because the required option TracePageSizes is a debug-only option.");
99 return;
100 }
101
102 WhiteBox wb = WhiteBox.getWhiteBox();
103 smallPageSize = wb.getVMPageSize();
104 largePageSize = wb.getVMLargePageSize();
105 allocGranularity = wb.getVMAllocationGranularity();
106
107 if (largePageSize == 0) {
108 System.out.println("Skip tests because large page support does not seem to be available on this platform.");
109 return;
110 }
111
112 // To get large pages for the card table etc. we need at least a 1G heap (with 4k page size).
113 // 32 bit systems will have problems reserving such an amount of contiguous space, so skip the
114 // test there.
115 if (!Platform.is32bit()) {
116 // Size that a single card covers.
117 final int cardSize = 512;
118
119 final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize;
120 final long heapSizeDiffForCardTable = Math.max(Math.max(allocGranularity * cardSize, HEAP_REGION_SIZE), largePageSize);
121
122 Asserts.assertGT(heapSizeForCardTableUsingLargePages, heapSizeDiffForCardTable,
123 "To test we would require to use an invalid heap size");
124 testVM("case1: card table and bitmap use large pages (barely)", heapSizeForCardTableUsingLargePages, true, true);
125 testVM("case2: card table and bitmap use large pages (extra slack)", heapSizeForCardTableUsingLargePages + heapSizeDiffForCardTable, true, true);
126 testVM("case3: only bitmap uses large pages (barely not)", heapSizeForCardTableUsingLargePages - heapSizeDiffForCardTable, false, true);
127 }
128
129 // Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test
130 // everywhere.
131 final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte
132 final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor;
133 final long heapSizeDiffForBitmap = Math.max(Math.max(allocGranularity * bitmapTranslationFactor, HEAP_REGION_SIZE), largePageSize);
134
135 Asserts.assertGT(heapSizeForBitmapUsingLargePages, heapSizeDiffForBitmap,
136 "To test we would require to use an invalid heap size");
137
138 testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true);
139 testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true);
140 testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false);
141 }
142 }
|