ebook img

Design and Implementation of an Ahead-of-Time Compiler for PHP Paul Biggar PDF

220 Pages·2010·1.48 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Design and Implementation of an Ahead-of-Time Compiler for PHP Paul Biggar

Design and Implementation of an Ahead-of-Time Compiler for PHP by Paul Biggar Dissertation Presented in fulfillment of the requirements for the Degree of Doctor of Philosophy TRINITY COLLEGE DUBLIN APRIL, 2010 Declaration I, the undersigned, declare that this work has not previously been submitted as an exerciseforadegreeatthis,oranyotherUniversity,andthatunlessotherwisestated, ismyownwork. PaulBiggar 14thApril,2010 ii / Permission to Lend and or Copy I,theundersigned,agreethatTrinityCollegeLibrarymaylendorcopythisdisserta- tionuponrequest. PaulBiggar 14thApril,2010 iii Abstract Inrecentyearstheimportanceofdynamicscriptinglanguages—suchasPHP,Python, RubyandJavascript—hasgrownastheyareusedforanincreasingamountofsoftware development. Scriptinglanguagesprovidehigh-levellanguagefeatures,afastcompile- modify-testenvironmentforrapidprototyping,strongintegrationwithdatabaseand webdevelopmentsystems,andextensivestandardlibraries. PHPpowersmanyofthe mostpopularwebapplicationssuchasFacebook,WikipediaandYahoo. Ingeneral, thereisatrendtowardswritinganincreasingamountofanapplicationinascripting language rather than in a traditional programming language, not least to avoid the complexityofcrossingbetweenlanguages. Despitetheirincreasingpopularity,mostscriptinglanguageimplementationsremain interpreted. Typically,theseimplementationsareslow,betweenoneandtwoorders ofmagnitudeslowerthanC. Improvingtheperformanceofscriptinglanguageimple- mentationswouldbeofsignificantbenefit,howevermanyofthefeaturesofscripting languagesmakethemdifficulttocompileaheadoftime. Inthisdissertationweargue thatahead-of-timecompilationofscriptinglanguagesisbothpossibleandvaluable. We present phc, an ahead-of-time compiler for the PHP language. We describe the design and implementation of the compiler, and identify specific challenges in the designofacompilerforadynamicscriptinglanguage. Wedeterminethattherearethreeimportantfeaturesofscriptinglanguagesthatare difficulttocompileorreimplement. Sincescriptinglanguagesaredefinedprimarily throughthesemanticsoftheiroriginalimplementations,theyoftenchangesemantics betweenreleases. TheyprovideCAPIs,usedbothforforeign-functioninterfacesand towritethird-partyextensions. TheseAPIstypicallyhavetightintegrationwiththe originalimplementation,andareusedtoprovidelargestandardlibraries,whichare difficult to re-use, and costly to reimplement. Finally, they support run-time code generation. Thesefeaturesmaketheimportantgoalofcorrectnessdifficulttoachieve forcompilersandreimplementations. We present a technique to support these features in ourahead-of-time compilerfor PHP. Our technique uses the original PHP implementation through the provided PHP C API, both in our compiler, and in our generated code. We support all of v vi theseimportantscriptinglanguagefeatures,particularlyfocusingonthecorrectness ofcompiledprograms. Additionally,ourapproachallowsustoautomaticallysupport limitedfuturelanguagechanges. Wepresentadiscussionandperformanceevaluation ofthistechnique,whichweshowincreasestheexecutionspeedofPHPprogramsby 1.55xinourbenchmarks. Inordertoimprovethisperformance,staticanalysisand optimizationarerequired. However, static analysis of scripting languages such as PHP is difficult due to the featuresfoundintheselanguages. Thesefeaturesincludedynamictypingwithimplicit typeconversions,dynamicaliasing,implicitobjectandarraycreation,andoverloading ofsimpleoperators. Wefindthatasaresult,simpleanalysistechniquessuchasSSA and def-use chains are not straightforward to use, and that a single unconstrained variablecanruinouranalysis. WedescribethechallengingsemanticsofPHP,anda staticanalysertomodelthem. Ouranalysiscombinesaliasanalysis,type-inference and constant-propagation for PHP, computing results that are essential for other analysesandoptimizations. Ourempiricalresultsshowthatouranalysisiscapableof determiningthatalmostallprogramvariablesareunaliased,andthatdynamictypes forover60%ofvariablescanbestaticallydeterminedbyouranalysis. Acknowledgements Morethananyone,I’dliketothankDavidGreggforhissupervision,helpandadvice throughout the last six and a half years. He guided me through my undergraduate research,throughmyPhDapplications,andthroughoutmyPhD. Ithinkitisfairto saythatnearlyeverythingIknowaboutresearchcomesfromDavid. Many supervisors are hands-off, David is certainly not. He has read everything I produced,hemetmefrequentlytoguidemyresearchandhisdoorisalwaysopen. His expertiseonallmanneroftopicsrelatedtocompilersandresearchhasbeeninvaluable. ItistherareproblemthatDavidcouldnothelpmeon. Davidmadeithisbusinessto understandeverythingIdid. I’mnotsureheknewanythingaboutscriptinglanguages whenImethim,buthespentaconsiderableamountoftimeandefforttounderstand myresearchthoroughly. FromthemomentIstartedthisPhD,Davidhasbeenthereforme. Anytimethere wasaproblem,hehadtimetohelpwithit. Inparticular,atthestartof2007Iwent through a particularly bad time. My then-current research wasn’t going anywhere, and a change was needed. At the time, neither of us was really sure I’d make it to finishmyPhD. Duringthattimeinparticular,hishelpandguidancewasverymuch appreciated. Manyofmycolleaguesmeritthanks,inparticularourresearchgroup: KevinWilliams, Nicholas Nash, Robert (Bobb) Crosbie, Jason McCandless and (Raymond) Scott Manley. They listened to my ideas and critiqued my work. Kevin also worked on scriptinglanguages,andIlearnedalotfromchattingtohim. Nickdidanamazingjob inourfirstpaper,andI’mveryproudoftheresult. JohnGilbertandEdskodeVrieswerecollaboratorsonphc. Isatintheirofficeforthe firstyearofmyresearch,andIthinkIlearnedmoreaboutcompilersfromthemthan fromanyothersource. Ofcourse,theyalsostartedphc,andinvitedmetoworkonit, towhichIowethemagreatdebt. Idon’tthinkthecompilerIwouldhaveotherwise workedonwouldhavebeenanythingassuccessful. IwanttothankEdskoinparticular. WorkingwithEdskoisalessoninhowtocode vii viii well,andIlearnedagreatdealfromworkingonphcwithhim. Hereadalotofmy code,mycommitlogs,andallmypapers. ArguingwithEdskohelpedmefleshouta greatmanyideas;nounclearideagetspasthim. Healsotookontheherculeaneffort ofreadingmywholePhDinonenight. I also want to thank Kevin, Nick, Bobb, Jason, Scott, John and Edsko for their friendship. Itwouldhavebeenalongfouryearswithoutit. Jimmy Cleary interned withme during the summerof2009. He workedon many aspectsofphc,writingfeatures,fixingbugs,andrunningamassiveamountofexper- iments. His output far outstripped the time it took to train him in, and I honestly believeIwouldnothavethisPhDfinishedwithouthishelp. Manypeopletookthetimetoreadmypapersanddissertation,andoffercomments, includingDavid,Kevin,Nick,Bobb,Jason,Scott,Edsko,JohnandJimmy. Thanks alsotoNunoLopes,GrahamKelly,ChristopherJones,AlexGaynor,JamesStanier, CorneliusRiemenschneider,andEtienneKneuss,whoallprovidedvaluablefeedback. PeterHayestaughtmethetrickofreadingmypapersoutloud. Ibelievethismadea considerabledifferencetothequalityofmywriting. ItravelledconsiderablythroughoutmyPhD. Ilearnedagreatdealfromtravellingto PLDI,ASPLOSandHOPL,fromspeakingtotoomanypeopletolisthere. Seminars andsummerschoolsalsotaughtmeagreatdeal. ThankstoMarkusSchordan,Sebas- tianHackandFabriceRastello,andKoendeBosschereforacceptingmetoDagstuhl, theSSAseminarandtheACACESsummerschool,respectively. Ilearnedagreatdeal, and met a lot of interesting people. Lectures from Mike Hind, Kathryn McKinley andBarbaraRyderwereparticularlyinterestingandinspiring. I had many opportunities thanks to the kind help of others. I want to thank Dan QuinlanforhisinvitationtoLivermore,toIanTaylorforarrangingtheGoogleTech Talk,toBrianShireforhavingmetoFacebook,andtoDanielBerlinformentoring meongccduringtheGoogleSummerofCode. Theseseeminglysmallopportunities havebenefitedmemuchmorethanyoumightknow. My work was funded by the Irish Research Council for Science, Engineering and TechnologyfundedbytheNationalDevelopmentPlan. Iwouldhavebeencompletely / unable to work on a PhD without this funding. The Dun Laoghaire Rathdown CountyCouncilpaidmyfees,andgavemeasmallstipend. Iwanttothankthemfor theirhelp. ix MyfamilyandfriendshavebeenverysupportivethroughoutthisPhD. Noamount ofthankscanexpresshowmuchIvaluetheirfriendshipandlove. IcouldneverhavegottentowhereIamwithoutmyfiancée,OrlaMcHenry. Thelast twoyearshavebeenalotofworkandstress,andwithouthertowelcomemehome,I would have struggled to make it through. She brought me cookies when I worked late,cheeredmeupwhenIwasdown,andtoldmeitwouldbefinewhenIworried. She was always there when I needed her. Knowing how proud she is of me always makesmesmile. OfallofthethingsI’vegainedinthelastfouryears,nothingmakes mehappierthanOrla. I’veneverfeltluckierthanIamtohaveher. Thankyouall.

Description:
Paul Biggar. Dissertation we do not discuss in this dissertation include Bash, Visual Basic, Tcl and ASP as Scheme, Lisp, Haskell or OCaml.
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.