Skip to content

Commit

Permalink
Track last exited trace (lasttrace) in global_State
Browse files Browse the repository at this point in the history
The VM now keeps track of the previous vmstate from before the most
recent exit to the interpreter. The field is global_State.lasttrace.

This is intended to help with profiling and diagnostics ("which trace
is to blame for all these expensive exits into the interpreter?")
  • Loading branch information
lukego committed Nov 17, 2017
1 parent 089c55a commit bd7266d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ typedef struct global_State {
GCState gc; /* Garbage collector. */
volatile int32_t vmstate; /* VM state or current JIT code trace number. */
volatile int32_t gcvmstate; /* Previous VM state (only when state is GC). */
volatile int32_t lasttrace; /* VM state before exit to interpreter. */
SBuf tmpbuf; /* Temporary string buffer. */
GCstr strempty; /* Empty string. */
uint8_t stremptyz; /* Zero terminator of empty string. */
Expand Down
4 changes: 4 additions & 0 deletions src/vm_x64.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,10 @@ static void build_subroutines(BuildCtx *ctx)
| mov KBASE, [KBASE+PC2PROTO(k)]
| mov L:RB->base, BASE
| mov qword [DISPATCH+DISPATCH_GL(jit_base)], 0
| mov TMPRd, dword [DISPATCH+DISPATCH_GL(vmstate)]
| // Record which trace exited to the interpreter, then switch state
| mov TMPRd, dword [DISPATCH+DISPATCH_GL(vmstate)]
| mov dword [DISPATCH+DISPATCH_GL(lasttrace)], TMPRd
| set_vmstate INTERP
| // Modified copy of ins_next which handles function header dispatch, too.
| mov RCd, [PC]
Expand Down

0 comments on commit bd7266d

Please sign in to comment.