Wed Feb 24 15:47:16 CET 2010 Paolo Molaro <lupus@ximian.com>
[mono.git] / web / runtime
index 908600e8f84b648122fe012f27724ea805dd61b9..d1dabab996859a2a487b5fa71da0898941fc91be 100644 (file)
@@ -1,70 +1,82 @@
 * The Mono runtime
 
-       The Mono runtime implements a JIT engine for the CIL virtual
-       machine (as well as a byte code interpreter, this is to
-       quickly port it to new systems), the class loader, the garbage
-       collector, threading system and metadata access libraries.
+       The Mono runtime engine is considered feature complete.
+
+       It implements a Just-in-Time compiler engine for the CIL
+       virtual machine, the class loader, the garbage collector,
+       threading system and metadata access libraries.
 
        We currently have two runtimes:
 
        <ul>
-               * <b>mono:</b> The Just In Time compiler implemented
-                 using a BURS instruction selector.  We only support
-                 x86 machines in the JIT engine at this point.
+               * <b>mono:</b> Our Just-in-Time and Ahead-of-Time code
+                 generator for maximum performance.  This supports
+                 x86, PowerPC and SPARC cpus.
        
                * <b>mint:</b> The Mono interpreter.  This is an
                  easy-to-port runtime engine.
        </ul>
 
-       Currently we are using the Bohem conservative garbage
-       collector, but we working on incorporating the ORP GC engine. 
+       We are using the Boehm conservative garbage collector.
+
+       The Mono runtime can be used as a stand-alone process, or it
+       can be <a href="embedded-api.html">embedded into applications</a> (see
+       the documentation in mono/samples/embed for more details).
 
-** Executing MSIL/CIL images
+       Embedding the Mono runtime allows applications to be extended
+       in C# while reusing all of the existing C and C++ code.  
 
-       The code will load an executable and map the references to
-       external assemblies to our own version of the assemblies on
-       Linux.
+       Paolo Molaro did a presentation on the current JIT engine and
+       the new JIT engine.  You can find his <a
+       href="http://primates.ximian.com/~lupus/slides/jit/">slides
+       here</a>
 
-       Our roadmap looks like this, this has been updated as of
-       <b>Dec 18, 2001</b>:
+** Current JIT Engine: technical details (<b>updated, June 28th, 2003</b>)
+
+       We have re-written our JIT compiler. We wanted to support a
+       number of features that were missing:
 
        <ul>
+               * Ahead-of-time compilation.  
 
-               * Milestone 1: <b>Done</b> Fully read and parse all CIL byte-codes
-                 and metadata tokens (ie, a disassembler).  
+            The idea is to allow developers to pre-compile their code
+            to native code to reduce startup time, and the working
+            set that is used at runtime in the just-in-time compiler.
 
-               * Milestone 2: <b>Done</b> Complete an interpreter for CIL byte
-                 codes.  This interpreter can be used temporarly to
-                 run CIL byte code on a system where no JIT is
-                 available.
+            Although in Mono this has not been a visible problem, we
+            wanted to pro-actively address this problem.
 
-               * Milestone 3: <b>Done</b>Define an <i>lburg</i>-like
-                 instruction selector for the JITer for Intel.
+            When an assembly (a Mono/.NET executable) is installed in
+            the system, it would then be possible to pre-compile the
+            code, and have the JIT compiler tune the generated code
+            to the particular CPU on which the software is
+            installed. 
 
-               * Milestone 4: <b>Done</b> Implement JITer.  This is where our
-                 current efforts are focused on, the JITer currently runs
-                 all of the code we have tested on it.  The major limitation
-                 is that our class libraries are not complete, and hence not
-                 every application can be ran.
+            This is done in the Microsoft.NET world with a tool
+            called ngen.exe
 
-               * Milestone 5: Port of the JITer to non IA32 systems.
-       </ul>
+               * Have a good platform for doing code optimizations. 
 
-       A setup similar to the Kaffe JIT engine will be used to
-       layout the code to support non-IA32 architectures.  Our work
-       will be focused on getting a IA32 version running first.  
+            The design called for a good architecture that would
+            enable various levels of optimizations: some
+            optimizations are better performed on high-level
+            intermediate representations, some on medium-level and
+            some at low-level representations.
 
-       The JIT engine works on Linux and Win32, although you
-       will need to install the CygWin32 development tools to get a
-       Unix-like compilation environment (mostly we use GNU make in 
-       a few of the makefiles).
+            Also it should be possible to conditionally turn these on
+            or off.  Some optimizations are too expensive to be used
+            in just-in-time compilation scenarios, but these
+            expensive optimizations can be turned on for
+            ahead-of-time compilations or when using profile-guided
+            optimizations on a subset of the executed methods.
 
-** JIT Engine (<b>updated, April 21, 2002</b>)
+               * Reduce the effort required to port the Mono code
+             generator to new architectures.
 
-       The JIT engine uses a code-generator generator approach for
-       compilation.  Given the properties of CIL byte codes, we can
-       take full advantage of a real instruction selector for our
-       code generator. 
+            For Mono to gain wide adoption in the Unix world, it is
+            necessary that the JIT engine works in most of today's
+            commercial hardware platforms. 
+       </ul>
 
        The JIT engine implements a number of optimizations:
 
                  
                * Inlining.
 
-               * Constant folding.  
+               * Constant folding, copy propagation, dead code elimination.
 
                  Although compilers typically do
                  constant folding, the combination of inlining with
                  constant folding gives some very good results.
+
+               * Linear scan register allocation.  In the past,
+                 register allocation was our achilles heel, but now 
+                 we have left this problem behind.
+
+               * SSA-based framework.  Various optimizations are
+                 implemented on top of this framework
        </ul>
 
        There are a couple of books that deal with this technique: "A
         technical description of <a
         href="http://research.microsoft.com/copyright/accept.asp?path=http://www.research.microsoft.com/~drh/pubs/iburg.pdf&pub=ACM">lbrug</a>.
 
-       A few papers that describe the instruction selector:
+       The new JIT engines uses three intermediate representations:
+       the source is the CIL which is transformed into a forest of
+       trees; This is fed into a BURS instruction selector that
+       generates the final low-level intermediate representation.
+
+       The instruction selector is documented in the following
+       papers:
 
        <ul>
                * <a href="http://research.microsoft.com/copyright/accept.asp?path=http://www.research.microsoft.com/~drh/pubs/interface.pdf&pub=wiley">A code generation interface for ANSI C</a>
 
        </ul>
 
-** Future plans
-
-       We are evaluating the future directions for the JIT engine:
-       both from our needs (optimizations like inlining, better register allocation,
-       instruction scheduling, and porting to other CPUs).
-
-       We have not yet decided how we will evolve the JIT engine.  We
-       might just upgrade our current architecture, and provide optimizations as
-       an extra layer.
-
 ** Garbage Collection
 
-       Currently we are using the Boehm conservative GC.  Although our plans 
-       are to move to the Intel ORP GC engine, our plans on a next generation
-       dual-JIT engine have to be taken into account.
-
-       We will be using the Intel ORP GC engine as it provides a precise
+       We are using the Boehm conservative GC.  We might consider
+       adopting other GC engines in the future, like the Intel ORP GC
+       engine.  The Intel ORP GC engine as it provides a precise
        garbage collector engine, similar to what is available on the
-       .NET environment. 
-
-       Although using a conservative garbage collector like Bohem's
-       would work, all the type information is available at runtime,
-       so we can actually implement a better collector than a
-       conservative collector.
+       .NET environment.
 
        <ul>
                * Garbage collection list and FAQ:<br>
        The ECMA runtime and the .NET runtime assume an IO model and a
        threading model that is very similar to the Win32 API.  
 
-       Dick Porter has been working on the Mono abstraction layer
+       Dick Porter has developed WAPI: the Mono abstraction layer
        that allows our runtime to execute code that depend on this
        behaviour.
 
        as well as talking to system libraries.
 
        Initially we used libffi, but it was fairly slow, so we have
-       reused parts of the JIT work to create efficient PInvoke trampolines. 
+       reused parts of the JIT work to create efficient PInvoke
+       trampolines.
 
 ** Remoting