Twitter
Essays
Random
« The Forever War by Dexter Filkins | Main | Building Tamarin on Windows »
Saturday
Mar282009

Tamarin Execution Flow

Tamarin Central's architecture seems relativley straightfoward. Tamarin directly executes ActionScript ByteCode instead of converting it to another intermediate representation. You can read all of the opcodes and their definitions in the AVM2 Overview. The overview is a bit out of date as a few opcodes have been added such as finddef. Tamarin predetermines if a function should be compiled or interpreted with a flag in the MethodInfo object. If the SUGGEST_INTERP bit is set, a method is interpreted, otherwise it is compiled into native code. So far, it seems that Tamarin compiles all methods other than the init methods. The init methods are set to be interpreted during ABC parsing:

AbcParser.cpp

// suggest that we don't jit the $init methods
script->setSuggestInterp();

When a method is called, if it is to be interpreted, the ABC is verified and is directly executed. Tamarin contains a direct threaded interpreter for GCC and a standard switch loop for Windows. If a method is slated for compilation, the ABC is translated to LIR during the verification stage. ABC is translated into LIR one opcode at a time. The LIR is passed into an NanoJit and compiled. The location of the native code is stored in the MethodInfo instance. The compiled code is then executed.
MethodInfo.cpp
MethodInfo::verifyEnter(MethodEnv* env, int argc, uint32* ap)
{
MethodInfo* f = env->method;
f->verify(env->toplevel()); // convert to LIR and Compile

return f->impl32()(env, argc, ap); // impl32 points the address of the JIT code
}

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (1)

Mason,

This is great stuff. Appreciate the effort.

Mike

May 13, 2009 | Unregistered CommenterMichael Labriola

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>