Using LLVM and Sulong for Language C Extensionsllvm.org/devmtg/2016-09/slides/Seaton-Sulong.pdf ·...
Transcript of Using LLVM and Sulong for Language C Extensionsllvm.org/devmtg/2016-09/slides/Seaton-Sulong.pdf ·...
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
UsingLLVMandSulongforLanguageCExtensions
ChrisSeatonResearchManagerVMResearchGroupOracleLabs
ManuelRigger,MatthiasGrimmerJKULinz
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
SafeHarborStatementThefollowingisintendedtoprovidesomeinsightintoalineofresearchinOracleLabs.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract. Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Oraclereservestherighttoalteritsdevelopmentplansandpracticesatanytime,andthedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedinconnectionwithanyOracleproductorserviceremainsatthesolediscretionofOracle. AnyviewsexpressedinthispresentationaremyownanddonotnecessarilyreflecttheviewsofOracle.
3
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Whoweareandwhatwe’redoing
4
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 5
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 6
Graal
Truffle
RRuby
Java Scala
JavaScript LLVM
TheRubyLogoisCopyright(c)2006,YukihiroMatsumoto.ItislicensedunderthetermsoftheCreativeCommonsAttribution-ShareAlike 2.5agreementJSLogoCopyright(c)2011ChristopherWilliams<[email protected]>,MITlicence
YoucandistributethelogounderthetermsoftheCreativeCommonsAttribution-ShareAlike 4.0Internationallicense(CC-BY-SA4.0)or(atyouroption)theGNUGeneralPublicLicenseversion2(GPL-2).
JVM
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
LanguageCextensions
7
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 8
TheRubyLogoisCopyright(c)2006,YukihiroMatsumoto.ItislicensedunderthetermsoftheCreativeCommonsAttribution-ShareAlike 2.5agreementJSLogoCopyright(c)2011ChristopherWilliams<[email protected]>,MITlicence
ThePythonlogoisatrademarkofthePythonSoftwareFoundation
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 9
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 10
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 11
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
PerformanceonRubyCExtensionsOilyPNGandPSDNative
12
M.Grimmer,C.Seaton,T.Würthinger,H.Mössenböck.DynamicallyComposingLanguagesinaModularWay:SupportingCExtensionsforDynamicLanguages.InProceedingsofthe14th InternationalConferenceonModularity,2015.
0
2
4
6
8
10
12
MRIPureRuby MRIWithCExtension
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
TheCextensionproblem
13
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 14
Structs declaredinthepublicAPI
Implementationdetailslikeembeddedstringsandsharing
exposed
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 15
RubyStringobject
Exposesinnerchar*
Stringobjectwithchar*alreadyexposednowreturnedtoRuby
CalltoarbitraryCcode
ManagedRubyvalueontheCstack
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 16
ValuesneedtobeconvertedastheygofromRubytonative
CallfromRubytonativeisextremelyhot
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 17
Arrayimplementationpointertakenandstored
forlater
Whenthey’reusedthere’snoindicationsomeoneelseis
managingthem
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Previoussolutions
18
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 19
Copy Copy
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Ournewsolution
20
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
• InterpretboththeRubyandtheC• Actually,interprettheLLVMIRoftheCtosimplify• JITcompiletheRubyandtheC• UseasinglehighandlowlevelIRforboth• ForgetwhichlanguagetheIRcamefromandoptimisethemtogether• GivevirtualisedpointerstotheCprogram
21
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
HowSulong andJRuby+Truffle work
22
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
JIT
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
JIT
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
JIT
JIT
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
JIT
JIT
Truffle
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
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
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
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
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
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
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 32
codon.com/compilers-for-free
Presentation,byTomStuart,licensedunderaCreativeCommonsAttributionShareAlike 3.0
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
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
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|13/09/2016
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
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
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|13/09/2016 OracleConfidential– Internal/Restricted/HighlyRestricted
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
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
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|13/09/2016 OracleConfidential– Internal/Restricted/HighlyRestricted
T.Würthinger,C.Wimmer,A.Wöß,L.Stadler,G.Duboscq,C.Humer,G.Richards,D.Simon,andM.Wolczko.OneVMtorulethemall.InProceedingsofOnward!,2013.
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
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 37
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 38
Frequently executed call
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 39
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 40
BigInteger
double
int
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 41
BigInteger
double
int
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 42
double
int
BigInteger
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
Graal
Truffle
JS RubyR
Java
C++JVMCI
(JVMCompilerInterface)
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Hotspot
Graal
Truffle
JS RubyR
viaMavenetc
Java9
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 45
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Completeness– languageandcorelibrary
OracleConfidential– Internal
RubylanguageJRuby passes94%
95% RubycorelibraryJRuby passes95%
99%
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Completeness– thebasicRailsstack
OracleConfidential– Internal
ActiveModel
ActiveSupport
ActiveRecord
ActionView
ActionPack
ActionMailer
Railties
Sprockets-Rails
ActiveJob
Spring
100%
100%
98%Basicfunctionalityworks
37%
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Classicresearchbenchmarks– 10-20xfaster
Confidential– OracleInternal/Restricted/HighlyRestricted 48
05
1015202530354045
Speedu
pCo
mparedtoRub
y
GraalVM JRuby+invokedynamic Ruby
BenchmarksboundbyallocationorBigInteger
performance
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 49
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 50
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 51
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
HowweimplementCextensions
52
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 53
cmyk_to_rgb
psd_native_util_clamp
FIX2INT
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 54
cmyk_to_rgb
psd_native_util_clamp
FIX2INT
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 55
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 56
InsteadofRARRAY_PTRreturningapointer(anumber),returna
properJavaobject
Operationslikegetelementptr canreturnanewJavaobjectthat
rememberstheoriginalobject,andwhatoffsettouse
LetSSAnamesstoreJavaobjectsaswellasnumbers
TheloadcanthenusewhateverlogicwewanttoactuallyreadavaluefromtheJavaobject– reusenormalRubyarray
logic
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 57
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 58
Virtualised pointer– reallypointstoaJavaobjectwhichrepresentsourRubystring
TheCprogramhasnowayofknowingit’snotarealchar*
Intrinsicoperationsonthepointerareredirectedtobe
methodcalls
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Evaluation
59
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Evaluationisbasedonearlierwork• WeusedtohaveaCinterpreter– TruffleC• We’vemovedonfromthis,becausewewanttosupportmorelanguages• Butwearen’tabletorunallthesamebenchmarksyet• Sowe’veshowingresultsfromouroldimplementationinthemeantime• We’reprettysureresultswillbesimilar,asthecompiledcodeissimilar
60
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
PerformanceonRubyCExtensionsOilyPNGandPSDNative
61
0
5
10
15
20
25
30
35
MRIPureRuby MRIWithCExtension
RubiniusWithCExtension
JRubyWithCExtension
JRuby+TruffleWithCExtension
JRuby+TruffleWithCExtension
(NoInline)
M.Grimmer,C.Seaton,T.Würthinger,H.Mössenböck.DynamicallyComposingLanguagesinaModularWay:SupportingCExtensionsforDynamicLanguages.InProceedingsofthe14th InternationalConferenceonModularity,2015.
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
PerformanceonRubyCExtensionsOilyPNGandPSDNative
62
0
5
10
15
20
25
30
35
MRIPureRuby MRIWithCExtension
RubiniusWithCExtension
JRubyWithCExtension
JRuby+TruffleWithCExtension
JRuby+TruffleWithCExtension
(NoInline)
M.Grimmer,C.Seaton,T.Würthinger,H.Mössenböck.DynamicallyComposingLanguagesinaModularWay:SupportingCExtensionsforDynamicLanguages.InProceedingsofthe14th InternationalConferenceonModularity,2015.
NativeCextensionsgiveanorderofmagnitudeperformanceboost
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
PerformanceonRubyCExtensionsOilyPNGandPSDNative
63
0
5
10
15
20
25
30
35
MRIPureRuby MRIWithCExtension
RubiniusWithCExtension
JRubyWithCExtension
JRuby+TruffleWithCExtension
JRuby+TruffleWithCExtension
(NoInline)
M.Grimmer,C.Seaton,T.Würthinger,H.Mössenböck.DynamicallyComposingLanguagesinaModularWay:SupportingCExtensionsforDynamicLanguages.InProceedingsofthe14th InternationalConferenceonModularity,2015.
Existingattempttomixmanaged/nativearevery
disappointing
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
PerformanceonRubyCExtensionsOilyPNGandPSDNative
64
0
5
10
15
20
25
30
35
MRIPureRuby MRIWithCExtension
RubiniusWithCExtension
JRubyWithCExtension
JRuby+TruffleWithCExtension
JRuby+TruffleWithCExtension
(NoInline)
M.Grimmer,C.Seaton,T.Würthinger,H.Mössenböck.DynamicallyComposingLanguagesinaModularWay:SupportingCExtensionsforDynamicLanguages.InProceedingsofthe14th InternationalConferenceonModularity,2015.
Oursolutionis3xfasterthannative!
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
PerformanceonRubyCExtensionsOilyPNGandPSDNative
65
0
5
10
15
20
25
30
35
MRIPureRuby MRIWithCExtension
RubiniusWithCExtension
JRubyWithCExtension
JRuby+TruffleWithCExtension
JRuby+TruffleWithCExtension
(NoInline)
M.Grimmer,C.Seaton,T.Würthinger,H.Mössenböck.DynamicallyComposingLanguagesinaModularWay:SupportingCExtensionsforDynamicLanguages.InProceedingsofthe14th InternationalConferenceonModularity,2015.
It’sclearthatcross-languageinlining isakeypartofthe
performance
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Conclusions
66
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 67
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
OpenSource• https://github.com/graalvm/graal-core
– Graal compiler• https://github.com/graalvm/truffle
– Trufflelanguageimplementationframework• https://github.com/graalvm/fastr
– FastRruntime• https://github.com/graalvm/sulong
– DynamicruntimeforLLVMbitcode• https://github.com/jruby/jruby/wiki/Truffle
– FastRubyruntime
68
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
Acknowledgements
69
OracleDaniloAnsaloniStefanAnzingerCosminBascaDanieleBonettaMatthiasBrantnerPetrChalupaJürgenChristLaurentDaynèsGillesDuboscqMartinEntlicherBrandonFishBastianHossbachChristianHumerMickJordanVojinJovanovicPeterKesslerDavidLeopoldsederKevinMenardJakubPodlešákAleksandarProkopecTomRodriguez
Oracle(continued)RolandSchatzChrisSeatonDougSimonŠtěpánŠindelářZbyněkŠlajchrtLukasStadlerCodrutStancuJanŠtolaJaroslavTulachMichaelVanDeVanterAdamWelcChristianWimmerChristianWirthPaulWögererMarioWolczkoAndreasWößThomasWürthinger
JKULinzProf.HanspeterMössenböckBenoitDalozeJosefEislThomasFeichtingerMatthiasGrimmerChristianHäublJosefHaiderChristianHuberStefanMarrManuelRiggerStefanRumzuckerBernhardUrban
Universityof EdinburghChristopheDubachJuanJoséFumero AlfonsoRanjeet SinghToomas Remmelg
LaBRIFloréal Morandat
Universityof California,IrvineProf.MichaelFranzGulfemSavrunYeniceriWeiZhang
Purdue UniversityProf.JanVitekTomasKaliberaPetrMajLeiZhao
T.U.DortmundProf.PeterMarwedelHelenaKotthausIngoKorb
Universityof California,DavisProf.DuncanTempleLangNicholasUlle
Universityof Lugano,SwitzerlandProf.WalterBinderSunHaiyangYudiZheng
OracleInternsBrianBellevilleMiguelGarciaShamsImamAlexeyKaryakinStephenKellAndreasKunftVolkerLantingGeroLeinemannJulianLettnerJoeNashDavidPiorkowskiGregorRichardsRobertSeilbeckRifatShariyar
AlumniErikEcksteinMichaelHauptChristosKotselidisHyunjinLeeDavidLeibsChrisThalingerTillWestmann
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.|
SafeHarborStatementTheprecedingisintendedtoprovidesomeinsightintoalineofresearchinOracleLabs.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract. Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Oraclereservestherighttoalteritsdevelopmentplansandpracticesatanytime,andthedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedinconnectionwithanyOracleproductorserviceremainsatthesolediscretionofOracle. AnyviewsexpressedinthispresentationaremyownanddonotnecessarilyreflecttheviewsofOracle.
70
Copyright©2016, Oracleand/oritsaffiliates.Allrightsreserved.| 71