Vous êtes sur la page 1sur 5

6/19/13

Searchforpeople,placesandthings

The HipHop Virtual Machine


EdwardRhodes FindFriends Home

TheHipHopVirtualMachine
byJasonEvansforFacebookEngineering(Notes)onFriday,December9,2011at2:00pm

Tagged

We'realwayslookingforwaystomakeourcomputinginfrastructuremore efficient,andin2010wedeployedHipHopforPHPtohelpsupportthegrowing numberofFacebookusers.WhileHipHophashelpedusmakesignificantgains intheperformanceofourcode,itsrelianceonstaticcompilationmakes optimizingourcodetimeconsuming.Wewerealsocompelledtodevelopa separateHipHopinterpreter(hphpi)thatrequiresalotofefforttomaintain.So, earlylastyear,weputtogetherasmallteamtoexperimentwithdynamic translationofPHPcodeintonativemachinecode.WhatresultedisanewPHP executionenginebasedontheHipHoplanguageruntimethatwecalltheHipHopVirtualMachine(hhvm). We'reexcitedtoreportthatFacebookisnowusinghhvmasafasterreplacementforhphpi,withplansto eventuallyusehhvmforallPHPexecution. Facebookuseshphpi(andnowhhvm)fordaytodaysoftwaredevelopment,butusestheHipHopcompiler (hphpc)tocreateoptimizedbinariesthatservetheFacebookwebsite.hphpcisinessenceatraditional staticcompilerthatconvertsPHPASTC++x64.Wehavelongbeenkeenlyawareofthelimitations tostaticanalysisimposedbysuchadynamiclanguageasPHP,nottomentiontherisksinherentin developingsoftwarewithhphpianddeployingwithhphpc.Ourexperienceswithhphpcledustostart experimentingwithdynamictranslationtonativemachinecode,alsoknownasjustintime(JIT) compilation.Adynamictranslatorcanobservedatatypesastheprogramexecutes,andgeneratetype specializedmachinecode.Unfortunatelywedidn'thaveacleanmodelofPHPlanguagesemanticsbuilt intoHipHop,ashphpcandhphpiarebaseddirectlyontwodistinctabstractsyntaxtree(AST) implementations,ratherthansharingaunifiedintermediaterepresentation.Thereforewedevelopedahigh levelstackbasedvirtualmachinespecificallytailoredtoPHPthatexecutesHipHopbytecode(HHBC). hhvmuseshphpc'sPHPASTimplementationandextendsthepipelinetoPHPASTHHBC.We iterativelycodevelopedbothaninterpreterandadynamicHHBCx64translatorthatseamlessly interoperate,withtheprimarygoalofcleanlysupportingtranslation. Throughoutthehhvmprojectwehavetendedtowardsimplesolutions.Thisisnowheremoreevidentthan inthecorepremiseofthedynamictranslatoritself.MostexistingsystemsusemethodatatimeJIT compilation(e.g.,JavaandC#),thoughtracebasedtranslationhasalsobeenexploredinrecentsystems (e.g.,TamarinandTraceMonkey).Wedecidedtotryaverysimpleformoftracingthatlimitseachtraceto asinglebasicblockwithknowninputtypes.This"tracelet"approachsimplifiesthetracecache managementproblem,becausecomplexapplicationcontrolflowcannotcreateacombinatorialexplosionof traces.Eachtracelethasasimplethreepartstructure: Typeguard(s) Body Linkagetosubsequenttracelet(s)
Chat(3)

GetNotesviaRSS Report Sponsored SeeAll

MENWATCHTHISVIDEO livingresearchinstitute.com ThisControversialVideo HasBeenBannedByBig Media.ClickHereToSee It!

Andrologix Don'tForgettoLikeMe!

Like15,586peoplelikeAndrologix. AmericanRadioSupply.com 24HourHamfest... AmateurRadioParts& SupplySuperstore

1,551peoplelikeAmericanRadioSupply. #1TiptoLoseBellyFat Youcanquicklylose7lb offateachweekby followingthisfamous doctor's1simpletip.

Like3,010peoplelikeMyHealthyLiving. AmateurRadiosforCheap nextag.com Clickhereforgreatdeals onamateurradio transceivers,antennas andmore!

Thetypeguardspreventexecutionforincompatibleinputtypes,andtheremainderofthetraceletdoesthe realwork.Eachtracelethasgreatfreedom,theonlyrequirementbeingthatitrestorethevirtualmachineto aconsistentstateanytimeexecutionescapesthetraceletanditshelpers.Theobviousdisadvantageis thattraceletguardsmayrepeatunnecessarywork.Thusfarwehavenotfoundthistobeaproblem,but wedohavesomesolutionsinmindshouldaneedarise. ForthosewhoareinterestedinunderstandingHHBCindetail,thebytecodespecificationisavailableinthe HipHopsourcetree.However,detailedknowledgeshouldnotbenecessaryforunderstandingthefollowing example:

ShockingLanguageVideo pimsleurapproach.com Ifyoudon'tknowSpanish andareage50+you'll wanttoseethis immediately!

MBAforEngineers PursueaparttimeMBA onlinewiththeacademic rigorofanoncampus program. 4,184peoplelike MBAatUNC:ShapingGlobalLeadersOnline.

https://www.facebook.com/note.php?note_id=10150415177928920

1/5

6/19/13

The HipHop Virtual Machine

ExamplePHPprogramtranslatedtoHHBC f ( ) isexecutedtwice,forwhichthetranslatorcreatesthreetraceletstotalasshownbelow.f ( $ a ,4 2 ) causescreationoftraceletsAandB,andf ( $ a ," h e l l o " ) causescreationoftraceletCBisusedby bothinvocations.

Traceletsinducedbyf($a,42)andf($a,"hello") Howwelldoeshhvmwork?Ascomparedtohphpi,thehhvmbytecodeinterpreterisapproximately1.6X fasterforasetofrealworldFacebookspecificbenchmarks.Rightnowthereisastabilitygapbetweenthe hhvminterpreterandtranslator,whichprecludesusreportingtranslatorperformanceforthesamesetof benchmarks.However,wecaninferfromasetofbenchmarksbasedontheLanguageShootoutthat translatorperformanceisclosertohphpccompiledprogramperformancethantointerpreterperformance, asindicatedbythegeometricmeanofthebenchmarks(rightmostcolumninthefollowingfigure).The interpretersareallroughly0.2Xasfastashphpc,andthetranslatorisapproximately0.6Xasfast.For perspectiveonwhythismatters,considerthatmanyFacebookengineersspendtheirdaysdeveloping PHPcodeinanendlesseditreloaddebugcycle.Thedifferencebetween8secondand5secondreloads duetoswitchingfromhphpitothehhvminterpretermakesabigdifferencetoproductivity,andthis improvementwillbeevenmoredramaticonceweenablethetranslator.

https://www.facebook.com/note.php?note_id=10150415177928920

2/5

6/19/13

The HipHop Virtual Machine

Weexpecthhvmtorapidlyclosetheperformancegapwithhphpccompiledbinariesoverthecoming monthsasthedynamictranslatorstabilizesandmatures.Infact,wepredictthathhvmwilleventually outperformstaticallycompiledbinariesinFacebook'sproductionenvironment,inpartbecauseweare alreadysharingenoughinfrastructurewiththestaticcompilerthatwewillsoonbeabletoleveragestatic analysisresultsduringtraceletcreation. Manychallengesremain,aswellassomeuncertaintyregardingthetranslator'sbehaviorwhenrunningthe entiretyofFacebook'sPHPcodebase.Intheneartermweneedtostabilizethetranslatorandcreatean ondiskbytecodeformat(toreducestartuptimeandtostoreglobalstaticanalysisresults).Thenwewill needtooptimize/tuneboththetranslatorandtheinterpreterasweobservehowthesystembehavesunder productionworkloads.Herearejustacoupleoftheinterestingproblemswewillsoonface: Thex64machinecodethatthetranslatorgeneratesconsumesapproximatelytentimesasmuch memoryasthecorrespondingHHBC.CPUinstructioncachemissesarealimitingfactorforthelarge PHPapplicationsthatFacebookruns,soahybridbetweeninterpretationandtranslationmay outperformpuretranslation. Thetranslatorcurrentlymakesnouseofprofilefeedback,thoughwedohavesamplebasedprofiling infrastructureinplace.Profileguidedoptimizationisanespeciallyinterestingproblemforusbecause Facebookdynamicallyreconfiguresitswebsitebetweencodepushes.Hotcodepathsmutateover time,andportionsofthex64translationcacheeffectivelybecomegarbage.Onesolutionmaybeto repeatedlycreateanewtranslationcachebasedonthepreviousone,takingadvantageofrecent profiledata.Thisapproachhasalotincommonwithsemispacegarbagecollection. Thefirst90%ofthehhvmprojectisdonenowwe'reontothesecond90%aswemakeitreallyshine.The hhvmcodeisdeeplyintegratedwiththeHipHopsourcecode,andwewillcontinuetoshareHipHopviathe publicGitHubsiteforHipHop,justaswehavesinceHipHop'sinitialreleaseinearly2010.Wehopethat thePHPcommunitywillfindhhvmusefulasitmaturesandengagewithustobroadenitsusefulness throughtechnicaldiscussions,bugreports,andcodecontributions.WeactivelymonitortheGitHubsite andmailinglist. JasonEvansisasoftwareengineerontheHipHopteamatFacebook,oneofnearly20peoplewhohave contributedtothehhvmprojectsofar. AdditionalHipHoparticles MoveFast(originalannouncement) Sixmonthslater(retrospectivesixmonthsafterrelease) MoreOptimizationsforEfficientServers MakingHPHPiFaster

LikeCommentShare

382

https://www.facebook.com/note.php?note_id=10150415177928920

3/5

6/19/13
1,370peoplelikethis. Viewpreviouscomments FanRobbinNiceWork.WillHHVMputonGitHub? December14,2011at1:12amLike 3

The HipHop Virtual Machine

41of145

ErnaniJoppert Iguessthisopensahugebenefitforbytecodeinstrumentationtoo,amIright? December14,2011at3:02amLike 1

TimPost Thisreallylooksinteresting.Performancenotwithstanding,theopportunitiesformuchbetterstatic analysisareobvioushere.Therealsoseemtobemoresubtlebenefits,suchassingletonsactuallymaking sense(presumablyoneobjectcouldserveconcurrentrequests,finetunedasneededbycallerswithdependency injection?)Thanksforreleasingthis. December14,2011at5:12amLike 1 AhmedDaif verygood December14,2011at10:36amLike 2

PeterPetermannijustwishthegithubpagewouldgetabitmoredocumentationlove. December14,2011at11:06amLike 1

AnciensAlbertinsCsatogoverygoodwork December14,2011at2:16pmLike SeeTranslation December14,2011at10:26pmLike 1

IvanPellizzariGreatcompanyisdoinggreattechnologyimprovements:compliments December15,2011at3:24pmLike MarkTicsayGuadalupeFTW!!! December19,2011at5:53pmLike CorrieZhao SeeTranslation December20,2011at11:06amLike 1 3

NarimanAbdullayevIthinkthisthemostneededfeatureforphp.itwillmakephpmorecompetitivein comparisonwithotherlanguages.andmaysometimeitwillcompetewithJVM... December21,2011at3:16amLike 1 CoryCharlieIhavenocluewhatuguysaredoinitsalientomelol,butawesomejobsguys December21,2011at7:45pmLike VincensiusAgustinust onlyPHP? December22,2011at11:22pmLike THX December25,2011at10:18pmLike 1 3 1

OzgurCapulcuKaratas@VincensiusnoPHPandC++ December26,2011at6:28pmLike 2 Yo!

IngusNeilandshmm,nowweneedpracticalimplementationonDebianbasedOSfortests December27,2011at7:17amLike 2

WayneRenbjorIsoneedtostartusingthisatwork.... January1,2012at11:07amLike 1

TonderaiWatsonZvidzwasothisgonemakeproducersgood,loanforstudio. January3,2012at5:50amLike 1

PurabKharat Iamgettingfollowingerror. CMakeErroratCMakeLists.txt:11(message): ThevalueofHPHP_HOMEdoesnotexist Configuringincomplete,errorsoccurred! January4,2012at8:58amLike 1 SakisKorinthosNiceWork February2,2012at1:31pmLike 1

LuisVegaso$hitandreturn$hitanddump($hit).niceeasteregg. February9,2012at1:13pmLike 3

YusukeNakagawa PHPer SeeTranslation February13,2012at2:43amLike 1 LeeFoxAnytimeframeontheVM? March23,2012at11:42amLike 3

JonSnellIsthisprojectdead?Therehaven'tbeenanycommitstogithubin4months. April16,2012at2:10pmLike 2

RishavRastoginocommitsfor4months,hardlyanyrepliesonthegooglegroups..idon'tthinkthereismuch dev/supportgoingonfortheproject

https://www.facebook.com/note.php?note_id=10150415177928920

4/5

6/19/13
May3,2012at3:18amLike 1

The HipHop Virtual Machine

AngeloDangelohello.howdoyoudoforservethecontentfrombinariesccompiled? whatserverdidyouuse=? May7,2012at7:24pmLike

AngeloDangelocanyouprovideabinaresversions.icantfindthem.compilertranslator,andserver May7,2012at7:25pmLike 1

AngeloDangelowellandphpscriptandresultingcbinaries May7,2012at7:25pmLike 1

YoAnLinithinkthecompiledbinaryincludesahttpserver,notusingothershttpserver. June26,2012at3:01amLike AdeelNasirverynice July16,2012at9:32amLike 1 1

InezKorczyskiSo..what'supwithHHVM,isitgoingtobereleasedanytimesoon? July27,2012at7:34pmLike 1

DavidStoneHHVMisongithubitsharesthesamecodebaseashiphopforphp.See https://github.com/facebook/hiphopphp/wiki/BuildingandinstallingHHVMonUbuntu12.04Basicallyyoujust needtoexportUSE_HHVM=1anditwillcompileHHVM hiphopphp github.com SourcecodetransformerfromPHPtoC++.Contributetohiphopphpdevelopmentbycreating anaccountonGitHub.

August18,2012at7:40pmLike

DenisTruffaut TechdiscussionswithHipHop/HHVMteam...righthere: http://www.facebook.com/pages/HipHopforPHP/282425744325 September26,2012at9:23amLike 1 HiroakiArakawa SeeTranslation November8,2012at1:04amLike LeeJack SeeTranslation January30at7:59amLike

NagaRajanhellosir:plsreadFacebookapplicationdevelopersintheapplicationsuser'scanbeusingmore "hi"word...everyonecansayasperday100andmoreso..Toadvancetechnologycanbeusedtodevelop on"icons"forHILabelorBatten.plsreferandVoteForMe...Thankingu March10at7:25pmLike TimoWitteToallthosepeoplebashingphp/sayingthatJavawouldbebetter.Iagreewithyouinsomeway. PHPismadeupofpartsthatdont"match",theyuseobjectshereandfunctionsthere,theorderofthe parametersdonthaveanysystembehindthem(look... SeeMore April10at4:56amLike 1 NadirConstantine June10at6:30amLike AngelLeondidyouexplorethepossibilityofseeingifjemallocwouldmaketheJavaVirtualMachinehandle memoryallocationbetterandinsteadcreateaPHPtoJavaByteCodecompilerthatwouldrunonajemalloc poweredversionoftheJavaVirtualMachine? Wh... SeeMore June11at2:05pmLike DavidYangnicearticleaboutHipHopVirtualMachine. June15at1:00pmLike LiDingwow.Waytogo. Sundayat11:16pmLike Writeacomment...
PressEntertopost.

hiphopalgiyrya

About

CreateAd

CreatePage

Developers

Careers

Privacy

Cookies

Terms

Help

Facebook2013English(US)

https://www.facebook.com/note.php?note_id=10150415177928920

5/5

Vous aimerez peut-être aussi