diff options
Diffstat (limited to 'src/lj_trace.c')
-rw-r--r-- | src/lj_trace.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/lj_trace.c b/src/lj_trace.c index 0d54c0af..19ddba41 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c | |||
@@ -117,15 +117,26 @@ static void perftools_addtrace(GCtrace *T) | |||
117 | } | 117 | } |
118 | #endif | 118 | #endif |
119 | 119 | ||
120 | /* Allocate space for copy of trace. */ | 120 | /* Allocate space for copy of T. */ |
121 | static GCtrace *trace_save_alloc(jit_State *J) | 121 | GCtrace * LJ_FASTCALL lj_trace_alloc(lua_State *L, GCtrace *T) |
122 | { | 122 | { |
123 | size_t sztr = ((sizeof(GCtrace)+7)&~7); | 123 | size_t sztr = ((sizeof(GCtrace)+7)&~7); |
124 | size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns); | 124 | size_t szins = (T->nins-T->nk)*sizeof(IRIns); |
125 | size_t sz = sztr + szins + | 125 | size_t sz = sztr + szins + |
126 | J->cur.nsnap*sizeof(SnapShot) + | 126 | T->nsnap*sizeof(SnapShot) + |
127 | J->cur.nsnapmap*sizeof(SnapEntry); | 127 | T->nsnapmap*sizeof(SnapEntry); |
128 | return lj_mem_newt(J->L, (MSize)sz, GCtrace); | 128 | GCtrace *T2 = lj_mem_newt(L, (MSize)sz, GCtrace); |
129 | char *p = (char *)T2 + sztr; | ||
130 | T2->gct = ~LJ_TTRACE; | ||
131 | T2->marked = 0; | ||
132 | T2->traceno = 0; | ||
133 | T2->ir = (IRIns *)p - T->nk; | ||
134 | T2->nins = T->nins; | ||
135 | T2->nk = T->nk; | ||
136 | T2->nsnap = T->nsnap; | ||
137 | T2->nsnapmap = T->nsnapmap; | ||
138 | memcpy(p, T->ir + T->nk, szins); | ||
139 | return T2; | ||
129 | } | 140 | } |
130 | 141 | ||
131 | /* Save current trace by copying and compacting it. */ | 142 | /* Save current trace by copying and compacting it. */ |
@@ -139,12 +150,12 @@ static void trace_save(jit_State *J, GCtrace *T) | |||
139 | setgcrefp(J2G(J)->gc.root, T); | 150 | setgcrefp(J2G(J)->gc.root, T); |
140 | newwhite(J2G(J), T); | 151 | newwhite(J2G(J), T); |
141 | T->gct = ~LJ_TTRACE; | 152 | T->gct = ~LJ_TTRACE; |
142 | T->ir = (IRIns *)p - J->cur.nk; | 153 | T->ir = (IRIns *)p - J->cur.nk; /* The IR has already been copied above. */ |
143 | memcpy(p, J->cur.ir+J->cur.nk, szins); | ||
144 | p += szins; | 154 | p += szins; |
145 | TRACE_APPENDVEC(snap, nsnap, SnapShot) | 155 | TRACE_APPENDVEC(snap, nsnap, SnapShot) |
146 | TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry) | 156 | TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry) |
147 | J->cur.traceno = 0; | 157 | J->cur.traceno = 0; |
158 | J->curfinal = NULL; | ||
148 | setgcrefp(J->trace[T->traceno], T); | 159 | setgcrefp(J->trace[T->traceno], T); |
149 | lj_gc_barriertrace(J2G(J), T->traceno); | 160 | lj_gc_barriertrace(J2G(J), T->traceno); |
150 | lj_gdbjit_addtrace(J, T); | 161 | lj_gdbjit_addtrace(J, T); |
@@ -449,7 +460,7 @@ static void trace_stop(jit_State *J) | |||
449 | BCOp op = bc_op(J->cur.startins); | 460 | BCOp op = bc_op(J->cur.startins); |
450 | GCproto *pt = &gcref(J->cur.startpt)->pt; | 461 | GCproto *pt = &gcref(J->cur.startpt)->pt; |
451 | TraceNo traceno = J->cur.traceno; | 462 | TraceNo traceno = J->cur.traceno; |
452 | GCtrace *T = trace_save_alloc(J); /* Do this first. May throw OOM. */ | 463 | GCtrace *T = J->curfinal; |
453 | lua_State *L; | 464 | lua_State *L; |
454 | 465 | ||
455 | switch (op) { | 466 | switch (op) { |
@@ -537,6 +548,10 @@ static int trace_abort(jit_State *J) | |||
537 | 548 | ||
538 | J->postproc = LJ_POST_NONE; | 549 | J->postproc = LJ_POST_NONE; |
539 | lj_mcode_abort(J); | 550 | lj_mcode_abort(J); |
551 | if (J->curfinal) { | ||
552 | lj_trace_free(J2G(J), J->curfinal); | ||
553 | J->curfinal = NULL; | ||
554 | } | ||
540 | if (tvisnumber(L->top-1)) | 555 | if (tvisnumber(L->top-1)) |
541 | e = (TraceError)numberVint(L->top-1); | 556 | e = (TraceError)numberVint(L->top-1); |
542 | if (e == LJ_TRERR_MCODELM) { | 557 | if (e == LJ_TRERR_MCODELM) { |