Skip to content

Commit 0c3b45f

Browse files
committed
8378319: Obsolete the MaxRAM flag
1 parent d02ac57 commit 0c3b45f

File tree

10 files changed

+76
-87
lines changed

10 files changed

+76
-87
lines changed

src/hotspot/share/gc/shared/gc_globals.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,13 @@
269269
product(bool, AlwaysActAsServerClassMachine, false, \
270270
"(Deprecated) Always act like a server-class machine") \
271271
\
272-
product(uint64_t, MaxRAM, 0, \
273-
"(Deprecated) Real memory size (in bytes) used to set maximum " \
274-
"heap size") \
275-
range(0, 0XFFFFFFFFFFFFFFFF) \
276-
\
277272
product(bool, AggressiveHeap, false, \
278273
"(Deprecated) Optimize heap options for long-running memory " \
279274
"intensive apps") \
280275
\
281276
product(size_t, ErgoHeapSizeLimit, 0, \
282277
"Maximum ergonomically set heap size (in bytes); zero means use " \
283-
"MaxRAM * MaxRAMPercentage / 100") \
278+
"(System RAM) * MaxRAMPercentage / 100") \
284279
range(0, max_uintx) \
285280
\
286281
product(double, MaxRAMPercentage, 25.0, \

src/hotspot/share/runtime/arguments.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ static SpecialFlag const special_jvm_flags[] = {
538538
#endif
539539
{ "ParallelRefProcEnabled", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
540540
{ "ParallelRefProcBalancingEnabled", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
541-
{ "MaxRAM", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
542541
{ "AggressiveHeap", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
543542
{ "NeverActAsServerClassMachine", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
544543
{ "AlwaysActAsServerClassMachine", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
@@ -553,6 +552,7 @@ static SpecialFlag const special_jvm_flags[] = {
553552
#endif
554553

555554
{ "PSChunkLargeArrays", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
555+
{ "MaxRAM", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) },
556556

557557
#ifdef ASSERT
558558
{ "DummyObsoleteTestFlag", JDK_Version::undefined(), JDK_Version::jdk(18), JDK_Version::undefined() },
@@ -1510,25 +1510,19 @@ void Arguments::set_heap_size() {
15101510
// Check if the user has configured any limit on the amount of RAM we may use.
15111511
bool has_ram_limit = !FLAG_IS_DEFAULT(MaxRAMPercentage) ||
15121512
!FLAG_IS_DEFAULT(MinRAMPercentage) ||
1513-
!FLAG_IS_DEFAULT(InitialRAMPercentage) ||
1514-
!FLAG_IS_DEFAULT(MaxRAM);
1513+
!FLAG_IS_DEFAULT(InitialRAMPercentage);
15151514

1516-
if (FLAG_IS_DEFAULT(MaxRAM)) {
1517-
if (CompilerConfig::should_set_client_emulation_mode_flags()) {
1518-
// Limit the available memory if client emulation mode is enabled.
1519-
FLAG_SET_ERGO(MaxRAM, 1ULL*G);
1520-
} else {
1521-
// Use the available physical memory on the system.
1522-
FLAG_SET_ERGO(MaxRAM, os::physical_memory());
1523-
}
1524-
}
1515+
// Limit the available memory if client emulation mode is enabled.
1516+
const size_t phys_mem = CompilerConfig::should_set_client_emulation_mode_flags()
1517+
? 1ULL*G
1518+
: os::physical_memory();
15251519

15261520
// If the maximum heap size has not been set with -Xmx, then set it as
15271521
// fraction of the size of physical memory, respecting the maximum and
15281522
// minimum sizes of the heap.
15291523
if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1530-
uint64_t min_memory = (uint64_t)(((double)MaxRAM * MinRAMPercentage) / 100);
1531-
uint64_t max_memory = (uint64_t)(((double)MaxRAM * MaxRAMPercentage) / 100);
1524+
uint64_t min_memory = (uint64_t)(((double)phys_mem * MinRAMPercentage) / 100);
1525+
uint64_t max_memory = (uint64_t)(((double)phys_mem * MaxRAMPercentage) / 100);
15321526

15331527
const size_t reasonable_min = clamp_by_size_t_max(min_memory);
15341528
size_t reasonable_max = clamp_by_size_t_max(max_memory);
@@ -1615,7 +1609,7 @@ void Arguments::set_heap_size() {
16151609
reasonable_minimum = limit_heap_by_allocatable_memory(reasonable_minimum);
16161610

16171611
if (InitialHeapSize == 0) {
1618-
uint64_t initial_memory = (uint64_t)(((double)MaxRAM * InitialRAMPercentage) / 100);
1612+
uint64_t initial_memory = (uint64_t)(((double)phys_mem * InitialRAMPercentage) / 100);
16191613
size_t reasonable_initial = clamp_by_size_t_max(initial_memory);
16201614
reasonable_initial = limit_heap_by_allocatable_memory(reasonable_initial);
16211615

src/java.base/share/man/java.md

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,8 +2454,8 @@ Java HotSpot VM.
24542454

24552455
[`-XX:InitialRAMPercentage=`]{#-XX_InitialRAMPercentage}*percent*
24562456
: Sets the initial amount of memory that the JVM will use for the Java heap
2457-
before applying ergonomics heuristics as a percentage of the maximum amount
2458-
determined as described in the `-XX:MaxRAM` option.
2457+
before applying ergonomics heuristics as a percentage of the available memory
2458+
to the JVM process.
24592459

24602460
The following example shows how to set the percentage of the initial
24612461
amount of memory used for the Java heap:
@@ -2575,9 +2575,8 @@ Java HotSpot VM.
25752575

25762576
[`-XX:MaxRAMPercentage=`]{#-XX_MaxRAMPercentage}*percent*
25772577
: Sets the maximum amount of memory that the JVM may use for the Java heap
2578-
before applying ergonomics heuristics as a percentage of the maximum amount
2579-
determined as described in the `-XX:MaxRAM` option. The default value is 25
2580-
percent.
2578+
before applying ergonomics heuristics as a percentage of the available memory
2579+
to the JVM process. The default value is 25 percent.
25812580

25822581
Specifying this option disables automatic use of compressed oops if
25832582
the combined result of this and other options influencing the maximum amount
@@ -2591,9 +2590,9 @@ Java HotSpot VM.
25912590

25922591
[`-XX:MinRAMPercentage=`]{#-XX_MinRAMPercentage}*percent*
25932592
: Sets the maximum amount of memory that the JVM may use for the Java heap
2594-
before applying ergonomics heuristics as a percentage of the maximum amount
2595-
determined as described in the `-XX:MaxRAM` option for small heaps. A small
2596-
heap is a heap of approximately 125 MB. The default value is 50 percent.
2593+
before applying ergonomics heuristics as a percentage of the available memory
2594+
to the JVM process for small heaps. A small heap is a heap of approximately
2595+
125 MB. The default value is 50 percent.
25972596

25982597
The following example shows how to set the percentage of the maximum amount
25992598
of memory used for the Java heap for small heaps:
@@ -2939,25 +2938,6 @@ they're used.
29392938
(`-XX:+UseParallelGC` or `-XX:+UseG1GC`). Other collectors employing multiple
29402939
threads always perform reference processing in parallel.
29412940

2942-
[`-XX:MaxRAM=`]{#-XX_MaxRAM}*size*
2943-
: Sets the maximum amount of memory that the JVM may use for the Java heap
2944-
before applying ergonomics heuristics. The default value is the amount of
2945-
available memory to the JVM process.
2946-
2947-
The maximum amount of available memory to the JVM process is the minimum
2948-
of the machine's physical memory and any constraints set by the environment
2949-
(e.g. container).
2950-
2951-
Specifying this option disables automatic use of compressed oops if
2952-
the combined result of this and other options influencing the maximum amount
2953-
of memory is larger than the range of memory addressable by compressed oops.
2954-
See `-XX:UseCompressedOops` for further information about compressed oops.
2955-
2956-
The following example shows how to set the maximum amount of available
2957-
memory for sizing the Java heap to 2 GB:
2958-
2959-
> `-XX:MaxRAM=2G`
2960-
29612941
[`-XX:+AggressiveHeap`]{#-XX__AggressiveHeap}
29622942
: Enables Java heap optimization. This sets various parameters to be
29632943
optimal for long-running jobs with intensive memory allocation, based on
@@ -2967,8 +2947,8 @@ they're used.
29672947
[`-XX:+NeverActAsServerClassMachine`]{#-XX__NeverActAsServerClassMachine}
29682948
: Enable the "Client VM emulation" mode which only uses the C1 JIT compiler,
29692949
a 32Mb CodeCache and the Serial GC. The maximum amount of memory that the
2970-
JVM may use (controlled by the `-XX:MaxRAM=n` flag) is set to 1GB by default.
2971-
The string "emulated-client" is added to the JVM version string.
2950+
JVM may use is set to 1GB by default. The string "emulated-client" is added
2951+
to the JVM version string.
29722952

29732953
By default the flag is set to `true` only on Windows in 32-bit mode and
29742954
`false` in all other cases.

test/hotspot/gtest/runtime/test_globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TEST_VM(FlagGuard, size_t_flag) {
5858
}
5959

6060
TEST_VM(FlagGuard, uint64_t_flag) {
61-
TEST_FLAG(MaxRAM, uint64_t, 1337);
61+
TEST_FLAG(ErrorLogTimeout, uint64_t, 1337);
6262
}
6363

6464
TEST_VM(FlagGuard, double_flag) {

test/hotspot/jtreg/gc/arguments/TestMaxRAMFlags.java renamed to test/hotspot/jtreg/gc/arguments/TestMaxRAMPercentage.java

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424
package gc.arguments;
2525

2626
/*
27-
* @test TestMaxRAMFlags
27+
* @test TestMaxRAMPercentage
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.TestMaxRAMPercentage
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

50-
public class TestMaxRAMFlags {
54+
public class TestMaxRAMPercentage {
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");
@@ -107,21 +116,32 @@ private static boolean getFlagBoolValue(String flag, String where) {
107116
}
108117

109118
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-
117119
// Hotspot startup logic reduces MaxHeapForCompressedOops by HeapBaseMinAddress
118120
// in order to get zero based compressed oops offsets.
119121
long heapbaseminaddr = getHeapBaseMinAddress();
120122
long maxcoopheap = TestUseCompressedOopsErgoTools.getMaxHeapForCompressedOops(new String [0]) - heapbaseminaddr;
121123

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);
126146
}
127147
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
/*
2727
* @test TestUseCompressedOopsFlagsWithUlimit
2828
* @bug 8280761
29-
* @summary Verify correct UseCompressedOops when MaxRAM and MaxRAMPercentage
30-
* are specified with ulimit -v.
29+
* @summary Verify that ergonomic setting of UseCompressedOops adheres to ulimit -v
3130
* @library /test/lib
3231
* @library /
3332
* @requires vm.bits == "64"
@@ -50,10 +49,9 @@
5049

5150
public class TestUseCompressedOopsFlagsWithUlimit {
5251

53-
private static void checkFlag(long ulimit, long maxram, int maxrampercent, boolean expectcoop) throws Exception {
52+
private static void checkFlag(long ulimit, int maxrampercent, boolean expectcoop) throws Exception {
5453

5554
ArrayList<String> args = new ArrayList<String>();
56-
args.add("-XX:MaxRAM=" + maxram);
5755
args.add("-XX:MaxRAMPercentage=" + maxrampercent);
5856
args.add("-XX:+PrintFlagsFinal");
5957

@@ -74,7 +72,7 @@ private static void checkFlag(long ulimit, long maxram, int maxrampercent, boole
7472
boolean actualcoop = getFlagBoolValue("UseCompressedOops", stdout);
7573
if (actualcoop != expectcoop) {
7674
throw new RuntimeException("UseCompressedOops set to " + actualcoop +
77-
", expected " + expectcoop + " when running with the following flags: " + Arrays.asList(args).toString());
75+
", expected " + expectcoop + " when running with the following flags: " + Arrays.asList(args).toString() + ", and ulimit: " + ulimit);
7876
}
7977
}
8078

@@ -91,10 +89,13 @@ public static void main(String args[]) throws Exception {
9189
// Verify that UseCompressedOops Ergo follows ulimit -v setting.
9290

9391
long oneG = 1L * 1024L * 1024L * 1024L;
92+
long ulimit = 10 * oneG;
9493

95-
// Args: ulimit, max_ram, max_ram_percent, expected_coop
96-
// Setting MaxRAMPercentage explicitly to make the test more resilient.
97-
checkFlag(10 * oneG, 32 * oneG, 100, true);
98-
checkFlag(10 * oneG, 128 * oneG, 100, true);
94+
// Regardless of how much memory that is available on the machine, we should
95+
// always get compressed oops if we have set a ulimit below the COOPS limit.
96+
// We set MaxRAMPercentage explicitly to make the test more resilient.
97+
98+
// Args: ulimit, maxrampercent, expectedcoop
99+
checkFlag(ulimit, 100, true);
99100
}
100101
}

test/hotspot/jtreg/gc/g1/TestRegionAlignment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
* @bug 8013791
2929
* @requires vm.gc.G1
3030
* @summary Make sure that G1 ergonomics pick a heap size that is aligned with the region size
31-
* @run main/othervm -XX:+UseG1GC -XX:G1HeapRegionSize=32m -XX:MaxRAM=555m gc.g1.TestRegionAlignment
32-
*
33-
* When G1 ergonomically picks a maximum heap size it must be aligned to the region size.
34-
* This test tries to get the VM to pick a small and unaligned heap size (by using MaxRAM=555) and a
35-
* large region size (by using -XX:G1HeapRegionSize=32m). This will fail without the fix for 8013791.
31+
* @comment When G1 ergonomically picks a maximum heap size it must be aligned to the region size.
32+
* This test tries to get the VM to pick a small and unaligned heap size (by using MaxRAM=555) and a
33+
* large region size (by using -XX:G1HeapRegionSize=32m). This will fail without the fix for 8013791.
34+
* @run main/othervm -XX:+UseG1GC -XX:G1HeapRegionSize=32m -Xmx140m gc.g1.TestRegionAlignment
3635
*/
36+
3737
public class TestRegionAlignment {
3838
public static void main(String[] args) { }
3939
}

test/hotspot/jtreg/runtime/7167069/PrintAsFlag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @test PrintAsFlag
2929
* @summary verify that Flag::print_as_flag() works correctly. This is used by "jinfo -flag" and -XX:+PrintCommandLineFlags.
30-
* @run main/othervm -XX:+PrintCommandLineFlags -XX:-ShowMessageBoxOnError -XX:ParallelGCThreads=4 -XX:MaxRAM=1G -XX:ErrorFile="file" PrintAsFlag
30+
* @run main/othervm -XX:+PrintCommandLineFlags -XX:-ShowMessageBoxOnError -XX:ParallelGCThreads=4 -XX:ErrorLogTimeout=12345 -XX:ErrorFile="file" PrintAsFlag
3131
*/
3232

3333
public class PrintAsFlag {

test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ public static void main(String[] args) throws Exception {
237237
excludeTestMaxRange("G1ConcRefinementThreads");
238238
excludeTestMaxRange("InitialHeapSize");
239239
excludeTestMaxRange("MaxHeapSize");
240-
excludeTestMaxRange("MaxRAM");
241240
excludeTestMaxRange("NewSize");
242241
excludeTestMaxRange("ParallelGCThreads");
243242
excludeTestMaxRange("TLABSize");

test/lib-test/jdk/test/whitebox/vm_flags/Uint64Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636

3737
public class Uint64Test {
38-
private static final String FLAG_NAME = "MaxRAM";
38+
private static final String FLAG_NAME = "StringDeduplicationHashSeed";
3939
private static final Long[] TESTS = {0L, 100L, (long) Integer.MAX_VALUE,
4040
-1L, Long.MAX_VALUE, Long.MIN_VALUE};
4141

0 commit comments

Comments
 (0)