Skip to content

Commit 106bdf8

Browse files
authored
Add dh-defaults.vmoptions file (#3057)
Consolidates the recommended VM options into a single place. Allows for these options to be defined in a single place. Moves dh-compiler-directives.txt and dh-defaults.vmoptions into the etc directory (instead of in lib alongside the jars). Fixes #3054
1 parent 9f875a1 commit 106bdf8

9 files changed

Lines changed: 59 additions & 28 deletions

File tree

buildSrc/src/main/groovy/io.deephaven.java-toolchain-conventions.gradle

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ tasks.withType(JavaCompile).configureEach {
9292

9393
def createCompilerDirectives = tasks.register('createCompilerDirectives') {
9494
def compilerDirectivesFile = project.layout.buildDirectory.file('dh-compiler-directives.txt')
95+
def compilerDirectivesText = new JsonBuilder([{
96+
match (['*.*'] as List)
97+
// Note: there seems to be a bug where this option doesn't actually get picked up
98+
// So using '-XX:DisableIntrinsic=_currentThread' explicitly
99+
// DisableIntrinsic('_currentThread')
100+
}]).toPrettyString()
101+
it.inputs.property('compilerDirectivesText', compilerDirectivesText)
95102
it.outputs.file(compilerDirectivesFile)
96-
97103
doFirst {
98-
def builder = new JsonBuilder([{
99-
match (['*.*'] as List)
100-
// Note: there seems to be a bug where this option doesn't actually get picked up
101-
// So using '-XX:DisableIntrinsic=_currentThread' explicitly
102-
// DisableIntrinsic('_currentThread')
103-
}])
104-
compilerDirectivesFile.get().asFile.text = builder.toPrettyString()
104+
compilerDirectivesFile.get().asFile.text = compilerDirectivesText
105105
}
106106
}
107107

@@ -123,30 +123,62 @@ def devJvmArgs = [
123123
// '-XX:+PrintCompilation', // this optional line shows jit operations as they happen
124124
]
125125

126+
// These are supposed to be generally applicable and recommended JVM options, but they aren't hard requirements.
127+
// Overly specific options do *not* belong here. For example, we should _not_ be setting something like `-Xmx4g` here.
128+
// If you are tempted to try and put system properties here (`-Dkey=value`), think again; there should be a more
129+
// appropriate place to set those.
130+
//
131+
// From the perspective of our application distribution, these options will be used as defaults for JAVA_OPTS
132+
// (if the user already has JAVA_OPTS set, these VM options will _not_ apply).
133+
def defaultJvmOptions = [
134+
'-XX:+UseG1GC',
135+
'-XX:MaxGCPauseMillis=100',
136+
'-XX:+UseStringDeduplication',
137+
]
138+
139+
def createVmOptions = tasks.register('createVmOptions') {
140+
def vmOptionsFile = project.layout.buildDirectory.file('dh-default.vmoptions')
141+
def vmOptionsText = defaultJvmOptions.join('\n')
142+
it.inputs.property('vmOptionsText', vmOptionsText)
143+
it.outputs.file(vmOptionsFile)
144+
doFirst {
145+
vmOptionsFile.get().asFile.text = vmOptionsText
146+
}
147+
}
148+
126149
tasks.withType(JavaExec).configureEach {
127150
def compilerDirectivesFile = createCompilerDirectives.get().outputs.files
151+
def vmOptionsFile = createVmOptions.get().outputs.files
128152
inputs.files compilerDirectivesFile
153+
inputs.files vmOptionsFile
129154
javaLauncher.set runtimeLauncher
130-
jvmArgs += compilerArgs(compilerDirectivesFile.singleFile.path) + devJvmArgs
155+
// Note: we _could_ have the vmOptionsFile constituents directly listed instead of using -XX:VMOptionsFile.
156+
// That said, the current approach used here more closely matches how the application start script is defined.
157+
jvmArgs += compilerArgs(compilerDirectivesFile.singleFile.path) + ["-XX:VMOptionsFile=${vmOptionsFile.singleFile.path}"] + devJvmArgs
131158
}
132159

133160
tasks.withType(Test).configureEach {
134161
def compilerDirectivesFile = createCompilerDirectives.get().outputs.files
162+
def vmOptionsFile = createVmOptions.get().outputs.files
135163
inputs.files compilerDirectivesFile
136-
164+
inputs.files vmOptionsFile
137165
javaLauncher.set testRuntimeLauncher
138-
jvmArgs += compilerArgs(compilerDirectivesFile.singleFile.path) + devJvmArgs
166+
// Note: we _could_ have the vmOptionsFile constituents directly listed instead of using -XX:VMOptionsFile.
167+
// That said, the current approach used here more closely matches how the application start script is defined.
168+
jvmArgs += compilerArgs(compilerDirectivesFile.singleFile.path) + ["-XX:VMOptionsFile=${vmOptionsFile.singleFile.path}"] + devJvmArgs
139169
}
140170

141171
tasks.withType(GroovyCompile).configureEach {
142172
javaLauncher.set groovyCompilerLauncher
143173
}
144174

145175
plugins.withType(ApplicationPlugin) {
146-
applicationDistribution.into('lib') {
176+
applicationDistribution.into('etc') {
147177
from(createCompilerDirectives.get().outputs.files)
178+
from(createVmOptions.get().outputs.files)
148179
}
149180
}
181+
150182
tasks.withType(CreateStartScripts).configureEach {
151183
def unixStartScript = resources.text.fromUri(getClass().classLoader.getResource('unixStartScript.txt'))
152184
inputs.files unixStartScript

buildSrc/src/main/resources/unixStartScript.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ APP_BASE_NAME=`basename "\$0"`
4747
DEFAULT_JVM_OPTS=${defaultJvmOpts}
4848

4949
# Customization for deephaven-core to reference a compiler directives file
50-
DEFAULT_JVM_OPTS="\${DEFAULT_JVM_OPTS} -XX:+UnlockDiagnosticVMOptions -XX:CompilerDirectivesFile=\"\${APP_HOME}/lib/dh-compiler-directives.txt\""
50+
# There is no easy way for users to override these options
51+
DEFAULT_JVM_OPTS="\${DEFAULT_JVM_OPTS} -XX:+UnlockDiagnosticVMOptions -XX:CompilerDirectivesFile=\"\${APP_HOME}/etc/dh-compiler-directives.txt\""
52+
53+
# Customization for deephaven-core to include vm options file by default
54+
# If users explicitly set JAVA_OPTS, they will be opting out of dh-default.vmoptions
55+
DH_DEFAULT_VMOPTIONS="-XX:VMOptionsFile=\"\${APP_HOME}/etc/dh-default.vmoptions\""
56+
JAVA_OPTS="\${JAVA_OPTS:-\${DH_DEFAULT_VMOPTIONS}}"
5157

5258
# Use the maximum available, or set MAX_FD != -1 to use that value.
5359
MAX_FD="maximum"

docker/server-jetty/src/main/docker/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ HEALTHCHECK --interval=3s --retries=3 --timeout=11s CMD /bin/grpc_health_probe -
3232
ENV \
3333
DEEPHAVEN_CACHE_DIR="/cache" \
3434
DEEPHAVEN_CONFIG_DIR="/opt/deephaven/config" \
35-
DEEPHAVEN_DATA_DIR="/data" \
36-
JAVA_OPTS="-XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:+UseStringDeduplication"
35+
DEEPHAVEN_DATA_DIR="/data"
3736
ENTRYPOINT [ "/opt/deephaven/server/bin/start" ]
3837
ARG DEEPHAVEN_VERSION
3938
ARG SERVER

docker/server-slim/src/main/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ENV \
3232
DEEPHAVEN_CACHE_DIR="/cache" \
3333
DEEPHAVEN_CONFIG_DIR="/opt/deephaven/config" \
3434
DEEPHAVEN_DATA_DIR="/data" \
35-
JAVA_OPTS="-XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:+UseStringDeduplication -Ddeephaven.console.type=groovy"
35+
START_OPTS="-Ddeephaven.console.type=groovy"
3636
ENTRYPOINT [ "/opt/deephaven/server/bin/start" ]
3737

3838
ARG DEEPHAVEN_VERSION

docker/server/src/main/docker/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ HEALTHCHECK --interval=3s --retries=3 --timeout=11s CMD /bin/grpc_health_probe -
3232
ENV \
3333
DEEPHAVEN_CACHE_DIR="/cache" \
3434
DEEPHAVEN_CONFIG_DIR="/opt/deephaven/config" \
35-
DEEPHAVEN_DATA_DIR="/data" \
36-
JAVA_OPTS="-XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:+UseStringDeduplication"
35+
DEEPHAVEN_DATA_DIR="/data"
3736
ENTRYPOINT [ "/opt/deephaven/server/bin/start" ]
3837
ARG DEEPHAVEN_VERSION
3938
ARG SERVER

py/embedded-server/deephaven_server/start_jvm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def _jars_path():
1717
def _compiler_directives():
1818
return _jars_path() / 'dh-compiler-directives.txt'
1919

20+
def _default_vmoptions():
21+
return _jars_path() / 'dh-default.vmoptions'
22+
2023
def _jars():
2124
return _jars_path().glob('*.jar')
2225

@@ -42,6 +45,7 @@ def _jars():
4245
f"-XX:CompilerDirectivesFile={_compiler_directives()}",
4346
# (deephaven-core#2500): Remove DisableIntrinsic for currentThread
4447
'-XX:DisableIntrinsic=_currentThread',
48+
f"-XX:VMOptionsFile={_default_vmoptions()}",
4549
]
4650

4751
# Provide a util func to start the JVM, will use its own defaults if none are offered

py/embedded-server/java-runtime/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def serverClasspath = tasks.register('serverClasspath', Sync) {
3333
from configurations.runtimeClasspath
3434
from jar
3535
from tasks.named('createCompilerDirectives')
36+
from tasks.named('createVmOptions')
3637
into layout.buildDirectory.dir('classpath')
3738
}
3839

server/jetty-app/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ if (hasProperty('quiet')) {
7676
tasks.withType(JavaExec).configureEach {
7777
// This appends to the existing jvm args, so that java-open-nio still takes effect
7878
jvmArgs extraJvmArgs
79-
80-
jvmArgs '-XX:+UseG1GC',
81-
'-XX:MaxGCPauseMillis=100',
82-
'-XX:+UseStringDeduplication'
8379
}
8480

8581
tasks.withType(CreateStartScripts).configureEach {

server/netty-app/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ if (hasProperty('quiet')) {
7676
tasks.withType(JavaExec).configureEach {
7777
// This appends to the existing jvm args, so that java-open-nio still takes effect
7878
jvmArgs extraJvmArgs
79-
80-
jvmArgs '-XX:+UseG1GC',
81-
'-XX:MaxGCPauseMillis=100',
82-
'-XX:+UseStringDeduplication',
83-
// For development in this repository via Gradle, use the top-level data directory
84-
"-Dstorage.path=${rootDir}/data"
8579
}
8680

8781
tasks.withType(CreateStartScripts).configureEach {

0 commit comments

Comments
 (0)