diff options
| author | Mike Pall <mike> | 2014-12-15 02:27:27 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2014-12-15 02:27:27 +0100 |
| commit | 881f48f9808a950f8e046a3b299db0269506a87d (patch) | |
| tree | 43584223f3b77d77af5a3515b3191c21fd012f01 /src | |
| parent | b93b624ad88a9455cb3f12db93a9c5e153ff8a62 (diff) | |
| download | luajit-881f48f9808a950f8e046a3b299db0269506a87d.tar.gz luajit-881f48f9808a950f8e046a3b299db0269506a87d.tar.bz2 luajit-881f48f9808a950f8e046a3b299db0269506a87d.zip | |
Cleanup of frame handling. No functional changes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.dep | 2 | ||||
| -rw-r--r-- | src/lj_api.c | 2 | ||||
| -rw-r--r-- | src/lj_ccallback.c | 2 | ||||
| -rw-r--r-- | src/lj_debug.c | 4 | ||||
| -rw-r--r-- | src/lj_err.c | 17 | ||||
| -rw-r--r-- | src/lj_ffrecord.c | 2 | ||||
| -rw-r--r-- | src/lj_frame.h | 23 | ||||
| -rw-r--r-- | src/lj_meta.c | 2 | ||||
| -rw-r--r-- | src/lj_record.c | 3 | ||||
| -rw-r--r-- | src/lj_snap.c | 4 | ||||
| -rw-r--r-- | src/lj_vm.h | 2 |
11 files changed, 28 insertions, 35 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 738203b6..9aefb236 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
| @@ -97,7 +97,7 @@ lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 97 | lj_ccallback.h | 97 | lj_ccallback.h |
| 98 | lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 98 | lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 99 | lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \ | 99 | lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \ |
| 100 | lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_vm.h lj_jit.h lj_ir.h | 100 | lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_jit.h lj_ir.h |
| 101 | lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 101 | lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 102 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \ | 102 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \ |
| 103 | lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \ | 103 | lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \ |
diff --git a/src/lj_api.c b/src/lj_api.c index e27123bf..1ccd7be1 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
| @@ -1102,7 +1102,7 @@ LUA_API int lua_yield(lua_State *L, int nresults) | |||
| 1102 | setcont(top+1, lj_cont_hook); | 1102 | setcont(top+1, lj_cont_hook); |
| 1103 | setframe_pc(top+1, cframe_pc(cf)-1); | 1103 | setframe_pc(top+1, cframe_pc(cf)-1); |
| 1104 | setframe_gc(top+2, obj2gco(L)); | 1104 | setframe_gc(top+2, obj2gco(L)); |
| 1105 | setframe_ftsz(top+2, (int)((char *)(top+3)-(char *)L->base)+FRAME_CONT); | 1105 | setframe_ftsz(top+2, ((char *)(top+3)-(char *)L->base)+FRAME_CONT); |
| 1106 | L->top = L->base = top+3; | 1106 | L->top = L->base = top+3; |
| 1107 | #if LJ_TARGET_X64 | 1107 | #if LJ_TARGET_X64 |
| 1108 | lj_err_throw(L, LUA_YIELD); | 1108 | lj_err_throw(L, LUA_YIELD); |
diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c index b234ec67..bef379a5 100644 --- a/src/lj_ccallback.c +++ b/src/lj_ccallback.c | |||
| @@ -432,7 +432,7 @@ static void callback_conv_args(CTState *cts, lua_State *L) | |||
| 432 | o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */ | 432 | o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */ |
| 433 | o++; | 433 | o++; |
| 434 | setframe_gc(o, obj2gco(fn)); | 434 | setframe_gc(o, obj2gco(fn)); |
| 435 | setframe_ftsz(o, (int)((char *)(o+1) - (char *)L->base) + FRAME_CONT); | 435 | setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT); |
| 436 | L->top = L->base = ++o; | 436 | L->top = L->base = ++o; |
| 437 | if (!ct) | 437 | if (!ct) |
| 438 | lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK); | 438 | lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK); |
diff --git a/src/lj_debug.c b/src/lj_debug.c index 889ac017..1b794753 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | #include "lj_frame.h" | 15 | #include "lj_frame.h" |
| 16 | #include "lj_bc.h" | 16 | #include "lj_bc.h" |
| 17 | #include "lj_strfmt.h" | 17 | #include "lj_strfmt.h" |
| 18 | #include "lj_vm.h" | ||
| 19 | #if LJ_HASJIT | 18 | #if LJ_HASJIT |
| 20 | #include "lj_jit.h" | 19 | #include "lj_jit.h" |
| 21 | #endif | 20 | #endif |
| @@ -88,8 +87,7 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) | |||
| 88 | if (frame_islua(f)) { | 87 | if (frame_islua(f)) { |
| 89 | f = frame_prevl(f); | 88 | f = frame_prevl(f); |
| 90 | } else { | 89 | } else { |
| 91 | if (frame_isc(f) || (LJ_HASFFI && frame_iscont(f) && | 90 | if (frame_isc(f) || (frame_iscont(f) && frame_iscont_fficb(f))) |
| 92 | (f-1)->u32.lo == LJ_CONT_FFI_CALLBACK)) | ||
| 93 | cf = cframe_raw(cframe_prev(cf)); | 91 | cf = cframe_raw(cframe_prev(cf)); |
| 94 | f = frame_prevd(f); | 92 | f = frame_prevd(f); |
| 95 | } | 93 | } |
diff --git a/src/lj_err.c b/src/lj_err.c index 07afc580..dc2e26f3 100644 --- a/src/lj_err.c +++ b/src/lj_err.c | |||
| @@ -114,9 +114,7 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode) | |||
| 114 | frame = frame_prevl(frame); | 114 | frame = frame_prevl(frame); |
| 115 | break; | 115 | break; |
| 116 | case FRAME_C: /* C frame. */ | 116 | case FRAME_C: /* C frame. */ |
| 117 | #if LJ_HASFFI | ||
| 118 | unwind_c: | 117 | unwind_c: |
| 119 | #endif | ||
| 120 | #if LJ_UNWIND_EXT | 118 | #if LJ_UNWIND_EXT |
| 121 | if (errcode) { | 119 | if (errcode) { |
| 122 | L->base = frame_prevd(frame) + 1; | 120 | L->base = frame_prevd(frame) + 1; |
| @@ -150,10 +148,8 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode) | |||
| 150 | } | 148 | } |
| 151 | return cf; | 149 | return cf; |
| 152 | case FRAME_CONT: /* Continuation frame. */ | 150 | case FRAME_CONT: /* Continuation frame. */ |
| 153 | #if LJ_HASFFI | 151 | if (frame_iscont_fficb(frame)) |
| 154 | if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) | ||
| 155 | goto unwind_c; | 152 | goto unwind_c; |
| 156 | #endif | ||
| 157 | case FRAME_VARG: /* Vararg frame. */ | 153 | case FRAME_VARG: /* Vararg frame. */ |
| 158 | frame = frame_prevd(frame); | 154 | frame = frame_prevd(frame); |
| 159 | break; | 155 | break; |
| @@ -522,10 +518,8 @@ static ptrdiff_t finderrfunc(lua_State *L) | |||
| 522 | frame = frame_prevd(frame); | 518 | frame = frame_prevd(frame); |
| 523 | break; | 519 | break; |
| 524 | case FRAME_CONT: | 520 | case FRAME_CONT: |
| 525 | #if LJ_HASFFI | 521 | if (frame_iscont_fficb(frame)) |
| 526 | if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) | ||
| 527 | cf = cframe_prev(cf); | 522 | cf = cframe_prev(cf); |
| 528 | #endif | ||
| 529 | frame = frame_prevd(frame); | 523 | frame = frame_prevd(frame); |
| 530 | break; | 524 | break; |
| 531 | case FRAME_CP: | 525 | case FRAME_CP: |
| @@ -652,13 +646,10 @@ LJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg) | |||
| 652 | if (frame_islua(frame)) { | 646 | if (frame_islua(frame)) { |
| 653 | pframe = frame_prevl(frame); | 647 | pframe = frame_prevl(frame); |
| 654 | } else if (frame_iscont(frame)) { | 648 | } else if (frame_iscont(frame)) { |
| 655 | #if LJ_HASFFI | 649 | if (frame_iscont_fficb(frame)) { |
| 656 | if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) { | ||
| 657 | pframe = frame; | 650 | pframe = frame; |
| 658 | frame = NULL; | 651 | frame = NULL; |
| 659 | } else | 652 | } else { |
| 660 | #endif | ||
| 661 | { | ||
| 662 | pframe = frame_prevd(frame); | 653 | pframe = frame_prevd(frame); |
| 663 | #if LJ_HASFFI | 654 | #if LJ_HASFFI |
| 664 | /* Remove frame for FFI metamethods. */ | 655 | /* Remove frame for FFI metamethods. */ |
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 1fff4f48..b65759a5 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
| @@ -109,7 +109,7 @@ static void recff_stitch(jit_State *J) | |||
| 109 | 109 | ||
| 110 | /* Move func + args up in Lua stack and insert continuation. */ | 110 | /* Move func + args up in Lua stack and insert continuation. */ |
| 111 | memmove(&base[1], &base[-1], sizeof(TValue)*(J->maxslot+1)); | 111 | memmove(&base[1], &base[-1], sizeof(TValue)*(J->maxslot+1)); |
| 112 | setframe_ftsz(base+1, (int)((char *)(base+1) - (char *)pframe) + FRAME_CONT); | 112 | setframe_ftsz(base+1, ((char *)(base+1) - (char *)pframe) + FRAME_CONT); |
| 113 | setcont(base, cont); | 113 | setcont(base, cont); |
| 114 | setframe_pc(base, pc); | 114 | setframe_pc(base, pc); |
| 115 | if (LJ_DUALNUM) setintV(base-1, traceno); else base[-1].u64 = traceno; | 115 | if (LJ_DUALNUM) setintV(base-1, traceno); else base[-1].u64 = traceno; |
diff --git a/src/lj_frame.h b/src/lj_frame.h index fb533b0e..2540f4d4 100644 --- a/src/lj_frame.h +++ b/src/lj_frame.h | |||
| @@ -22,8 +22,11 @@ enum { | |||
| 22 | 22 | ||
| 23 | /* Macros to access and modify Lua frames. */ | 23 | /* Macros to access and modify Lua frames. */ |
| 24 | #define frame_gc(f) (gcref((f)->fr.func)) | 24 | #define frame_gc(f) (gcref((f)->fr.func)) |
| 25 | #define frame_func(f) (&frame_gc(f)->fn) | 25 | #define frame_ftsz(f) ((ptrdiff_t)(f)->fr.tp.ftsz) |
| 26 | #define frame_ftsz(f) ((f)->fr.tp.ftsz) | 26 | #define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns)) |
| 27 | #define setframe_gc(f, p) (setgcref((f)->fr.func, (p))) | ||
| 28 | #define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (int32_t)(sz)) | ||
| 29 | #define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc))) | ||
| 27 | 30 | ||
| 28 | #define frame_type(f) (frame_ftsz(f) & FRAME_TYPE) | 31 | #define frame_type(f) (frame_ftsz(f) & FRAME_TYPE) |
| 29 | #define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP) | 32 | #define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP) |
| @@ -33,8 +36,14 @@ enum { | |||
| 33 | #define frame_isvarg(f) (frame_typep(f) == FRAME_VARG) | 36 | #define frame_isvarg(f) (frame_typep(f) == FRAME_VARG) |
| 34 | #define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL) | 37 | #define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL) |
| 35 | 38 | ||
| 36 | #define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns)) | 39 | #define frame_func(f) (&frame_gc(f)->fn) |
| 40 | #define frame_delta(f) (frame_ftsz(f) >> 3) | ||
| 41 | #define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP) | ||
| 42 | |||
| 43 | enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */ | ||
| 44 | |||
| 37 | #define frame_contpc(f) (frame_pc((f)-1)) | 45 | #define frame_contpc(f) (frame_pc((f)-1)) |
| 46 | #define frame_contv(f) (((f)-1)->u32.lo) | ||
| 38 | #if LJ_64 | 47 | #if LJ_64 |
| 39 | #define frame_contf(f) \ | 48 | #define frame_contf(f) \ |
| 40 | ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \ | 49 | ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \ |
| @@ -42,18 +51,14 @@ enum { | |||
| 42 | #else | 51 | #else |
| 43 | #define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void)) | 52 | #define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void)) |
| 44 | #endif | 53 | #endif |
| 45 | #define frame_delta(f) (frame_ftsz(f) >> 3) | 54 | #define frame_iscont_fficb(f) \ |
| 46 | #define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP) | 55 | (LJ_HASFFI && frame_contv(f) == LJ_CONT_FFI_CALLBACK) |
| 47 | 56 | ||
| 48 | #define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1]))) | 57 | #define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1]))) |
| 49 | #define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f))) | 58 | #define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f))) |
| 50 | #define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f)) | 59 | #define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f)) |
| 51 | /* Note: this macro does not skip over FRAME_VARG. */ | 60 | /* Note: this macro does not skip over FRAME_VARG. */ |
| 52 | 61 | ||
| 53 | #define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc))) | ||
| 54 | #define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz)) | ||
| 55 | #define setframe_gc(f, p) (setgcref((f)->fr.func, (p))) | ||
| 56 | |||
| 57 | /* -- C stack frame ------------------------------------------------------- */ | 62 | /* -- C stack frame ------------------------------------------------------- */ |
| 58 | 63 | ||
| 59 | /* Macros to access and modify the C stack frame chain. */ | 64 | /* Macros to access and modify the C stack frame chain. */ |
diff --git a/src/lj_meta.c b/src/lj_meta.c index dea456f2..9c11dd86 100644 --- a/src/lj_meta.c +++ b/src/lj_meta.c | |||
| @@ -84,7 +84,7 @@ int lj_meta_tailcall(lua_State *L, cTValue *tv) | |||
| 84 | top->u32.lo = LJ_CONT_TAILCALL; | 84 | top->u32.lo = LJ_CONT_TAILCALL; |
| 85 | setframe_pc(top, pc); | 85 | setframe_pc(top, pc); |
| 86 | setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */ | 86 | setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */ |
| 87 | setframe_ftsz(top+1, (int)((char *)(top+2) - (char *)base) + FRAME_CONT); | 87 | setframe_ftsz(top+1, ((char *)(top+2) - (char *)base) + FRAME_CONT); |
| 88 | L->base = L->top = top+2; | 88 | L->base = L->top = top+2; |
| 89 | /* | 89 | /* |
| 90 | ** before: [old_mo|PC] [... ...] | 90 | ** before: [old_mo|PC] [... ...] |
diff --git a/src/lj_record.c b/src/lj_record.c index 3ccba777..98296633 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
| @@ -1627,7 +1627,8 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults) | |||
| 1627 | if (nvararg >= nresults) | 1627 | if (nvararg >= nresults) |
| 1628 | emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults)); | 1628 | emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults)); |
| 1629 | else | 1629 | else |
| 1630 | emitir(IRTGI(IR_EQ), fr, lj_ir_kint(J, frame_ftsz(J->L->base-1))); | 1630 | emitir(IRTGI(IR_EQ), fr, |
| 1631 | lj_ir_kint(J, (int32_t)frame_ftsz(J->L->base-1))); | ||
| 1631 | vbase = emitir(IRTI(IR_SUB), REF_BASE, fr); | 1632 | vbase = emitir(IRTI(IR_SUB), REF_BASE, fr); |
| 1632 | vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8)); | 1633 | vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8)); |
| 1633 | for (i = 0; i < nload; i++) { | 1634 | for (i = 0; i < nload; i++) { |
diff --git a/src/lj_snap.c b/src/lj_snap.c index 3438f7bb..8bfbd3d1 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c | |||
| @@ -796,7 +796,7 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) | |||
| 796 | MSize n, nent = snap->nent; | 796 | MSize n, nent = snap->nent; |
| 797 | SnapEntry *map = &T->snapmap[snap->mapofs]; | 797 | SnapEntry *map = &T->snapmap[snap->mapofs]; |
| 798 | SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; | 798 | SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; |
| 799 | int32_t ftsz0; | 799 | ptrdiff_t ftsz0; |
| 800 | TValue *frame; | 800 | TValue *frame; |
| 801 | BloomFilter rfilt = snap_renamefilter(T, snapno); | 801 | BloomFilter rfilt = snap_renamefilter(T, snapno); |
| 802 | const BCIns *pc = snap_pc(map[nent]); | 802 | const BCIns *pc = snap_pc(map[nent]); |
| @@ -838,7 +838,7 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) | |||
| 838 | o->u32.hi = tmp.u32.lo; | 838 | o->u32.hi = tmp.u32.lo; |
| 839 | } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { | 839 | } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { |
| 840 | /* Overwrite tag with frame link. */ | 840 | /* Overwrite tag with frame link. */ |
| 841 | o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0; | 841 | setframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0); |
| 842 | L->base = o+1; | 842 | L->base = o+1; |
| 843 | } | 843 | } |
| 844 | } | 844 | } |
diff --git a/src/lj_vm.h b/src/lj_vm.h index a69d699f..17b62d85 100644 --- a/src/lj_vm.h +++ b/src/lj_vm.h | |||
| @@ -105,8 +105,6 @@ LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */ | |||
| 105 | LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */ | 105 | LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */ |
| 106 | LJ_ASMF void lj_cont_stitch(void); /* Trace stitching. */ | 106 | LJ_ASMF void lj_cont_stitch(void); /* Trace stitching. */ |
| 107 | 107 | ||
| 108 | enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */ | ||
| 109 | |||
| 110 | /* Start of the ASM code. */ | 108 | /* Start of the ASM code. */ |
| 111 | LJ_ASMF char lj_vm_asm_begin[]; | 109 | LJ_ASMF char lj_vm_asm_begin[]; |
| 112 | 110 | ||
