Skip to content

Commit ed65182

Browse files
committed
[OPENJDK-78] allow JAVA_OPTS to override options processing
If JAVA_OPTS is defined, don't attempt to expand the various options we might otherwise provide: debug options, proxy settings, JVM/GC tuning, etc. https://issues.redhat.com/browse/OPENJDK-78 Signed-off-by: Jonathan Dowland <[email protected]>
1 parent 94b5829 commit ed65182

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

modules/jvm/module.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ envs:
1616
- name: JBOSS_CONTAINER_JAVA_JVM_MODULE
1717
value: /opt/jboss/container/java/jvm
1818
- name: JAVA_OPTS
19-
description: JVM options passed to the `java` command.
19+
description: If set, this prevents all default and generated options (such
20+
as JVM and GC tuning, proxy settings, etc.) from being applied. Instead the
21+
user should specify exactly the `java` options they want in this variable.
2022
example: "-verbose:class"
2123
- name: JAVA_OPTS_APPEND
22-
description: User specified Java options to be appended to generated options in JAVA_OPTS.
24+
description: User specified Java options to be appended to the generated options.
25+
This variable has no effect if `JAVA_OPTS` has been defined.
2326
example: "-Dsome.property=foo"
2427
- name: JAVA_MAX_MEM_RATIO
2528
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`.

modules/run/artifacts/opt/jboss/container/java/run/run-java.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ load_env() {
105105

106106
# Combine all java options
107107
get_java_options() {
108-
local java_opts
108+
local jvm_opts
109109
local debug_opts
110+
local proxy_opts
111+
local opts
110112
if [ -f "${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options" ]; then
111-
java_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options)
113+
jvm_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options)
112114
fi
113115
if [ -f "${JBOSS_CONTAINER_JAVA_JVM_MODULE}/debug-options" ]; then
114116
debug_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/debug-options)
@@ -117,8 +119,10 @@ get_java_options() {
117119
source "${JBOSS_CONTAINER_JAVA_PROXY_MODULE}/proxy-options"
118120
proxy_opts="$(proxy_options)"
119121
fi
120-
# Normalize spaces with awk (i.e. trim and elimate double spaces)
121-
echo "${JAVA_OPTS} ${debug_opts} ${proxy_opts} ${java_opts} ${JAVA_OPTS_APPEND}" | awk '$1=$1'
122+
123+
opts=${JAVA_OPTS-${debug_opts} ${proxy_opts} ${jvm_opts} ${JAVA_OPTS_APPEND}}
124+
# Normalize spaces with awk (i.e. trim and eliminate double spaces)
125+
echo "${opts}" | awk '$1=$1'
122126
}
123127

124128
# Read in a classpath either from a file with a single line, colon separated

tests/features/java/runtime.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ Feature: Openshift OpenJDK Runtime tests
1111
And container log should contain -XX:NativeMemoryTracking=summary
1212
And file /usr/local/s2i/run should not contain JVM_ARGS
1313
And container log should not contain unique unique
14+
15+
@ubi9
16+
Scenario: Check JAVA_OPTS overrides defaults
17+
Given container is started with env
18+
| variable | value |
19+
| JAVA_OPTS | --show-version |
20+
Then container log should not contain -XX:MaxRAMPercentage
21+
22+
@ubi9
23+
Scenario: Check empty JAVA_OPTS overrides defaults
24+
Given container is started with env
25+
| variable | value |
26+
| JAVA_OPTS | |
27+
Then container log should not contain -XX:MaxRAMPercentage

0 commit comments

Comments
 (0)