Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby & JVM: A (JRuby) Love Story - RubyConfTh

Ruby & JVM: A (JRuby) Love Story - RubyConfTh

Yarden Laifenfeld

December 12, 2022
Tweet

More Decks by Yarden Laifenfeld

Other Decks in Programming

Transcript

  1. 2 Who Am I? • Software Engineer at Rookout •

    Background in low level C programming in linux IOT environments • Ruby, Java, Go • C#, Python, JavaScript, C++
  2. What is JRuby? 4 “ JRuby is a 100% Java

    implementation of the Ruby programming language. It is Ruby for the JVM. ” - the JRuby wiki
  3. Running an app 10 ➜ tutorial-ruby git:(master) ✗ jruby -S

    rails server -p 8080 -e development => Booting Puma => Rails 6.0.3.4 application starting in development => Run `rails server --help` for more startup options Puma starting in single mode... * Version 4.3.7 (jruby 9.2.9.0 - ruby 2.5.7), codename: Mysterious Traveller * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://[::1]:8080 * Listening on tcp://127.0.0.1:8080 Use Ctrl-C to stop
  4. Running an app 11 ➜ tutorial-ruby git:(master) ✗ jruby -S

    rails server -p 8080 -e development => Booting Puma => Rails 6.0.3.4 application starting in development => Run `rails server --help` for more startup options Puma starting in single mode... * Version 4.3.7 (jruby 9.2.9.0 - ruby 2.5.7), codename: Mysterious Traveller * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://[::1]:8080 * Listening on tcp://127.0.0.1:8080 Use Ctrl-C to stop
  5. Running an app 12 ➜ tutorial-ruby git:(master) ✗ jruby -S

    rails server -p 8080 -e development => Booting Puma => Rails 6.0.3.4 application starting in development => Run `rails server --help` for more startup options Puma starting in single mode... * Version 4.3.7 (jruby 9.2.9.0 - ruby 2.5.7), codename: Mysterious Traveller * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://[::1]:8080 * Listening on tcp://127.0.0.1:8080 Use Ctrl-C to stop
  6. Java 15 • JVM API • Instrument bytecode • No

    debugger • Ruby API • Use built in functionality • Pry already exists Ruby
  7. Running an app 20 ➜ tutorial-ruby git:(master) ✗ jruby -S

    rails server -p 8080 -e development [Rookout] Successfully connected to controller.
  8. TracePoints 26 trace_point = TracePoint.new :script_compiled do |tp| iseq =

    tp.instruction_sequence @iseqs << iseq end trace_point.enable
  9. TracePoints 27 @iseqs.each do |iseq| if iseq.absolute_path == filename t

    = TracePoint.new :line do |tp| # Collect locals, stacktrace... end t.enable target: iseq, target_line: lineno end end
  10. Running an app - Java Agents 35 • -javaagent flag

    • premain entrypoint • Instrumentation API App JavaAgent Instrumentation API
  11. Running an app 37 ➜ tutorial-ruby git:(master) ✗ jruby -J-javaagent:rook.jar

    -S rails server -p 8080 -e development [Rookout] Successfully connected to controller.
  12. Running an app 38 ➜ tutorial-ruby git:(master) ✗ jruby -J-javaagent:rook.jar

    -S rails server -p 8080 -e development [Rookout] Successfully connected to controller. => Booting Puma => Rails 6.0.6 application starting in development => Run `rails server --help` for more startup options Puma starting in single mode... * Version 4.3.12 (jruby 9.3.8.0 - ruby 2.6.8), codename: Mysterious Traveller * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://[::1]:8080 * Listening on tcp://127.0.0.1:8080 Use Ctrl-C to stop
  13. Adding a breakpoint - Class Loaders 41 JVM 32 |

    … 33 | new Item() 34 | … Class Loader Get Item class bytecode Return Item class bytecode
  14. Java Agent - ClassFileTransformer 42 JVM 32 | … 33

    | new Item() 34 | … Class Loader Get Item class bytecode Return Item class bytecode Class File Transformer Return new Item class bytecode Item class bytecode
  15. 43

  16. 44

  17. 45

  18. 46

  19. 47

  20. 48

  21. 49

  22. 54

  23. 55

  24. 56

  25. 58

  26. Things I Learned 62 • We can do awesome things

    • Smash your keyboard • Do meet your heroes
  27. JRuby Advantages 64 • Integration with Java libraries • Running

    atop the JVM ◦ Threads ◦ Long running applications