Skip to content

Commit 58f13e7

Browse files
authored
Merge pull request #302 from jmtd/tuning-override
[OPENJDK-78] Re-work JAVA_OPTS to override script-calculated java options
2 parents 9b73a12 + 9e0e1c9 commit 58f13e7

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,14 @@ load_env() {
103103
fi
104104
}
105105

106-
# Check for standard /opt/run-java-options first, fallback to run-java-options in the path if not existing
107-
run_java_options() {
108-
if [ -f "/opt/run-java-options" ]; then
109-
echo `sh /opt/run-java-options`
110-
else
111-
type -p run-java-options >/dev/null 2>&1
112-
if [ $? = 0 ]; then
113-
echo `run-java-options`
114-
fi
115-
fi
116-
}
117-
118106
# Combine all java options
119107
get_java_options() {
120-
local java_opts
108+
local jvm_opts
121109
local debug_opts
110+
local proxy_opts
111+
local opts
122112
if [ -f "${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options" ]; then
123-
java_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options)
113+
jvm_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options)
124114
fi
125115
if [ -f "${JBOSS_CONTAINER_JAVA_JVM_MODULE}/debug-options" ]; then
126116
debug_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/debug-options)
@@ -129,8 +119,10 @@ get_java_options() {
129119
source "${JBOSS_CONTAINER_JAVA_PROXY_MODULE}/proxy-options"
130120
proxy_opts="$(proxy_options)"
131121
fi
132-
# Normalize spaces with awk (i.e. trim and elimate double spaces)
133-
echo "${JAVA_OPTS} $(run_java_options) ${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'
134126
}
135127

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

tests/features/java/runtime.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,27 @@ 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
28+
29+
@ubi9
30+
Scenario: Check JAVA_OPTS overrides JAVA_OPTS_APPEND
31+
piv
32+
Given container is started with env
33+
| variable | value |
34+
| JAVA_OPTS | -verbose:gc |
35+
| JAVA_OPTS_APPEND | -Xint |
36+
Then container log should contain -verbose:gc
37+
And container log should not contain -Xint

0 commit comments

Comments
 (0)