arton / rjb

Ruby Java Bridge
https://www.artonx.org/collabo/backyard/?RubyJavaBridge
GNU Lesser General Public License v2.1
117 stars 34 forks source link

Crash: illegal hardware instruction when used inside Ruby Fiber #87

Open bmulholland opened 2 years ago

bmulholland commented 2 years ago

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

test.rb

require "rjb"

Fiber.new {
  Rjb.import("java.lang.String")
}.resume

% RUBYOPT=-w ruby test.rb test.rb:4: warning: Rjb::implicit jvm loading [1] 11701 illegal hardware instruction RUBYOPT=-w ruby test.rb

bmulholland commented 2 years ago

Alternatively:

require "rjb"

Rjb.load # ADDED

Fiber.new {
  Rjb.import("java.lang.String")
}.resume

% RUBYOPT=-w ruby test.rb Exception in thread "main" test.rb:6:in `import': unknown exception (RuntimeError) from test.rb:6:in `block in \<main>'

bmulholland commented 2 years ago

If it makes a difference in choosing with of the three issues I've filed to look into first, this one is my top priority -- it's blocking me from using GraphQL Dataloader to improve the performance of my app.

arton commented 2 years ago

Hi bmulholland I could reproduce the crash on x64 box. Therefore it should be fiber and rjb (jvm initialization including class load) combination.

I think it's critical issue between Ruby-Rjb-JVM and I suppose the fix is the long way travel. ~I wonder if you could change your code such as~ (remove 1st exapmle)

In ruby's fiber, any JVM invokation may fail. I think it's caused by fiber and jvm implementation behavior/design. At this time, we can have no chance to use Rjb in fiber.

bmulholland commented 2 years ago

Thanks for your investigation. We'll look into alternative approaches.