diff options
author | Mike Pall <mike> | 2012-07-02 13:37:55 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2012-07-02 13:37:55 +0200 |
commit | 7ae3832f2048edaa14c0050326aaa3ce2273975f (patch) | |
tree | cf853d259d9788472f074413f14b504ffe419811 /src | |
parent | cda3630565ad0f715fb9acd5c208e35b02466e32 (diff) | |
download | luajit-7ae3832f2048edaa14c0050326aaa3ce2273975f.tar.gz luajit-7ae3832f2048edaa14c0050326aaa3ce2273975f.tar.bz2 luajit-7ae3832f2048edaa14c0050326aaa3ce2273975f.zip |
Move snapshot replay for side traces to lj_snap.c.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_record.c | 60 | ||||
-rw-r--r-- | src/lj_snap.c | 64 | ||||
-rw-r--r-- | src/lj_snap.h | 1 |
3 files changed, 67 insertions, 58 deletions
diff --git a/src/lj_record.c b/src/lj_record.c index 837f61f4..2ce8564c 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -2066,63 +2066,6 @@ static const BCIns *rec_setup_root(jit_State *J) | |||
2066 | return pc; | 2066 | return pc; |
2067 | } | 2067 | } |
2068 | 2068 | ||
2069 | /* Setup recording for a side trace. */ | ||
2070 | static void rec_setup_side(jit_State *J, GCtrace *T) | ||
2071 | { | ||
2072 | SnapShot *snap = &T->snap[J->exitno]; | ||
2073 | SnapEntry *map = &T->snapmap[snap->mapofs]; | ||
2074 | MSize n, nent = snap->nent; | ||
2075 | BloomFilter seen = 0; | ||
2076 | J->framedepth = 0; | ||
2077 | /* Emit IR for slots inherited from parent snapshot. */ | ||
2078 | for (n = 0; n < nent; n++) { | ||
2079 | SnapEntry sn = map[n]; | ||
2080 | IRRef ref = snap_ref(sn); | ||
2081 | BCReg s = snap_slot(sn); | ||
2082 | IRIns *ir = &T->ir[ref]; | ||
2083 | IRType t = irt_type(ir->t); | ||
2084 | TRef tr; | ||
2085 | /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */ | ||
2086 | if (bloomtest(seen, ref)) { | ||
2087 | MSize j; | ||
2088 | for (j = 0; j < n; j++) | ||
2089 | if (snap_ref(map[j]) == ref) { | ||
2090 | tr = J->slot[snap_slot(map[j])]; | ||
2091 | goto setslot; | ||
2092 | } | ||
2093 | } | ||
2094 | bloomset(seen, ref); | ||
2095 | switch ((IROp)ir->o) { | ||
2096 | /* Only have to deal with constants that can occur in stack slots. */ | ||
2097 | case IR_KPRI: tr = TREF_PRI(t); break; | ||
2098 | case IR_KINT: tr = lj_ir_kint(J, ir->i); break; | ||
2099 | case IR_KGC: tr = lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t)); break; | ||
2100 | case IR_KNUM: tr = lj_ir_k64(J, IR_KNUM, ir_knum(ir)); break; | ||
2101 | case IR_KINT64: tr = lj_ir_k64(J, IR_KINT64, ir_kint64(ir)); break; | ||
2102 | case IR_KPTR: tr = lj_ir_kptr(J, ir_kptr(ir)); break; /* Continuation. */ | ||
2103 | /* Inherited SLOADs don't need a guard or type check. */ | ||
2104 | case IR_SLOAD: | ||
2105 | if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; | ||
2106 | tr = emitir_raw(IRT(IR_SLOAD, t), s, | ||
2107 | (ir->op2&IRSLOAD_READONLY) | IRSLOAD_INHERIT|IRSLOAD_PARENT); | ||
2108 | break; | ||
2109 | /* Parent refs are already typed and don't need a guard. */ | ||
2110 | default: | ||
2111 | if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; | ||
2112 | tr = emitir_raw(IRT(IR_SLOAD, t), s, IRSLOAD_INHERIT|IRSLOAD_PARENT); | ||
2113 | break; | ||
2114 | } | ||
2115 | setslot: | ||
2116 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ | ||
2117 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); | ||
2118 | if ((sn & SNAP_FRAME)) | ||
2119 | J->baseslot = s+1; | ||
2120 | } | ||
2121 | J->base = J->slot + J->baseslot; | ||
2122 | J->maxslot = snap->nslots - J->baseslot; | ||
2123 | lj_snap_add(J); | ||
2124 | } | ||
2125 | |||
2126 | /* Setup for recording a new trace. */ | 2069 | /* Setup for recording a new trace. */ |
2127 | void lj_record_setup(jit_State *J) | 2070 | void lj_record_setup(jit_State *J) |
2128 | { | 2071 | { |
@@ -2178,7 +2121,8 @@ void lj_record_setup(jit_State *J) | |||
2178 | } else { | 2121 | } else { |
2179 | J->startpc = NULL; /* Prevent forming an extra loop. */ | 2122 | J->startpc = NULL; /* Prevent forming an extra loop. */ |
2180 | } | 2123 | } |
2181 | rec_setup_side(J, T); | 2124 | lj_snap_replay(J, T); |
2125 | lj_snap_add(J); | ||
2182 | sidecheck: | 2126 | sidecheck: |
2183 | if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] || | 2127 | if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] || |
2184 | T->snap[J->exitno].count >= J->param[JIT_P_hotexit] + | 2128 | T->snap[J->exitno].count >= J->param[JIT_P_hotexit] + |
diff --git a/src/lj_snap.c b/src/lj_snap.c index 3371375a..c04d622d 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c | |||
@@ -351,6 +351,70 @@ IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir) | |||
351 | return ir; | 351 | return ir; |
352 | } | 352 | } |
353 | 353 | ||
354 | /* -- Snapshot replay ----------------------------------------------------- */ | ||
355 | |||
356 | /* Replay constant from parent trace. */ | ||
357 | static TRef snap_replay_const(jit_State *J, IRIns *ir) | ||
358 | { | ||
359 | /* Only have to deal with constants that can occur in stack slots. */ | ||
360 | switch ((IROp)ir->o) { | ||
361 | case IR_KPRI: return TREF_PRI(irt_type(ir->t)); | ||
362 | case IR_KINT: return lj_ir_kint(J, ir->i); | ||
363 | case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t)); | ||
364 | case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir)); | ||
365 | case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir)); | ||
366 | case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */ | ||
367 | default: lua_assert(0); return TREF_NIL; break; | ||
368 | } | ||
369 | } | ||
370 | |||
371 | /* Replay snapshot state to setup side trace. */ | ||
372 | void lj_snap_replay(jit_State *J, GCtrace *T) | ||
373 | { | ||
374 | SnapShot *snap = &T->snap[J->exitno]; | ||
375 | SnapEntry *map = &T->snapmap[snap->mapofs]; | ||
376 | MSize n, nent = snap->nent; | ||
377 | BloomFilter seen = 0; | ||
378 | J->framedepth = 0; | ||
379 | /* Emit IR for slots inherited from parent snapshot. */ | ||
380 | for (n = 0; n < nent; n++) { | ||
381 | SnapEntry sn = map[n]; | ||
382 | BCReg s = snap_slot(sn); | ||
383 | IRRef ref = snap_ref(sn); | ||
384 | IRIns *ir = &T->ir[ref]; | ||
385 | TRef tr; | ||
386 | /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */ | ||
387 | if (bloomtest(seen, ref)) { | ||
388 | MSize j; | ||
389 | for (j = 0; j < n; j++) | ||
390 | if (snap_ref(map[j]) == ref) { | ||
391 | tr = J->slot[snap_slot(map[j])]; | ||
392 | goto setslot; | ||
393 | } | ||
394 | } | ||
395 | bloomset(seen, ref); | ||
396 | if (irref_isk(ref)) { | ||
397 | tr = snap_replay_const(J, ir); | ||
398 | } else { | ||
399 | IRType t = irt_type(ir->t); | ||
400 | uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT; | ||
401 | lua_assert(regsp_used(ir->prev)); | ||
402 | if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; | ||
403 | if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY); | ||
404 | tr = emitir_raw(IRT(IR_SLOAD, t), s, mode); | ||
405 | } | ||
406 | setslot: | ||
407 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ | ||
408 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); | ||
409 | if ((sn & SNAP_FRAME)) | ||
410 | J->baseslot = s+1; | ||
411 | } | ||
412 | J->base = J->slot + J->baseslot; | ||
413 | J->maxslot = snap->nslots - J->baseslot; | ||
414 | } | ||
415 | |||
416 | /* -- Snapshot restore ---------------------------------------------------- */ | ||
417 | |||
354 | /* Restore a value from the trace exit state. */ | 418 | /* Restore a value from the trace exit state. */ |
355 | static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex, | 419 | static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex, |
356 | SnapNo snapno, BloomFilter rfilt, | 420 | SnapNo snapno, BloomFilter rfilt, |
diff --git a/src/lj_snap.h b/src/lj_snap.h index 0c267a9c..e41b98f6 100644 --- a/src/lj_snap.h +++ b/src/lj_snap.h | |||
@@ -14,6 +14,7 @@ LJ_FUNC void lj_snap_add(jit_State *J); | |||
14 | LJ_FUNC void lj_snap_purge(jit_State *J); | 14 | LJ_FUNC void lj_snap_purge(jit_State *J); |
15 | LJ_FUNC void lj_snap_shrink(jit_State *J); | 15 | LJ_FUNC void lj_snap_shrink(jit_State *J); |
16 | LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir); | 16 | LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir); |
17 | LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T); | ||
17 | LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr); | 18 | LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr); |
18 | LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need); | 19 | LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need); |
19 | LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need); | 20 | LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need); |