Skip to content

Commit 6c59e7e

Browse files
committed
Rework TestMaxRAMFlags.java
1 parent 8c2ba85 commit 6c59e7e

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

test/hotspot/jtreg/gc/arguments/TestMaxRAMFlags.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@
2626
/*
2727
* @test TestMaxRAMFlags
2828
* @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
3130
* @library /test/lib
3231
* @library /
3332
* @requires vm.bits == "64"
3433
* @modules java.base/jdk.internal.misc
3534
* java.management
3635
* @build jdk.test.whitebox.WhiteBox
3736
* @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.TestMaxRAMFlags
4042
*/
4143

4244
import java.util.regex.Matcher;
@@ -45,14 +47,21 @@
4547
import java.util.ArrayList;
4648
import java.util.Arrays;
4749

50+
import jdk.test.whitebox.WhiteBox;
4851
import jdk.test.lib.process.OutputAnalyzer;
52+
import jtreg.SkippedException;
4953

5054
public class TestMaxRAMFlags {
5155

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 {
5363

5464
ArrayList<String> args = new ArrayList<String>();
55-
args.add("-XX:MaxRAM=" + maxram);
5665
args.add("-XX:MaxRAMPercentage=" + maxrampercent);
5766
if (forcecoop) {
5867
args.add("-XX:+UseCompressedOops");
@@ -108,20 +117,29 @@ private static boolean getFlagBoolValue(String flag, String where) {
108117

109118
public static void main(String args[]) throws Exception {
110119
// 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.
114120

115-
long oneG = 1L * 1024L * 1024L * 1024L;
121+
long M = 1L * 1024L * 1024L;
116122

117123
// Hotspot startup logic reduces MaxHeapForCompressedOops by HeapBaseMinAddress
118124
// in order to get zero based compressed oops offsets.
119125
long heapbaseminaddr = getHeapBaseMinAddress();
120126
long maxcoopheap = TestUseCompressedOopsErgoTools.getMaxHeapForCompressedOops(new String [0]) - heapbaseminaddr;
121127

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);
128+
double headroom = (double)64 * M;
129+
130+
// Get host memory
131+
long hostMemory = getHostMaxMemory();
132+
133+
if (hostMemory > (maxcoopheap + headroom)) {
134+
double MaxRAMPercentage = ((double)maxcoopheap / hostMemory) * 100.0;
135+
double headroomPercentage = ((double)headroom / hostMemory) * 100.0;
136+
137+
// Args: MaxRAMPercentage, forcecoop, expect heap, expect coop
138+
checkMaxRAMSize(MaxRAMPercentage - headroomPercentage, false, maxcoopheap - (long)headroom, true);
139+
checkMaxRAMSize(MaxRAMPercentage + headroomPercentage, false, maxcoopheap + (long)headroom, false);
140+
checkMaxRAMSize(MaxRAMPercentage, true, maxcoopheap, true);
141+
} else {
142+
throw new SkippedException("Not enough RAM on machine to run. Test skipped!");
143+
}
126144
}
127145
}

0 commit comments

Comments
 (0)