SpiderMonkey (JavaScript engine)
   HOME

TheInfoList



OR:

SpiderMonkey is the first
JavaScript engine 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. JavaScript engines are typical ...
, written by
Brendan Eich Brendan Eich (; born July 4, 1961) 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 ...
at
Netscape Netscape Communications Corporation (originally Mosaic Communications Corporation) was an American independent computer services company with headquarters in Mountain View, California and then Dulles, Virginia. Its Netscape web browser was on ...
Communications, later released as
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized so ...
and currently maintained by the
Mozilla Foundation The Mozilla Foundation (stylized as moz://a) is an American non-profit organization that exists to support and collectively lead the open source Mozilla project. Founded in July 2003, the organization sets the policies that govern development, ...
. It is used in the
Firefox 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 ...
web browser A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used o ...
.


History

Eich "wrote JavaScript in ten days" in 1995, having been "recruited to Netscape with the promise of 'doing
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
' in the browser". (The idea of using Scheme was abandoned when "engineering management ecidedthat the language must 'look like Java.) In late 1996, Eich, needing to "pay off hesubstantial
technical debt In software development, technical debt (also known as design debt or code debt) is the implied cost of additional rework caused by choosing an easy (limited) solution now instead of using a better approach that would take longer. Analogous with ...
" left from the first year, "stayed home for two weeks to rewrite Mocha as the codebase that became known as SpiderMonkey". (Mocha was the original working name for the language.) In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin.


Versions


Standards

SpiderMonkey implements the ECMA-262 specification (
ECMAScript ECMAScript (; ES) is a JavaScript standard intended to ensure the interoperability of web pages across different browsers. It is standardized by Ecma International in the documenECMA-262 ECMAScript is commonly used for client-side scripti ...
). ECMA-357 (
ECMAScript for XML ECMAScript for XML (E4X) is the standar programming language extension that adds native XML support to ECMAScript (which includes ActionScript, JavaScript, and JScript). The goal is to provide an alternative to DOM interfaces that uses a simpler ...
(E4X)) was dropped in early 2013.


Internals

SpiderMonkey is written in C/ C++ and contains an interpreter, the IonMonkey JIT compiler, and a
garbage collector A waste collector, also known as a garbageman, garbage collector, trashman (in the US), binman or (rarely) dustman (in the UK), is a person employed by a public or private enterprise to collect and dispose of municipal solid waste (refuse) and ...
.


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 Mozilla Firefox 3.5 is a version of the Firefox web browser released in June 2009, adding a variety of new features to Firefox. Version 3.5 was touted as being twice as fast as 3.0 (due its TraceMonkey JavaScript engine and rendering improveme ...
, 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 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 an ...
, which operates by recording
control flow In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an '' ...
and
data type In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed operations on it. A data type tells the compiler or interpreter how the programmer intends to use the data. Most progra ...
s during interpreter execution. This data then informed the construction of trace trees, highly specialized paths of
native code In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a ver ...
. Improvements to JägerMonkey eventually made TraceMonkey obsolete, especially with the development of the SpiderMonkey
type inference Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistic ...
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 In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a ver ...
. It was first released in
Firefox 4 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 (a base for the final version) was released on March 18, 2011. It was codenamed Tumu ...
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 In computer science, a control-flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution. The control-flow graph was discovered by Frances E. Allen, who noted that ...
representing the function, JägerMonkey instead operated by iterating linearly forward through SpiderMonkey
bytecode Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
, 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 cache Inline caching is an optimization technique employed by some language runtimes, and first developed for Smalltalk. The goal of inline caching is to speed up runtime method binding by remembering the results of a previous method lookup directly a ...
s and
type inference Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistic ...
. The difference between TraceMonkey and JägerMonkey JIT techniques and the need for both was explained i
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
dvanderdmandelin


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. IonMonkey was a more traditional compiler: it translated SpiderMonkey
bytecode Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
into a
control-flow graph In computer science, a control-flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution. The control-flow graph was discovered by Frances E. Allen, who noted that ...
, using static single assignment form (SSA) for the
intermediate representation An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
. This architecture enabled well-known optimizations from other programming languages to be used for JavaScript, including type specialization,
function inlining In computing, inline expansion, or inlining, is a manual or compiler optimization that replaces a function call site with the body of the called function. Inline expansion is similar to macro expansion, but occurs during compilation, without ch ...
, linear-scan
register allocation In compiler optimization, register allocation is the process of assigning local automatic variables and expression results to a limited number of processor registers. Register allocation can happen over a basic block (''local register allocatio ...
, dead code elimination, and loop-invariant code motion. The compiler can emit fast
native code In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a ver ...
translations of JavaScript functions on the ARM, x86, and
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging ...
platforms. It has been the default engine since Firefox 18.


OdinMonkey

OdinMonkey is the name of Mozilla's new optimization module for
asm.js 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 l ...
, 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. 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 An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
(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.


Use

SpiderMonkey is intended to be embedded in other applications that provide host environments for JavaScript. An incomplete list follows: * Mozilla
Firefox 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 ...
,
Thunderbird Thunderbird, thunder bird or thunderbirds may refer to: * Thunderbird (mythology), a legendary creature in certain North American indigenous peoples' history and culture * Ford Thunderbird, a car Birds * Dromornithidae, extinct flightless birds ...
,
SeaMonkey SeaMonkey is a free and open-source Internet suite. It is the continuation of the former Mozilla Application Suite, based on the same source code, which itself grew out of Netscape Communicator and formed the base of Netscape 6 and Netscape ...
, and other applications that use the Mozilla application framework **
Forks In cutlery or kitchenware, a fork (from la, furca 'pitchfork') is a utensil, now usually made of metal, whose long handle terminates in a head that branches into several narrow and often slightly curved tines with which one can spear foods eit ...
of Firefox including the Pale Moon,
Basilisk In European bestiaries and legends, a basilisk ( or ) is a legendary reptile reputed to be a serpent king, who causes death to those who look into its eyes. According to the '' Naturalis Historia'' of Pliny the Elder, the basilisk of Cyre ...
and
Waterfox Waterfox is an open-source web browser that is forked from Firefox and developed by System1. There are official Waterfox releases for Windows, macOS, and Linux. Divisions Waterfox Waterfox shares core features and technologies like the Gecko b ...
web browsers. *Data storage applications: **
MongoDB MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the S ...
moved from V8 to SpiderMonkey in version 3.2 ** Riak uses SpiderMonkey as the runtime for JavaScript MapReduce operations **
CouchDB Apache CouchDB is an open-source document-oriented NoSQL database, implemented in Erlang. CouchDB uses multiple formats and protocols to store, transfer, and process its data. It uses JSON to store data, JavaScript as its query language using ...
database system (written in Erlang). JavaScript is used for defining maps, filters, reduce functions and viewing data, for example in HTML format. *
Adobe Acrobat Adobe Acrobat is a family of application software and Web services developed by Adobe Inc. to view, create, manipulate, print and manage Portable Document Format (PDF) files. The family comprises Acrobat Reader (formerly Reader), Acrobat (forme ...
and Adobe Reader, Adobe Flash Professional, and
Adobe Dreamweaver Adobe Dreamweaver is a proprietary web development tool from Adobe Inc. It was created by Macromedia in 1997 and developed by them until Macromedia was acquired by Adobe Systems in 2005. Adobe Dreamweaver is available for the macOS and Windo ...
. Adobe Acrobat DC uses Spidermonkey 24.2 with ECMA-357 support forward ported. *
GNOME A gnome is a mythological creature and diminutive spirit in Renaissance magic and alchemy, first introduced by Paracelsus in the 16th century and later adopted by more recent authors including those of modern fantasy literature. Its characte ...
desktop environment, version 3 and later *
Yahoo! Widgets Yahoo Widgets is a discontinued free application platform for macOS, Mac OS X and Microsoft Windows, specifically Windows XP, Windows Vista, Vista and Windows 7. The software was previously called Konfabulator, but after being acquired by computer ...
, formerly named Konfabulator *
FreeSWITCH FreeSWITCH is free and open-source server software for real-time communication applications, including WebRTC, video, and voice over Internet Protocol (VoIP). It runs on Linux, Windows, macOS, and FreeBSD. FreeSWITCH is used to build private bran ...
, open-source telephony engine, uses SpiderMonkey to allow users to write call management scripts in JavaScript * The text-based web browser
ELinks ELinks is a free text-based web browser for Unix-like operating systems. It began in late 2001 as an experimental fork by Petr Baudiš of the Links Web browser, hence the E in the name. Since then, the E has come to stand for Enhanced or Ex ...
uses SpiderMonkey to support JavaScript * Parts of SpiderMonkey are used in the
Wine Wine is an alcoholic drink typically made from Fermentation in winemaking, fermented grapes. Yeast in winemaking, Yeast consumes the sugar in the grapes and converts it to ethanol and carbon dioxide, releasing heat in the process. Different ...
project's
JScript JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer 11 and older. JScript is implemented as an Active Scripting engine. This means that it can be "plugged in" to OLE Automation applica ...
(re-)implementation *
Synchronet Synchronet is a multiplatform BBS software package, with current ports for Microsoft Windows, Linux, and BSD variants. Past versions also ran on MS-DOS and OS/2, but support for those platforms were dropped in version 3.0 (circa 2000). Histor ...
, a BBS, e-mail, Web, and application server using the SpiderMonkey engine *
JavaScript OSA JavaScript OSA, (originally ''JavaScript for OSA'', abbreviated as ''JSOSA''), is a freeware inter-process communication scripting language for the Macintosh computer. JavaScript OSA uses the "core language" of the Mozilla implementation of the ...
, a SpiderMonkey
inter-process communication In computer science, inter-process communication or interprocess communication (IPC) refers specifically to the mechanisms an operating system provides to allow the processes to manage shared data. Typically, applications can use IPC, categoriz ...
language for the
Macintosh The Mac (known as Macintosh until 1999) is a family of personal computers designed and marketed by Apple Inc., Apple Inc. Macs are known for their ease of use and minimalist designs, and are popular among students, creative professionals, and ...
computer * '' 0 A.D.'', a real-time strategy game * SpiderMonkey is also used in many other open-source projects; an external list is maintained at Mozilla's developer site. SpiderMonkey includes a JavaScript Shell for interactive JavaScript development and for command-line invocation of JavaScript program files.


See also

*
Rhino (JavaScript engine) 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 ...
*
List of ECMAScript engines An ECMAScript engine is a program that executes source code written in a version of the ECMAScript language standard, for example, JavaScript. Just-in-time compilation engines These are new generation ECMAScript engines for web browsers, all i ...


References


External links

* , SpiderMonkey (JavaScript-C) engine
Firefox (and Spidermonkey) Release Calendar
{{DEFAULTSORT:Spidermonkey (JavaScript engine) Cross-platform software JavaScript engines Mozilla Software using the Mozilla license