Pushing the Java Platform         Further
MeCharles Oliver Nutter ● headius@headius.com ● @headius ● JRuby co-lead, fulltime since 2006 ● JVM enthusiast ● http://bl...
JRuby● Ruby atop the JVM   ○ "Just another Ruby implementation"   ○ "Just another JVM language"● A challenge for the JVM  ...
JRuby● Ruby atop the JVM   ○ "Just another Ruby implementation"   ○ "Just another JVM language"● A challenge for the JVM  ...
Custom Core Classes          
What Classes?● Array: a mutable, growable list of objects● Hash: an ordered associative collection● String: a collection o...
Why Custom?● Array, Hash    ○ Behavior must match Ruby exactly    ○ Many operations must redispatch into Ruby● String    ○...
String    
String ● Used for both binary and character data    ○ "Its just bytes"    ○ IO operations receive, return String ● Arbitra...
ByteListhttp://github.com/jruby/bytelist
ByteList● A list of bytes   ○ Abstraction around byte[] + encoding   ○ Similar operations to StringBuffer   ○ CoW-capable
ByteList Demo       
Regexp    
Regexp● Operates against byte[] in String   ○ All other engines operate against char[]   ○ Transcoding cost == death● Supp...
Jonihttp://github.com/jruby/joni
Joni ● Java port of Oniguruma ● Ruby-friendly    ○ byte[] based    ○ Arbitrary encodings    ○ Bytecoded engine ● Fast    ○...
Joni Demo     
OS-level Features         
OS-level Features● Process management    ○ getpid, waitpid, kill, signal, ...● Filesystem operations    ○ symlink, ownersh...
Java Native Runtime  http://github.com/jnr
Java Native RuntimeA collection of libraries to make interfacing with OS-levelfeatures easier. ● Easy binding of native li...
JNR-FFI(foreign function interface)   http://github.com/jnr/jnr-ffi
JNR-FFI● Base of the JNR libraries● Easy binding of native functions● Struct mapping● Memory/pointer management● As fast a...
JNR-FFI Demo       
JNR-POSIXhttp://github.com/jnr/jnr-posix
JNR-POSIX● Commonly used POSIX functions not in JDK   ○ Symlinks   ○ Filesystem metadata   ○ Ownership, permissions   ○ Tr...
JNR-POSIX Demo        
JNR-ENXIO(Extended Native X-platform IO)    http://github.com/jnr/jnr-enxio
JNR-ENXIO● Mimics NIO    ○ Same or similar API    ○ Channels, Selectors, etc● Implemented atop JNR-FFI    ○ 100% Java (oth...
JNR-ENXIO Demo        
JNR-UNIXSOCKEThttp://github.com/jnr/jnr-unixsocket
JNR-UNIXSOCKET● Built atop jnr-enxio● UNIX sockets   ○ Need I say more?
JNR-UNIXSOCKET        
JNR-X86ASM(yes, its what you think)http://github.com/jnr/jnr-x86asm
JNR-X86ASM● API for x86/x86_64 ASM generation● Huh?   ○ Down to the metal, baybee   ○ Faster bindings to native functions ...
JNR-X86ASM Demo        
Ruby FFIhttp://github.com/ffi/ffi
Ruby FFI● Ruby DSL for binding native libraries● Cross-impl   ○ Supported on JRuby and standard Ruby● Fun!
Ruby FFI Demo       
What Have We Learned?● The JVM can be a great native platform● No problem is impossible to solve ;-)● JRuby gives you all ...
Links and Q/A(All on Github)http://github/  ● jruby - JRuby organization      ○ /jruby - JRuby itself      ○ /bytelist - b...
Upcoming SlideShare
Loading in...5
×

JRuby: Pushing the Java Platform Further

2,746

Published on

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,746
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

JRuby: Pushing the Java Platform Further

  1. 1. Pushing the Java Platform Further
  2. 2. MeCharles Oliver Nutter ● headius@headius.com ● @headius ● JRuby co-lead, fulltime since 2006 ● JVM enthusiast ● http://blog.headius.com
  3. 3. JRuby● Ruby atop the JVM ○ "Just another Ruby implementation" ○ "Just another JVM language"● A challenge for the JVM ○ Dynamic typing/dispatch ○ Own set of core classes ○ Heavy use of OS-level features
  4. 4. JRuby● Ruby atop the JVM ○ "Just another Ruby implementation" ○ "Just another JVM language"● A challenge for the JVM ○ Dynamic typing/dispatch ○ Own set of core classes ○ Heavy use of OS-level features
  5. 5. Custom Core Classes  
  6. 6. What Classes?● Array: a mutable, growable list of objects● Hash: an ordered associative collection● String: a collection of bytes (w/ an encoding in 1.9)● Symbol: a named identifier● IO: a stream of bytes (w/ an encoding in 1.9)● File: a stream of bytes from filesystem● Range: a range of values
  7. 7. Why Custom?● Array, Hash ○ Behavior must match Ruby exactly ○ Many operations must redispatch into Ruby● String ○ Javas String is immutable ○ Javas String is UTF-16 char[] based● Regexp ○ byte[] based String necessitates it ○ Ruby Regexp is rich in features● IO, File ○ Blocking IO simulated atop non-blocking ○ No good abstractions over NIO
  8. 8. String  
  9. 9. String ● Used for both binary and character data ○ "Its just bytes" ○ IO operations receive, return String ● Arbitrary encoding ○ Implicit encoding in 1.8 (set globally) ○ Explicit encoding in 1.9 (String aggregates Encoding) ● Mutable ○ More efficient to mutate in-place ○ Copy-on-write to reduce object churn
  10. 10. ByteListhttp://github.com/jruby/bytelist
  11. 11. ByteList● A list of bytes ○ Abstraction around byte[] + encoding ○ Similar operations to StringBuffer ○ CoW-capable
  12. 12. ByteList Demo  
  13. 13. Regexp  
  14. 14. Regexp● Operates against byte[] in String ○ All other engines operate against char[] ○ Transcoding cost == death● Supports arbitrary encoding ○ Not all encodings transcode losslessly ○ Mismatched but compatible encodings?● Bytecode engine ○ Avoids StackOverflow bugs in java.util.regex ○ Optimization potential● Advanced regex features ○ Encoding-agnostic ○ Named groups
  15. 15. Jonihttp://github.com/jruby/joni
  16. 16. Joni ● Java port of Oniguruma ● Ruby-friendly ○ byte[] based ○ Arbitrary encodings ○ Bytecoded engine ● Fast ○ Avoids transcoding costs ○ Sometimes faster than j.u.regexThanks to Marcin Mielzynski (github.com/lopex)!
  17. 17. Joni Demo  
  18. 18. OS-level Features  
  19. 19. OS-level Features● Process management ○ getpid, waitpid, kill, signal, ...● Filesystem operations ○ symlink, ownership, permissions, ...● User-friendly IO ○ Interruptible, inherit TTY, "select" function, ...● Binding native libs ○ Avoid hand-written native shim (JNI) ○ Route around JVM APIs● UNIX sockets
  20. 20. Java Native Runtime http://github.com/jnr
  21. 21. Java Native RuntimeA collection of libraries to make interfacing with OS-levelfeatures easier. ● Easy binding of native libs ● NIO-like IO atop file descriptors ● UNIX sockets ● POSIX filesystem operationsBig thanks to Wayne Meissner (@wmeissner)!
  22. 22. JNR-FFI(foreign function interface) http://github.com/jnr/jnr-ffi
  23. 23. JNR-FFI● Base of the JNR libraries● Easy binding of native functions● Struct mapping● Memory/pointer management● As fast as JNI? ○ Within 10-20% (comparing invocation overhead) ○  "a viable alternative, even for reasonably performance-sensitive libraries" - @wmeissner ○ "A hell of a lot nicer than using JNI!" - @headius
  24. 24. JNR-FFI Demo  
  25. 25. JNR-POSIXhttp://github.com/jnr/jnr-posix
  26. 26. JNR-POSIX● Commonly used POSIX functions not in JDK ○ Symlinks ○ Filesystem metadata ○ Ownership, permissions ○ True "exec" ○ Process management
  27. 27. JNR-POSIX Demo  
  28. 28. JNR-ENXIO(Extended Native X-platform IO) http://github.com/jnr/jnr-enxio
  29. 29. JNR-ENXIO● Mimics NIO ○ Same or similar API ○ Channels, Selectors, etc● Implemented atop JNR-FFI ○ 100% Java (other than JNR-FFI)● Multiple backends ○ poll, kqueue currently ○ epoll, win32 needed...volunteers?● Full set of operations for *any* IO type ○ NIO cant select on stdio, files
  30. 30. JNR-ENXIO Demo  
  31. 31. JNR-UNIXSOCKEThttp://github.com/jnr/jnr-unixsocket
  32. 32. JNR-UNIXSOCKET● Built atop jnr-enxio● UNIX sockets ○ Need I say more?
  33. 33. JNR-UNIXSOCKET  
  34. 34. JNR-X86ASM(yes, its what you think)http://github.com/jnr/jnr-x86asm
  35. 35. JNR-X86ASM● API for x86/x86_64 ASM generation● Huh? ○ Down to the metal, baybee ○ Faster bindings to native functions ○ Other weird stuff...
  36. 36. JNR-X86ASM Demo  
  37. 37. Ruby FFIhttp://github.com/ffi/ffi
  38. 38. Ruby FFI● Ruby DSL for binding native libraries● Cross-impl ○ Supported on JRuby and standard Ruby● Fun!
  39. 39. Ruby FFI Demo  
  40. 40. What Have We Learned?● The JVM can be a great native platform● No problem is impossible to solve ;-)● JRuby gives you all this (and more) for free
  41. 41. Links and Q/A(All on Github)http://github/ ● jruby - JRuby organization ○ /jruby - JRuby itself ○ /bytelist - byte[] container ○ /jcodings - byte[] encoding support ○ /joni - byte[] regex ● /jnr - Java Runtime ○ /jnr-ffi - foreign function interface ○ /jnr-posix - POSIX features ○ /jnr-enxio - native IO ○ /jnr-unixsocket - UNIX sockets ○ /jnr-x86asm - x86 assembly ● /ffi/ffi - Ruby FFI
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×