27

Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:
Page 2: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

PolyglotontheJVMwithGraal

ThomasWuerthingerSeniorResearchDirector,OracleLabs@thomaswue

QCon NewYork,June2017

Page 3: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

SafeHarborStatementThefollowingisintendedtoprovidesomeinsightintoalineofresearchinOracleLabs.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedinconnectionwithanyOracleproductorserviceremainsatthesolediscretionofOracle.AnyviewsexpressedinthispresentationaremyownanddonotnecessarilyreflecttheviewsofOracle.

3

Page 4: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 4

The World Is Polyglot!

Java

C

C++

Python

C#

VB.NET

JavaScript

AssemblylanguagePHP

PerlRubyVBSwiftR

Objective-CGo

MATLAB

Delphi/Object Pascal

PL/SQL

Scratch

Others

PROGRAMMINGLANGUAGEPOPULARITY(TOP20LANGUAGESFROMMAY2017TIOBE INDEX)

Page 5: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 5

Page 6: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 6

Page 7: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 7

PolyglotChallenges

Onlylanguageswithhighindustryattentionachievehighperformance.

Languagesrequiredifferenttoolsforconfiguring,debugging,profiling…

Languagesexecuteintheirownboxwithcostlyserializationbetweenboxes.

Page 8: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 8

Graal Vision

Highperformance foralllanguages

Language-levelvirtualizationlayerforsharedmanageabilityandtooling

Zerooverheadinteroperability betweenlanguages

Page 9: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 9

You can execute any language on the JVM / CLR- as long as it looks like Java / C#.

Mismatchbetweentypesystemandbytecodes ofhostVMandsemanticsofguestlanguage.

Page 10: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 10

After5+yearsofresearch…

Page 11: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 11

U

U U

U

U I

I I

G

G I

I I

G

G

Node Rewriting for Profiling Feedback

AST InterpreterRewritten Nodes

AST InterpreterUninitialized Nodes

Compilation usingPartial Evaluation

Compiled Code

Node Transitions

S

UI

D

G

Uninitialized Integer

Generic

DoubleString

OptimizationandSpeculation…

Page 12: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 12

I

I I

G

G I

I I

G

G

Deoptimizationto AST Interpreter

D

I D

G

G D

I D

G

G

Node Rewriting to Update Profiling Feedback

Recompilation usingPartial Evaluation

AndDeoptimization!

Page 13: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 13

Graal VMArchitecture

JavaHotSpotVM

JVMCompilerInterface(JVMCI)JEP243

Graal Compiler

TruffleFramework

Sulong(LLVM)

Page 14: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Let‘s talk about R...

14

function(a, x) (a[x]+42)

• Does„+“resolvetotheadditionbuiltin function?• Classof„a“?• Does„[]“resolvetothearrayaccessbuiltin function?• Is„x“avectorofspecificlength?• Does„x“havenegativeelements?The0element?Positiveelements?In-boundsorout-of-bounds?AnNAelement?• Anycodecanbeexecutedatthepointwhere„a“or„x“isevaluated(lazypromiseevaluationofarguments)• Doesevaluatedcoderedefine„+“or„[]“functions?• Isintermediatevectorresultneeded?

Page 15: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 15

Graal.js Architecture

JavaScript

C++

Java

nodemoduleswithonlyJavaScriptnodemoduleswithnativeextensions

nodestandardlibrary

nodebindings(socket,http,…)

V8APIthreadpool(libeio)

eventloop(libev)

DNS(c-ares)

crypto(OpenSSL)

Graal.js JavaScriptEngine

AdapterV8APItoGraal.js viaJNI

nativeextensions

Fullycompatibleincludingnativemodulesupport!

Page 16: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

ProjectSulong:LLVMfront-endforGraal

int add(x, y) {return x + y;

} define i32 @add(i32 %x, i32 %y) #0 {%1 = alloca i32, align 4%2 = alloca i32, align 4store i32 %x, i32* %1, align 4store i32 %y, i32* %2, align 4%3 = load i32* %1, align 4%4 = load i32* %2, align 4%5 = add nsw i32 %3, %4ret i32 %5

}

FUNCTION add(x, y)INTEGER :: addINTEGER :: aINTEGER :: badd = a + bRETURN

END FUNCTION

func add(x int, y int) int {return x + y;

}

https://github.com/graalvm/sulong

C/C++

Fortran

Go

Page 17: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

High-PerformanceforEach Language

17

1.02 1.2

4.14.5

0.85 0.9

0

1

2

3

4

5

Java Scala Ruby R Native JavaScript

Speedup,higherisbetter

Performanceon64-bitx86onwell-knownbenchmarksuitesrelativeto:HotSpot/Server,JRuby,GNUR,LLVMAOTcompiled,V8

GraalBestSpecializedCompetition

Page 18: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

TwitterEvaluatedEarlyVersionofGraal• LargenumberofScalamicroservices• MoreTweetsperCPUmsec intheircoreservice• https://www.jfokus.se/jfokus17/preso/Graal-at-Twitter.pdf

Page 19: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

ZeroOverheadInteroperability

19

Page 20: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| Confidential– OracleInternal/Restricted/HighlyRestricted 20

Graal runtimesupportscompleteseparationofphysicalandlogicallayoutforguestlanguagedatastructures.

Page 21: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

• DefininglambdamethodinJavaScript:

• Callingfromsamelanguage:

• Orfromotherlanguage(e.g.,Java):

• Orfromcustommemorylayouts:

Ø row-orientedformat=>rawpointertocurrentrowandschemaØ column-orientedformat=>tworawpointerstocurrentpositionswithincolumnsandschema

Page 22: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 22

#include<stdio.h>

struct complex {double r;double i;

}

int main() {struct complex *a = …;struct complex *b = …;

add(a, b);}

function add(a, b) {var result = {r:0, i:0};

result.r = a.r + b.r;

result.i = a.i + b.i;

return result; }

add(a, b)

a->r b->r

a->i b->i

main.c

complex.js

DataSharingAcrossLanguageBoundaries

Page 23: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 23

1x

8x11x

32x

0

5

10

15

20

25

30

35

CRuby Graal/Ruby CRuby+C Graal/Ruby+C

ImageProcessingCompositeSpeedup

Pure Ruby Ruby + C

High

er is

bette

r

Page 24: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 24

DEMO

Page 25: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 25

Graal ExtendedVision

Highperformance,polyglot,language-levelvirtualizationlayer…

embeddableacrossthestackinnativeandJVM-basedapplications.

Page 26: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

ResourcesonGraal

• OTNproductpageincludingdownload:–www.oracle.com/technetwork/oracle-labs/program-languages

• Graal projectsongithub:– github.com/graalvm

• Graal onOpenJDK:– openjdk.java.net/projects/graal

26

Page 27: Polyglot on the JVM with Graal - QCon New York...Java Scala Ruby R Native JavaScript Speedup, higher is better Performance on 64-bit x86 on well-known benchmark suites relative to:

Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|

Q/A

27

@graal

@thomaswue