Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|
PolyglotontheJVMwithGraal
ThomasWuerthingerSeniorResearchDirector,OracleLabs@thomaswue
QCon NewYork,June2017
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|
SafeHarborStatementThefollowingisintendedtoprovidesomeinsightintoalineofresearchinOracleLabs.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedinconnectionwithanyOracleproductorserviceremainsatthesolediscretionofOracle.AnyviewsexpressedinthispresentationaremyownanddonotnecessarilyreflecttheviewsofOracle.
3
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)
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 5
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 6
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 7
PolyglotChallenges
Onlylanguageswithhighindustryattentionachievehighperformance.
Languagesrequiredifferenttoolsforconfiguring,debugging,profiling…
Languagesexecuteintheirownboxwithcostlyserializationbetweenboxes.
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 8
Graal Vision
Highperformance foralllanguages
Language-levelvirtualizationlayerforsharedmanageabilityandtooling
Zerooverheadinteroperability betweenlanguages
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.
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 10
After5+yearsofresearch…
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…
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!
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 13
Graal VMArchitecture
JavaHotSpotVM
JVMCompilerInterface(JVMCI)JEP243
Graal Compiler
TruffleFramework
Sulong(LLVM)
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?
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!
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
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
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|
TwitterEvaluatedEarlyVersionofGraal• LargenumberofScalamicroservices• MoreTweetsperCPUmsec intheircoreservice• https://www.jfokus.se/jfokus17/preso/Graal-at-Twitter.pdf
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|
ZeroOverheadInteroperability
19
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| Confidential– OracleInternal/Restricted/HighlyRestricted 20
Graal runtimesupportscompleteseparationofphysicalandlogicallayoutforguestlanguagedatastructures.
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|
• DefininglambdamethodinJavaScript:
• Callingfromsamelanguage:
• Orfromotherlanguage(e.g.,Java):
• Orfromcustommemorylayouts:
Ø row-orientedformat=>rawpointertocurrentrowandschemaØ column-orientedformat=>tworawpointerstocurrentpositionswithincolumnsandschema
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
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
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 24
DEMO
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.| 25
Graal ExtendedVision
Highperformance,polyglot,language-levelvirtualizationlayer…
embeddableacrossthestackinnativeandJVM-basedapplications.
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
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.|
Q/A
27
@graal
@thomaswue