diff options
-rw-r--r-- | src/lj_asm_arm.h | 2 | ||||
-rw-r--r-- | src/lj_asm_ppc.h | 2 | ||||
-rw-r--r-- | src/lj_asm_x86.h | 2 | ||||
-rw-r--r-- | src/lj_jit.h | 10 | ||||
-rw-r--r-- | src/lj_opt_loop.c | 18 | ||||
-rw-r--r-- | src/lj_record.c | 3 | ||||
-rw-r--r-- | src/lj_snap.c | 5 |
7 files changed, 25 insertions, 17 deletions
diff --git a/src/lj_asm_arm.h b/src/lj_asm_arm.h index d4f1113a..0ab4917e 100644 --- a/src/lj_asm_arm.h +++ b/src/lj_asm_arm.h | |||
@@ -1460,8 +1460,8 @@ static void asm_stack_check(ASMState *as, BCReg topslot, | |||
1460 | static void asm_stack_restore(ASMState *as, SnapShot *snap) | 1460 | static void asm_stack_restore(ASMState *as, SnapShot *snap) |
1461 | { | 1461 | { |
1462 | SnapEntry *map = &as->T->snapmap[snap->mapofs]; | 1462 | SnapEntry *map = &as->T->snapmap[snap->mapofs]; |
1463 | SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; | ||
1463 | MSize n, nent = snap->nent; | 1464 | MSize n, nent = snap->nent; |
1464 | SnapEntry *flinks = map + nent + snap->depth; | ||
1465 | /* Store the value of all modified slots to the Lua stack. */ | 1465 | /* Store the value of all modified slots to the Lua stack. */ |
1466 | for (n = 0; n < nent; n++) { | 1466 | for (n = 0; n < nent; n++) { |
1467 | SnapEntry sn = map[n]; | 1467 | SnapEntry sn = map[n]; |
diff --git a/src/lj_asm_ppc.h b/src/lj_asm_ppc.h index 196ca2ed..c03d0102 100644 --- a/src/lj_asm_ppc.h +++ b/src/lj_asm_ppc.h | |||
@@ -1793,8 +1793,8 @@ static void asm_stack_check(ASMState *as, BCReg topslot, | |||
1793 | static void asm_stack_restore(ASMState *as, SnapShot *snap) | 1793 | static void asm_stack_restore(ASMState *as, SnapShot *snap) |
1794 | { | 1794 | { |
1795 | SnapEntry *map = &as->T->snapmap[snap->mapofs]; | 1795 | SnapEntry *map = &as->T->snapmap[snap->mapofs]; |
1796 | SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; | ||
1796 | MSize n, nent = snap->nent; | 1797 | MSize n, nent = snap->nent; |
1797 | SnapEntry *flinks = map + nent + snap->depth; | ||
1798 | /* Store the value of all modified slots to the Lua stack. */ | 1798 | /* Store the value of all modified slots to the Lua stack. */ |
1799 | for (n = 0; n < nent; n++) { | 1799 | for (n = 0; n < nent; n++) { |
1800 | SnapEntry sn = map[n]; | 1800 | SnapEntry sn = map[n]; |
diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index 391e2de9..4d47e389 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h | |||
@@ -2316,8 +2316,8 @@ static void asm_stack_check(ASMState *as, BCReg topslot, | |||
2316 | static void asm_stack_restore(ASMState *as, SnapShot *snap) | 2316 | static void asm_stack_restore(ASMState *as, SnapShot *snap) |
2317 | { | 2317 | { |
2318 | SnapEntry *map = &as->T->snapmap[snap->mapofs]; | 2318 | SnapEntry *map = &as->T->snapmap[snap->mapofs]; |
2319 | SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1]; | ||
2319 | MSize n, nent = snap->nent; | 2320 | MSize n, nent = snap->nent; |
2320 | SnapEntry *flinks = map + nent + snap->depth; | ||
2321 | /* Store the value of all modified slots to the Lua stack. */ | 2321 | /* Store the value of all modified slots to the Lua stack. */ |
2322 | for (n = 0; n < nent; n++) { | 2322 | for (n = 0; n < nent; n++) { |
2323 | SnapEntry sn = map[n]; | 2323 | SnapEntry sn = map[n]; |
diff --git a/src/lj_jit.h b/src/lj_jit.h index 8f87899c..e80547ab 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h | |||
@@ -139,8 +139,8 @@ typedef struct SnapShot { | |||
139 | IRRef1 ref; /* First IR ref for this snapshot. */ | 139 | IRRef1 ref; /* First IR ref for this snapshot. */ |
140 | uint8_t nslots; /* Number of valid slots. */ | 140 | uint8_t nslots; /* Number of valid slots. */ |
141 | uint8_t nent; /* Number of compressed entries. */ | 141 | uint8_t nent; /* Number of compressed entries. */ |
142 | uint8_t depth; /* Number of frame links. */ | ||
143 | uint8_t count; /* Count of taken exits for this snapshot. */ | 142 | uint8_t count; /* Count of taken exits for this snapshot. */ |
143 | uint8_t unused; | ||
144 | } SnapShot; | 144 | } SnapShot; |
145 | 145 | ||
146 | #define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */ | 146 | #define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */ |
@@ -224,6 +224,14 @@ typedef struct GCtrace { | |||
224 | 224 | ||
225 | LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist)); | 225 | LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist)); |
226 | 226 | ||
227 | static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap) | ||
228 | { | ||
229 | if (snap+1 == &T->snap[T->nsnap]) | ||
230 | return T->nsnapmap; | ||
231 | else | ||
232 | return (snap+1)->mapofs; | ||
233 | } | ||
234 | |||
227 | /* Round-robin penalty cache for bytecodes leading to aborted traces. */ | 235 | /* Round-robin penalty cache for bytecodes leading to aborted traces. */ |
228 | typedef struct HotPenalty { | 236 | typedef struct HotPenalty { |
229 | MRef pc; /* Starting bytecode PC. */ | 237 | MRef pc; /* Starting bytecode PC. */ |
diff --git a/src/lj_opt_loop.c b/src/lj_opt_loop.c index d1512468..8d2935f6 100644 --- a/src/lj_opt_loop.c +++ b/src/lj_opt_loop.c | |||
@@ -182,7 +182,8 @@ static void loop_subst_snap(jit_State *J, SnapShot *osnap, | |||
182 | SnapEntry *loopmap, IRRef1 *subst) | 182 | SnapEntry *loopmap, IRRef1 *subst) |
183 | { | 183 | { |
184 | SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs]; | 184 | SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs]; |
185 | MSize nmapofs, depth; | 185 | SnapEntry *nextmap = &J->cur.snapmap[snap_nextofs(&J->cur, osnap)]; |
186 | MSize nmapofs; | ||
186 | MSize on, ln, nn, onent = osnap->nent; | 187 | MSize on, ln, nn, onent = osnap->nent; |
187 | BCReg nslots = osnap->nslots; | 188 | BCReg nslots = osnap->nslots; |
188 | SnapShot *snap = &J->cur.snap[J->cur.nsnap]; | 189 | SnapShot *snap = &J->cur.snap[J->cur.nsnap]; |
@@ -194,11 +195,9 @@ static void loop_subst_snap(jit_State *J, SnapShot *osnap, | |||
194 | nmapofs = snap->mapofs; | 195 | nmapofs = snap->mapofs; |
195 | } | 196 | } |
196 | J->guardemit.irt = 0; | 197 | J->guardemit.irt = 0; |
197 | depth = osnap->depth; | ||
198 | /* Setup new snapshot. */ | 198 | /* Setup new snapshot. */ |
199 | snap->mapofs = (uint16_t)nmapofs; | 199 | snap->mapofs = (uint16_t)nmapofs; |
200 | snap->ref = (IRRef1)J->cur.nins; | 200 | snap->ref = (IRRef1)J->cur.nins; |
201 | snap->depth = (uint8_t)depth; | ||
202 | snap->nslots = nslots; | 201 | snap->nslots = nslots; |
203 | snap->count = 0; | 202 | snap->count = 0; |
204 | nmap = &J->cur.snapmap[nmapofs]; | 203 | nmap = &J->cur.snapmap[nmapofs]; |
@@ -220,11 +219,11 @@ static void loop_subst_snap(jit_State *J, SnapShot *osnap, | |||
220 | while (snap_slot(loopmap[ln]) < nslots) /* Copy remaining loop slots. */ | 219 | while (snap_slot(loopmap[ln]) < nslots) /* Copy remaining loop slots. */ |
221 | nmap[nn++] = loopmap[ln++]; | 220 | nmap[nn++] = loopmap[ln++]; |
222 | snap->nent = (uint8_t)nn; | 221 | snap->nent = (uint8_t)nn; |
223 | J->cur.nsnapmap = (uint16_t)(nmapofs + nn + 1 + depth); | ||
224 | omap += onent; | 222 | omap += onent; |
225 | nmap += nn; | 223 | nmap += nn; |
226 | for (nn = 0; nn <= depth; nn++) /* Copy PC + frame links. */ | 224 | while (omap < nextmap) /* Copy PC + frame links. */ |
227 | nmap[nn] = omap[nn]; | 225 | *nmap++ = *omap++; |
226 | J->cur.nsnapmap = (uint16_t)(nmap - J->cur.snapmap); | ||
228 | } | 227 | } |
229 | 228 | ||
230 | /* Unroll loop. */ | 229 | /* Unroll loop. */ |
@@ -335,13 +334,13 @@ static void loop_unroll(jit_State *J) | |||
335 | } | 334 | } |
336 | 335 | ||
337 | /* Undo any partial changes made by the loop optimization. */ | 336 | /* Undo any partial changes made by the loop optimization. */ |
338 | static void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap) | 337 | static void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap, MSize nsnapmap) |
339 | { | 338 | { |
340 | ptrdiff_t i; | 339 | ptrdiff_t i; |
341 | SnapShot *snap = &J->cur.snap[nsnap-1]; | 340 | SnapShot *snap = &J->cur.snap[nsnap-1]; |
342 | SnapEntry *map = J->cur.snapmap; | 341 | SnapEntry *map = J->cur.snapmap; |
343 | map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent]; /* Restore PC. */ | 342 | map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent]; /* Restore PC. */ |
344 | J->cur.nsnapmap = (uint16_t)(snap->mapofs + snap->nent + 1 + snap->depth); | 343 | J->cur.nsnapmap = (uint16_t)nsnapmap; |
345 | J->cur.nsnap = nsnap; | 344 | J->cur.nsnap = nsnap; |
346 | J->guardemit.irt = 0; | 345 | J->guardemit.irt = 0; |
347 | lj_ir_rollback(J, ins); | 346 | lj_ir_rollback(J, ins); |
@@ -370,6 +369,7 @@ int lj_opt_loop(jit_State *J) | |||
370 | { | 369 | { |
371 | IRRef nins = J->cur.nins; | 370 | IRRef nins = J->cur.nins; |
372 | SnapNo nsnap = J->cur.nsnap; | 371 | SnapNo nsnap = J->cur.nsnap; |
372 | MSize nsnapmap = J->cur.nsnapmap; | ||
373 | int errcode = lj_vm_cpcall(J->L, NULL, J, cploop_opt); | 373 | int errcode = lj_vm_cpcall(J->L, NULL, J, cploop_opt); |
374 | if (LJ_UNLIKELY(errcode)) { | 374 | if (LJ_UNLIKELY(errcode)) { |
375 | lua_State *L = J->L; | 375 | lua_State *L = J->L; |
@@ -382,7 +382,7 @@ int lj_opt_loop(jit_State *J) | |||
382 | if (--J->instunroll < 0) /* But do not unroll forever. */ | 382 | if (--J->instunroll < 0) /* But do not unroll forever. */ |
383 | break; | 383 | break; |
384 | L->top--; /* Remove error object. */ | 384 | L->top--; /* Remove error object. */ |
385 | loop_undo(J, nins, nsnap); | 385 | loop_undo(J, nins, nsnap, nsnapmap); |
386 | return 1; /* Loop optimization failed, continue recording. */ | 386 | return 1; /* Loop optimization failed, continue recording. */ |
387 | default: | 387 | default: |
388 | break; | 388 | break; |
diff --git a/src/lj_record.c b/src/lj_record.c index 35ec1456..c8502d5d 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -2047,6 +2047,7 @@ static void rec_setup_side(jit_State *J, GCtrace *T) | |||
2047 | SnapEntry *map = &T->snapmap[snap->mapofs]; | 2047 | SnapEntry *map = &T->snapmap[snap->mapofs]; |
2048 | MSize n, nent = snap->nent; | 2048 | MSize n, nent = snap->nent; |
2049 | BloomFilter seen = 0; | 2049 | BloomFilter seen = 0; |
2050 | J->framedepth = 0; | ||
2050 | /* Emit IR for slots inherited from parent snapshot. */ | 2051 | /* Emit IR for slots inherited from parent snapshot. */ |
2051 | for (n = 0; n < nent; n++) { | 2052 | for (n = 0; n < nent; n++) { |
2052 | SnapEntry sn = map[n]; | 2053 | SnapEntry sn = map[n]; |
@@ -2087,12 +2088,12 @@ static void rec_setup_side(jit_State *J, GCtrace *T) | |||
2087 | } | 2088 | } |
2088 | setslot: | 2089 | setslot: |
2089 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ | 2090 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ |
2091 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); | ||
2090 | if ((sn & SNAP_FRAME)) | 2092 | if ((sn & SNAP_FRAME)) |
2091 | J->baseslot = s+1; | 2093 | J->baseslot = s+1; |
2092 | } | 2094 | } |
2093 | J->base = J->slot + J->baseslot; | 2095 | J->base = J->slot + J->baseslot; |
2094 | J->maxslot = snap->nslots - J->baseslot; | 2096 | J->maxslot = snap->nslots - J->baseslot; |
2095 | J->framedepth = snap->depth; | ||
2096 | lj_snap_add(J); | 2097 | lj_snap_add(J); |
2097 | } | 2098 | } |
2098 | 2099 | ||
diff --git a/src/lj_snap.c b/src/lj_snap.c index e29b5357..a2025d88 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c | |||
@@ -118,7 +118,6 @@ static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap) | |||
118 | snap->mapofs = (uint16_t)nsnapmap; | 118 | snap->mapofs = (uint16_t)nsnapmap; |
119 | snap->ref = (IRRef1)J->cur.nins; | 119 | snap->ref = (IRRef1)J->cur.nins; |
120 | snap->nent = (uint8_t)nent; | 120 | snap->nent = (uint8_t)nent; |
121 | snap->depth = (uint8_t)J->framedepth; | ||
122 | snap->nslots = (uint8_t)nslots; | 121 | snap->nslots = (uint8_t)nslots; |
123 | snap->count = 0; | 122 | snap->count = 0; |
124 | J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth); | 123 | J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth); |
@@ -274,7 +273,7 @@ void lj_snap_shrink(jit_State *J) | |||
274 | map[m++] = map[n]; /* Only copy used slots. */ | 273 | map[m++] = map[n]; /* Only copy used slots. */ |
275 | } | 274 | } |
276 | snap->nent = (uint8_t)m; | 275 | snap->nent = (uint8_t)m; |
277 | nlim = nent + snap->depth; | 276 | nlim = J->cur.nsnapmap - snap->mapofs - 1; |
278 | while (n <= nlim) map[m++] = map[n++]; /* Move PC + frame links down. */ | 277 | while (n <= nlim) map[m++] = map[n++]; /* Move PC + frame links down. */ |
279 | J->cur.nsnapmap = (uint16_t)(snap->mapofs + m); /* Free up space in map. */ | 278 | J->cur.nsnapmap = (uint16_t)(snap->mapofs + m); /* Free up space in map. */ |
280 | } | 279 | } |
@@ -337,7 +336,7 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) | |||
337 | SnapShot *snap = &T->snap[snapno]; | 336 | SnapShot *snap = &T->snap[snapno]; |
338 | MSize n, nent = snap->nent; | 337 | MSize n, nent = snap->nent; |
339 | SnapEntry *map = &T->snapmap[snap->mapofs]; | 338 | SnapEntry *map = &T->snapmap[snap->mapofs]; |
340 | SnapEntry *flinks = map + nent + snap->depth; | 339 | SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; |
341 | int32_t ftsz0; | 340 | int32_t ftsz0; |
342 | BCReg nslots = snap->nslots; | 341 | BCReg nslots = snap->nslots; |
343 | TValue *frame; | 342 | TValue *frame; |