SpiderMonkey


SpiderMonkey is the code name for the first JavaScript engine, written by Brendan Eich at Netscape Communications, later released as open-source and currently maintained by the Mozilla Foundation.

History

Eich "wrote JavaScript in ten days" in 1995,
having been "recruited to Netscape with the promise of 'doing Scheme' in the browser".
In the fall of 1996, Eich, needing to "pay off substantial technical debt" left from the first year, "stayed home for two weeks to rewrite Mocha as the codebase that became known as SpiderMonkey".
In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin.

Versions

VersionRelease dateCorresponding ECMAScript versionBrowser versionAdded functionality
scope="row" March 1996Netscape Navigator 2.0
scope="row" August 1996Netscape Navigator 3.0
scope="row" June 1997Netscape Navigator 4.0 - 4.05
scope="row" October 1998ECMA-262 1st + 2nd editionNetscape Navigator 4.06-4.7x
scope="row" Netscape Server
scope="row" November 2000ECMA-262 3rd editionNetscape Navigator 6, Firefox 1.0
scope="row" November 2005Firefox 1.5additional array methods, array and string generics, E4X
scope="row" October 2006Firefox 2.0iterators and generators, let statement, array comprehensions, destructuring assignment
scope="row" June 2008Firefox 3.0generator expressions, expression closures
scope="row" March 2011ECMA-262 5th editionFirefox 4.0JSON support
scope="row" January 2012Firefox 10.0
scope="row" November 2012Firefox 17.0
scope="row" September 2013Firefox 24.0
scope="row" July 2014Firefox 31.0
scope="row" May 2015Firefox 38.0
scope="row" March 2016Firefox 45.0
scope="row" March 2017Firefox 52.0

Standards

SpiderMonkey implements ECMA-262 edition 5.1 and several added features. ECMA-357 was dropped in early 2013.
Even though SpiderMonkey is used in Firefox, it does not provide host environments such as Document Object Model. In Mozilla projects that support the DOM, Gecko provides the host environment.

Internals

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

TraceMonkey

TraceMonkey 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, 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.
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 , 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.

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. 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.
The difference between TraceMonkey and JägerMonkey JIT techniques and the need for both was explained in . A more in-depth explanation of the technical details was provided by Chris Leary, one of SpiderMonkey's developers, . More technical information can be found in other developer's blogs: , .

IonMonkey

IonMonkey is the name of Mozilla's current JavaScript JIT compiler, which aims to enable many new optimizations that were impossible with the prior JägerMonkey architecture.
IonMonkey is a more traditional compiler: it translates SpiderMonkey bytecode into a control flow graph, using static single assignment form for the intermediate representation. This architecture enables 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.
The compiler can emit fast native code translations of JavaScript functions on the ARM, x86, and x86-64 platforms. It is the default engine since Firefox 18.

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.

Use

SpiderMonkey is intended to be embedded in other applications that provide host environments for JavaScript. An incomplete list follows:
SpiderMonkey includes a JavaScript Shell for interactive JavaScript development and for command-line invocation of JavaScript program files.