32 * @build TestSmallHeap |
32 * @build TestSmallHeap |
33 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
33 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
34 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestSmallHeap |
34 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestSmallHeap |
35 */ |
35 */ |
36 |
36 |
37 /* Note: It would be nice to verify the minimal supported heap size (2m) here, |
37 /* Note: It would be nice to verify the minimal supported heap size here, |
38 * but we align the heap size based on the card table size. And the card table |
38 * but we align the heap size based on the card table size. And the card table |
39 * size is aligned based on the minimal pages size provided by the os. This |
39 * size is aligned based on the minimal pages size provided by the os. This |
40 * means that on most platforms, where the minimal page size is 4k, we get a |
40 * means that on most platforms, where the minimal page size is 4k, we get a |
41 * minimal heap size of 2m but on Solaris/Sparc we have a page size of 8k and |
41 * minimal heap size of 2m but on Solaris/Sparc we have a page size of 8k and |
42 * get a minimal heap size of 4m. And on platforms where the page size is 64k |
42 * get a minimal heap size of 4m. And on platforms where the page size is 64k |
43 * we get a minimal heap size of 32m. We never use large pages for the card table. |
43 * we get a minimal heap size of 32m. We never use large pages for the card table. |
44 * |
44 * |
45 * There is also no check in the VM for verifying that the maximum heap size |
45 * There is also no check in the VM for verifying that the maximum heap size |
46 * is larger than the supported minimal heap size. This means that specifying |
46 * is larger than the supported minimal heap size. |
47 * -Xmx1m on the command line is fine but will give a heap of 2m (or 4m or 32m). |
|
48 * |
47 * |
49 * To work around these rather strange behaviors this test uses -Xmx2m but then |
48 * To work around these behaviors this test uses -Xmx4m but then |
50 * calculates what the expected heap size should be. The calculation is a |
49 * calculates what the expected heap size should be. The calculation is a |
51 * simplified version of the code in the VM. We assume that the card table will |
50 * simplified version of the code in the VM. We assume that the card table will |
52 * use one page. Each byte in the card table corresponds to 512 bytes on the heap. |
51 * use one page. Each byte in the card table corresponds to 512 bytes on the heap. |
53 * So, the expected heap size is page_size * 512. |
52 * So, the expected heap size is page_size * 512. |
|
53 * |
|
54 * There is no formal requirement for the minimal value of the maximum heap size |
|
55 * the VM should support. In most cases the VM could start with -Xmx2m. |
|
56 * But with 2m limit GC could be triggered before VM initialization completed. |
|
57 * Therefore we start the VM with 4M heap. |
54 */ |
58 */ |
55 |
59 |
56 import jdk.test.lib.Asserts; |
60 import jdk.test.lib.Asserts; |
57 import jdk.test.lib.process.OutputAnalyzer; |
61 import jdk.test.lib.process.OutputAnalyzer; |
58 import jdk.test.lib.process.ProcessTools; |
62 import jdk.test.lib.process.ProcessTools; |
77 verifySmallHeapSize("-XX:+UseG1GC", expectedMaxHeap); |
81 verifySmallHeapSize("-XX:+UseG1GC", expectedMaxHeap); |
78 verifySmallHeapSize("-XX:+UseConcMarkSweepGC", expectedMaxHeap); |
82 verifySmallHeapSize("-XX:+UseConcMarkSweepGC", expectedMaxHeap); |
79 } |
83 } |
80 |
84 |
81 private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception { |
85 private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception { |
|
86 long minMaxHeap = 4 * 1024 * 1024; |
82 LinkedList<String> vmOptions = new LinkedList<>(); |
87 LinkedList<String> vmOptions = new LinkedList<>(); |
83 vmOptions.add(gc); |
88 vmOptions.add(gc); |
84 vmOptions.add("-Xmx2m"); |
89 vmOptions.add("-Xmx" + minMaxHeap); |
85 vmOptions.add("-XX:+PrintFlagsFinal"); |
90 vmOptions.add("-XX:+PrintFlagsFinal"); |
86 vmOptions.add(VerifyHeapSize.class.getName()); |
91 vmOptions.add(VerifyHeapSize.class.getName()); |
87 |
92 |
88 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[0])); |
93 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[0])); |
89 OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); |
94 OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); |
90 analyzer.shouldHaveExitValue(0); |
95 analyzer.shouldHaveExitValue(0); |
91 |
96 |
|
97 expectedMaxHeap = Math.max(expectedMaxHeap, minMaxHeap); |
92 long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1)); |
98 long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1)); |
93 long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1)); |
99 long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1)); |
94 Asserts.assertEQ(maxHeapSize, expectedMaxHeap); |
100 Asserts.assertEQ(maxHeapSize, expectedMaxHeap); |
95 Asserts.assertLessThanOrEqual(actualHeapSize, maxHeapSize); |
101 Asserts.assertLessThanOrEqual(actualHeapSize, maxHeapSize); |
96 } |
102 } |