Developer(s) | Mozilla Foundation / Mozilla Corporation |
---|---|
Written in | C++ |
Operating system | Cross-platform |
Type | JavaScript engine |
License | MPL/GPL/LGPL tri-license |
Website | developer.mozilla.org/en/SpiderMonkey |
SpiderMonkey is the code name for the first-ever JavaScript engine, written by Brendan Eich at Netscape Communications, later released as open source and now maintained by the Mozilla Foundation. SpiderMonkey currently provides JavaScript support for Mozilla Firefox and various embeddings such as the GNOME 3 desktop.
Contents |
Eich "wrote JavaScript in ten days" in 1995,[1] having been "recruited to Netscape with the promise of “doing Scheme” in the browser".[2] (The idea of using Scheme itself was abandoned when "engineering management [decided] that the language must ‘look like Java’".[2]) In fall 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".[1] The name SpiderMonkey was chosen as a reference to the movie Beavis and Butt-head Do America, in which the character Tom Anderson mentions that the title characters were "whacking off like a couple of spider monkeys."[3] In 2011, Eich transferred "ownership" of the SpiderMonkey code to Dave Mandelin.[1]
SpiderMonkey implements ECMA-262 edition 5 (ECMAScript), along with ECMA-357 (E4X) and several additional features.
Even though SpiderMonkey is used in Firefox, it does not itself provide host environments such as Document Object Model (DOM).
SpiderMonkey is written in C++ and contains an interpreter, several JIT compilers (TraceMonkey, JägerMonkey, and IonMonkey), a decompiler, and a garbage collector.
TraceMonkey is the first JIT compiler written for the JavaScript language. The compiler was first released 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.[4]
Instead of compiling whole functions, TraceMonkey operates by recording control flow and data types during interpreter execution. This data then informs the construction of Trace Trees, highly specialized paths of native code.
TraceMonkey has been obsoleted by improvements to JägerMonkey, especially by the development of the SpiderMonkey Type inference engine. TraceMonkey is absent from SpiderMonkey from Firefox 11 onward.[5]
JägerMonkey, internally named MethodJIT, is a whole-method JIT compiler designed to improve performance in cases where TraceMonkey cannot generate stable native code.[6][7] It was first released in Firefox 4 and has since entirely supplanted TraceMonkey.
JägerMonkey operates very differently from other compilers in its class: while typical compilers work by constructing and optimizing a control flow graph representing the function, JägerMonkey instead operates by iterating linearly forward through SpiderMonkey bytecode, the internal function representation. Although this prohibits optimizations that require instruction reordering, JägerMonkey compilation has the advantage of being extremely fast, which is useful for JavaScript since recompilation 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.[8]
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 developers, in a blog post. More technical information can be found in other developer's blogs: dvander, dmandelin.
IonMonkey is the name of Mozilla’s future JavaScript JIT compiler, which aims to enable many new optimizations that were impossible with the previous JägerMonkey architecture.[9]
IonMonkey is a compiler in the traditional sense: it translates SpiderMonkey bytecode into a control flow graph, using SSA 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.[10]
The compiler is capable of producing fast native code translations of JavaScript functions on the ARM, x86, and x86_64 platforms.
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.[15]
Several large organizations use SpiderMonkey for managing their JavaScript for front-end applications.
|
|