Jump to content

SpiderMonkey

From Wikipedia, the free encyclopedia
(Redirected fromTraceMonkey)

SpiderMonkey
Developer(s)
Repositorygithub/mozilla-spidermonkey
Written inC,C++,Rust
Operating systemCross-platform
PlatformIA-32,x86-64,ARM,MIPS,SPARC,[1]RISC-V[2]
TypeJavaScriptandWebAssemblyengine
LicenseMPL 2.0[3]
Websitespidermonkey.dev

SpiderMonkeyis anopen-sourceJavaScriptandWebAssemblyengine by theMozilla Foundation.[4]

It is the firstJavaScript engine,written byBrendan EichatNetscapeCommunications, and later released as open source and currently maintained by the Mozilla Foundation. It is used in theFirefoxweb browser.

History

[edit]

Eich "wrote JavaScript in ten days" in 1995,[5] having been "recruited to Netscape with the promise of 'doingScheme' in the browser ".[6] (The idea of using Scheme was abandoned when "engineering management [decided] that the language must 'look likeJava'".)[6]In late 1996, Eich, needing to "pay off [the] substantialtechnical debt"left from the first year," stayed home for two weeks to rewrite Mocha as the codebase that became known as SpiderMonkey ".[5](Mocha was the original working name for the language.)[6][7] In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin.[5]

Versions

[edit]
SpiderMonkey version history
Version Release date Corresponding ECMAScript version Browser version Added functionality
Old version, no longer maintained:1.0 March 1996 Netscape Navigator 2.0
Old version, no longer maintained:1.1 August 1996 Netscape Navigator 3.0
Old version, no longer maintained:1.2 June 1997 Netscape Navigator 4.0 - 4.05
Old version, no longer maintained:1.3 October 1998 ECMA-262 1st + 2nd edition Netscape Navigator 4.06-4.7x
Old version, no longer maintained:1.4 Netscape Server
Old version, no longer maintained:1.5 November 2000 ECMA-262 3rd edition Netscape Navigator 6, Firefox 1.0
Old version, no longer maintained:1.6 November 2005[8] Firefox 1.5 additional array methods, array and string generics,E4X
Old version, no longer maintained:1.7 October 2006 Firefox 2.0 iterators and generators, let statement, array comprehensions, destructuring assignment
Old version, no longer maintained:1.8 June 2008 Firefox 3.0 generator expressions, expression closures
Old version, no longer maintained:1.8.5 March 2011 ECMA-262 5th edition Firefox 4.0 JSON support
Old version, no longer maintained:1.8.8 January 2012 Firefox 10.0
Old version, no longer maintained:17 November 2012 Firefox 17.0
Old version, no longer maintained:24 September 2013 Firefox 24.0
Old version, no longer maintained:31 July 2014 Firefox 31.0
Old version, no longer maintained:38 May 2015 Firefox 38.0
Old version, no longer maintained:45 March 2016 Firefox 45.0
Old version, no longer maintained:52 March 2017 Firefox 52.0
Old version, no longer maintained:60 May 2018 Firefox 60.0
Old version, no longer maintained:68 July 2019 Firefox 68.0
Old version, no longer maintained:78 June 2020 Firefox 78.0
Old version, no longer maintained:91 August 2021 Firefox 91.0
Old version, no longer maintained:102 June 2022 Firefox 102.0
Current stable version:103 July 2022 Firefox 103.0

Standards

[edit]

SpiderMonkey implements the ECMA-262 specification (ECMAScript). ECMA-357 (ECMAScript for XML(E4X)) was dropped in early 2013.[9]

Internals

[edit]

SpiderMonkey is written inC/C++and contains aninterpreter,the IonMonkeyJIT compiler,and agarbage collector.

TraceMonkey

[edit]

TraceMonkey[10]was the first JIT compiler written for the JavaScript language. Initially introduced as an option in a beta release and introduced in Brendan Eich's blog on August 23, 2008,[11]the compiler became part of the mainline release as part of SpiderMonkey inFirefox 3.5,providing "performance improvements ranging between 20 and 40 times faster" than the baseline interpreter inFirefox 3.[12]

Instead of compiling whole functions, TraceMonkey was atracing JIT,which operates by recordingcontrol flowanddata typesduring interpreter execution. This data then informed the construction oftrace trees,highly specialized paths ofnative code.

Improvements to JägerMonkey eventually made TraceMonkey obsolete, especially with the development of the SpiderMonkeytype inferenceengine. TraceMonkey is absent from SpiderMonkey from Firefox 11 onward.[13]

JägerMonkey

[edit]

JägerMonkey, internally named MethodJIT, was a whole-method JIT compiler designed to improve performance in cases where TraceMonkey could not generate stablenative code.[14][15]It was first released inFirefox 4and eventually entirely supplanted TraceMonkey. It has itself been replaced by IonMonkey.

JägerMonkey operated very differently from other compilers in its class: while typical compilers worked by constructing and optimizing acontrol-flow graphrepresenting the function, JägerMonkey instead operated by iterating linearly forward through SpiderMonkeybytecode,the internal function representation. Although this prohibits optimizations that require instruction reordering, JägerMonkey compiling has the advantage of being very fast, which is useful for JavaScript since recompiling due to changing variable types is frequent.

Mozilla implemented a number of critical optimizations in JägerMonkey, most importantlypolymorphic inline cachesandtype inference.[16]

The difference between TraceMonkey and JägerMonkey JIT techniques and the need for both was explained ina hacks.mozilla.org article.A more in-depth explanation of the technical details was provided by Chris Leary, one of SpiderMonkey's developers,in a blog postArchived9 December 2012 atarchive.today.More technical information can be found in other developer's blogs:dvander,dmandelin.

IonMonkey

[edit]

IonMonkey was a JavaScript JIT compiler of Mozilla, which was aimed to enable many new optimizations that were impossible with the prior JägerMonkey architecture.[17]

IonMonkey was a more traditional compiler: it translated SpiderMonkeybytecodeinto acontrol-flow graph,usingstatic single assignment form(SSA) for theintermediate representation.This architecture enabled well-known optimizations from other programming languages to be used for JavaScript, including type specialization,function inlining,linear-scanregister allocation,dead code elimination,andloop-invariant code motion.[18]

The compiler can emit fastnative codetranslations of JavaScript functions on theARM,x86,andx86-64platforms. It has been the default engine since Firefox 18.[19]

OdinMonkey

[edit]

OdinMonkey is the name of Mozilla's new optimization module forasm.js,an easily compilable subset of JavaScript. OdinMonkey itself is not a JIT compiler, it uses the current JIT compiler. It's included with Firefox from release 22.

WarpMonkey

[edit]

The WarpMonkey JIT replaces the former IonMonkey engine from version 83.[20]It is able to inline other scripts and specialize code based on the data and arguments being processed. It translates the bytecode and Inline Cache data into a Mid-levelIntermediate Representation(Ion MIR) representation. This graph is transformed and optimized before being lowered to a Low-level Intermediate Representation (Ion LIR). This LIR performs register allocation and then generates native machine code in a process called Code Generation. The optimizations here assume that a script continues to see data similar what has been seen before. The Baseline JITs are essential to success here because they generate ICs that match observed data. If after a script is compiled with Warp, it encounters data that it is not prepared to handle it performs a bailout. The bailout mechanism reconstructs the native machine stack frame to match the layout used by the Baseline Interpreter and then branches to that interpreter as though we were running it all along. Building this stack frame may use special side-table saved by Warp to reconstruct values that are not otherwise available.[21]

Use

[edit]

SpiderMonkey is intended to be embedded in other applications that provide host environments for JavaScript. An incomplete list follows:

  • MozillaFirefox,Thunderbird,SeaMonkey,and other applications that use theMozilla application framework
  • Data storage applications:
    • MongoDBmoved fromV8to SpiderMonkey in version 3.2[22]
    • Riakuses SpiderMonkey as the runtime for JavaScript MapReduce operations[23]
    • CouchDBdatabase system (written inErlang). JavaScript is used for defining maps, filters, reduce functions and viewing data, for example in HTML format.
  • Adobe Acrobatand Adobe Reader,Adobe Flash Professional,andAdobe Dreamweaver.Adobe Acrobat DC uses Spidermonkey 24.2 with ECMA-357 support forward ported.[24]
  • GNOMEdesktop environment, version 3 and later
  • Yahoo! Widgets,formerly named Konfabulator
  • FreeSWITCH,open-source telephony engine, uses SpiderMonkey to allow users to write call management scripts in JavaScript
  • PythonMonkeyuses SpiderMonkey to allow users to write programs where JavaScript and Python functions, types, and events interoperate and (where possible) share memory storage.[25]
  • The text-based web browserELinksuses SpiderMonkey to support JavaScript[26]
  • Parts of SpiderMonkey are used in theWineproject'sJScript(re-)implementation[27]
  • Synchronet,a BBS, e-mail, Web, and application server using the SpiderMonkey engine
  • JavaScript OSA,a SpiderMonkeyinter-process communicationlanguage for theMaccomputer
  • 0 A.D.,a real-time strategy game
  • Wasmer has incorporated SpiderMonkey into their WinterJS open-source project; a JavaScript runtime environment.
  • SpiderMonkey is also used in many other open-source projects; an external list is maintained at Mozilla's developer site.[28]

SpiderMonkey includes a JavaScript Shell for interactive JavaScript development and for command-line invocation of JavaScript program files.[29]

See also

[edit]

References

[edit]
  1. ^"1.8.8 – SpiderMonkey | MDN".Developer.mozilla.org. 10 January 2013.Archivedfrom the original on 2 May 2013.Retrieved21 March2013.
  2. ^"SpiderMonkey Newsletter (Firefox 110-111)".spidermonkey.dev.16 February 2023.Retrieved27 December2023.
  3. ^Mozilla Licensing Policies,mozilla.org,archivedfrom the original on 2 April 2013,retrieved26 March2013
  4. ^"Home".SpiderMonkey JavaScript/WebAssembly Engine.Retrieved24 April2023.
  5. ^abc Eich, Brendan(21 June 2011)."New JavaScript Engine Module Owner".BrendanEich.Archivedfrom the original on 14 July 2011.Retrieved1 July2011.
  6. ^abc Eich, Brendan(3 April 2008)."Popularity".BrendanEich.Archivedfrom the original on 3 July 2011.Retrieved1 July2011.
  7. ^ Eich, Brendan(19 August 2011)."Mapping the Monkeysphere".Archivedfrom the original on 13 January 2013.Retrieved19 August2011.
  8. ^"New in JavaScript 1.6".Archived fromthe originalon 5 September 2015.Retrieved28 July2015.
  9. ^"759422 – Remove use of e4x in account creation".Retrieved5 February2013.
  10. ^"JavaScript:TraceMonkey, MozillaWiki".Retrieved22 July2020.
  11. ^"TraceMonkey: JavaScript Lightspeed, Brendan Eich's Blog".Retrieved22 July2020.
  12. ^Paul, Ryan (22 August 2008)."Firefox to get massive JavaScript performance boost".Ars Technica.Archivedfrom the original on 6 May 2012.Retrieved21 March2013.
  13. ^Nethercote, Nicholas (1 November 2011)."SpiderMonkey is on a diet | Nicholas Nethercote".Blog.mozilla.Archivedfrom the original on 28 March 2012.Retrieved21 March2013.
  14. ^"JaegerMonkey – Fast JavaScript, Always! » Mystery Bail Theater".Bailopan.net. 26 February 2010.Archivedfrom the original on 24 March 2013.Retrieved21 March2013.
  15. ^Paul, Ryan (9 March 2010)."Mozilla borrows from WebKit to build fast new JS engine".Ars Technica.Archivedfrom the original on 16 April 2012.Retrieved21 March2013.
  16. ^"JaegerMonkey - MozillaWiki".Wiki.mozilla.org.Archivedfrom the original on 23 August 2013.Retrieved21 March2013.
  17. ^"Platform/Features/IonMonkey - MozillaWiki".Wiki.mozilla.org. 11 February 2013.Archivedfrom the original on 8 March 2013.Retrieved21 March2013.
  18. ^"IonMonkey: Mozilla's new JavaScript JIT compiler".Infoq.Archivedfrom the original on 8 December 2012.Retrieved21 March2013.
  19. ^"Firefox Notes - Desktop".Mozilla.org. 8 January 2013.Archivedfrom the original on 2 September 2014.Retrieved21 March2013.
  20. ^"Warp: Improved JS performance in Firefox 83 – Mozilla Hacks - the Web developer blog".Mozilla Hacks – the Web developer blog.13 November 2020.Retrieved28 August2021.
  21. ^"SpiderMonkey — Firefox Source Docs documentation".firefox-source-docs.mozilla.org.Retrieved28 August2021.
  22. ^"JavaScript Changes in MongoDB 3.2 — MongoDB Manual 3.4".Archivedfrom the original on 6 June 2017.Retrieved23 November2016.
  23. ^"The Release Riak 0.8 and JavaScript Map/Reduce".Archivedfrom the original on 3 November 2011.Retrieved24 April2011.
  24. ^"Acrobat DC SDK Documentation".helpx.adobe.Retrieved5 November2021.
  25. ^"Distributive-Network/PythonMonkey: A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment".GitHub.7 July 2023.Retrieved10 July2023.
  26. ^Bolso, Erik Inge (8 March 2005)."2005 Text Mode Browser Roundup".Linux Journal.Archivedfrom the original on 15 March 2010.Retrieved5 August2010.
  27. ^wine-cvs mailing listArchived7 February 2009 at theWayback Machine,16 September 2008: "jscript: Added regular expression compiler based on Mozilla regexp implementation"
  28. ^"SpiderMonkey > FOSS".MDN Web Docs.Retrieved2 April2019.
  29. ^"Introduction to the JavaScript shell".MDN.Mozilla Developer Network. 29 September 2010. Archived fromthe originalon 29 June 2011.Retrieved14 December2010.The JavaScript shell is a command-line program included in the SpiderMonkey source distribution. [...] You can use it as an interactive shell [...] You can also pass in, on the command line, a JavaScript program file to run [...]
[edit]