SlideShare a Scribd company logo
1 of 18
Perl on the JVM
     Ben Evans
Why?

• Haven’t we been here before?
• Has anything changed?
• Is C-based Perl a 10-point Stag?
• Doesn’t Perl already have a VM?
• Isn’t Java really slow?
• Isn’t Java proprietary / not OSS?
What could we gain?
• Threads
• Exceptions
• Uniformity of Deployments
• Performance (mostly via JIT tech)
• Interop (not just with Java)
• Static type improvements
Open Source Aspects
•   Java is, to all intents and purposes, Open Source
    now
•   Virtually everything is GPL, Iced Tea is plugging the
    tiny remaining gaps
•   Open processes, as well as open code - this has
    problems as well as benefits
•   Consensus building among competing vendors is
    important - similar to standards work in some ways
•   OpenJDK7
•   MLVM and jvm-l
JVM Basics
• Stack-based VM : No Registers
• Single byte opcodes, with restricted args
• Constant pools
• Classloaders
• JIT subsystem
• Almost-typelessness of JVM (as opposed
  to .NET)
My approach
• Perl package == Java class
• Perl function == Java method
• Perl object == Instance of subclass of SV
• Aligned calling conventions
• Java types hosted as a ‘foreign’ type within
  an SV
The SV class



• Houses all basic SV information
• New “foreign object” slot - for proxying
  Java (and other) objects
• AV and HV are subclasses of SV
• AOT to begin with (no eval)
invokedynamic
• No way to directly manipulate the JVM stack frame
• JVM has several invoke* opcodes
• All are tightly type-constrained at compile time
• Not good for dynamic languages
• JRuby tries to get round it - but problems
• Some dynlangs invent private calling conventions -
  not good
• Need a “typesafe function pointer”
invokedynamic example




•   New opcode, and a new “bootstrap” type - MethodHandle
•   invoke() doesn’t exist at compile-time
•   will use the new invokedynamic bytecode
•   This is all pre-release and may change a bit before Java 7...
Tools for Compilation
• AOT Compilation to start with (ie no eval)
• SableCC
• Choice of an AST / Codegen lib:
• Homegrown, using ASM + invokedynamic
• Kawa (Scheme implementation)
• JRuby
Example Code
SableCC
• Automated Parser Generator
• Java-based (some .NET support)
• Compiles a grammar to a set of Node
  classes
• Automatic CST to AST transformations
• Node is a class, not an interface, subclasses
  are final
• Walks of the parse tree cannot directly
  annotate it - have to use auxiliary structures
  for semantic information
Simple use of SableCC
JRuby
•   Very nice and clean AST
•   Pretty damn close in many ways...
•   BUT
•   Everything-Is-An-Object seems unPerly
•   Ruby strings are fubared from a Perl POV
•   BUT
•   Plenty of ideas to borrow
•   Key people are approachable and friendly
•   Basic approach - take a yacc parser and port it
    directly to Java as a starting point seems sound
Using a foreign AST
Compiling using JRuby
A Modest Proposal
• Restricted semantics (also: new)
• Subset of syntax?
• Moose as new core keywords
• New keywords for exceptions?
• Sanitizing a core set of Pure-Perl modules
• Lots of work needed to get the parser right
• Tasks should segregate well, once the
  parser was approaching decent coverage
Thank You
 Questions?

More Related Content

What's hot

Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
JAX London
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
deimos
 
Verification with LoLA: 4 Using LoLA
Verification with LoLA: 4 Using LoLAVerification with LoLA: 4 Using LoLA
Verification with LoLA: 4 Using LoLA
Universität Rostock
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
Tomas Doran
 

What's hot (20)

Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Rails traps
Rails trapsRails traps
Rails traps
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Children of Ruby
Children of RubyChildren of Ruby
Children of Ruby
 
Verification with LoLA: 4 Using LoLA
Verification with LoLA: 4 Using LoLAVerification with LoLA: 4 Using LoLA
Verification with LoLA: 4 Using LoLA
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Concurrency in Java
Concurrency in JavaConcurrency in Java
Concurrency in Java
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 
Correct and efficient synchronization of java thread
Correct and efficient synchronization of java threadCorrect and efficient synchronization of java thread
Correct and efficient synchronization of java thread
 
A tour on Spur for non-VM experts
A tour on Spur for non-VM expertsA tour on Spur for non-VM experts
A tour on Spur for non-VM experts
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
 
Thinking Functionally
Thinking FunctionallyThinking Functionally
Thinking Functionally
 

Similar to Perl On The JVM (London.pm Talk 2009-04)

Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian
 
T4T Training day - NodeJS
T4T Training day - NodeJST4T Training day - NodeJS
T4T Training day - NodeJS
Tim Sommer
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter
 

Similar to Perl On The JVM (London.pm Talk 2009-04) (20)

Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Ruby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterRuby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles Nutter
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Dev-Friendly Ops
Dev-Friendly OpsDev-Friendly Ops
Dev-Friendly Ops
 
Jvm2
Jvm2Jvm2
Jvm2
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)
 
T4T Training day - NodeJS
T4T Training day - NodeJST4T Training day - NodeJS
T4T Training day - NodeJS
 
How to-node-core
How to-node-coreHow to-node-core
How to-node-core
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Redis Day Keynote Salvatore Sanfillipo Redis Labs
Redis Day Keynote Salvatore Sanfillipo Redis LabsRedis Day Keynote Salvatore Sanfillipo Redis Labs
Redis Day Keynote Salvatore Sanfillipo Redis Labs
 
Java Programming Important Topics
Java Programming Important Topics Java Programming Important Topics
Java Programming Important Topics
 
Java Online Training
Java Online TrainingJava Online Training
Java Online Training
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabad
 

Recently uploaded

Recently uploaded (20)

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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Perl On The JVM (London.pm Talk 2009-04)

  • 1. Perl on the JVM Ben Evans
  • 2. Why? • Haven’t we been here before? • Has anything changed? • Is C-based Perl a 10-point Stag? • Doesn’t Perl already have a VM? • Isn’t Java really slow? • Isn’t Java proprietary / not OSS?
  • 3. What could we gain? • Threads • Exceptions • Uniformity of Deployments • Performance (mostly via JIT tech) • Interop (not just with Java) • Static type improvements
  • 4. Open Source Aspects • Java is, to all intents and purposes, Open Source now • Virtually everything is GPL, Iced Tea is plugging the tiny remaining gaps • Open processes, as well as open code - this has problems as well as benefits • Consensus building among competing vendors is important - similar to standards work in some ways • OpenJDK7 • MLVM and jvm-l
  • 5. JVM Basics • Stack-based VM : No Registers • Single byte opcodes, with restricted args • Constant pools • Classloaders • JIT subsystem • Almost-typelessness of JVM (as opposed to .NET)
  • 6. My approach • Perl package == Java class • Perl function == Java method • Perl object == Instance of subclass of SV • Aligned calling conventions • Java types hosted as a ‘foreign’ type within an SV
  • 7. The SV class • Houses all basic SV information • New “foreign object” slot - for proxying Java (and other) objects • AV and HV are subclasses of SV • AOT to begin with (no eval)
  • 8. invokedynamic • No way to directly manipulate the JVM stack frame • JVM has several invoke* opcodes • All are tightly type-constrained at compile time • Not good for dynamic languages • JRuby tries to get round it - but problems • Some dynlangs invent private calling conventions - not good • Need a “typesafe function pointer”
  • 9. invokedynamic example • New opcode, and a new “bootstrap” type - MethodHandle • invoke() doesn’t exist at compile-time • will use the new invokedynamic bytecode • This is all pre-release and may change a bit before Java 7...
  • 10. Tools for Compilation • AOT Compilation to start with (ie no eval) • SableCC • Choice of an AST / Codegen lib: • Homegrown, using ASM + invokedynamic • Kawa (Scheme implementation) • JRuby
  • 12. SableCC • Automated Parser Generator • Java-based (some .NET support) • Compiles a grammar to a set of Node classes • Automatic CST to AST transformations • Node is a class, not an interface, subclasses are final • Walks of the parse tree cannot directly annotate it - have to use auxiliary structures for semantic information
  • 13. Simple use of SableCC
  • 14. JRuby • Very nice and clean AST • Pretty damn close in many ways... • BUT • Everything-Is-An-Object seems unPerly • Ruby strings are fubared from a Perl POV • BUT • Plenty of ideas to borrow • Key people are approachable and friendly • Basic approach - take a yacc parser and port it directly to Java as a starting point seems sound
  • 17. A Modest Proposal • Restricted semantics (also: new) • Subset of syntax? • Moose as new core keywords • New keywords for exceptions? • Sanitizing a core set of Pure-Perl modules • Lots of work needed to get the parser right • Tasks should segregate well, once the parser was approaching decent coverage