diff options
| author | Mike Pall <mike> | 2016-10-16 21:04:38 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2016-10-16 21:04:38 +0200 |
| commit | 6a25014c1c33448cabdc013ccb9e5c4fc98a0238 (patch) | |
| tree | c3c3bfc7ceadd3f38c02e31fa8754bfaea90c323 | |
| parent | 3f43f09413c49a1f4cffc0e060d755e84c5df85e (diff) | |
| download | luajit-6a25014c1c33448cabdc013ccb9e5c4fc98a0238.tar.gz luajit-6a25014c1c33448cabdc013ccb9e5c4fc98a0238.tar.bz2 luajit-6a25014c1c33448cabdc013ccb9e5c4fc98a0238.zip | |
LJ_FR2: Fix slot 1 handling.
Contributed by Peter Cawley.
| -rw-r--r-- | src/jit/dump.lua | 2 | ||||
| -rw-r--r-- | src/lj_record.c | 4 | ||||
| -rw-r--r-- | src/lj_snap.c | 16 |
3 files changed, 16 insertions, 6 deletions
diff --git a/src/jit/dump.lua b/src/jit/dump.lua index fbadccec..a8bc2af2 100644 --- a/src/jit/dump.lua +++ b/src/jit/dump.lua | |||
| @@ -338,6 +338,8 @@ local function formatk(tr, idx, sn) | |||
| 338 | elseif t == 21 then -- int64_t | 338 | elseif t == 21 then -- int64_t |
| 339 | s = sub(tostring(k), 1, -3) | 339 | s = sub(tostring(k), 1, -3) |
| 340 | if sub(s, 1, 1) ~= "-" then s = "+"..s end | 340 | if sub(s, 1, 1) ~= "-" then s = "+"..s end |
| 341 | elseif sn == 0x1057fff then -- SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL) | ||
| 342 | return "----" -- Special case for LJ_FR2 slot 1. | ||
| 341 | else | 343 | else |
| 342 | s = tostring(k) -- For primitives. | 344 | s = tostring(k) -- For primitives. |
| 343 | end | 345 | end |
diff --git a/src/lj_record.c b/src/lj_record.c index 48018f42..a858ffa9 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
| @@ -105,7 +105,7 @@ static void rec_check_slots(jit_State *J) | |||
| 105 | lua_assert(tref_isfunc(tr)); | 105 | lua_assert(tref_isfunc(tr)); |
| 106 | #if LJ_FR2 | 106 | #if LJ_FR2 |
| 107 | } else if (s == 1) { | 107 | } else if (s == 1) { |
| 108 | lua_assert(0); | 108 | lua_assert((tr & ~TREF_FRAME) == 0); |
| 109 | #endif | 109 | #endif |
| 110 | } else if ((tr & TREF_FRAME)) { | 110 | } else if ((tr & TREF_FRAME)) { |
| 111 | GCfunc *fn = gco2func(frame_gc(tv)); | 111 | GCfunc *fn = gco2func(frame_gc(tv)); |
| @@ -747,7 +747,7 @@ void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs) | |||
| 747 | } | 747 | } |
| 748 | /* Move func + args down. */ | 748 | /* Move func + args down. */ |
| 749 | if (LJ_FR2 && J->baseslot == 2) | 749 | if (LJ_FR2 && J->baseslot == 2) |
| 750 | J->base[func+1] = 0; | 750 | J->base[func+1] = TREF_FRAME; |
| 751 | memmove(&J->base[-1-LJ_FR2], &J->base[func], sizeof(TRef)*(J->maxslot+1+LJ_FR2)); | 751 | memmove(&J->base[-1-LJ_FR2], &J->base[func], sizeof(TRef)*(J->maxslot+1+LJ_FR2)); |
| 752 | /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */ | 752 | /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */ |
| 753 | /* Tailcalls can form a loop, so count towards the loop unroll limit. */ | 753 | /* Tailcalls can form a loop, so count towards the loop unroll limit. */ |
diff --git a/src/lj_snap.c b/src/lj_snap.c index 48259972..8ca6deb7 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c | |||
| @@ -69,9 +69,13 @@ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) | |||
| 69 | TRef tr = J->slot[s]; | 69 | TRef tr = J->slot[s]; |
| 70 | IRRef ref = tref_ref(tr); | 70 | IRRef ref = tref_ref(tr); |
| 71 | #if LJ_FR2 | 71 | #if LJ_FR2 |
| 72 | if (s == 1) continue; | 72 | if (s == 1) { /* Ignore slot 1 in LJ_FR2 mode, except if tailcalled. */ |
| 73 | if ((tr & TREF_FRAME)) | ||
| 74 | map[n++] = SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL); | ||
| 75 | continue; | ||
| 76 | } | ||
| 73 | if ((tr & (TREF_FRAME | TREF_CONT)) && !ref) { | 77 | if ((tr & (TREF_FRAME | TREF_CONT)) && !ref) { |
| 74 | TValue *base = J->L->base - J->baseslot; | 78 | cTValue *base = J->L->base - J->baseslot; |
| 75 | tr = J->slot[s] = (tr & 0xff0000) | lj_ir_k64(J, IR_KNUM, base[s].u64); | 79 | tr = J->slot[s] = (tr & 0xff0000) | lj_ir_k64(J, IR_KNUM, base[s].u64); |
| 76 | ref = tref_ref(tr); | 80 | ref = tref_ref(tr); |
| 77 | } | 81 | } |
| @@ -470,7 +474,11 @@ void lj_snap_replay(jit_State *J, GCtrace *T) | |||
| 470 | goto setslot; | 474 | goto setslot; |
| 471 | bloomset(seen, ref); | 475 | bloomset(seen, ref); |
| 472 | if (irref_isk(ref)) { | 476 | if (irref_isk(ref)) { |
| 473 | tr = snap_replay_const(J, ir); | 477 | /* See special treatment of LJ_FR2 slot 1 in snapshot_slots() above. */ |
| 478 | if (LJ_FR2 && (sn == SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL))) | ||
| 479 | tr = 0; | ||
| 480 | else | ||
| 481 | tr = snap_replay_const(J, ir); | ||
| 474 | } else if (!regsp_used(ir->prev)) { | 482 | } else if (!regsp_used(ir->prev)) { |
| 475 | pass23 = 1; | 483 | pass23 = 1; |
| 476 | lua_assert(s != 0); | 484 | lua_assert(s != 0); |
| @@ -484,7 +492,7 @@ void lj_snap_replay(jit_State *J, GCtrace *T) | |||
| 484 | } | 492 | } |
| 485 | setslot: | 493 | setslot: |
| 486 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ | 494 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ |
| 487 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); | 495 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && (s != LJ_FR2)); |
| 488 | if ((sn & SNAP_FRAME)) | 496 | if ((sn & SNAP_FRAME)) |
| 489 | J->baseslot = s+1; | 497 | J->baseslot = s+1; |
| 490 | } | 498 | } |
