During the execution:
- Trace and collect the argument types for the method and the return value type. (some method returns mixed type variable, we should ignore that kind of the method)
- Add the type signature to the method, each type signature refers to the compiled machine code.
- Calculate the execution times of a method and see if it exceeds the threshold.
When compiling a method, the compiler:
- Will be given a method, and the compiler generates the corresponding compiled machine code for each type signature.
- The compiled method should base on the argument types. (that is, type signature, e.g. [int, int] => [int])
When compiling:
sub square { my ($a, $b) = @_; return $a * $b; }
-
For the runtime system, we need to know the variable address, the address of the stack...
-
Just use the machine stack (not the perl's runtime stack) to push arguments before calling a compiled method, for example, when compiling:
square(3,5);
we compile it to:
; push arguments to the machine stack movl eax, resolve_int_address_for_scalar($b) push eax movl eax, resolve_int_address_for_scalar($a) push eax call [square:int=int,int] movl [scalar address for return value], eax
-
And the instructions in the compiled method will do:
; prolog push ebp movl ebp, esp movl eax, [ebp-4] imul eax, [ebp-8] ; epilog pop ebp ret
Update:
gist --update https://gist.github.com/27533f296523d290e0af perl5-jit-plan.md