Skip to content

Xmx limited to 500m on JRuby 9.3.x with 2.x #52

Open

Description

@seanstory

Description

I've observed that jruby-launcher 2.0.1 is causing installations of JRuby 9.3.x.x to be limited to 500 MB of heap. This cannot be overridden with JAVA_OPTS or JRUBY_OPTS. Attempting to do wso will result in a ps aux like:

seanstory        70590   0.0  0.4 413864832 246672 s001  S+   12:51PM   0:04.51 java -Xmx1g -client -Xmx500m -Xss2048k -Djffi.boot.library.path=/opt/homebrew/Cellar/rbenv/1.3.2/versions/jruby-9.3.15.0/lib/jni -Dfile.encoding=UTF-8 -Xbootclasspath/a:/opt/homebrew/Cellar/rbenv/1.3.2/versions/jruby-9.3.15.0/lib/jruby.jar -classpath : -Djruby.home=/opt/homebrew/Cellar/rbenv/1.3.2/versions/jruby-9.3.15.0 -Djruby.lib=/opt/homebrew/Cellar/rbenv/1.3.2/versions/jruby-9.3.15.0/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main /opt/homebrew/opt/rbenv/versions/jruby-9.3.15.0/bin/irb

Note both the -Xmx1g (expected) and the -Xmx500m (unexpected).

This does not appear to be an issue with JRuby versions 9.4.x.x.

I found a reference to 500m here: https://github.com/jruby/jruby/blob/0db23ddd14b02c90f37c9161b0ca76aee57c6b35/bin/jruby.sh#L113-L115 which is present in the jruby.sh files in 9.3.x.x. I expect therefore that this bug is related to rbenv/ruby-build#2517

Reproduction Steps

  1. brew install rbenv
  2. rbenv install jruby-9.3.14.0
  3. create a file, test.rb, with contents puts Java::JavaLangManagement::ManagementFactory.memory_mx_bean.heap_memory_usage.max / 1024 / 1024
  4. run JAVA_OPTS="-Xmx1g" ruby test.rb, and see output ~500
  5. install instead jruby-9.4.12.0
  6. execute JAVA_OPTS="-Xmx1g" ruby test.rb, see expected default output of ~1024

Workarounds

  • uninstall jruby-launcher: gem uninstall jruby-launcher
  • replace jruby-launcher with an older verion: gem uninstall jruby-launcher -v 2.0.1 && gem install jruby-launcher -v 1.1.19
  • set heap instead with JAVA_MEM environment variable: export JAVA_MEM="-Xmx=1g"

Activity

  1. headius commented on Apr 22, 2025

    @headius
    Member

    @mrnoname1000 maybe you can help me look into this? It's either an issue with the new native launcher or the shell script.

  2. headius commented on Apr 23, 2025

    @headius
    Member

    @seanstory Have not been able to reproduce outside of rbenv with the same script. Could you provide the output of jruby --environment with you env and setup?

  3. seanstory commented on Apr 25, 2025

    @seanstory
    Author

    heh. This is fun.

    Seans-MacBook-Pro:ent-search seanstory$ jruby --environment
    jruby: unknown option --environment
    Seans-MacBook-Pro:ent-search seanstory$ jruby --version
    jruby 9.3.14.0 (2.6.8) 2024-02-20 0db23ddd14 OpenJDK 64-Bit Server VM 11.0.25+9 on 11.0.25+9 +jit [arm64-darwin]
    Seans-MacBook-Pro:ent-search seanstory$ which jruby
    /opt/homebrew/opt/rbenv/shims/jruby
    Seans-MacBook-Pro:ent-search seanstory$ jruby -h
    Usage: jruby [switches] [--] [programfile] [arguments]
      -0[octal]         specify record separator (\0, if no argument)
      -a                autosplit mode with -n or -p (splits $_ into $F)
      -c                check syntax only
      -Cdirectory       cd to directory, before executing your script
      -d                set debugging flags (set $DEBUG to true)
      -e 'command'      one line of script. Several -e's allowed. Omit [programfile]
      -Eex[:in]         specify the default external and internal character encodings
      -Fpattern         split() pattern for autosplit (-a)
      -G                load a Bundler Gemspec before executing any user code
      -i[extension]     edit ARGV files in place (make backup if extension supplied)
      -Idirectory       specify $LOAD_PATH directory (may be used more than once)
      -J[java option]   pass an option on to the JVM (e.g. -J-Xmx512m)
                          use --properties to list JRuby properties
                          run 'java -help' for a list of other Java options
      -l                enable line ending processing
      -n                assume 'while gets(); ... end' loop around your script
      -p                assume loop like -n but print line also like sed
      -rlibrary         require the library, before executing your script
      -s                enable some switch parsing for switches after script name
      -S                look for the script in bin or using PATH environment variable
      -T[level]         turn on tainting checks
      -U                use UTF-8 as default internal encoding
      -v                print version number, then turn on verbose mode
      -w                turn warnings on for your script
      -W[level]         set warning level; 0=silence, 1=medium, 2=verbose (default)
      -x[directory]     strip off text before #!ruby line and perhaps cd to directory
      -X[option]        enable extended option (omit option to list)
      -y                enable parsing debug output
      --copyright       print the copyright
      --debug           sets the execution mode most suitable for debugger
                          functionality
      --jdb             runs JRuby process under JDB
      --properties      List all configuration Java properties
                          (prepend "jruby." when passing directly to Java)
      --environment     Log environment and command line flags but do not run JRuby
      --sample          run with profiling using the JVM's sampling profiler
      --profile         run with instrumented (timed) profiling, flat format
      --profile.api     activate Ruby profiler API
      --profile.flat    synonym for --profile
      --profile.graph   run with instrumented (timed) profiling, graph format
      --profile.html    run with instrumented (timed) profiling, graph format in HTML
      --profile.json    run with instrumented (timed) profiling, graph format in JSON
      --profile.out     [file]
      --profile.service <ProfilingService implementation classname>
                        output profile data to [file]
      --client          use the non-optimizing "client" JVM
                          (improves startup; default)
      --server          use the optimizing "server" JVM (improves perf)
      --headless        do not launch a GUI window, no matter what
      --dev             prioritize startup time over long term performance
      --manage          enable remote JMX management and monitoring of JVM and JRuby
      --bytecode        show the JVM bytecode produced by compiling specified code
      --version         print the version
      --disable-gems    do not load RubyGems on startup
      --enable=feature[,...], --disable=feature[,...]
                        enable or disable features
    Features:
      gems                   rubygems (default: enabled)
      did_you_mean           did_you_mean (default: enabled)
      rubyopt                RUBYOPT environment variable (default: enabled)
      frozen-string-literal  freeze all string literals (default: disabled)
    Seans-MacBook-Pro:ent-search seanstory$
    
  4. seanstory commented on Apr 25, 2025

    @seanstory
    Author

    Trying to provide any extra info

    `gems list`
    Seans-MacBook-Pro:ent-search seanstory$ gem list
    
    *** LOCAL GEMS ***
    
    bundler (default: 2.2.33)
    cmath (default: 1.0.0)
    csv (default: 3.2.5)
    did_you_mean (1.3.0)
    e2mmap (default: 0.1.0)
    ffi (default: 1.15.4 java)
    fileutils (default: 1.4.1)
    forwardable (default: 1.2.0)
    io-console (default: 0.5.9 java)
    ipaddr (default: 1.2.2)
    irb (default: 1.0.0)
    jar-dependencies (default: 0.4.1)
    jruby-launcher (2.0.1 java)
    jruby-openssl (default: 0.14.2 java)
    jruby-readline (default: 1.3.7 java)
    json (default: 2.5.1 java)
    logger (default: 1.5.1)
    matrix (default: 0.3.0)
    minitest (5.11.3)
    mutex_m (default: 0.1.0)
    net-telnet (0.1.1)
    ostruct (default: 0.5.5)
    power_assert (1.1.3)
    prime (default: 0.1.0)
    psych (default: 3.3.4 java)
    racc (default: 1.5.2 java)
    rake (12.3.3)
    rake-ant (default: 1.0.4)
    rdoc (default: 6.3.3)
    rexml (default: 3.2.5)
    rss (default: 0.2.7)
    rubygems-update (default: 3.2.33)
    scanf (default: 1.0.0)
    shell (default: 0.7)
    sync (default: 0.5.0)
    test-unit (3.2.9)
    thwait (default: 0.1.0)
    tracer (default: 0.1.0)
    webrick (default: 1.7.0)
    xmlrpc (0.3.0)
    
    `env` (secure bits removed)
    Seans-MacBook-Pro:ent-search seanstory$ env
    NVM_INC=/Users/seanstory/.nvm/versions/node/v16.19.1/include/node
    TERM_PROGRAM=Apple_Terminal
    NVM_CD_FLAGS=
    PYENV_ROOT=/Users/seanstory/.pyenv
    TERM=xterm-256color
    SHELL=/bin/bash
    HOMEBREW_REPOSITORY=/opt/homebrew
    TMPDIR=/var/folders/2t/bkqn7m1j7j3fcrwrxblms92r0000gn/T/
    TERM_PROGRAM_VERSION=455.1
    TERM_SESSION_ID=7559AB27-E76D-4E74-A67A-E369B989C038
    NVM_DIR=/Users/seanstory/.nvm
    USER=seanstory
    RBENV_ROOT=/opt/homebrew/opt/rbenv
    MAVEN_OPTS=-Xmx3g
    LSCOLORS=exfxcxdxbxegedabagacad
    PATH=/Users/seanstory/.asdf/shims/:/opt/homebrew/opt/curl/bin:/Users/seanstory/.jenv/shims:/Users/seanstory/.jenv/bin:/Users/seanstory/.nvm/versions/node/v16.19.1/bin:/Users/seanstory/.cargo/bin:/Users/seanstory/.pyenv/shims:/opt/homebrew/opt/rbenv/shims:/opt/homebrew/opt/rbenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/seanstory/bin
    LaunchInstanceID=EC3B42AB-95A6-48B7-A82D-1B7EAB935C40
    __CFBundleIdentifier=com.apple.Terminal
    JENV_LOADED=1
    PWD=/Users/seanstory/Desktop/Dev/ent-search
    LANG=en_US.UTF-8
    XPC_FLAGS=0x0
    RBENV_SHELL=bash
    XPC_SERVICE_NAME=0
    PYENV_SHELL=bash
    HOME=/Users/seanstory
    SHLVL=1
    HOMEBREW_PREFIX=/opt/homebrew
    LOGNAME=seanstory
    JENV_SHELL=bash
    NVM_BIN=/Users/seanstory/.nvm/versions/node/v16.19.1/bin
    INFOPATH=/opt/homebrew/share/info:
    HOMEBREW_CELLAR=/opt/homebrew/Cellar
    _=/usr/bin/env
    
  5. seanstory commented on Apr 25, 2025

    @seanstory
    Author

    fwiw, I can reproduce from a clean environment with just a few steps of:

    1. brew install rbenv
    2. rbenv install jruby-9.3.14.0
    3. rbenv local jruby-9.3.14.0
    echo '#! /bin/ruby
    puts Java::JavaLangManagement::ManagementFactory.memory_mx_bean.heap_memory_usage.max / 1024 / 1024' > test.rb
    
    1. JAVA_OPTS="-Xmx1g" ruby test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions