Skip to content

OOM due to unbounded rescuePCs growth #4865

@andrewdotn

Description

@andrewdotn

Environment

Provide at least:

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)

      $ jruby -v
      jruby 9.1.14.0 (2.3.3) 2017-11-08 2176f24 Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [darwin-x86_64]
    
  • Operating system and platform (e.g. uname -a)

    Observed on both CentOS 7 and Mac OS 10.13.1

Actual Behavior

The following short program, extracted from a much larger application, runs out of memory due to unbounded growth in StartupInterpreterEngine.rescuePCs.

$ cat foo.rb 
require_relative 'bar'

run(Queue.new)
$ cat bar.rb 
def run(work_queue)
  while true
    begin
      work = work_queue.pop(true)
    rescue ThreadError => e
      next
    end
  end
end
$ time JRUBY_OPTS="-w -J-Xmx32m" jruby foo.rb
Error: Your application used more memory than the safety cap of 32M.
Specify -J-Xmx####M to increase it (#### = cap size in MB).
java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Arrays.java:3210)
	at java.util.Arrays.copyOf(Arrays.java:3181)
	at java.util.Vector.grow(Vector.java:266)
	at java.util.Vector.ensureCapacityHelper(Vector.java:246)
	at java.util.Vector.addElement(Vector.java:620)
	at java.util.Stack.push(Stack.java:67)
	at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:101)
	at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:84)
	at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:179)
	at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:165)
	at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:200)
	at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
	at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:155)
	at foo.invokeOther3:run(foo.rb:3)
	at foo.RUBY$script(foo.rb:3)
	at java.lang.invoke.LambdaForm$DMH/989110044.invokeStatic_L7_L(LambdaForm$DMH)
	at java.lang.invoke.LambdaForm$BMH/1182461167.reinvoke(LambdaForm$BMH)
	at java.lang.invoke.LambdaForm$MH/198761306.invoker(LambdaForm$MH)
	at java.lang.invoke.LambdaForm$MH/1058025095.invokeExact_MT(LambdaForm$MH)
	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
	at org.jruby.ir.Compiler$1.load(Compiler.java:95)
	at org.jruby.Ruby.runScript(Ruby.java:828)
	at org.jruby.Ruby.runNormally(Ruby.java:747)
	at org.jruby.Ruby.runNormally(Ruby.java:765)
	at org.jruby.Ruby.runFromMain(Ruby.java:578)
	at org.jruby.Main.doRunFromMain(Main.java:417)
	at org.jruby.Main.internalRun(Main.java:305)
	at org.jruby.Main.run(Main.java:232)
	at org.jruby.Main.main(Main.java:204)

real	0m41.864s
user	0m51.344s
sys	0m0.495s
Returned 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions