|
24 | 24 | package gc.arguments; |
25 | 25 |
|
26 | 26 | /* |
27 | | - * @test TestMaxRAMFlags |
| 27 | + * @test TestMaxRAMPercentage |
28 | 28 | * @bug 8222252 |
29 | | - * @summary Verify correct MaxHeapSize and UseCompressedOops when MaxRAM and MaxRAMPercentage |
30 | | - * are specified. |
| 29 | + * @summary Verify correct MaxHeapSize and UseCompressedOops when MaxRAMPercentage is specified |
31 | 30 | * @library /test/lib |
32 | 31 | * @library / |
33 | 32 | * @requires vm.bits == "64" |
34 | 33 | * @modules java.base/jdk.internal.misc |
35 | 34 | * java.management |
36 | 35 | * @build jdk.test.whitebox.WhiteBox |
37 | 36 | * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox |
38 | | - * @run driver gc.arguments.TestMaxRAMFlags |
39 | | - * @author bob.vandette@oracle.com |
| 37 | + * @run main/othervm |
| 38 | + * -Xbootclasspath/a:. |
| 39 | + * -XX:+UnlockDiagnosticVMOptions |
| 40 | + * -XX:+WhiteBoxAPI |
| 41 | + * gc.arguments.TestMaxRAMPercentage |
40 | 42 | */ |
41 | 43 |
|
42 | 44 | import java.util.regex.Matcher; |
|
45 | 47 | import java.util.ArrayList; |
46 | 48 | import java.util.Arrays; |
47 | 49 |
|
| 50 | +import jdk.test.whitebox.WhiteBox; |
48 | 51 | import jdk.test.lib.process.OutputAnalyzer; |
| 52 | +import jtreg.SkippedException; |
49 | 53 |
|
50 | | -public class TestMaxRAMFlags { |
| 54 | +public class TestMaxRAMPercentage { |
51 | 55 |
|
52 | | - private static void checkMaxRAMSize(long maxram, int maxrampercent, boolean forcecoop, long expectheap, boolean expectcoop) throws Exception { |
| 56 | + private static final WhiteBox wb = WhiteBox.getWhiteBox(); |
| 57 | + |
| 58 | + private static long getHostMaxMemory() { |
| 59 | + return Long.valueOf(wb.hostPhysicalMemory()); |
| 60 | + } |
| 61 | + |
| 62 | + private static void checkMaxRAMSize(double maxrampercent, boolean forcecoop, long expectheap, boolean expectcoop) throws Exception { |
53 | 63 |
|
54 | 64 | ArrayList<String> args = new ArrayList<String>(); |
55 | | - args.add("-XX:MaxRAM=" + maxram); |
56 | 65 | args.add("-XX:MaxRAMPercentage=" + maxrampercent); |
57 | 66 | if (forcecoop) { |
58 | 67 | args.add("-XX:+UseCompressedOops"); |
@@ -107,21 +116,32 @@ private static boolean getFlagBoolValue(String flag, String where) { |
107 | 116 | } |
108 | 117 |
|
109 | 118 | public static void main(String args[]) throws Exception { |
110 | | - // Tests |
111 | | - // 1. Verify that MaxRAMPercentage overrides UseCompressedOops Ergo |
112 | | - // 2. Verify that UseCompressedOops forces compressed oops limit even |
113 | | - // when other flags are specified. |
114 | | - |
115 | | - long oneG = 1L * 1024L * 1024L * 1024L; |
116 | | - |
117 | 119 | // Hotspot startup logic reduces MaxHeapForCompressedOops by HeapBaseMinAddress |
118 | 120 | // in order to get zero based compressed oops offsets. |
119 | 121 | long heapbaseminaddr = getHeapBaseMinAddress(); |
120 | 122 | long maxcoopheap = TestUseCompressedOopsErgoTools.getMaxHeapForCompressedOops(new String [0]) - heapbaseminaddr; |
121 | 123 |
|
122 | | - // Args: MaxRAM , MaxRAMPercentage, forcecoop, expect heap, expect coop |
123 | | - checkMaxRAMSize(maxcoopheap - oneG, 100, false, maxcoopheap - oneG, true); |
124 | | - checkMaxRAMSize(maxcoopheap + oneG, 100, false, maxcoopheap + oneG, false); |
125 | | - checkMaxRAMSize(maxcoopheap + oneG, 100, true, maxcoopheap, true); |
| 124 | + // The headroom is used to get/not get compressed oops from the maxcoopheap size |
| 125 | + long M = 1L * 1024L * 1024L; |
| 126 | + long headroom = 64 * M; |
| 127 | + |
| 128 | + long requiredHostMemory = maxcoopheap + headroom; |
| 129 | + |
| 130 | + // Get host memory |
| 131 | + long hostMemory = getHostMaxMemory(); |
| 132 | + |
| 133 | + System.out.println("hostMemory: " + hostMemory + ", requiredHostMemory: " + requiredHostMemory); |
| 134 | + |
| 135 | + if (hostMemory < requiredHostMemory) { |
| 136 | + throw new SkippedException("Not enough RAM on machine to run. Test skipped!"); |
| 137 | + } |
| 138 | + |
| 139 | + double MaxRAMPercentage = ((double)maxcoopheap / hostMemory) * 100.0; |
| 140 | + double headroomPercentage = ((double)headroom / hostMemory) * 100.0; |
| 141 | + |
| 142 | + // Args: MaxRAMPercentage, forcecoop, expectheap, expectcoop |
| 143 | + checkMaxRAMSize(MaxRAMPercentage - headroomPercentage, false, maxcoopheap - (long)headroom, true); |
| 144 | + checkMaxRAMSize(MaxRAMPercentage + headroomPercentage, false, maxcoopheap + (long)headroom, false); |
| 145 | + checkMaxRAMSize(MaxRAMPercentage, true, maxcoopheap, true); |
126 | 146 | } |
127 | 147 | } |
0 commit comments