The difference between JAVA_OPTS and JRUBY_OPTS

I would like some clarity on how to use java performance options with
jruby.

It seems like there is a -J-X… flag for the jruby which mimic the
java
options but I don’t know which takes preference and what’s the best way
to
deal with these options.

Normally I run things from scripts which end up constructing something
like
this

JRUBY_OPTS="-J-XX:+TieredCompilation …"
JAVA_OPTS=“JAVA_OPTS=”-noverify …"

JRUBY="${JAVA} ${JAVA_OPTS} -jar ${JRUBY_COMPLETE_JAR} ${JRUBY_OPTS} "

sometimes I just export the JRUBY_OPTS and don’t include them in the
command line.

So which is the preferred way to do this? Is a .jruby directory better
than
either one of them?

If I have conflicting directives which one takes priority?

Why do I get a “ignored” on a bunch of my options?

Sorry my java-fu is rather weak and it seems like there really ought to
be
a clear way to deal with this stuff.

Hey Guys.

Hate to bump myself but I would really appreciate some clarity about
this
issue.

Today I am fooling around with to torqbox the next generation of
torquebox.
I installed the gem and am running jruby 1.7.8

I run the torqbox command on my sample rails app (no real controllers,
just
a large gemfile) and it shows a running memory size of a little under
400
megs. I then run the following command

/usr/bin/java -jar jruby/jruby-complete-1.7.8-with-bundler.jar
bin/torqbox
(I also tried it with a plain old jruby-complete no bundler)

and the same app now takes up almost twice as much memory (700K+).

Next I run it like this

usr/bin/java -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify
-Xmx500m -Xss2048k -Xcompile.invokedynamic=false
-Djruby.launch.inproc=false -jar
jruby/jruby-complete-1.7.8-with-bundler.jar bin/torqbox

And voila the memory drops again to 300+ megs

next I put this in the script

export JRUBY_OPTS="-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1
-J-noverify -J-Xmx500m -J-Xss2048k -J-Xcompile.invokedynamic=false
-J-Djruby.launch.inproc=false"

and run the above commands WITHOUT the java opts and voila the memory
usage is up again so the JRUBY_OPTS is completely being ignored!

Next I try this

/usr/bin/java -jar ruby/jruby-complete-1.7.8-with-bundler.jar
-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify
-J-Xmx500m
-J-Xss2048k -J-Xcompile.invokedynamic=false
-J-Djruby.launch.inproc=false

warning: -J-XX:+TieredCompilation argument ignored (launched in same
VM?)
warning: -J-XX:TieredStopAtLevel=1 argument ignored (launched in same
VM?)
warning: -J-noverify argument ignored (launched in same VM?)
warning: -J-Xmx500m argument ignored (launched in same VM?)
warning: -J-Xss2048k argument ignored (launched in same VM?)
warning: -J-Xcompile.invokedynamic=false argument ignored (launched in
same
VM?)
warning: -J-Djruby.launch.inproc=false argument ignored (launched in
same
VM?)

and no change still large amount of memory being used.

So it looks like JRUBY_OPTS is being ignored altogether. Can anybody
explain how JRUBY_OPTS is supposed to work.

Thanks.

So how do I pass jruby specific options to it like --1.9 and such?

This is an artifact of the way you’re starting JRuby. The “-J” prefixed
JRUBY_OPTS are JVM options that have to be set before the JVM boots.
This is why your options work when passed directly to the ‘java’ command
and why it warns about the arguments being ignored when you set
$JRUBY_OPTS but do not use the jruby launcher (and instead use java -jar
…).

Because you’re using JRuby as a jar instead of downloading a JRuby
distribution and using its launchers, it’s up to use to make sure you
set the appropriate JVM options before the JVM boots.

Ben

Is there a preference as to which one I should set.

From what I can gather you can set _JAVA_OPTIONS in your environment and
you can set JRUBY_OPTS . if I set _JAVA_OPTIONS will invoking jruby use
those options? If I set both which gets priority?

Thanks.

JAVA_OPTS is used by the jruby launcher to pass options to the JVM
as it starts. That environment variable does nothing if you use the
jruby jar directly.

JRUBY_OPTS is used by both the jruby launcher and JRuby itself. When
using the launcher, all command-line arguments will work as if passed
to the jruby command. When using the jar directly, only options
processed after the JVM starts will be honored (Ruby compat version,
etc). In this latter case, options handled only by the launcher will
not work (-Xjit.threshold=# style options, --manage, others you see
processed by bin/jruby.bash).

The -J options are processed by the JRuby launcher and used to pass
options directly to the JVM. When using the jar directly, remove the
-J and pass those options to the java command.

There’s no real preference as to which you use. they are all provided
as convenience mechanisms for the various launch scenarios.

  • Charlie

Those options can still be passed via JRUBY_OPTS or directly on the
commandline. It’s just the “-J” prefixed options that won’t be supported
with “java -jar …”

Ben

Huh, I didn’t even know _JAVA_OPTIONS existed. Given the leading
underscore, I would guess it is nonstandard, but I’m glad to hear it
works
for you.

  • Charlie (mobile)

After experimenting a bit I found that _JAVA_OPTIONS is picked up by
java
no matter what you are doing with it.

As far as I can tell JRUBY_OPTS don’t get used if I use java -jar
jruby-complete-1.7.8.jar they do get used if I invoke ruby command.

I didn’t seem to have much luck with JAVA_OPTS at all when I was calling
java -jar I didn’t test them with the jruby binary.

In the end I set both _JAVA_OPTIONS and JRUBY_OPTS in my bashrc which
covers all my use cases.

On Fri, Dec 20, 2013 at 2:22 AM, Charles Oliver N.