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

Ruby & JVM: A (JRuby) Love Story

Ruby & JVM: A (JRuby) Love Story

Yarden Laifenfeld

October 17, 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? 3 “ JRuby is a 100% Java

    implementation of the Ruby programming language. It is Ruby for the JVM. ” - the JRuby wiki
  3. JRuby Advantages 5 • Integration with Java libraries • Running

    atop the JVM ◦ Threads ◦ Long running applications
  4. Why JRuby.md - Jordan Sissel, 2010 https://gist.github.com/jordansissel/978956 6 • core

    and stdlib ruby changes violently and without notice and without backwards compatibility. I want nothing of that. • need a cross-ruby date library that isn't part of stdlib (see previous point) and is also good. • need an easy way to use multiple cpus that is cross-ruby (threads are not it)
  5. Running an app 18 ➜ 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. Running an app 19 ➜ 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
  7. Running an app 20 ➜ 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
  8. Supporting JRuby 21 ? Running an app ❏ Adding a

    breakpoint ❏ Collecting data
  9. Running an app 24 ➜ tutorial-ruby git:(master) ✗ jruby -S

    rails server -p 8080 -e development [Rookout] Successfully connected to controller.
  10. Running an app 25 ➜ tutorial-ruby git:(master) ✗ jruby -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
  11. Running an app - Java Agents 37 • -javaagent flag

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

    -S rails server -p 8080 -e development [Rookout] Successfully connected to controller.
  13. Running an app 40 ➜ 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
  14. Adding a breakpoint - Class Loaders 43 JVM 32 |

    … 33 | new Item() 34 | … Class Loader Get Item class bytecode Return Item class bytecode
  15. Adding a breakpoint - Class Loaders 44 JVM 32 |

    … 33 | new Item() 34 | … Class Loader Get Item class bytecode Return Item class bytecode Class Transformer Return transformed Item class bytecode
  16. 46

  17. 47

  18. 48

  19. 49

  20. 50

  21. 51

  22. 52

  23. 57

  24. 58

  25. 59

  26. Collecting data 61 class TasksController def create params.require(:task).permit(:task) task =

    Task.new(params[:task][:title]) $tasks_storage.push(task) redirect_back(fallback_location: 'tasks') end end
  27. Collecting data 62 class TasksController def create params.require(:task).permit(:task) task =

    Task.new(params[:task][:title]) $tasks_storage.push(task) redirect_back(fallback_location: 'tasks') end end
  28. Collecting data 63 class TasksController def create params.require(:task).permit(:task) task =

    Task.new(params[:task][:title]) $tasks_storage.push(task) redirect_back(fallback_location: 'tasks') end end