review of the doppio runtime execution environment for web...

6
Mario Lorenzo CISD 700 10/8/2017 Review of the Doppio Runtime Execution Environment for Web Browsers Abstract Since the early 1990’s when Web browsers first emerged, they became the primary mechanism for computer users to explore information served over the Internet. Web browsers went through numerous evolutions, constantly expanding support for multimedia features and greater participation in standards. Early on it became clear that web pages required additional dynamic elements in order to serve the user experience that consumers were looking for. This drove the inclusion of an execution environment in the form of an interpreter that could parse and execute programs embedded in web pages. Today, web browsers are pervasive and can be found on any device with Internet connectivity. This makes web browsers a prime runtime target for application developers who want to reach a massive volume of users across many different devices. Unfortunately, the only established language supported by all these browsers is JavaScript (ECMAScript). JavaScript is found in virtually all web applications providing dynamic client-side UI rendering as well as client-server interaction through Ajax and even server-side JavaScript (such as NodeJS runtime). JavaScript lacks many important features provided by modern high-level programming language. The authors and inventors [Vilk and Berger] of the Doppio Runtime Environment looked to solve these limitations by implementing an execution runtime in JavaScript that would fully support programs written in High-level programming languages (such as Java and C++) without sacrificing on capabilities and standard libraries featured in those languages. This paper will review the Doppio Execution model and understand its major limitations and technical challenges. Problem Browsers serve as an ideal environment for developing applications because of its ubiquitous nature and cross-platform support. This is very attractive to companies and developers who want to build applications while avoiding the cost of supporting different fragmented runtime environments, such as the differences in device and their operating systems. Much like what the Java Virtual Machine solved by creating a virtualized environment where the source language could be compiled into an intermediate representation and defer the generation of machine code until the moment it is executed on a device. This allowed for developers to build and maintain one version of their source code that did not have to account for various native platform differences. That work was left to the implementation of the JVM. The JVM converts the intermediate representation, such as Java bytecode, into the target language machine code. Vilk and Berger similarly position the Web Browser as an Operating System that provides this kind of abstraction through it cross- platform support and its ubiquitous nature. They contend that JavaScript’s lack of support for fundamental capabilities found in modern high-level programming

Upload: others

Post on 15-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Review of the Doppio Runtime Execution Environment for Web …blog.mjlorenzo.com/papers/MarioLorenzo_DoppioReview.pdf · 2017-10-11 · virtually all web applications providing dynamic

MarioLorenzoCISD700

10/8/2017ReviewoftheDoppioRuntimeExecutionEnvironmentforWebBrowsersAbstractSincetheearly1990’swhenWebbrowsersfirstemerged,theybecametheprimarymechanism for computer users to explore information served over the Internet.Web browsers went through numerous evolutions, constantly expanding supportformultimedia featuresandgreaterparticipation instandards.Earlyon itbecameclear thatweb pages required additional dynamic elements in order to serve theuser experience that consumers were looking for. This drove the inclusion of anexecutionenvironment in the formofan interpreter that couldparseandexecuteprogramsembeddedinwebpages.Today,webbrowsersarepervasiveandcanbefoundonanydevicewithInternetconnectivity.Thismakeswebbrowsersaprimeruntime target forapplicationdeveloperswhowant to reachamassivevolumeofusers acrossmany different devices. Unfortunately, the only established languagesupportedbyall thesebrowsers is JavaScript (ECMAScript). JavaScript is found invirtuallyallwebapplicationsprovidingdynamicclient-sideUIrenderingaswellasclient-server interaction through Ajax and even server-side JavaScript (such asNodeJS runtime). JavaScript lacks many important features provided by modernhigh-level programming language.The authors and inventors [Vilk andBerger] oftheDoppioRuntimeEnvironmentlookedtosolvetheselimitationsbyimplementingan execution runtime in JavaScript that would fully support programs written inHigh-level programming languages (such as Java and C++) without sacrificing oncapabilities and standard libraries featured in those languages. This paper willreview the Doppio Execution model and understand its major limitations andtechnicalchallenges.ProblemBrowsersserveasan idealenvironment fordevelopingapplicationsbecauseof itsubiquitousnatureandcross-platformsupport.Thisisveryattractivetocompaniesanddeveloperswhowanttobuildapplicationswhileavoidingthecostofsupportingdifferent fragmented runtimeenvironments, such as thedifferences indevice andtheiroperatingsystems.MuchlikewhattheJavaVirtualMachinesolvedbycreatinga virtualized environment where the source language could be compiled into anintermediate representation and defer the generation of machine code until themoment it is executed on a device. This allowed for developers to build andmaintainoneversionoftheirsourcecodethatdidnothavetoaccountforvariousnativeplatformdifferences.Thatworkwas left to the implementationof the JVM.The JVMconverts the intermediaterepresentation,suchas Javabytecode, into thetargetlanguagemachinecode.VilkandBergersimilarlypositiontheWebBrowseras an Operating System that provides this kind of abstraction through it cross-platformsupport and itsubiquitousnature.They contend that JavaScript’s lackofsupport for fundamental capabilities found in modern high-level programming

Page 2: Review of the Doppio Runtime Execution Environment for Web …blog.mjlorenzo.com/papers/MarioLorenzo_DoppioReview.pdf · 2017-10-11 · virtually all web applications providing dynamic

languagessuchasJavaandC++makesitunsuitableandunattractivetoapplicationdevelopers. They also point out that there is a massive amount of code that hasalready been written and tested in other popular languages that could be madeavailable for use. Vilk and Berger propose a new Runtime Environment calledDoppio that can serve as the virtualized layer, much like a JVM, that runs in thebrowser that can interpret Java or C++ without requiring any alterations to theprogramimplementation.The paper enumerates various key abstractions that are missing from WebBrowsers that existing programming languages expect. The first is concurrencysupport through multi-threading support. JavaScript is a single-threaded event-drivenlanguagethatdoesnotsupportthreadsuspension.Thismeansthatonceaneventexecutes,itmustcontinuetoexecuteuntilitcompletes.Thereisnowayforablock of code to suspend it self. Take for example a worker thread in a Javaapplication,itcanenterawait-loopconditionandallowtheenvironmenttosuspendit and activate another thread. This characteristic is something that other UIframeworks exhibit andwhy even listener code should be kept to aminimum. InJavaSwing,onecouldregisteraneventlistener,andit istypicallygoodpracticetomove amajor computation to aworker thread to free theUI to respond to otheruserevents.Unfortunately,browsersdonotallowformulti-threadinginJavaScriptand therefore is amajor limitation. This limitationmeans that even portingmostmulti-threaded programs to JavaScript is not possible. Vilk and Berger provide asimple example of a C++ program that prompts the user for input through thekeyboard. They demonstrated how this simple example looks as a JavaScriptprogramandgoontoassertthatanythingbeyondasimplescenariowouldnotbeimplementableinJavaScript.Another critical limitation of JavaScript deals with Asynchronous APIs. Most allclient-server APIs in JavaScript today are asynchronous (non-blocking). Any onethat has written a non-trivial JavaScript web application has run into this issue.There is no way to create a synchronous API from an asynchronous one inJavaScript, since it is single-threaded and no support for suspending or blockingwithouttyinguptheprimarythreadusedtohandleuserevents.The paper goes on to describe how the new WebWorkers support added inBrowserstooffloadcomputationtoaseparatethreadofexecutiondoesnotaddressthe limitation.WebWorkersdonotsharememorywiththeJavaScriptthread.Theonly communication between the two threads is through an asynchronousmessaging channel. Web Workers also do not have access to user input or UIelementsonthewebpage.Still other issuesbesidesasynchronicityandsingle-threadedmodelexist.VilkandBergerdescribethekeyabstractionsandcapabilitiesthatwouldberequiredbyanexecutionenvironmenttosupporthigh-levelprogramminglanguageslikeJavaandC++.Theseincludeafilesystemabstraction,unmanagedheap,networksockets,andblockingI/O.Assuch,VilkandBergerconcludethatit isnotpossibletoperformadirect translation of arbitrary code into JavaScript for execution within the webbrowser.Therefore, theyproposeadifferentexecutionenvironmentthatemulatesthesource languagesemantics.ThepaperdescribesDoppio,asentirelywritten in

Page 3: Review of the Doppio Runtime Execution Environment for Web …blog.mjlorenzo.com/papers/MarioLorenzo_DoppioReview.pdf · 2017-10-11 · virtually all web applications providing dynamic

JavaScript providing an execution environment that solves the aforementionedchallengesandprovesitsfeasibilityofthisapproachthroughtwocasestudies.ThefirstistheDoppioJVM,whichtakesJavasourceprogramsandexecutesthemwithinthebrowser.Theother is theC++case studywhere they leverage theEmscriptenframeworkanddemonstratethatitcansuccessfulrunagame.BackgroundandpriorresearchPrior attempts have been made to allow programmers to use high-levelprogramminglanguagesthatwouldbecompiledortranslatedintoJavaScript.Theseinitiatives include GWT (Google Web Toolkit), ASM, Emscripten, II2JS, andWeScheme. Google’s GWT and Microsoft’s II2JS are among the more popular oftheseframeworks.Theyalsoreceivedasignificant investment fromtherespectivecompaniesinvolved.GWTprovidesaJavaAPIandJava-to-JavaScript“transpiler”(translator/compiler)used to emit JavaScript from Java programs that are able to interact with UIelements and perform Ajax requests to a web server. GWT did not attempt toprovidegeneralsupportforJavabutratherlimitedtheJavaAPIsavailableinorderto achieve a translation to JavaScript. Some of the key benefits of GWT includedleveragingstatic/strongtypinginJavathatcouldproducecompiletimeerrorsandJava’sclass-basedobject-orientationmodelthatJavaScriptlacksbutunderstoodbya largepopulationofJavadevelopers.VilkandBergerassertthatGWTstillsuffersfromallthelimitationstheyoutlinedbecauseitproducesJavaScriptthatmustrunwithin the Browsers execution environment. GWT also only provides access to alimited set of Java APIs and introduces new classes that are friendly for Java-to-JavaScripttranslation.MicrosoftprovidedII2JSasawaytotranslateCommonIntermediateLanguage(CIL)intoJavaScript.II2JScancompilearbitrary.NETprogramsintoJavaScript,butonlyiftheydonotuseOSfeaturessuchasfilesystem,unmanagedheap,andstandardI/O.JavaScriptprogramsproducedbyGWTandII2JSbotharevulnerabletofreezingthebrowser when running for long periods because neither framework attemps toconvert the programs into finite-duration events. As explained earlier, the single-threaded nature of the browser’s JavaScript execution environment means thatother events are not processed until the current event completes execution. Thisproduceshangingorfreezingofthebrowserfromausersperspective.Thesefindingsfrompriorworkdemonstratetheneedtonotonlyprovideasource-to-source languagetranslatorbutalsorequiresanewexecutionmodel thatsolvestheseinherentlimitationsthroughemulation.

SignificanceVilk and Berger provide several contributions to these issues by defining anExecution Environment that is fully implemented in JavaScript. They provide anemulation layer in order to support key operating system abstractions like filesystem and network sockets and execution support for multi-threaded programswith the ability to suspend and resumes threads. SinceDoppio is implemented inJavaScript, it preserves the valuable qualities of running within a web browserincludingcross-platformsupportandboardadoption.

Page 4: Review of the Doppio Runtime Execution Environment for Web …blog.mjlorenzo.com/papers/MarioLorenzo_DoppioReview.pdf · 2017-10-11 · virtually all web applications providing dynamic

Multi-threadingDoppio’s execution environment first addressed the issue of multi-threading bybreakinguptheexecutionofexistingprogramsintofinite-durationeventsbyusingasuspend-and-resumemechanism.Whenaprogramissuspended,itwritesitsstatetotheheapsothatitscontextcanberecoveredatalaterpointwhenitisresumed.To do this, Doppio stores the call stack into JavaScript objects and augments theoriginalprogramwithperiodic checks to see if it shouldbe suspended.Thishookallows Doppio to suspend the running thread, save its state and call-stack, andactivatedifferentthread.ThishookisrequiredbecauseJavaScriptdoesnotprovidea way to interrupt or preempt untilexecution is complete. Doppio uses a“resumptioncallback”techniquewherethecall-stackandstaterecoverylogicexistsforresuming the thread. Doppio leverages acounter that isdecrementedeach time therunning thread checks to see if it needs tobe suspended. Once this counter reacheszero, the thread is suspendedasdescribedabove. Doppio keeps track of how long ittooktoreachzeroandsetsanewvalue tothe counter upon resuming a thread to avaluecomputed fromacumulativemovingaverage. This is done to ensure that thedurationofexecutiondoesnotsurpass thelimitsimposedbyabrowsertoensurethata program is not freezing/hanging and therefore affecting the browser’sresponsivenesstotheuser.SynchronicityDoppioalsousesthissuspend-and-resumetechniquetoconvertasynchronousAPIsinto a synchronous one by suspending the thread invoking the asynchronous calland passing to the asynchronous function the “resumption call-back” hook thatwould then resume the thread once the call completes and invokes the call-backfunctionwhichwould thenrecover thecall-stackandresume theexecutionof thethread.ThreadManagementDoppiokeepstrackofthethreadsbyusinga“threadpool”asaJavaScriptarrayofobjects that represent the call-stack of each thread. When a context switch istriggered,itwillsavethecall-stackofthecurrentlyrunningthreadintothisthreadpool array and chooses another thread from this pool to resume by invoking theresumption call-back function. Different language implementations can providedifferent scheduling functions to decide when a thread should resume and whatthreadtoactivatenext.SinceDoppioreliesontheunderlyingbrowsereventqueuetoinvokethe“resumptioncall-back”,itneedsafastwaytoinserttheeventintothequeue. The paper describes exploring options of using “setTimeout” function, butfounditinadequateduetoaminimumof4msdelaytoplacetheeventinthequeue.Thiswouldresultinamajorperformanceimpacttotheexecutionoftheapplication.

Page 5: Review of the Doppio Runtime Execution Environment for Web …blog.mjlorenzo.com/papers/MarioLorenzo_DoppioReview.pdf · 2017-10-11 · virtually all web applications providing dynamic

Instead, Doppio uses the “sendMessage” function to place a message eventimmediately on the event queue.Once the event is processed,Doppio gets a call-backwhere it then can invoke the “resumption call-back” andperforms a contextswitchandresumesthesuspendedthread.There isanexceptionwhenrunning inInternet Explorer due to “sendMessage” being a synchronous (blocking) call andthereforeDoppiomustusetheslower“setTimeout” functiontoplacetheeventontheeventqueue.EmulatingOperatingSystemServicesInordertoallowforarbitraryprogramswritteninthesourcelanguage(likeJavaorC++) the Doppio Execution Environmentmust provide operating system servicesthat these programs expect to access. These services include file system andnetworksocketsAPIsthatdecouplesthefront-endinterfaceusedbytheprogramsfromthebackendimplementation.Because web browsers do not offer a consistent file system abstraction, DoppiomustprovidewhatVilkandBergercallthe“UnifiedFileSystemAPI”whichsupportsdifferent types of backing store persistence including Cloud Storage. BecauseJavaScript does not provide support for manipulating binary data required forinteractingwithstorage,DoppiooffersaBufferthatcanbeusedtoprocessbinarydata and allows for read/writeoperations. Each backing storeimplementation must implementseveral standard Unix file commandsincluding open, close, rename, anddirectoryCRUDoperations.Inadditionto these basic file system operations,Doppio provides “mountable filesystem” emulation. This allows forprogramstocopyfilesacrossdifferentmountedbackendstoragedevices.In order to emulate Network sockets, Doppio makes use of a feature calledWebSockets.Becausebrowsersdonotexposedirectaccesstonetworksocketsforsecurity reasons, itmustmake use ofWebSockets for establishing out-going TCPconnections.Doppioprovidesanemulationfornetworksocketsbutmustdependona3rdpartylibrarycalled“Websockify”inordertosupportserversockets.ObservationsVilkandBergerhaveaccomplishedan impressiveamountofwork indefining theDoppioExecutionEnvironmentandprovidingsupportandemulationforallthetherequirednativecapabilitiesexpectedbymodernhigh-levelprogramminglanguages.They demonstrate how they overcome numerous browser limitations anddeficienciesthroughemulation.VilkandBergerprovedtheirviabilityoftheDoppioExecutionEnvironment through language support inDoppioJVMandDoppio C++.Theyprovideda complete JVM interpreter supportingall bytecode instructions inthe JVM Specification. The researchers used several benchmarks to comparebetween standard JVM programs and DoppioJVM, noting that the DoppioJVMperformancewas24xto42xslower.Theynotedthatdifferentbrowsersexhibited

Page 6: Review of the Doppio Runtime Execution Environment for Web …blog.mjlorenzo.com/papers/MarioLorenzo_DoppioReview.pdf · 2017-10-11 · virtually all web applications providing dynamic

differentperformancesomeofthesecanbeexplainedduetobugsorlimitationsinAPIsthatwereused.FurtherresearchThe Doppio Execution Environment can stand to benefit from multipleenhancements.Many of these enhancements are required in theWebBrowser toreduce the amount of limitations or 3rd party libraries required today to supportsomeoftheoperatingsystemservicesormulti-threading.Thereareseveraloftheselimitations that represent the largest impacts to performance caused by excessemulation. Some of these include 64-bit numeric support (like long and double),whichrequirespecialprocessingbecausebrowsersdonotoffer64bitsupport.Further improvements can be made by providing Synchronous message passingsupport thatwould helpwith blocking call support (such as in blocking I/O) andthreadsuspend-and-resumecontextswitching.ThiscouldbeachievedbyenhancingWebWorkers with a synchronous channel to communicate with the JavaScriptthread that spawned it. Lackofbinarydata functions also impacts I/OoperationsthatmusttakedataofavarietyoftypesandconstructabinarybufferforstreamingtoanI/Odeviceorthroughanetworksocket.ThereisalsolackofsupportforUDPsocket connections. Lastly, there is no support for Java Swing or SWT GUIframeworksthatrequireaccesstographicrenderingAPIs.This limitsprogramstoconsole or server-side applications. Much like the Doppio C++ leveraged theEmscripten 3rd party framework to access graphic and audio support in order torender gameswritten in C++, a similar approach can be explored for Java Swingsupport. Additional investigations should be focused onmobile phone browsersand howwell they support these findings. Given the vastmajority of devices arenowmobile,itisimportanttoensureadequatesupportforthesedevices.TheDoppioworkisimplementedandmadeavailablebyVilkandBergerat:http://www.doppiojvm.org/anddemonstratedathttp://codemoo.comasaneducationalmoduleforlearningJavaprogramminglanguage.

References[1]Vilk,J.,&Berger,E.D.(2014).Doppio:breakingthebrowserlanguagebarrier.ACMSIGPLANNotices,49(6),508-518.[2]Google.JREEmulationReference-GoogleWebToolkit-GoogleDevelopers.https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation[3] Microsoft Corporation. IL2JS - an intermediate language to JavaScript compiler. https://github.com/Reactive-Extensions/IL2JS [4]University of Illinois. Code Moo – A playful way to learn programming. http://www.codemoo.com/index2.html.