Skip to content

Commit 51262e5

Browse files
committed
[OPENJDK-1523] accept integers for JAVA_*_MEM_RATIO
This is a cherry-pick-and-fixup of OPENJDK-1510 (06a5d27) on the ubi8 branch, to have consistency in the handling of JAVA_MAX_MEM_RATIO between the ubi8 and ubi9 images. Signed-off-by: Jonathan Dowland <[email protected]>
1 parent ec80b28 commit 51262e5

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

modules/jvm/artifacts/opt/jboss/container/java/jvm/java-default-options

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,18 @@ fi
2121

2222
# Check for memory options and calculate a sane default if not given
2323
max_memory() {
24-
# Check if explicitly disabled
25-
if [ "x$JAVA_MAX_MEM_RATIO" = "x0" ]; then
26-
return
27-
fi
28-
echo "-XX:MaxRAMPercentage=${JAVA_MAX_MEM_RATIO:-80.0}"
24+
case "$JAVA_MAX_MEM_RATIO" in
25+
"0") # explicitly disabled
26+
return
27+
;;
28+
"")
29+
maxmem="80.0"
30+
;;
31+
*)
32+
maxmem="$(printf "%.0f.0" "$JAVA_MAX_MEM_RATIO")"
33+
;;
34+
esac
35+
echo "-XX:MaxRAMPercentage=$maxmem"
2936
}
3037

3138
# Switch on diagnostics except when switched off

modules/jvm/module.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ envs:
2525
This variable has no effect if `JAVA_OPTS` has been defined.
2626
example: "-Dsome.property=foo"
2727
- name: JAVA_MAX_MEM_RATIO
28-
description: Specify the maximum heap memory. Corresponds to the JVM argument `-XX:MaxRAMPercentage`. The default is `80.0` which means 80% of the available memory. You can disable this mechanism by setting the value to `0`.
28+
description: Specify the maximum heap memory. Corresponds to the JVM argument `-XX:MaxRAMPercentage`. The default is `80.0` which means 80% of the available memory. You can disable this mechanism by setting the value to `0`. The supplied value can be an integer or float, but only the whole number part is used.
2929
example: "90.0"
3030
- name: JAVA_DIAGNOSTICS
3131
description: "Set this to get some diagnostics information to standard output when things are happening. **Note: ** This option, if set to true, will set `-XX :+UnlockDiagnosticVMOptions`. **Disabled by default.**"

tests/features/java/memory.feature

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@ Feature: OPENJDK-559 JVM Memory tests
66
Then container log should contain -XX:MaxRAMPercentage=80.0
77

88
@ubi9
9-
Scenario: Check configured JVM max heap configuration
9+
Scenario: Check configured JVM max heap configuration and ensure JAVA_MAX_MEM_RATIO accepts floats but only takes whole number part
1010
Given container is started with env
1111
| variable | value |
12-
| JAVA_MAX_MEM_RATIO | 90.0 |
12+
| JAVA_MAX_MEM_RATIO | 90.4 |
1313
Then container log should contain -XX:MaxRAMPercentage=90.0
1414

15+
@ubi9
16+
Scenario: Ensure JAVA_MAX_MEM_RATIO accepts Integers
17+
Given container is started with env
18+
| variable | value |
19+
| JAVA_MAX_MEM_RATIO | 90 |
20+
Then container log should contain -XX:MaxRAMPercentage=90.0
21+
22+
@ubi9
23+
Scenario: Ensure JAVA_MAX_MEM_RATIO=0 disables parameter
24+
Given container is started with env
25+
| variable | value |
26+
| JAVA_MAX_MEM_RATIO | 0 |
27+
Then container log should not contain -XX:MaxRAMPercentage
28+
1529
@ubi9
1630
Scenario: Check default JVM initial heap configuration is unspecified
1731
Given container is started as uid 1000

0 commit comments

Comments
 (0)