aboutsummaryrefslogtreecommitdiff
path: root/src/lj_snap.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_snap.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/lj_snap.c b/src/lj_snap.c
index 788500af..8638d9ed 100644
--- a/src/lj_snap.c
+++ b/src/lj_snap.c
@@ -94,8 +94,10 @@ static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map)
94{ 94{
95 cTValue *frame = J->L->base - 1; 95 cTValue *frame = J->L->base - 1;
96 cTValue *lim = J->L->base - J->baseslot; 96 cTValue *lim = J->L->base - J->baseslot;
97 cTValue *ftop = frame + funcproto(frame_func(frame))->framesize; 97 GCfunc *fn = frame_func(frame);
98 cTValue *ftop = isluafunc(fn) ? (frame+funcproto(fn)->framesize) : J->L->top;
98 MSize f = 0; 99 MSize f = 0;
100 lua_assert(!LJ_FR2); /* TODO_FR2: store 64 bit PCs. */
99 map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */ 101 map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */
100 while (frame > lim) { /* Backwards traversal of all frames above base. */ 102 while (frame > lim) { /* Backwards traversal of all frames above base. */
101 if (frame_islua(frame)) { 103 if (frame_islua(frame)) {
@@ -143,8 +145,8 @@ void lj_snap_add(jit_State *J)
143 MSize nsnap = J->cur.nsnap; 145 MSize nsnap = J->cur.nsnap;
144 MSize nsnapmap = J->cur.nsnapmap; 146 MSize nsnapmap = J->cur.nsnapmap;
145 /* Merge if no ins. inbetween or if requested and no guard inbetween. */ 147 /* Merge if no ins. inbetween or if requested and no guard inbetween. */
146 if (J->mergesnap ? !irt_isguard(J->guardemit) : 148 if ((nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins) ||
147 (nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins)) { 149 (J->mergesnap && !irt_isguard(J->guardemit))) {
148 if (nsnap == 1) { /* But preserve snap #0 PC. */ 150 if (nsnap == 1) { /* But preserve snap #0 PC. */
149 emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); 151 emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);
150 goto nomerge; 152 goto nomerge;
@@ -237,7 +239,8 @@ static BCReg snap_usedef(jit_State *J, uint8_t *udf,
237 case BCMbase: 239 case BCMbase:
238 if (op >= BC_CALLM && op <= BC_VARG) { 240 if (op >= BC_CALLM && op <= BC_VARG) {
239 BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ? 241 BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ?
240 maxslot : (bc_a(ins) + bc_c(ins)); 242 maxslot : (bc_a(ins) + bc_c(ins)+LJ_FR2);
243 if (LJ_FR2) DEF_SLOT(bc_a(ins)+1);
241 s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0); 244 s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0);
242 for (; s < top; s++) USE_SLOT(s); 245 for (; s < top; s++) USE_SLOT(s);
243 for (; s < maxslot; s++) DEF_SLOT(s); 246 for (; s < maxslot; s++) DEF_SLOT(s);
@@ -596,6 +599,7 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
596 } 599 }
597 if (LJ_UNLIKELY(bloomtest(rfilt, ref))) 600 if (LJ_UNLIKELY(bloomtest(rfilt, ref)))
598 rs = snap_renameref(T, snapno, ref, rs); 601 rs = snap_renameref(T, snapno, ref, rs);
602 lua_assert(!LJ_GC64); /* TODO_GC64: handle 64 bit references. */
599 if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */ 603 if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */
600 int32_t *sps = &ex->spill[regsp_spill(rs)]; 604 int32_t *sps = &ex->spill[regsp_spill(rs)];
601 if (irt_isinteger(t)) { 605 if (irt_isinteger(t)) {
@@ -609,8 +613,7 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
609 o->u64 = *(uint64_t *)sps; 613 o->u64 = *(uint64_t *)sps;
610 } else { 614 } else {
611 lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */ 615 lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */
612 setgcrefi(o->gcr, *sps); 616 setgcV(J->L, o, (GCobj *)(uintptr_t)*(GCSize *)sps, irt_toitype(t));
613 setitype(o, irt_toitype(t));
614 } 617 }
615 } else { /* Restore from register. */ 618 } else { /* Restore from register. */
616 Reg r = regsp_reg(rs); 619 Reg r = regsp_reg(rs);
@@ -625,13 +628,13 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
625 } else if (irt_isnum(t)) { 628 } else if (irt_isnum(t)) {
626 setnumV(o, ex->fpr[r-RID_MIN_FPR]); 629 setnumV(o, ex->fpr[r-RID_MIN_FPR]);
627#endif 630#endif
628 } else if (LJ_64 && irt_islightud(t)) { 631 } else if (LJ_64 && irt_is64(t)) {
629 /* 64 bit lightuserdata which may escape already has the tag bits. */ 632 /* 64 bit values that already have the tag bits. */
630 o->u64 = ex->gpr[r-RID_MIN_GPR]; 633 o->u64 = ex->gpr[r-RID_MIN_GPR];
634 } else if (irt_ispri(t)) {
635 setpriV(o, irt_toitype(t));
631 } else { 636 } else {
632 if (!irt_ispri(t)) 637 setgcV(J->L, o, (GCobj *)ex->gpr[r-RID_MIN_GPR], irt_toitype(t));
633 setgcrefi(o->gcr, ex->gpr[r-RID_MIN_GPR]);
634 setitype(o, irt_toitype(t));
635 } 638 }
636 } 639 }
637} 640}
@@ -708,8 +711,9 @@ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,
708 if (ir->o == IR_CNEW || ir->o == IR_CNEWI) { 711 if (ir->o == IR_CNEW || ir->o == IR_CNEWI) {
709 CTState *cts = ctype_cts(J->L); 712 CTState *cts = ctype_cts(J->L);
710 CTypeID id = (CTypeID)T->ir[ir->op1].i; 713 CTypeID id = (CTypeID)T->ir[ir->op1].i;
711 CTSize sz = lj_ctype_size(cts, id); 714 CTSize sz;
712 GCcdata *cd = lj_cdata_new(cts, id, sz); 715 CTInfo info = lj_ctype_info(cts, id, &sz);
716 GCcdata *cd = lj_cdata_newx(cts, id, sz, info);
713 setcdataV(J->L, o, cd); 717 setcdataV(J->L, o, cd);
714 if (ir->o == IR_CNEWI) { 718 if (ir->o == IR_CNEWI) {
715 uint8_t *p = (uint8_t *)cdataptr(cd); 719 uint8_t *p = (uint8_t *)cdataptr(cd);
@@ -792,7 +796,7 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr)
792 MSize n, nent = snap->nent; 796 MSize n, nent = snap->nent;
793 SnapEntry *map = &T->snapmap[snap->mapofs]; 797 SnapEntry *map = &T->snapmap[snap->mapofs];
794 SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; 798 SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1];
795 int32_t ftsz0; 799 ptrdiff_t ftsz0;
796 TValue *frame; 800 TValue *frame;
797 BloomFilter rfilt = snap_renamefilter(T, snapno); 801 BloomFilter rfilt = snap_renamefilter(T, snapno);
798 const BCIns *pc = snap_pc(map[nent]); 802 const BCIns *pc = snap_pc(map[nent]);
@@ -833,8 +837,9 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr)
833 snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp); 837 snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp);
834 o->u32.hi = tmp.u32.lo; 838 o->u32.hi = tmp.u32.lo;
835 } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { 839 } else if ((sn & (SNAP_CONT|SNAP_FRAME))) {
840 lua_assert(!LJ_FR2); /* TODO_FR2: store 64 bit PCs. */
836 /* Overwrite tag with frame link. */ 841 /* Overwrite tag with frame link. */
837 o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0; 842 setframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0);
838 L->base = o+1; 843 L->base = o+1;
839 } 844 }
840 } 845 }