aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-01-18 21:08:23 +0100
committerMike Pall <mike>2011-01-18 21:08:23 +0100
commit751eff9f97d5055fb3f64405771aeee2f34696c2 (patch)
treee365c8123df898f9ba08e7cee23fae12b99b46ba /src
parentf385af7084f300380167bf2261e8109927bd1e18 (diff)
downloadluajit-751eff9f97d5055fb3f64405771aeee2f34696c2.tar.gz
luajit-751eff9f97d5055fb3f64405771aeee2f34696c2.tar.bz2
luajit-751eff9f97d5055fb3f64405771aeee2f34696c2.zip
Cleanup and fix trace flush logic.
Diffstat (limited to 'src')
-rw-r--r--src/lj_gdbjit.c3
-rw-r--r--src/lj_jit.h3
-rw-r--r--src/lj_record.c1
-rw-r--r--src/lj_trace.c50
4 files changed, 29 insertions, 28 deletions
diff --git a/src/lj_gdbjit.c b/src/lj_gdbjit.c
index 260796ea..513954c5 100644
--- a/src/lj_gdbjit.c
+++ b/src/lj_gdbjit.c
@@ -709,8 +709,7 @@ void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
709 GDBJITctx ctx; 709 GDBJITctx ctx;
710 GCproto *pt = &gcref(T->startpt)->pt; 710 GCproto *pt = &gcref(T->startpt)->pt;
711 TraceNo parent = T->ir[REF_BASE].op1; 711 TraceNo parent = T->ir[REF_BASE].op1;
712 uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent); 712 const BCIns *startpc = mref(T->startpc, const BCIns);
713 const BCIns *startpc = snap_pc(T->snapmap[pcofs]);
714 ctx.T = T; 713 ctx.T = T;
715 ctx.mcaddr = (uintptr_t)T->mcode; 714 ctx.mcaddr = (uintptr_t)T->mcode;
716 ctx.szmcode = T->szmcode; 715 ctx.szmcode = T->szmcode;
diff --git a/src/lj_jit.h b/src/lj_jit.h
index 55d6d0df..34f37d02 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -172,9 +172,10 @@ typedef struct GCtrace {
172 SnapShot *snap; /* Snapshot array. */ 172 SnapShot *snap; /* Snapshot array. */
173 SnapEntry *snapmap; /* Snapshot map. */ 173 SnapEntry *snapmap; /* Snapshot map. */
174 GCRef startpt; /* Starting prototype. */ 174 GCRef startpt; /* Starting prototype. */
175 MRef startpc; /* Bytecode PC of starting instruction. */
175 BCIns startins; /* Original bytecode of starting instruction. */ 176 BCIns startins; /* Original bytecode of starting instruction. */
176 MCode *mcode; /* Start of machine code. */
177 MSize szmcode; /* Size of machine code. */ 177 MSize szmcode; /* Size of machine code. */
178 MCode *mcode; /* Start of machine code. */
178 MSize mcloop; /* Offset of loop start in machine code. */ 179 MSize mcloop; /* Offset of loop start in machine code. */
179 uint16_t nchild; /* Number of child traces (root trace only). */ 180 uint16_t nchild; /* Number of child traces (root trace only). */
180 uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */ 181 uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
diff --git a/src/lj_record.c b/src/lj_record.c
index c150e2e4..4939d3af 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1996,6 +1996,7 @@ void lj_record_setup(jit_State *J)
1996 J->cur.nk = REF_TRUE; 1996 J->cur.nk = REF_TRUE;
1997 1997
1998 J->startpc = J->pc; 1998 J->startpc = J->pc;
1999 setmref(J->cur.startpc, J->pc);
1999 if (J->parent) { /* Side trace. */ 2000 if (J->parent) { /* Side trace. */
2000 GCtrace *T = traceref(J, J->parent); 2001 GCtrace *T = traceref(J, J->parent);
2001 TraceNo root = T->root ? T->root : J->parent; 2002 TraceNo root = T->root ? T->root : J->parent;
diff --git a/src/lj_trace.c b/src/lj_trace.c
index 421278e1..5ab6c852 100644
--- a/src/lj_trace.c
+++ b/src/lj_trace.c
@@ -96,8 +96,7 @@ static void perftools_addtrace(GCtrace *T)
96{ 96{
97 static FILE *fp; 97 static FILE *fp;
98 GCproto *pt = &gcref(T->startpt)->pt; 98 GCproto *pt = &gcref(T->startpt)->pt;
99 uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent); 99 const BCIns *startpc = mref(T->startpc, const BCIns);
100 const BCIns *startpc = snap_pc(T->snapmap[pcofs]);
101 const char *name = strdata(proto_chunkname(pt)); 100 const char *name = strdata(proto_chunkname(pt));
102 BCLine lineno; 101 BCLine lineno;
103 if (name[0] == '@' || name[0] == '=') 102 if (name[0] == '@' || name[0] == '=')
@@ -183,34 +182,35 @@ void lj_trace_reenableproto(GCproto *pt)
183static void trace_unpatch(jit_State *J, GCtrace *T) 182static void trace_unpatch(jit_State *J, GCtrace *T)
184{ 183{
185 BCOp op = bc_op(T->startins); 184 BCOp op = bc_op(T->startins);
186 MSize pcofs = T->snap[0].mapofs + T->snap[0].nent; 185 BCIns *pc = mref(T->startpc, BCIns);
187 BCIns *pc = ((BCIns *)snap_pc(T->snapmap[pcofs])) - 1;
188 UNUSED(J); 186 UNUSED(J);
189 switch (op) { 187 if (op == BC_JMP)
190 case BC_FORL: 188 return; /* No need to unpatch branches in parent traces (yet). */
191 lua_assert(bc_op(*pc) == BC_JFORI); 189 switch (bc_op(*pc)) {
192 setbc_op(pc, BC_FORI); /* Unpatch JFORI, too. */ 190 case BC_JFORI:
191 lua_assert(op == BC_FORL);
192 setbc_op(pc, BC_FORI);
193 pc += bc_j(*pc); 193 pc += bc_j(*pc);
194 lua_assert(bc_op(*pc) == BC_JFORL && traceref(J, bc_d(*pc)) == T); 194 lua_assert(bc_op(*pc) == BC_JFORL && traceref(J, bc_d(*pc)) == T);
195 *pc = T->startins; 195 *pc = T->startins;
196 break; 196 break;
197 case BC_LOOP: 197 case BC_JLOOP:
198 lua_assert(bc_op(*pc) == BC_JLOOP && traceref(J, bc_d(*pc)) == T); 198 lua_assert(op == BC_LOOP || bc_isret(op));
199 *pc = T->startins; 199 *pc = T->startins;
200 break; 200 break;
201 case BC_ITERL: 201 case BC_JMP:
202 lua_assert(bc_op(*pc) == BC_JMP); 202 lua_assert(op == BC_ITERL);
203 pc += bc_j(*pc)+2; 203 pc += bc_j(*pc)+2;
204 lua_assert(bc_op(*pc) == BC_JITERL && traceref(J, bc_d(*pc)) == T); 204 if (bc_op(*pc) == BC_JITERL) {
205 *pc = T->startins; 205 lua_assert(traceref(J, bc_d(*pc)) == T);
206 *pc = T->startins;
207 }
206 break; 208 break;
207 case BC_FUNCF: 209 case BC_JFUNCF:
208 lua_assert(bc_op(*pc) == BC_JFUNCF && traceref(J, bc_d(*pc)) == T); 210 lua_assert(op == BC_FUNCF);
209 *pc = T->startins; 211 *pc = T->startins;
210 break; 212 break;
211 case BC_JMP: /* No need to unpatch branches in parent traces (yet). */ 213 default: /* Already unpatched. */
212 default:
213 lua_assert(0);
214 break; 214 break;
215 } 215 }
216} 216}
@@ -227,11 +227,11 @@ static void trace_flushroot(jit_State *J, GCtrace *T)
227 pt->trace = T->nextroot; 227 pt->trace = T->nextroot;
228 } else { /* Otherwise search in chain of root traces. */ 228 } else { /* Otherwise search in chain of root traces. */
229 GCtrace *T2 = traceref(J, pt->trace); 229 GCtrace *T2 = traceref(J, pt->trace);
230 while (T2->nextroot != T->traceno) { 230 for (; T2->nextroot; T2 = traceref(J, T2->nextroot))
231 lua_assert(T2->nextroot != 0); 231 if (T2->nextroot == T->traceno) {
232 T2 = traceref(J, T2->nextroot); 232 T2->nextroot = T->nextroot; /* Unlink from chain. */
233 } 233 break;
234 T2->nextroot = T->nextroot; /* Unlink from chain. */ 234 }
235 } 235 }
236} 236}
237 237
@@ -408,7 +408,7 @@ static void trace_start(jit_State *J)
408/* Stop tracing. */ 408/* Stop tracing. */
409static void trace_stop(jit_State *J) 409static void trace_stop(jit_State *J)
410{ 410{
411 BCIns *pc = (BCIns *)J->startpc; /* Not const here. */ 411 BCIns *pc = mref(J->cur.startpc, BCIns);
412 BCOp op = bc_op(J->cur.startins); 412 BCOp op = bc_op(J->cur.startins);
413 GCproto *pt = &gcref(J->cur.startpt)->pt; 413 GCproto *pt = &gcref(J->cur.startpt)->pt;
414 TraceNo traceno = J->cur.traceno; 414 TraceNo traceno = J->cur.traceno;