SpiderMonkey

SpiderMonkey
Developer(s) Mozilla Foundation / Mozilla Corporation
Written in C/C++
Operating system Cross-platform
Platform IA-32, x86-64, ARM, MIPS, SPARC[1]
Type JavaScript engine
License MPL 2.0[2]
Website developer.mozilla.org/en/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. SpiderMonkey provides JavaScript support for Mozilla Firefox and various embeddings such as the GNOME 3 desktop.

History

Eich "wrote JavaScript in ten days" in 1995,[3] having been "recruited to Netscape with the promise of 'doing Scheme' in the browser".[4] (The idea of using Scheme was abandoned when "engineering management [decided] that the language must ‘look like Java’".[4]) In the fall of 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".[3] The name SpiderMonkey may have been 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." [5] In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin.[3]

Versions

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

Standards

SpiderMonkey implements ECMA-262 edition 5.1 (ECMAScript) and several added features. ECMA-357 (ECMAScript for XML (E4X)) was dropped in early 2013.[7]

Even though SpiderMonkey is used in Firefox, it does not provide host environments such as Document Object Model (DOM). 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. 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.[8]

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

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.[10][11] 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.[12]

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. More technical information can be found in other developer's blogs: dvander, dmandelin.

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

IonMonkey is a more traditional compiler: it translates SpiderMonkey bytecode into a control flow graph, using static single assignment form (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.[14]

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

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

See also

References

  1. "1.8.8 - SpiderMonkey | MDN". Developer.mozilla.org. 10 January 2013. Retrieved 21 March 2013.
  2. Mozilla Licensing Policies, mozilla.org, retrieved 26 March 2013
  3. 1 2 3 Eich, Brendan (21 June 2011). "New JavaScript Engine Module Owner". BrendanEich.com.
  4. 1 2 Eich, Brendan (3 April 2008). "Popularity". BrendanEich.com.
  5. Eich, Brendan (19 August 2011). "Mapping the Monkeysphere".
  6. "New in JavaScript 1.6".
  7. "759422 Remove use of e4x in account creation". Retrieved 5 February 2013.
  8. Paul, Ryan (22 August 2008). "Firefox to get massive JavaScript performance boost". Ars Technica. Retrieved 21 March 2013.
  9. Nethercote, Nicholas (1 November 2011). "SpiderMonkey is on a diet | Nicholas Nethercote". Blog.mozilla.com. Retrieved 21 March 2013.
  10. "JaegerMonkey – Fast JavaScript, Always! » Mystery Bail Theater". Bailopan.net. 26 February 2010. Retrieved 21 March 2013.
  11. Paul, Ryan (9 March 2010). "Mozilla borrows from WebKit to build fast new JS engine". Ars Technica. Retrieved 21 March 2013.
  12. "JaegerMonkey - MozillaWiki". Wiki.mozilla.org. Retrieved 21 March 2013.
  13. "Platform/Features/IonMonkey - MozillaWiki". Wiki.mozilla.org. 11 February 2013. Retrieved 21 March 2013.
  14. "IonMonkey: Mozilla's new JavaScript JIT compiler". Infoq.com. Retrieved 21 March 2013.
  15. "Firefox Notes - Desktop". Mozilla.org. 8 January 2013. Retrieved 21 March 2013.
  16. https://docs.mongodb.com/manual/release-notes/3.2-javascript
  17. Bolso, Erik Inge (8 March 2005). "2005 Text Mode Browser Roundup". Linux Journal. Retrieved 5 August 2010.
  18. wine-cvs mailing list, 16 September 2008: "jscript: Added regular expression compiler based on Mozilla regexp implementation"
  19. "The Release Riak 0.8 and JavaScript Map/Reduce". Retrieved 24 April 2011.
  20. "Introduction to the JavaScript shell". MDN. Mozilla Developer Network. 29 September 2010. Retrieved 14 December 2010. 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 [...]
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.