Marcus Lagergren | Oracle
Why dynamic languages
on the JVM matter
Marcus Lagergren | Oracle
Why dynamic languages
on the JVM matter
Marcus Lagergren | Oracle
Why dynamic languages
on the JVM matter
Marcus Lagergren | Oracle
Why dynamic languages
on the JVM matter
[and project Nashorn]
The Legal Slide
"THE FOLLOWING IS INTENDED TO OUTLINE OUR GENERAL
PRODUCT DIRECTION. IT IS INTENDED FOR INFORMATION
PURPOSES ONLY, AND MAY NOT BE INCORPORATED INTO
ANY CONTRACT. IT IS NOT A COMMITMENT TO DELIVER ANY
MATERIAL, CODE, OR FUNCTIONALITY, AND SHOULD NOT BE
RELIED UPON IN MAKING PURCHASING DECISION. THE
DEVELOPMENT, RELEASE, AND TIMING OF ANY FEATURES
OR FUNCTIONALITY DESCRIBED FOR ORACLE'S PRODUCTS
REMAINS AT THE SOLE DISCRETION OF ORACLE."
Who am I?
@lagergren
I am here to talk about…
The Java Runtime:
The JVM
I am here to talk about…
The Universal Meta-
execution environment
I am here to talk about…
The Universal Meta-
execution environment
I am here to talk about…
The JVM as a multi-
language runtime
I am here to talk about…
The JVM as a multi-
language runtime
(especially in the context of dynamic languages)
History
(what is a runtime, anyway?)
LISP
LISP
1950s – First compiler in 1962
LISP
Just-in-time compilation
LISP
Just-in-time compilation
LISP
Also – Garbage Collection!
LISP
Also – Garbage Collection!
Smalltalk
Smalltalk
First class library.
Smalltalk
First class library. First visual GUI
driven IDE.
Smalltalk
First class library. First visual GUI
driven IDE. Bytecode.
Smalltalk
First class library. First visual GUI
driven IDE. Bytecode.
Emerging
(dynamic)
Languages
Dynamic languages
ActionScript Adenine APL BASIC
BeanShell Clojure ColdFusion Dart
Dylan Groovy E Fancy JavaScript
Julia Lua MATLAB Objective-C Perl
PHP Powershell Python Qore R
REBOL REXX Ruby Scheme
Smalltalk Snit Tcl VBScript Yoix etc
etc etc etc…
Dynamic languages
ActionScript Adenine APL BASIC
BeanShell Clojure ColdFusion Dart
Dylan Groovy E Fancy JavaScript
Julia Lua MATLAB Objective-C Perl
PHP Powershell Python Qore R
REBOL REXX Ruby Scheme
Smalltalk Snit Tcl VBScript Yoix etc
etc etc etc…
Dynamic languages
•  Dynamic languages are hot today because
–  They are easy to use
–  Have no explicit compile stage
–  Have good code readability
–  Allow short development time for small projects
–  Performance is good enough
Trendy Dynamic Languages
Trendy Dynamic Languages
Trendy Dynamic Languages
Trendy Dynamic Languages
Trendy Dynamic Languages
Already on top of the JVM
…and of course
V8, Futhark, Carakan, SpiderMonkey,
JägerMonkey, *Monkey, Nitro, Rhino,
Nashorn, etc etc
Putting your
language on top of
the JVM
Why?
•  You get so much for free!
–  Automatic memory management
–  State of the art JIT optimizations
–  Native threading capability
–  Hybridization (javax.scripting, JSR-223)
–  Extending Java
–  Man decades of high tech
Why?
0
100000
200000
300000
400000
500000
Code bases
Lines
Why?
0
100000
200000
300000
400000
500000
Code bases
Lines
If it were all about code complexity – TOTALLY WORTH IT!
“All problems in computer science can be solved
by another level of indirection”
- David Wheeler
Sounds good – implement it!
•  Just serve up some bytecode
•  People have been doing it since 1996
They have been doing it a lot,
actually…
Fantom
Fortress
BeanShell
Jaskell
ANTLR
JudoScript
ABCL
Erjang
X10
jdart
jgo
Nice
Gosu
Jacl
“All problems in computer science can be solved
by another level of indirection”
- David Wheeler
“All problems in computer science can be solved
by another level of indirection”
- David Wheeler
“Except for the problem of too many layers of
indirection”
- Kevlin Henney
So why is it hard?
So why is it hard?
•  “Java bytecode”
–  Notice the “Java”
•  There are “classes”, “methods”, size
limitations, strong types
•  Languages can be much more dynamic than
Java
–  Different linkage
–  Loose types
So why is it hard?
•  Different levels of “hard”
•  Square peg, round hole or round peg, oval
hole
•  Scala is a fairly good fit
•  Ruby or JavaScript are (at least at first
glance) pretty lousy ones
Not every language has
exactly 5 strong types
int, float, long, double, Object
Not every language has
exactly 5 strong types
int sum(int a, int b) {
return a + b;
}
int, float, long, double, Object
Not every language has
exactly 5 strong types
int, float, long, double, Object
iload_1
iload_2
iadd
ireturn
Not every language has
exactly 5 strong types
int, float, long, double, Object
function sum(a, b) {
return a + b;
}
Not every language has
exactly 5 strong types
int, float, long, double, Object
???
???
???
???
Not every language has
exactly 5 strong types
int, float, long, double, Object
???
???
???
???
Also: It is hard to
swap out code
with other code
Also: It is hard to
swap out code
with other code
Applicability and Performance
•  The extra layer also costs us performance
•  How can we work around it?
Applicability and Performance
•  The extra layer also costs us performance
•  How can we work around it?
•  Passive
–  Just wait
–  JIT is getting better all the time, GC is getting
better all the time
Applicability and Performance
•  The extra layer also costs us performance
•  How can we work around it?
•  Passive
–  Just wait
–  JIT is getting better all the time, GC is getting
better all the time
•  Active
–  Punch through the indirection layer
–  There are tools these days
Punch through the indirection
layer
invokedynamic is my ice pick
Invokedynamic
•  Breaks the constraints of Java calls and
linkage
•  Can implement calls that act like function
pointers
•  More general: can implement custom data
access
•  Makes it possible to efficiently swap out code
The whole point:
The JVM can
optimize this!
The Nashorn
Project
(a Rhino for 2013)
Rationale
•  Proof of concept: invokedynamic
•  Does it provide all required functionality?
•  Does it perform?
•  Back in late 2010:
–  We must become the ultimate invokedynamic
consumer and find out
–  Cross communication with other teams
Rationale – JavaScript?
•  Extremely dynamic
–  All (well, most) getters, setters, calls have to be
invokedynamics
•  Rhino is slow and old
•  JSR-223
–  Should make it easy to provide POC apps for
Nashorn
Full ECMAScript Compliance
Full ECMAScript Compliance
Performance
rhino	

0	

2000	

4000	

6000	

8000	

10000	

12000	

rhino	

nashorn
Performance
rhino	

0	

2000	

4000	

6000	

8000	

10000	

12000	

rhino	

nashorn
Further POC: node.jar
•  A node.js implmentation in only Java and
JavaScript
–  Forked the original node.js – threw out all native
code
–  Async I/O implemented with Grizzly
•  Deploys fine on the ARM JVM on Raspberry
PI
•  Might just as easy be a Java EE cloud
offering
Nashorn already in OpenJDK 8
Now: more Nashorn & JVM performance
enhancements
Now: more powerful hybrid proof of
concepts, e.g. node.jar, JavaFX
Contribute!
1.  Ask the community to contribute
functionality, testing, performance [analysis],
bug fixes, library optimizations, browser
simulation frameworks, kick-ass hybrid Java
solutions. JVM optimizations
2.  …
3.  PROFIT!
blogs.oracle.com/nashorn
nashorn-dev@openjdk.java.net
The Da Vinci
Machine (MLVM)
Can we do better than the ice
pick?
Reshape the hole!
Let’s continue building our
“future VM”
•  An open source incubator for
JVM futures
•  Contains code fragments
(patches)
•  Migration to OpenJDK requires
–  A standard
–  A feature release plan
mlvm-dev@openjdk.java.net
It’s more than just
invokedynamic
•  Unified type systems
•  Pluggable frontends, “bytecode 2.0”
•  Tail calls
•  (delimited) Continuations / Coroutines
•  Tuple types or C-style structs
•  Tagged values
•  Arrays 2.0
•  …
Da Vinci Machine Patches
It’s not just invokedynamic
The JVM is evolving to become the
multi-language runtime
Danke!
[Hopefully, I’ll see you again at the
Nashorn / invokedynamic deep dive 16.45 this
afternoon]
@lagergren

Jax keynote