SpiderMonkey

Last updated

SpiderMonkey
Developer(s)
Repository github.com/mozilla-spidermonkey
Written in C, C++, Rust
Operating system Cross-platform
Platform IA-32, x86-64, ARM, MIPS, SPARC [1]
Type JavaScript and WebAssembly engine
License MPL 2.0 [2]
Website spidermonkey.dev

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

Contents

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, [4] having been "recruited to Netscape with the promise of 'doing Scheme' in the browser". [5] (The idea of using Scheme was abandoned when "engineering management [decided] that the language must 'look like Java'".) [5] 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". [4] (Mocha was the original working name for the language.) [5] [6] In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin. [4]

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

Internals

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

TraceMonkey

TraceMonkey [9] 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, [10] 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. [11]

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

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

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

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

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

WarpMonkey

The WarpMonkey JIT replaces the former IonMonkey engine from version 83. [19] 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. [20]

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

See also

Related Research Articles

<span class="mw-page-title-main">JavaScript</span> High-level programming language

JavaScript, often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2023, 98.7% of websites use JavaScript on the client side for webpage behavior, often incorporating third-party libraries. All major web browsers have a dedicated JavaScript engine to execute the code on users' devices.

Gecko is a browser engine developed by Mozilla. It is used in the Firefox browser, the Thunderbird email client, and many other projects.

<span class="mw-page-title-main">Firefox</span> Free and open-source web browser by Mozilla

Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements current and anticipated web standards. In November 2017, Firefox began incorporating new technology under the code name "Quantum" to promote parallelism and a more intuitive user interface. Firefox is available for Windows 10 or later versions, macOS, and Linux. Its unofficial ports are available for various Unix and Unix-like operating systems, including FreeBSD, OpenBSD, NetBSD, illumos, and Solaris Unix. It is also available for Android and iOS. However, as with all other iOS web browsers, the iOS version uses the WebKit layout engine instead of Gecko due to platform requirements. An optimized version is also available on the Amazon Fire TV as one of the two main browsers available with Amazon's Silk Browser.

In computing, just-in-time (JIT) compilation is compilation during execution of a program rather than before execution. This may consist of source code translation but is more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

Rhino is a JavaScript engine written fully in Java and managed by the Mozilla Foundation as open source software. It is separate from the SpiderMonkey engine, which is also developed by Mozilla, but written in C++ and used in Mozilla Firefox.

<span class="mw-page-title-main">Brendan Eich</span> American computer scientist and technology executive

Brendan Eich is an American computer programmer and technology executive. He created the JavaScript programming language and co-founded the Mozilla project, the Mozilla Foundation, and the Mozilla Corporation. He served as the Mozilla Corporation's chief technical officer before he was appointed chief executive officer, but resigned shortly after his appointment due to pressure over his firm opposition to same-sex marriage. He subsequently became the CEO of Brave Software.

Netscape Plugin Application Programming Interface (NPAPI) is a deprecated application programming interface (API) for web browser plugins, initially developed for Netscape Navigator 2.0 in 1995 and subsequently adopted by other browsers.

A JavaScript engine is a software component that executes JavaScript code. The first JavaScript engines were mere interpreters, but all relevant modern engines use just-in-time compilation for improved performance.

ECMAScript for XML (E4X) is the standard ISO/IEC 22537:2006 programming language extension that adds native XML support to ECMAScript. The goal is to provide an alternative to DOM interfaces that uses a simpler syntax for accessing XML documents. It also offers a new way of making XML visible. Before the release of E4X, XML was always accessed at an object level. E4X instead treats XML as a primitive. This implies faster access, better support, and acceptance as a building block of a program.

In the context of the World Wide Web, a bookmark is a Uniform Resource Identifier (URI) that is stored for later retrieval in any of various storage formats. All modern web browsers include bookmark features. Bookmarks are called favorites or Internet shortcuts in Internet Explorer and Microsoft Edge, and by virtue of that browser's large market share, these terms have been synonymous with bookmark since the First Browser War. Bookmarks are normally accessed through a menu in the user's web browser, and folders are commonly used for organization. In addition to bookmarking methods within most browsers, many external applications offer bookmarks management.

Tamarin is a discontinued free software virtual machine with just-in-time compilation (JIT) support intended to implement the 4th edition of the ECMAScript (ES4) language standard. Tamarin source code originates from ActionScript Virtual Machine 2 (AVM2) developed by Adobe Systems, as introduced within Adobe Flash Player 9, which implements ActionScript 3 scripting language. ActionScript Virtual Machine 2 was donated as open-source to Mozilla Foundation on November 7, 2006, to develop Tamarin as a high-performance virtual machine, with the support from broad Mozilla community, to be used by Mozilla and Adobe Systems in the next generation of their JavaScript and ActionScript engines with the ultimate aim to unify the scripting languages across web browsers and Adobe Flash platform and ease the development of better performing rich web applications.

<span class="mw-page-title-main">Firefox 4</span> Firefox browser released in 2011

Mozilla Firefox 4 is a version of the Firefox web browser, released on March 22, 2011. The first beta was made available on July 6, 2010; Release Candidate 2 was released on March 18, 2011. It was codenamed Tumucumaque, and was Firefox's last large release cycle. The Mozilla team planned smaller and quicker releases following other browser vendors. The primary goals for this version included improvements in performance, standards support, and user interface.

Chakra is a proprietary JScript engine developed by Microsoft. It is used in the Internet Explorer web browser.

River Trail is an open-source software engine designed by Intel for executing JavaScript code using parallel computing on multi-core processors.

Tracing just-in-time compilation is a technique used by virtual machines to optimize the execution of a program at runtime. This is done by recording a linear sequence of frequently executed operations, compiling them to native machine code and executing them. This is opposed to traditional just-in-time (JIT) compilers that work on a per-method basis.

Mozilla is a free software community founded in 1998 by members of Netscape. The Mozilla community uses, develops, publishes and supports Mozilla products, thereby promoting exclusively free software and open standards, with only minor exceptions. The community is supported institutionally by the non-profit Mozilla Foundation and its tax-paying subsidiary, the Mozilla Corporation.

<span class="mw-page-title-main">Andreas Gal</span>

Andreas Gal is former chief technology officer at Mozilla. He is most notable for his work on several open source projects and Mozilla technologies.

asm.js is a subset of JavaScript designed to allow computer software written in languages such as C to be run as web applications while maintaining performance characteristics considerably better than standard JavaScript, which is the typical language used for such applications.

References

  1. "1.8.8 – SpiderMonkey | MDN". Developer.mozilla.org. 10 January 2013. Archived from the original on 2 May 2013. Retrieved 21 March 2013.
  2. Mozilla Licensing Policies, mozilla.org, archived from the original on 2 April 2013, retrieved 26 March 2013
  3. "Home". SpiderMonkey JavaScript/WebAssembly Engine. Retrieved 24 April 2023.
  4. 1 2 3 Eich, Brendan (21 June 2011). "New JavaScript Engine Module Owner". BrendanEich.com. Archived from the original on 14 July 2011. Retrieved 1 July 2011.
  5. 1 2 3 Eich, Brendan (3 April 2008). "Popularity". BrendanEich.com. Archived from the original on 3 July 2011. Retrieved 1 July 2011.
  6. Eich, Brendan (19 August 2011). "Mapping the Monkeysphere". Archived from the original on 13 January 2013. Retrieved 19 August 2011.
  7. "New in JavaScript 1.6". Archived from the original on 5 September 2015. Retrieved 28 July 2015.
  8. "759422 Remove use of e4x in account creation" . Retrieved 5 February 2013.
  9. "JavaScript:TraceMonkey, MozillaWiki" . Retrieved 22 July 2020.
  10. "TraceMonkey: JavaScript Lightspeed, Brendan Eich's Blog" . Retrieved 22 July 2020.
  11. Paul, Ryan (22 August 2008). "Firefox to get massive JavaScript performance boost". Ars Technica. Archived from the original on 6 May 2012. Retrieved 21 March 2013.
  12. Nethercote, Nicholas (1 November 2011). "SpiderMonkey is on a diet | Nicholas Nethercote". Blog.mozilla.com. Archived from the original on 28 March 2012. Retrieved 21 March 2013.
  13. "JaegerMonkey – Fast JavaScript, Always! » Mystery Bail Theater". Bailopan.net. 26 February 2010. Archived from the original on 24 March 2013. Retrieved 21 March 2013.
  14. Paul, Ryan (9 March 2010). "Mozilla borrows from WebKit to build fast new JS engine". Ars Technica. Archived from the original on 16 April 2012. Retrieved 21 March 2013.
  15. "JaegerMonkey - MozillaWiki". Wiki.mozilla.org. Archived from the original on 23 August 2013. Retrieved 21 March 2013.
  16. "Platform/Features/IonMonkey - MozillaWiki". Wiki.mozilla.org. 11 February 2013. Archived from the original on 8 March 2013. Retrieved 21 March 2013.
  17. "IonMonkey: Mozilla's new JavaScript JIT compiler". Infoq.com. Archived from the original on 8 December 2012. Retrieved 21 March 2013.
  18. "Firefox Notes - Desktop". Mozilla.org. 8 January 2013. Archived from the original on 2 September 2014. Retrieved 21 March 2013.
  19. "Warp: Improved JS performance in Firefox 83 – Mozilla Hacks - the Web developer blog". Mozilla Hacks – the Web developer blog. 13 November 2020. Retrieved 28 August 2021.
  20. "SpiderMonkey — Firefox Source Docs documentation". firefox-source-docs.mozilla.org. Retrieved 28 August 2021.
  21. "JavaScript Changes in MongoDB 3.2 — MongoDB Manual 3.4". Archived from the original on 6 June 2017. Retrieved 23 November 2016.
  22. "The Release Riak 0.8 and JavaScript Map/Reduce". Archived from the original on 3 November 2011. Retrieved 24 April 2011.
  23. "Acrobat DC SDK Documentation". helpx.adobe.com. Retrieved 5 November 2021.
  24. "Distributive-Network/PythonMonkey: A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment". GitHub. 7 July 2023. Retrieved 10 July 2023.
  25. Bolso, Erik Inge (8 March 2005). "2005 Text Mode Browser Roundup". Linux Journal. Archived from the original on 15 March 2010. Retrieved 5 August 2010.
  26. wine-cvs mailing list Archived 7 February 2009 at the Wayback Machine , 16 September 2008: "jscript: Added regular expression compiler based on Mozilla regexp implementation"
  27. "SpiderMonkey > FOSS". MDN Web Docs. Retrieved 2 April 2019.
  28. "Introduction to the JavaScript shell". MDN. Mozilla Developer Network. 29 September 2010. Archived from the original on 29 June 2011. 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 [...]