Add support for .jruby.java_opts home and cwd files #5826
This implements the dotfile idea from jruby#5824 in our bash launcher. The order of precedence for options, indicated by their position in the java command line, goes as follows: * home dir .jruby.java_opts * current dir .jruby.java_opts * JAVA_OPTS environment variable * command line flags This allows users to set up global, local, and environment-based java options but still override those at the command line. An equivalent change will need to go into jruby-launcher.
* Only use @file syntax on Java 9+. * Java 8 expands .java_opts files directly on the command line. * Add a default bin/.dev_mode.jruby_opts with our --dev flags. This will allow users or distributors of JRuby to customize these flags for a particular installation, for example by adding flags for OpenJ9. * Add support for bin/.jruby.java_opts for installation-specific always-on options. * Re-ordered some logic. * Set JAVA_HOME to provide better detection of Java 9.
Most recent commit adds a bit more logic:
It also turns out that this feature was added in Java 9, so I modified the script to source the related files directly into the command line when we are not running on Java 9 or higher.
The commit also contains logic to set JAVA_HOME if it is not set, based on the result of
Here's a page documenting this feature. It can move into the wiki once this is accepted.
Passing JVM options to JRuby's launcher
JRuby is a JVM language, and that means you will frequently want to pass JVM options for tuning the garbage collector or JIT, opening up classes and modules, or logging and profiling. If you want to have these options passed to every JRuby run, you can either put them in the JAVA_OPTS environment variable, or use JRuby-specific
Command-line Argument Files
Java 9 introduced support for command-line argument files, which allows you to aggregate JVM options in a file and include those options on the command line with the syntax
The format of
On startup, JRuby will look for
Options passed through JRuby to the JVM via different mechanisms will override each other. Given options are processed in the following order, with later options overriding earlier ones:
An example file, used by JRuby's
@enebo raised a concern about how we'll know where options are coming from with all these options, which was really a valid concern before but moreso with .java_opts files. I'm going to look at adding a
This also needs to be matched in the C++ launcher. That will be a bit of work.
Here's a quick prototype output from
Slightly less verbose version of output:
Note that the native launcher does have a verbose mode that outputs some of this information.
This flag gathers relevant environment info from environment variables, JVM argument files, and command line flags to produce a log of every config used to boot the JVM for JRuby. Note this does not currently include .jrubyrc contents because that file is processed after JVM startup and is only used for JRuby system properties. Support could be added but would duplicate the logic we do at runtime (unless we also move that logic to the launchers).
Final output pending input from others:
Wiki page content for --environment
Inspect JRuby's Environment
JRuby's command-line launcher provides a
This information may help you figure out configuration problems. We recommend including this output when filing a JRuby issue.
* Better formatting for environment flag * Juggled sections around to keep relevent bits closer together * All options files use the same function and formatting * Options from options files are also printed out * Removed no-longer-necessary MacOS file.encoding hack * Removed JAVA_VM env logic for -client vs -server