SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

HTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleHTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS module
Kazuho Oku
 
T4T Training day - NodeJS
T4T Training day - NodeJST4T Training day - NodeJS
T4T Training day - NodeJS
Tim Sommer
 
tDiary annual report 2009 - Sapporo Ruby Kaigi02
tDiary annual report 2009 - Sapporo Ruby Kaigi02tDiary annual report 2009 - Sapporo Ruby Kaigi02
tDiary annual report 2009 - Sapporo Ruby Kaigi02
Hiroshi SHIBATA
 

Tendances (20)

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

Similaire à JRuby: Pushing the Java Platform Further

NetflixOSS meetup lightning talks and roadmap
NetflixOSS meetup lightning talks and roadmapNetflixOSS meetup lightning talks and roadmap
NetflixOSS meetup lightning talks and roadmap
Ruslan Meshenberg
 

Similaire à JRuby: Pushing the Java Platform Further (20)

PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json  postgre-sql vs. mongodbPGConf APAC 2018 - High performance json  postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
 
High performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodbHigh performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodb
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Network Automation: Ansible 101
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101
 
Java Memory Descreption
Java Memory DescreptionJava Memory Descreption
Java Memory Descreption
 
NetflixOSS meetup lightning talks and roadmap
NetflixOSS meetup lightning talks and roadmapNetflixOSS meetup lightning talks and roadmap
NetflixOSS meetup lightning talks and roadmap
 
Deep Dive into Node.js Event Loop.pdf
Deep Dive into Node.js Event Loop.pdfDeep Dive into Node.js Event Loop.pdf
Deep Dive into Node.js Event Loop.pdf
 
Python Generators
Python GeneratorsPython Generators
Python Generators
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
 
WebAssembly: In a Nutshell
WebAssembly: In a NutshellWebAssembly: In a Nutshell
WebAssembly: In a Nutshell
 
Reverse Engineering 101
Reverse Engineering 101Reverse Engineering 101
Reverse Engineering 101
 
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
Ruxmon.2015-08.-.proxenet
Ruxmon.2015-08.-.proxenetRuxmon.2015-08.-.proxenet
Ruxmon.2015-08.-.proxenet
 
Load testing in Zonky with Gatling
Load testing in Zonky with GatlingLoad testing in Zonky with Gatling
Load testing in Zonky with Gatling
 
Onyx
OnyxOnyx
Onyx
 
Rusty Python
Rusty PythonRusty Python
Rusty Python
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsdBsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsd
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 

Plus de Charles Nutter

Plus de Charles Nutter (20)

The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Open Source Software Needs You!
Open Source Software Needs You!Open Source Software Needs You!
Open Source Software Needs You!
 
InvokeBinder: Fluent Programming for Method Handles
InvokeBinder: Fluent Programming for Method HandlesInvokeBinder: Fluent Programming for Method Handles
InvokeBinder: Fluent Programming for Method Handles
 
Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Over 9000: JRuby in 2015
Over 9000: JRuby in 2015
 
Doing Open Source the Right Way
Doing Open Source the Right WayDoing Open Source the Right Way
Doing Open Source the Right Way
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013
 
Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013
 
Down the Rabbit Hole
Down the Rabbit HoleDown the Rabbit Hole
Down the Rabbit Hole
 
The Future of JRuby - Baruco 2013
The Future of JRuby - Baruco 2013The Future of JRuby - Baruco 2013
The Future of JRuby - Baruco 2013
 
High Performance Ruby - E4E Conference 2013
High Performance Ruby - E4E Conference 2013High Performance Ruby - E4E Conference 2013
High Performance Ruby - E4E Conference 2013
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
Invokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesInvokedynamic: Tales from the Trenches
Invokedynamic: Tales from the Trenches
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

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