JavaScript程序的动态行为分析外文翻译节选.docx
《JavaScript程序的动态行为分析外文翻译节选.docx》由会员分享,可在线阅读,更多相关《JavaScript程序的动态行为分析外文翻译节选.docx(10页珍藏版)》请在冰点文库上搜索。
JavaScript程序的动态行为分析外文翻译节选
1800单词,1万英文字符,3600汉字
出处:
RichardsG,LebresneS,BurgB,etal.AnanalysisofthedynamicbehaviorofJavaScriptprograms[C]//AcmSigplanConferenceonProgrammingLanguageDesign&Implementation.ACM,2010:
1-12.
AnAnalysisoftheDynamicBehaviorofJavaScriptPrograms
GregorRichardsSylvainLebresneBrianBurgJanVitek
Abstract
TheJavaScriptprogramminglanguageiswidelyusedforwebprogrammingand,increasingly,forgeneralpurposecomputing.Assuch,improvingthecorrectness,securityandperformanceofJavaScriptapplicationshasbeenthedrivingforceforresearchintypesystems,staticanalysisandcompilertechniquesforthislanguage.Manyofthesetechniquesaimtoreigninsomeofthemostdynamicfeaturesofthelanguage,yetlittleseemstobeknownabouthowprogrammersactuallyutilizethelanguageorthesefeatures.Inthispaperweperformanempiricalstudyofthedynamicbehaviorofacorpusofwidely-usedJavaScriptprograms,andanalyzehowandwhythedynamicfeaturesareused.WereportonthedegreeofdynamismthatisexhibitedbytheseJavaScriptprogramsandcomparethatwithassumptionscommonlymadeintheliteratureandacceptedindustrybenchmarksuites.
Keywords:
DynamicBehavior,ExecutionTracing,DynamicMetrics,ProgramAnalysis,JavaScript
1.Introduction
JavaScriptisanobject-orientedlanguagedesignedin1995byBrendanEichatNetscapetoallownon-programmerstoextendwebsiteswithclient-sideexecutablecode.UnlikemoretraditionallanguagessuchasJava,C#orevenSmalltalk,itdoesnothaveclasses,anddoesnotencourageencapsulationorevenstructuredprogramming.InsteadJavaScriptstrivestomaximizeflexibility.JavaScript’ssuccessisundeniable.Asadatapoint,itisusedby97outoftheweb’s100mostpopularsites.2Thelanguageisalsobecomingageneralpurposecomputingplatformwithofficeapplications,browsersanddevelopmentenvironmentsbeingdevelopedinJavaScript.Ithasbeendubbedthe“assemblylanguage”oftheInternetandistargetedbycodegeneratorsfromthelikesofJavaandScheme.Inresponsetothissuccess,JavaScripthasstartedtogarneracademicattentionandrespect.Researchershavefocusedonthreemainproblems:
security,correctnessandperformance.SecurityisarguablyJavaScript’smostpressingproblem:
anumberofattackshavebeendiscoveredthatexploitthelanguage’sdynamism(mostlytheabilitytoaccessandmodifysharedobjectsandtoinjectcodeviaeval).Researchershaveproposedapproachesthatmarrystaticanalysisandruntimemonitoringtopreventasubsetofknownattacks.Anotherstrandofresearchhastriedtoinvestigatehowtoprovidebettertoolsfordevelopersforcatchingerrorsearly.Beingaweaklytypedlanguagewithnotypedeclarationsandonlyrun-timecheckingofcallsandfieldaccesses,itisnaturaltotrytoprovideastatictypesystemforJavaScript.Finally,aftermanyyearsofneglect,modernimplementationsofJavaScripthavestartedtoappearwhichusestateoftheartjust-in-timecompilationtechniques.
2.MotivationandRelatedWork
TheoriginalimpetusforourinterestinJavaScriptwastoassessthefeasibilityofastatictypesystemabletosuccessfullyandmeaningfullytypecheckexistingJavaScriptprograms.OtherdynamiclanguagessuchasSchemehavehadrecentsuccessintroducinggradualtypingsystems,buttheyhavestoppedshortoftypecheckingobject-orientedextensions(implementedbymacrosinScheme).ForJavaScript,Andersonetal.proposedatypesystemwithdefiniteandpotentialtypes,whileHeideggerandThiemannfollowinguponsomeoftheirearlierworkproposerecencytypesin,andFurretal.proposedarelatedsystemforDRuby.Whileallofthesetypesystemsacknowledgesomeminorsimplificationstothetargetlanguage,theyrelyonfairlysimilarassumptions.Forinstance,Thiemannwrites:
“Usually,nofurtherpropertiesaredefinedaftertheinitializationandthetypeofthepropertiesrarelychanges.”
CommonAssumptionsaboutthedynamicbehaviorofJavaScript.
Weproceedtoenumeratetheexplicitandimplicitassumptionsthatarecommonlyfoundintheliteratureandinimplementations.
1.Theprototypehierarchyisinvariant.Theassumptionthattheprototypehierarchydoesnotchangeafteranobjectiscreatedissocentraltothetypesystemworkthatchosetonotevenmodelprototypes.Researchonstaticanalysistypicallydoesnotmentionprototypeupdates.Yet,anymodificationtotheprototypehierarchycanpotentiallyimpactthecontrolflowgraphoftheapplicationjustaswellasthetypesofaffectedobjects.
2.Propertiesareaddedatobjectinitialization.Folkloreholdsthatthereissomethingakintoan“initializationphase”indynamiclanguageswheremostofthedynamicactivityoccursandafterwhichtheapplicationismostlystatic.ForJavaScriptthisisembodiedbytheassumptionthatmostchangestothefieldsandmethodsofobjectsoccuratinitialization,andthusthatitisreasonabletoassignanalmostcompletetypetoobjectsatcreation,leavingasmallnumberofpropertiesaspotential.
3.Propertiesarerarelydeleted.Removalofmethodsorfieldsisdifficulttoccommodateinatypesystemasitpermitsnonmonotonicevolutionoftypesthatbreakssubtypingguaranteesusuallyenforcedinmoderntypedlanguages.Ifdeletionisanexceptionaloccurrence(andonethatcanbepredicted),onecouldusepotentialtypesforpropertiesthatmaybedeletedinthefuture.But,thiswouldreducethebenefitsofhavingatype.
systeminthefirstplace,whichisprobablywhyrelatedworkchoosestoforbidit.Staticanalysisapproachesareusuallyabitmoretoleranttoimprecisionandcanhandledeletes,butwehavenotfoundanyexplanationofitshandlinginexistingdataflowanalysistechniques.
4.Theuseofevalisinfrequentanddoesnotaffectsemantics.Theuseofevalonarbitrarystringshasthepotentialofinvalidatinganyresultsobtainedbystaticanalysisorstatictypechecking.Thusmanyworkssimplyignoreit,whileotherassumethatusesareeithertrivialorrelatedtodeserializationusingtheJSONprotocol.
5.Declaredfunctionsignaturesareindicativeoftypes.TypesystemsforJavaScripttypicallyassumethatthedeclaredarityofafunctionisrepresentativeofthewayitwillbeinvoked.ThisisnotnecessarilythecasebecauseJavaScriptallows
callswithdifferentarities.
6.Programsizeismodest.SomepapersjustifyveryexpensiveanalyseswiththeexplicitassumptionthathandwrittenJavaScriptprogramsaresmall,andothersimplicitlyrelyonthisastheypresentanalyseswhichwouldnotscaletolargesystems.
7.Call-sitedynamismislow.SomeJavaScriptimplementationssuchasGoogleV8relyonwell-knownimplementationtechniquestooptimizeJavaScriptprogramssuchascreatingclasses(intheJavasense)forobjectsandinlinecaches.ThesetechniqueswillleadtogoodperformanceonlyifthebehaviorofJavaScriptisbroadlysimilartothatofotherobject-orientedlanguages
8.Executiontimeisdominatedbyhotloops.Trace-basedJustin-timecompilerssuchasTraceMonkeyrelyonthetraditionalassumptionthatexecutiontimeisdominatedbysmallloops.
9.IndustrybenchmarksarerepresentativeofJavaScriptworkloads.StandardenchmarksuitessuchasSunSpider,DromaeoandV8,areusedtotuneandcompareJavaScriptimplementationsandtoevaluatetheaccuracyofstaticanalysistechniques.ButconclusionsobtainedfromuseofthosebenchmarksareonlymeaningfuliftheyaccuratelyrepresenttherangeofJavaScriptworkloadsinthewild.
Thegoalofthispaperistoprovidesupportingevidencetoeitherconfirmorinvalidatetheseassumptions.Wearenotdisputingthevalidityofpreviousresearch,asevenifacoupleoftheaboveassumptionsprovedtobeunfounded,previousworkcanstillserveasausefulstartingpointforhandlingfullJavaScript.Butwedowanttohighlightlimitationstowidespreadadoptionofexistingtechniquesandpointtochallengesthatshouldbeaddressedinfutureresearch.
RelatedWork.Untilnow,tothebestofourknowledge,therehasbeennostudyofthedynamicbehaviorofJavaScriptprogramsofcomparabledepthorbreadth.Ratanaworabhanetal.haveperformedasimilarstudyconcurrentlytoourown,anditsresultsaresimilartoours.TherehavebeenstudiesofJavaScript’sdynamicbehaviorasitappliestosecurity,butthebehaviorsstudiedwererestrictedtothoseparticularlyrelevanttosecurity.WeconductedasmallscalestudyofJavaScriptandreportedpreliminaryresultsin,andthoseresultsareconsistentwiththenewresultspresentedhere.HolknerandHarlandhaveconductedastudyoftheuseofdynamicfeatures(additionanddeletionoffieldsandmethods)inthePythonprogramminglanguage.Theirstudyfocusedonasmallersetofprogramsandconcludedthatthereisaclearphasedistinction.Intheircorpusdynamicfeaturesoccurmostlyintheinitializationphaseofprogramsandlesssoduringthemaincomputation.OurresultssuggestthatJavaScriptismoredynamicthanPythoninpractice.Therearemanystudiesoftheruntimeuseofselectedfeaturesofobject-orientedlanguages.Forexample,Garretetal.reportedonthedynamismofmessagesendsinSelf,Calderetal.characterizedthedifferenceofbetweenCandC++programsin,andTemporoetal.studiedtheusageofinheritanceinJavain.Thesepreviouspapersstudyingreatdetailoneparticularaspectofeachlanguage.Inthisparticularwork,westriveforanoverviewofJavaScript,andleavedetailedanalysisforfuturework.Finally,wewereinspiredbytheworkofDufouretal.andtheirrigorousframeworkfordiscussingruntimemetricsforJava.
3.TracingandAnalysisInfrastructure
Thetracing