diff options
author | Mike Pall <mike> | 2013-09-08 02:53:23 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-09-08 02:53:23 +0200 |
commit | d1194a82eb24afa1c749a0a8080b67d168f9f201 (patch) | |
tree | fb3bebc2cbf5032a49653dd6a0bd31c420dd8083 /src/lj_record.c | |
parent | d3d30d389b504495d054d71bdee0fe2677d4b44c (diff) | |
download | luajit-d1194a82eb24afa1c749a0a8080b67d168f9f201.tar.gz luajit-d1194a82eb24afa1c749a0a8080b67d168f9f201.tar.bz2 luajit-d1194a82eb24afa1c749a0a8080b67d168f9f201.zip |
Low-overhead profiler, part 4: JIT compiler support.
Diffstat (limited to 'src/lj_record.c')
-rw-r--r-- | src/lj_record.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lj_record.c b/src/lj_record.c index bdf0212a..3dcb0a85 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -20,6 +20,9 @@ | |||
20 | #endif | 20 | #endif |
21 | #include "lj_bc.h" | 21 | #include "lj_bc.h" |
22 | #include "lj_ff.h" | 22 | #include "lj_ff.h" |
23 | #if LJ_HASPROFILE | ||
24 | #include "lj_debug.h" | ||
25 | #endif | ||
23 | #include "lj_ir.h" | 26 | #include "lj_ir.h" |
24 | #include "lj_jit.h" | 27 | #include "lj_jit.h" |
25 | #include "lj_ircall.h" | 28 | #include "lj_ircall.h" |
@@ -579,6 +582,52 @@ static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev) | |||
579 | } /* Side trace continues across a loop that's left or not entered. */ | 582 | } /* Side trace continues across a loop that's left or not entered. */ |
580 | } | 583 | } |
581 | 584 | ||
585 | /* -- Record profiler hook checks ----------------------------------------- */ | ||
586 | |||
587 | #if LJ_HASPROFILE | ||
588 | |||
589 | /* Need to insert profiler hook check? */ | ||
590 | static int rec_profile_need(jit_State *J, GCproto *pt, const BCIns *pc) | ||
591 | { | ||
592 | GCproto *ppt; | ||
593 | lua_assert(J->prof_mode == 'f' || J->prof_mode == 'l'); | ||
594 | if (!pt) | ||
595 | return 0; | ||
596 | ppt = J->prev_pt; | ||
597 | J->prev_pt = pt; | ||
598 | if (pt != ppt && ppt) { | ||
599 | J->prev_line = -1; | ||
600 | return 1; | ||
601 | } | ||
602 | if (J->prof_mode == 'l') { | ||
603 | BCLine line = lj_debug_line(pt, proto_bcpos(pt, pc)); | ||
604 | BCLine pline = J->prev_line; | ||
605 | J->prev_line = line; | ||
606 | if (pline != line) | ||
607 | return 1; | ||
608 | } | ||
609 | return 0; | ||
610 | } | ||
611 | |||
612 | static void rec_profile_ins(jit_State *J, const BCIns *pc) | ||
613 | { | ||
614 | if (J->prof_mode && rec_profile_need(J, J->pt, pc)) { | ||
615 | emitir(IRTG(IR_PROF, IRT_NIL), 0, 0); | ||
616 | lj_snap_add(J); | ||
617 | } | ||
618 | } | ||
619 | |||
620 | static void rec_profile_ret(jit_State *J) | ||
621 | { | ||
622 | if (J->prof_mode == 'f') { | ||
623 | emitir(IRTG(IR_PROF, IRT_NIL), 0, 0); | ||
624 | J->prev_pt = NULL; | ||
625 | lj_snap_add(J); | ||
626 | } | ||
627 | } | ||
628 | |||
629 | #endif | ||
630 | |||
582 | /* -- Record calls and returns -------------------------------------------- */ | 631 | /* -- Record calls and returns -------------------------------------------- */ |
583 | 632 | ||
584 | /* Specialize to the runtime value of the called function or its prototype. */ | 633 | /* Specialize to the runtime value of the called function or its prototype. */ |
@@ -1770,6 +1819,10 @@ void lj_record_ins(jit_State *J) | |||
1770 | rec_check_ir(J); | 1819 | rec_check_ir(J); |
1771 | #endif | 1820 | #endif |
1772 | 1821 | ||
1822 | #if LJ_HASPROFILE | ||
1823 | rec_profile_ins(J, pc); | ||
1824 | #endif | ||
1825 | |||
1773 | /* Keep a copy of the runtime values of var/num/str operands. */ | 1826 | /* Keep a copy of the runtime values of var/num/str operands. */ |
1774 | #define rav (&ix.valv) | 1827 | #define rav (&ix.valv) |
1775 | #define rbv (&ix.tabv) | 1828 | #define rbv (&ix.tabv) |
@@ -2074,6 +2127,9 @@ void lj_record_ins(jit_State *J) | |||
2074 | rc = (BCReg)(J->L->top - J->L->base) - ra + 1; | 2127 | rc = (BCReg)(J->L->top - J->L->base) - ra + 1; |
2075 | /* fallthrough */ | 2128 | /* fallthrough */ |
2076 | case BC_RET: case BC_RET0: case BC_RET1: | 2129 | case BC_RET: case BC_RET0: case BC_RET1: |
2130 | #if LJ_HASPROFILE | ||
2131 | rec_profile_ret(J); | ||
2132 | #endif | ||
2077 | lj_record_ret(J, ra, (ptrdiff_t)rc-1); | 2133 | lj_record_ret(J, ra, (ptrdiff_t)rc-1); |
2078 | break; | 2134 | break; |
2079 | 2135 | ||
@@ -2303,6 +2359,10 @@ void lj_record_setup(jit_State *J) | |||
2303 | if (1 + J->pt->framesize >= LJ_MAX_JSLOTS) | 2359 | if (1 + J->pt->framesize >= LJ_MAX_JSLOTS) |
2304 | lj_trace_err(J, LJ_TRERR_STACKOV); | 2360 | lj_trace_err(J, LJ_TRERR_STACKOV); |
2305 | } | 2361 | } |
2362 | #if LJ_HASPROFILE | ||
2363 | J->prev_pt = NULL; | ||
2364 | J->prev_line = -1; | ||
2365 | #endif | ||
2306 | #ifdef LUAJIT_ENABLE_CHECKHOOK | 2366 | #ifdef LUAJIT_ENABLE_CHECKHOOK |
2307 | /* Regularly check for instruction/line hooks from compiled code and | 2367 | /* Regularly check for instruction/line hooks from compiled code and |
2308 | ** exit to the interpreter if the hooks are set. | 2368 | ** exit to the interpreter if the hooks are set. |