-
Notifications
You must be signed in to change notification settings - Fork 6
JIT Compilation: Fast: x86_64 (TD)
This page describes the implementation of the fast JIT compiler for the x84_64.
There are two types of calling conventions: for JIT generated methods and for interop methods.
The calling convention for JIT generated methods is as follows:
-
[0] globals
: A pointer to the global data (see JIT Compilation (TD)), -
[1] argc
: The number of arguments provided to the function; -
[2] args
: A pointer to the arguments provided to the function with the following layout:-
[0] return
: Allocated space for the return value; -
[1] this
: The this value; -
[2] function
: The function being called; -
[3...args + 3] arguments
: The arguments to the function.
-
The result of a function is a Boolean specifying whether the function completed successfully. If this is set to false, the exception in flight will be assigned to the global data.
Interop methods are methods that expose standard functionality like e.g. JsEnv::add
. These methods wrap methods on JsEnv
so that this functionality can be used in JIT generated methods.
These methods have the following calling convention:
-
[0] globals
: A pointer to the global data (see JIT Compilation (TD)), -
[1] argc
: The number of arguments provided to the function; -
[2] args
: A pointer to the arguments provided to the function with the following layout:-
[0...args] arguments
: The arguments to the function.
-
The first position of the args
array is also used for the return value. This means that when argc
is 0
, the length of the args
array is still one to accommodate the return value.
The result of a function is a Boolean specifying whether the function completed successfully. If this is set to false, the exception in flight will be assigned to the global data.
The stack layout for a fast JIT compiled function is as follows:
-
[0] EBP
: The previous base stack pointer; -
[1] metadata
: A pointer to the meta data associated with the function. This metadata describes the stack layout and exception frame map of the function; -
[2...n + 2] locals
: Local and temporary variables. These are instances of theJsRawValue
struct and used by the GC to find roots; -
[n + 2...] temporaries
: Temporaries used by running code. These are not rooted and not walked by the GC. These can beJsRawValue
instances or other types.
The metadata describes the number of locals and temporaries that are on the stack. Everything beyond this number of locals and temporaries are not walked by the GC. The stack can contain both JIT'ed methods and native methods.
The space for locals and temporaries is zeroed at the start of the function. This is to make sure that the GC does not read garbage. Sometimes values will also be zeroed while the function is running. This is to make sure that objects are not kept on the stack (i.e. rooted) too long.
TODO: Decide on an algorithm to differentiate between JIT'ed and native methods.