Jax keynote

82
Marcus Lagergren | Oracle Why dynamic languages on the JVM matter

description

Keynote I did at JAX2013 with the topic basically being "the JVM is over - enter the Polyglot Runtime". It is about the work that Oracle and the community is doing to facilitate multiple languages (non Java) on the Java Virtual Machine. This is both relevant for dynamic languages as well as "non dynamic" ones.

Transcript of Jax keynote

Page 1: Jax keynote

Marcus Lagergren | Oracle

Why dynamic languages on the JVM matter

Page 2: Jax keynote

Marcus Lagergren | Oracle

Why dynamic languages on the JVM matter

Page 3: Jax keynote

Marcus Lagergren | Oracle

Why dynamic languages on the JVM matter

Page 4: Jax keynote

Marcus Lagergren | Oracle

Why dynamic languages on the JVM matter

[and project Nashorn]

Page 5: Jax keynote

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."

Page 6: Jax keynote

Who am I?

@lagergren

Page 7: Jax keynote

I am here to talk about…

The Java Runtime: The JVM

Page 8: Jax keynote

I am here to talk about…

The Universal Meta-execution environment

Page 9: Jax keynote

I am here to talk about…

The Universal Meta-execution environment

Page 10: Jax keynote

I am here to talk about…

The JVM as a multi-language runtime

Page 11: Jax keynote

I am here to talk about…

The JVM as a multi-language runtime

(especially in the context of dynamic languages)

Page 12: Jax keynote

History (what is a runtime, anyway?)

Page 13: Jax keynote

LISP

Page 14: Jax keynote

LISP

1950s – First compiler in 1962

Page 15: Jax keynote

LISP

Just-in-time compilation

Page 16: Jax keynote

LISP

Just-in-time compilation

Page 17: Jax keynote

LISP

Also – Garbage Collection!

Page 18: Jax keynote

LISP

Also – Garbage Collection!

Page 19: Jax keynote

Smalltalk

Page 20: Jax keynote

Smalltalk

First class library.

Page 21: Jax keynote

Smalltalk

First class library. First visual GUI driven IDE.

Page 22: Jax keynote

Smalltalk

First class library. First visual GUI driven IDE. Bytecode.

Page 23: Jax keynote

Smalltalk

First class library. First visual GUI driven IDE. Bytecode.

Page 24: Jax keynote

Emerging (dynamic)

Languages

Page 25: Jax keynote

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…

Page 26: Jax keynote

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…

Page 27: Jax keynote

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

Page 28: Jax keynote

Trendy Dynamic Languages

Page 29: Jax keynote

Trendy Dynamic Languages

Page 30: Jax keynote

Trendy Dynamic Languages

Page 31: Jax keynote

Trendy Dynamic Languages

Page 32: Jax keynote

Trendy Dynamic Languages

Already on top of the JVM

Page 33: Jax keynote

…and of course

V8, Futhark, Carakan, SpiderMonkey, JägerMonkey, *Monkey, Nitro, Rhino, Nashorn, etc etc

Page 34: Jax keynote
Page 35: Jax keynote
Page 36: Jax keynote
Page 37: Jax keynote
Page 38: Jax keynote

Putting your language on top of

the JVM

Page 39: Jax keynote

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

Page 40: Jax keynote

Why?

0

100000

200000

300000

400000

500000

Code bases

Lines

Page 41: Jax keynote

Why?

0

100000

200000

300000

400000

500000

Code bases

Lines

If it were all about code complexity – TOTALLY WORTH IT!

Page 42: Jax keynote

“All problems in computer science can be solved

by another level of indirection” - David Wheeler

Page 43: Jax keynote

Sounds good – implement it! •  Just serve up some bytecode •  People have been doing it since 1996

Page 44: Jax keynote

They have been doing it a lot, actually…

Fantom

Fortress

BeanShell

Jaskell

ANTLR

JudoScript

ABCL

Erjang

X10

myForth

jdart

jgo

Nice

Gosu

Jacl

Page 45: Jax keynote

“All problems in computer science can be solved

by another level of indirection” - David Wheeler

Page 46: Jax keynote

“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

Page 47: Jax keynote

So why is it hard?

Page 48: Jax keynote

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

Page 49: Jax keynote

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

Page 50: Jax keynote

Not every language has exactly 5 strong types

int, float, long, double, Object

Page 51: Jax keynote

Not every language has exactly 5 strong types

int sum(int a, int b) { return a + b; }

int, float, long, double, Object

Page 52: Jax keynote

Not every language has exactly 5 strong types

int, float, long, double, Object

iload_1 iload_2 iadd ireturn

Page 53: Jax keynote

Not every language has exactly 5 strong types

int, float, long, double, Object

function sum(a, b) { return a + b; }

Page 54: Jax keynote

Not every language has exactly 5 strong types

int, float, long, double, Object

??? ??? ??? ???

Page 55: Jax keynote

Not every language has exactly 5 strong types

int, float, long, double, Object

??? ??? ??? ???

Page 56: Jax keynote

Also: It is hard to swap out code with other code

Page 57: Jax keynote

Also: It is hard to swap out code with other code

Page 58: Jax keynote

Applicability and Performance •  The extra layer also costs us performance •  How can we work around it?

Page 59: Jax keynote

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

Page 60: Jax keynote

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

Page 61: Jax keynote

Punch through the indirection layer

invokedynamic is my ice pick

Page 62: Jax keynote

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

Page 63: Jax keynote

The whole point: The JVM can optimize this!

Page 64: Jax keynote

The Nashorn Project

(a Rhino for 2013)

Page 65: Jax keynote
Page 66: Jax keynote
Page 67: Jax keynote

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

Page 68: Jax keynote

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

Page 69: Jax keynote

Full ECMAScript Compliance

Page 70: Jax keynote

Full ECMAScript Compliance

Page 71: Jax keynote

Performance

rhino 0

2000

4000

6000

8000

10000

12000

rhino

nashorn

Page 72: Jax keynote

Performance

rhino 0

2000

4000

6000

8000

10000

12000

rhino

nashorn

Page 73: Jax keynote

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

Page 74: Jax keynote

Nashorn already in OpenJDK 8

Now: more Nashorn & JVM performance enhancements

Now: more powerful hybrid proof of

concepts, e.g. node.jar, JavaFX

Page 75: Jax keynote

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 [email protected]

Page 76: Jax keynote

The Da Vinci Machine (MLVM)

Page 77: Jax keynote

Can we do better than the ice pick?

Reshape the hole!

Page 78: Jax keynote

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

[email protected]

Page 79: Jax keynote

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 •  …

Page 80: Jax keynote

Da Vinci Machine Patches

Page 81: Jax keynote

It’s not just invokedynamic

The JVM is evolving to become the multi-language runtime

Page 82: Jax keynote

Danke!

[Hopefully, I’ll see you again at the Nashorn / invokedynamic deep dive 16.45 this

afternoon]

@lagergren