Template:Short description Template:About Template:Use dmy dates {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other

SpiderMonkey is an open-source JavaScript and WebAssembly engine by the Mozilla Foundation.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The engine powers the Firefox Web browser and has used multiple generations of JavaScript just-in-time (JIT) compilers, including TraceMonkey, JägerMonkey, IonMonkey, and the current WarpMonkey.

It is the first JavaScript engine, written by Brendan Eich at Netscape Communications, and later released as open source and currently maintained by the Mozilla Foundation. Its design allows it to be embedded in applications beyond Web browsers, with implementations including MongoDB database system, Adobe Acrobat, and the GNOME desktop environment.

HistoryEdit

Eich "wrote JavaScript in ten days" in 1995,<ref name=BE201106> {{#invoke:citation/CS1|citation |CitationClass=web }} </ref> having been "recruited to Netscape with the promise of 'doing Scheme' in the browser".<ref name=BE200804> {{#invoke:citation/CS1|citation |CitationClass=web }} </ref> (The idea of using Scheme was abandoned when "engineering management [decided] that the language must 'look like JavaTemplate:'".)<ref name=BE200804/> In late 1996, Eich, needing to "pay off [the] substantial technical debt" left from the first year, "stayed home for two weeks to rewrite Mocha as the codebase that became known as SpiderMonkey".<ref name=BE201106/> (Mocha was the original working name for the language.)<ref name="BE200804" /><ref name=BE201108> {{#invoke:citation/CS1|citation |CitationClass=web }} </ref> In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin.<ref name=BE201106/>

VersionsEdit

SpiderMonkey version history
Version Release date Corresponding ECMAScript version Browser version Added functionality
scope="row" Template:Version March 1996 Netscape Navigator 2.0
scope="row" Template:Version August 1996 Netscape Navigator 3.0
scope="row" Template:Version June 1997 Netscape Navigator 4.0 - 4.05
scope="row" Template:Version October 1998 ECMA-262 1st + 2nd edition Netscape Navigator 4.06-4.7x
scope="row" Template:Version Netscape Server
scope="row" Template:Version November 2000 ECMA-262 3rd edition Netscape Navigator 6, Firefox 1.0
scope="row" Template:Version citation CitationClass=web

}}</ref>|| || Firefox 1.5 || additional array methods, array and string generics, E4X

scope="row" Template:Version October 2006 Firefox 2.0 iterators and generators, let statement, array comprehensions, destructuring assignment
scope="row" Template:Version June 2008 Firefox 3.0 generator expressions, expression closures
scope="row" Template:Version March 2011 ECMA-262 5th edition Firefox 4.0 JSON support
scope="row" Template:Version January 2012 Firefox 10.0
scope="row" Template:Version November 2012 Firefox 17.0
scope="row" Template:Version September 2013 Firefox 24.0
scope="row" Template:Version July 2014 Firefox 31.0
scope="row" Template:Version May 2015 Firefox 38.0
scope="row" Template:Version March 2016 Firefox 45.0
scope="row" Template:Version March 2017 Firefox 52.0
scope="row" Template:Version May 2018 Firefox 60.0
scope="row" Template:Version July 2019 Firefox 68.0
scope="row" Template:Version June 2020 Firefox 78.0
scope="row" Template:Version August 2021 Firefox 91.0
scope="row" Template:Version June 2022 Firefox 102.0
scope="row" Template:Version July 2022 Firefox 103.0
scope="row" Template:Version citation CitationClass=web

}}</ref>|| || Firefox 131.0 ||

Template:Version

StandardsEdit

SpiderMonkey implements the ECMA-262 specification (ECMAScript). ECMA-357 (ECMAScript for XML (E4X)) was dropped in early 2013.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

InternalsEdit

SpiderMonkey is written in C/C++ and contains an interpreter, the WarpMonkey JIT compiler, and a garbage collector.

TraceMonkeyEdit

TraceMonkey<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> 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,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> the compiler became part of the mainline release as part of SpiderMonkey in Firefox 3.5, providing "performance improvements ranging between 20 and 40 times faster" than the baseline interpreter in Firefox 3.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Instead of compiling whole functions, TraceMonkey was a tracing JIT, which operates by recording control flow and data types during interpreter execution. This data then informed the construction of trace trees, highly specialized paths of native code.

Improvements to JägerMonkey eventually made TraceMonkey obsolete, especially with the development of the SpiderMonkey type inference engine. TraceMonkey is absent from SpiderMonkey from Firefox 11 onward.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

JägerMonkeyEdit

JägerMonkey, internally named MethodJIT, was a whole-method JIT compiler designed to improve performance in cases where TraceMonkey could not generate stable native code.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref name="hunted">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> It was first released in Firefox 4 and 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 a control-flow graph representing the function, JägerMonkey instead operated by iterating linearly forward through SpiderMonkey bytecode, 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 importantly polymorphic inline caches and type inference.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

The difference between TraceMonkey and JägerMonkey JIT techniques and the need for both was explained in a 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 post Template:Webarchive. More technical information can be found in other developer's blogs: dvander, dmandelin.

IonMonkeyEdit

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.<ref name="mozilla1">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

IonMonkey was a more traditional compiler: it translated SpiderMonkey bytecode into a control-flow graph, using static single assignment form (SSA) for the intermediate representation. This architecture enabled well-known optimizations from other programming languages to be used for JavaScript, including type specialization, function inlining, linear-scan register allocation, dead code elimination, and loop-invariant code motion.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

The compiler can emit fast native code translations of JavaScript functions on the ARM, x86, and x86-64 platforms. It has been the default engine since Firefox 18.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

OdinMonkeyEdit

OdinMonkey is the name of Mozilla's new optimization module for asm.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.

WarpMonkeyEdit

The WarpMonkey JIT replaces the former IonMonkey engine from version 83.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> 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-level Intermediate 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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

UseEdit

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

|CitationClass=web }}</ref>

    • Riak uses SpiderMonkey as the runtime for JavaScript MapReduce operations<ref>{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref>

    • CouchDB database system (written in Erlang). JavaScript is used for defining maps, filters, reduce functions and viewing data, for example in HTML format.
  • Adobe Acrobat and Adobe Reader, Adobe Flash Professional, and Adobe Dreamweaver. Adobe Acrobat DC uses Spidermonkey 24.2 with ECMA-357 support forward ported.<ref>{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref>

  • GNOME desktop environment, version 3 and later
  • Cinnamon desktop environment, version 1.0 and later
  • Yahoo! Widgets, formerly named Konfabulator
  • FreeSWITCH, open-source telephony engine, uses SpiderMonkey to allow users to write call management scripts in JavaScript
  • PythonMonkey uses SpiderMonkey to allow users to write programs where JavaScript and Python functions, types, and events interoperate and (where possible) share memory storage. <ref>{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref>

  • The text-based web browser ELinks uses SpiderMonkey to support JavaScript<ref name="linuxjournal">{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref>

  • Parts of SpiderMonkey are used in the Wine project's JScript (re-)implementation<ref>wine-cvs mailing list Template:Webarchive, 16 September 2008: "jscript: Added regular expression compiler based on Mozilla regexp implementation"</ref>
  • Synchronet, a BBS, e-mail, Web, and application server using the SpiderMonkey engine
  • JavaScript OSA, a SpiderMonkey inter-process communication language for the Mac computer
  • 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.<ref>{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref>

SpiderMonkey includes a JavaScript Shell for interactive JavaScript development and for command-line invocation of JavaScript program files.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

See alsoEdit

Template:Portal

ReferencesEdit

Template:Reflist

External linksEdit

Template:Mozilla Template:ECMAScript