SlideShare a Scribd company logo
Pushing the Java Platform
         Further
Me

Charles Oliver Nutter
 ● headius@headius.com
 ● @headius
 ● JRuby co-lead, fulltime since 2006
 ● JVM enthusiast
 ● http://blog.headius.com
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
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
Custom Core Classes

          
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
Why Custom?

● Array, Hash
    ○ Behavior must match Ruby exactly
    ○ Many operations must redispatch into Ruby
● String
    ○ Java's String is immutable
    ○ Java's 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
String

    
String

 ● Used for both binary and character data
    ○ "It's 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
ByteList

http://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
● 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
Joni

http://github.com/jruby/joni
Joni

 ● Java port of Oniguruma
 ● Ruby-friendly
    ○ byte[] based
    ○ Arbitrary encodings
    ○ Bytecoded engine
 ● Fast
    ○ Avoids transcoding costs
    ○ Sometimes faster than j.u.regex

Thanks to Marcin Mielzynski (github.com/lopex)!
Joni Demo

     
OS-level Features

         
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
Java Native Runtime

  http://github.com/jnr
Java Native Runtime

A collection of libraries to make interfacing with OS-level
features easier.

 ● Easy binding of native libs
 ● NIO-like IO atop file descriptors
 ● UNIX sockets
 ● POSIX filesystem operations

Big thanks to Wayne Meissner (@wmeissner)!
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 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
JNR-FFI Demo

       
JNR-POSIX

http://github.com/jnr/jnr-posix
JNR-POSIX

● Commonly used POSIX functions not in JDK
   ○ Symlinks
   ○ Filesystem metadata
   ○ Ownership, permissions
   ○ True "exec"
   ○ Process management
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 (other than JNR-FFI)
● Multiple backends
    ○ poll, kqueue currently
    ○ epoll, win32 needed...volunteers?
● Full set of operations for *any* IO type
    ○ NIO can't select on stdio, files
JNR-ENXIO Demo

        
JNR-UNIXSOCKET

http://github.com/jnr/jnr-unixsocket
JNR-UNIXSOCKET

● Built atop jnr-enxio
● UNIX sockets
   ○ Need I say more?
JNR-UNIXSOCKET

        
JNR-X86ASM
(yes, it's 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
   ○ Other weird stuff...
JNR-X86ASM Demo

        
Ruby FFI

http://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 this (and more) for free
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

More Related Content

PDF
Bringing Concurrency to Ruby - RubyConf India 2014
PPTX
Taming the resource tiger
PDF
Writing a fast HTTP parser
PDF
Golang Performance : microbenchmarks, profilers, and a war story
PDF
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
PDF
Painless Data Storage with MongoDB & Go
PDF
Ruby projects of interest for DevOps
KEY
Messaging, interoperability and log aggregation - a new framework
Bringing Concurrency to Ruby - RubyConf India 2014
Taming the resource tiger
Writing a fast HTTP parser
Golang Performance : microbenchmarks, profilers, and a war story
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Painless Data Storage with MongoDB & Go
Ruby projects of interest for DevOps
Messaging, interoperability and log aggregation - a new framework

What's hot (20)

KEY
Rails development environment talk
PDF
JRuby with Java Code in Data Processing World
PPTX
HTTP::Parser::XS - writing a fast & secure XS module
PDF
Getting Started with Go
PDF
How to develop the Standard Libraries of Ruby?
PDF
Building Awesome CLI apps in Go
PPTX
Kotlin - A very quick introduction
PPT
Rust Programming Language
PPTX
Mongo db - How we use Go and MongoDB by Sam Helman
PDF
Ruby is dying. What languages are cool now?
PPTX
Rust 101 (2017 edition)
PDF
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
PDF
Fluentd at HKOScon
PPTX
Concurrency & Parallel Programming
PDF
Middleware as Code with mruby
PDF
Type safe, versioned, and rewindable stream processing with Apache {Avro, K...
PPTX
T4T Training day - NodeJS
KEY
tDiary annual report 2009 - Sapporo Ruby Kaigi02
PPTX
Rabbits, indians and... Symfony meets queueing brokers
Rails development environment talk
JRuby with Java Code in Data Processing World
HTTP::Parser::XS - writing a fast & secure XS module
Getting Started with Go
How to develop the Standard Libraries of Ruby?
Building Awesome CLI apps in Go
Kotlin - A very quick introduction
Rust Programming Language
Mongo db - How we use Go and MongoDB by Sam Helman
Ruby is dying. What languages are cool now?
Rust 101 (2017 edition)
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Fluentd at HKOScon
Concurrency & Parallel Programming
Middleware as Code with mruby
Type safe, versioned, and rewindable stream processing with Apache {Avro, K...
T4T Training day - NodeJS
tDiary annual report 2009 - Sapporo Ruby Kaigi02
Rabbits, indians and... Symfony meets queueing brokers
Ad

Similar to JRuby: Pushing the Java Platform Further (20)

PDF
JRuby: The Hard Parts
PPTX
GOTO Night with Charles Nutter Slides
PDF
Beyond JVM - YOW! Brisbane 2013
KEY
Charles nutter star techconf 2011 - jvm languages
PDF
Ola Bini Evolving The Java Platform
PDF
Beyond JVM - YOW Melbourne 2013
PDF
Bitter Java, Sweeten with JRuby
PDF
The Enterprise Strikes Back
ODP
First Day With J Ruby
PDF
Java: Rumours of my demise are greatly exaggerated
PDF
JRoR Deploying Rails on JRuby
PDF
Ola Bini J Ruby Power On The Jvm
PPT
Dynamic Languages on the JVM
PDF
J Ruby Power On The Jvm
PDF
The Future of JRuby - Baruco 2013
KEY
TSSJS 2011 - JRuby
PDF
JRuby - Enterprise 2.0
KEY
Практики применения JRuby
PDF
JRuby - The Best of Java and Ruby
KEY
JRuby: What's Different (RORO Melbourne October 2011)
JRuby: The Hard Parts
GOTO Night with Charles Nutter Slides
Beyond JVM - YOW! Brisbane 2013
Charles nutter star techconf 2011 - jvm languages
Ola Bini Evolving The Java Platform
Beyond JVM - YOW Melbourne 2013
Bitter Java, Sweeten with JRuby
The Enterprise Strikes Back
First Day With J Ruby
Java: Rumours of my demise are greatly exaggerated
JRoR Deploying Rails on JRuby
Ola Bini J Ruby Power On The Jvm
Dynamic Languages on the JVM
J Ruby Power On The Jvm
The Future of JRuby - Baruco 2013
TSSJS 2011 - JRuby
JRuby - Enterprise 2.0
Практики применения JRuby
JRuby - The Best of Java and Ruby
JRuby: What's Different (RORO Melbourne October 2011)
Ad

More from Charles Nutter (20)

PDF
The Year of JRuby - RubyC 2018
PDF
Down the Rabbit Hole: An Adventure in JVM Wonderland
PDF
Ruby Performance - The Last Mile - RubyConf India 2016
PDF
JRuby 9000 - Optimizing Above the JVM
PDF
JRuby and Invokedynamic - Japan JUG 2015
PDF
JRuby 9000 - Taipei Ruby User's Group 2015
PDF
Fast as C: How to Write Really Terrible Java
PDF
Open Source Software Needs You!
PDF
InvokeBinder: Fluent Programming for Method Handles
PDF
Over 9000: JRuby in 2015
PDF
Doing Open Source the Right Way
PDF
Beyond JVM - YOW! Sydney 2013
PDF
Down the Rabbit Hole
PDF
High Performance Ruby - E4E Conference 2013
PDF
Invokedynamic in 45 Minutes
PDF
Invokedynamic: Tales from the Trenches
KEY
Why JRuby? - RubyConf 2012
KEY
Aloha RubyConf 2012 - JRuby
KEY
JavaOne 2012 - JVM JIT for Dummies
KEY
High Performance Ruby - Golden Gate RubyConf 2012
The Year of JRuby - RubyC 2018
Down the Rabbit Hole: An Adventure in JVM Wonderland
Ruby Performance - The Last Mile - RubyConf India 2016
JRuby 9000 - Optimizing Above the JVM
JRuby and Invokedynamic - Japan JUG 2015
JRuby 9000 - Taipei Ruby User's Group 2015
Fast as C: How to Write Really Terrible Java
Open Source Software Needs You!
InvokeBinder: Fluent Programming for Method Handles
Over 9000: JRuby in 2015
Doing Open Source the Right Way
Beyond JVM - YOW! Sydney 2013
Down the Rabbit Hole
High Performance Ruby - E4E Conference 2013
Invokedynamic in 45 Minutes
Invokedynamic: Tales from the Trenches
Why JRuby? - RubyConf 2012
Aloha RubyConf 2012 - JRuby
JavaOne 2012 - JVM JIT for Dummies
High Performance Ruby - Golden Gate RubyConf 2012

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Teaching material agriculture food technology
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
“AI and Expert System Decision Support & Business Intelligence Systems”

JRuby: Pushing the Java Platform Further

  • 1. Pushing the Java Platform Further
  • 2. Me Charles Oliver Nutter ● headius@headius.com ● @headius ● JRuby co-lead, fulltime since 2006 ● JVM enthusiast ● http://blog.headius.com
  • 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. 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
  • 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. Why Custom? ● Array, Hash ○ Behavior must match Ruby exactly ○ Many operations must redispatch into Ruby ● String ○ Java's String is immutable ○ Java's 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. String  
  • 9. String ● Used for both binary and character data ○ "It's 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
  • 11. ByteList ● A list of bytes ○ Abstraction around byte[] + encoding ○ Similar operations to StringBuffer ○ CoW-capable
  • 13. Regexp  
  • 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
  • 16. Joni ● Java port of Oniguruma ● Ruby-friendly ○ byte[] based ○ Arbitrary encodings ○ Bytecoded engine ● Fast ○ Avoids transcoding costs ○ Sometimes faster than j.u.regex Thanks to Marcin Mielzynski (github.com/lopex)!
  • 17. Joni Demo  
  • 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. Java Native Runtime http://github.com/jnr
  • 21. Java Native Runtime A collection of libraries to make interfacing with OS-level features easier. ● Easy binding of native libs ● NIO-like IO atop file descriptors ● UNIX sockets ● POSIX filesystem operations Big thanks to Wayne Meissner (@wmeissner)!
  • 22. JNR-FFI (foreign function interface) http://github.com/jnr/jnr-ffi
  • 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
  • 26. JNR-POSIX ● Commonly used POSIX functions not in JDK ○ Symlinks ○ Filesystem metadata ○ Ownership, permissions ○ True "exec" ○ Process management
  • 28. JNR-ENXIO (Extended Native X-platform IO) http://github.com/jnr/jnr-enxio
  • 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 can't select on stdio, files
  • 32. JNR-UNIXSOCKET ● Built atop jnr-enxio ● UNIX sockets ○ Need I say more?
  • 34. JNR-X86ASM (yes, it's what you think) http://github.com/jnr/jnr-x86asm
  • 35. JNR-X86ASM ● API for x86/x86_64 ASM generation ● Huh? ○ Down to the metal, baybee ○ Faster bindings to native functions ○ Other weird stuff...
  • 38. Ruby FFI ● Ruby DSL for binding native libraries ● Cross-impl ○ Supported on JRuby and standard Ruby ● Fun!
  • 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. 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