Skip to content

Instantly share code, notes, and snippets.

@kares
Created September 27, 2019 12:29
Show Gist options
  • Select an option

  • Save kares/7a15f344485042c6e27a7ae4e5d33cc1 to your computer and use it in GitHub Desktop.

Select an option

Save kares/7a15f344485042c6e27a7ae4e5d33cc1 to your computer and use it in GitHub Desktop.

Revisions

  1. kares revised this gist Sep 27, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jit_max_force.rb
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    def self.start_thread
    return unless JIT_MAX > 0
    Thread.start do
    loop { sleep 9.0; new.check_and_force_jit_max }
    loop { sleep 90; new.check_and_force_jit_max }
    end
    end

  2. kares created this gist Sep 27, 2019.
    42 changes: 42 additions & 0 deletions jit_max_force.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    # force -Xjit.max setting on JRuby <= 9.2.8
    #
    # forcing is not perfect -
    # counter for existing methods will still keep incrementing but compilation is expected to halt
    #
    # @note -Xjit.max has no effect on JRuby 9K - its only enforced since 9.2.9
    #

    (Class.new do

    JIT_MAX = ENV_JAVA['jruby.jit.max'].to_i

    if JRUBY_VERSION >= '9.2.9'
    fail "-Xjit.max enforcing no longer necessary on JRuby #{JRUBY_VERSION}, remove #{__FILE__}"
    end

    def self.start_thread
    return unless JIT_MAX > 0
    Thread.start do
    loop { sleep 9.0; new.check_and_force_jit_max }
    end
    end

    def check_and_force_jit_max
    success_count = mbean_server.getAttribute jit_compiler_mbean_name, 'SuccessCount'
    if success_count > JIT_MAX
    org.jruby.util.cli.Options::JIT_THRESHOLD.force '1000000000'
    warn "halting JRuby JIT by forcing JIT_THRESHOLD to #{org.jruby.util.cli.Options::JIT_THRESHOLD.load}"
    raise StopIteration
    end
    end

    def jit_compiler_mbean_name
    name = javax.management.ObjectName.getInstance("org.jruby:*,service=JITCompiler")
    mbean_server.queryNames(name, nil).first
    end

    def mbean_server
    java.lang.management.ManagementFactory.getPlatformMBeanServer
    end

    end.start_thread) if defined?(JRUBY_VERSION)