SpiderMonkey

(Redirected from TraceMonkey)

SpiderMonkey is an open-source JavaScript and WebAssembly engine by the Mozilla Foundation.[4]

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

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. It is used in the Firefox web browser.

History

Eich "wrote JavaScript in ten days" in 1995,[5]having been "recruited to Netscape with the promise of 'doing Scheme' in the browser".[6](The idea of using Scheme was abandoned when "engineering management [decided] that the language must 'look like Java'".)[6] 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".[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

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

Standards

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

Internals

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

TraceMonkey

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 in Firefox 3.5, providing "performance improvements ranging between 20 and 40 times faster" than the baseline interpreter in Firefox 3.[12]

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.[13]

JägerMonkey

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.[14][15] 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.[16]

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 Archived 9 December 2012 at archive.today. More technical information can be found in other developer's blogs: dvander, dmandelin.

IonMonkey

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 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.[18]

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.[19]

OdinMonkey

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.

WarpMonkey

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-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.[21]

Use

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

  • Mozilla Firefox, Thunderbird, SeaMonkey, and other applications that use the Mozilla application framework
  • Data storage applications:
    • MongoDB moved from V8 to SpiderMonkey in version 3.2[22]
    • Riak uses SpiderMonkey as the runtime for JavaScript MapReduce operations[23]
    • 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.[24]
  • GNOME desktop 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
  • PythonMonkey uses 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 browser ELinks uses SpiderMonkey to support JavaScript[26]
  • Parts of SpiderMonkey are used in the Wine project's JScript (re-)implementation[27]
  • 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.[28]

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

See also

References