NanoJIT

http://www-archive.mozilla.org/projects/tamarin/

Tamarin Project

Goals

The goal of the "Tamarin" project is to implement a high-performance, open source implementation of the ECMAScript 4th edition (ES4) language specification. The Tamarin virtual machine will be used by Mozilla within SpiderMonkey, the core JavaScript engine embedded in Firefox®, and other products based on Mozilla technology. The code will continue to be used by Adobe as part of the ActionScript™ Virtual Machine within Adobe® Flash® Player.

The Tamarin virtual machine currently implements the ECMAScript 3rd edition language standard that is the basis for JavaScript, Adobe ActionScript, and Microsoft Jscript, plus some of the new language features proposed in the ECMAScript 4th edition specification. By working on an open source implementation of ES4 with the community, Adobe and Mozilla hope to accelerate the adoption of a standard language for creating engaging Web applications. We hope the Tamarin project accelerates the ability of developers to create and deliver richer, more interactive experiences that work across multiple platforms.

Roadmap

Tamarin will support the forthcoming ECMAScript Edition 4 ("JS2") language and will be integrated into SpiderMonkey as part of the Mozilla 2 project, to be released in 2008. Brendan Eich's Roadmap Update for Mozilla 2 provides broad details on Mozilla 2 and Tamarin's role in this roadmap.

The Tamarin project is just getting started so the roadmap is not yet fully developed, but some of the technical goals include:

  1. Integrating the Tamarin VM and garbage collector within SpiderMonkey
  2. Using the SpiderMonkey compiler to generate code for Tamarin
  3. Porting the just-in-time compiler to new hardware platforms
  4. Completing the self-hosting ECMAScript 4 compiler

This page will be updated as the roadmap is defined.

Current Status

The primary source code for Tamarin is available via Mercurial at http://hg.mozilla.org/tamarin-central. There is an experimental branch available at http://hg.mozilla.org/tamarin-tracing. This code is licensed under the same Mozilla tri-license (MPL/GPL/LGPL) as other Mozilla code.

Preliminary documentation for Tamarin, as well as build instructions, can be found at the Mozilla Developer Center.

The self-hosting compiler contains the foundation of a compiler but much work remains to make it fully functional.

Adding More Cowbell to Tamarin

Many dynamic language virtual machines (VM) written in C++ work by compiling code that passes parameters into VM C++ methods which do most of the heavy lifting. For example, adding two values becomes two x86 pushes onto the stack with a x86 call into a C++ method add. When I last looked at Apple's SquirrelFish, that's all it did. The generated x86 code in Tamarin more or less does the same thing with a few optimizations. And having such a simple compiler works surprisingly well, but it only takes you so far. Sooner or later, you'll want to generate better, faster machine code.

An effective way of generating faster code is method inlining. Instead of generating calls, the JIT should inline the methods that do the real work. The problem for Tamarin's JIT, is that it doesn't know how to inline C++ methods. NanoJIT only compiles LIR, not C++. Enter the C++ to LIR translator.

We do this by statically compiling Tamarin with LLVM. LLVM is a pretty awesome GCC replacement that is nicely designed, object oriented, and generally a pleasure to work with. The output of LLVM is like an object file, but instead contains LLVM bitcode. This new tool then translates LLVM bitcode into LIR. At runtime, Tamarin compiles the LIR, which really represents a VM C++ method. Boom, inlinable C++ methods.

We don't have to apply the translator to only method inlining. In essence, Tamarin compiles VM C++ methods as if they were ActionScript methods. Application ActionScript, such as a youtube video, prior to execution, is translated into LIR, which is then compiled into machine code. We also translate most of Tamarin, written in C++, into LIR, which is then compilable into machine code by NanoJIT. NanoJIT has the power to compile, inline, and optimize VM C++ methods for the performance win.

You may be thinking, hmm this sounds an awfully like a self-interpreting VM. A self-interpreting VM is a VM written in the language it executes. For example, writing a JavaScript VM in JavaScript would make it self-interpreting. Well, you're right. This approach hacks in self-interpreting/JITting into a VM written in C++.

Consider the three images above just to clarify the differences. The "standard" VM approach, and what Tamarin did before, is to JIT code that calls into C++ methods. The host C++ compiler (Visual Studio/GCC) does a lot of work, and the JIT has no idea what was going on. In a self-interpreting VM, the JIT compiles everything, application and VM code, and knows everything about itself. This approach mimics a self-interpreting VM by translating C++ methods into LIR, and JITing both application and VM code.

Over the next few weeks, I'll be detailing the implementation/design decisions in Tamarin.

Thanks to Michael Bebenita for proofreading and creating the images. Checkout this great SNL skit if you are wondering what More Cowbell is.

原文地址:https://www.cnblogs.com/lexus/p/2209808.html