backtrace.c: use mrb_irep references instead of struct RProc

To reduce GC burden (no mark needed). We use `mrb_irep_incref()` and
`mrb_irep_decref()` instead to track irep memory usage; ref #6161
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-02-04 16:46:09 +09:00
parent 4dfadb4f9f
commit 2f63b49542
3 changed files with 15 additions and 18 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ struct RBacktrace {
struct mrb_backtrace_location {
mrb_sym method_id;
int32_t idx;
const struct RProc *proc;
const mrb_irep *irep;
};
/* gc */
+11 -8
View File
@@ -33,22 +33,22 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *
if (!ci->proc || MRB_PROC_CFUNC_P(ci->proc)) {
if (!ci->mid) continue;
loc.proc = NULL;
loc.irep = NULL;
}
else {
loc.proc = ci->proc;
if (!loc.proc->body.irep) continue;
if (!loc.proc->body.irep->debug_info) continue;
loc.irep = ci->proc->body.irep;
if (!loc.irep) continue;
if (!loc.irep->debug_info) continue;
if (mrb->c->cibase[i].pc) {
pc = &mrb->c->cibase[i].pc[-1];
}
else {
continue;
}
loc.idx = (uint32_t)(pc - loc.proc->body.irep->iseq);
loc.idx = (uint32_t)(pc - loc.irep->iseq);
}
loc.method_id = ci->mid;
if (loc.proc == NULL) {
if (loc.irep == NULL) {
for (ptrdiff_t j=i-1; j >= 0; j--) {
ci = &mrb->c->cibase[j];
@@ -66,7 +66,7 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *
continue;
}
loc.proc = ci->proc;
loc.irep = irep;
loc.idx = (uint32_t)(pc - irep->iseq);
break;
}
@@ -85,6 +85,9 @@ pack_backtrace_i(mrb_state *mrb,
struct mrb_backtrace_location **pptr = (struct mrb_backtrace_location**)data;
struct mrb_backtrace_location *ptr = *pptr;
if (loc->irep) {
mrb_irep_incref(mrb, (mrb_irep*)loc->irep);
}
*ptr = *loc;
*pptr = ptr+1;
}
@@ -161,7 +164,7 @@ mrb_unpack_backtrace(mrb_state *mrb, struct RObject *backtrace)
int32_t lineno;
const char *filename;
if (!entry->proc || !mrb_debug_get_position(mrb, entry->proc->body.irep, entry->idx, &lineno, &filename)) {
if (!entry->irep || !mrb_debug_get_position(mrb, entry->irep, entry->idx, &lineno, &filename)) {
btline = mrb_str_new_lit(mrb, "(unknown):0");
}
else if (lineno != -1) {//debug info was available
+3 -9
View File
@@ -688,15 +688,6 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
mrb_gc_mark(mrb, (struct RBasic*)((struct RException*)obj)->backtrace);
break;
case MRB_TT_BACKTRACE:
{
struct RBacktrace *bt = (struct RBacktrace*)obj;
for (size_t i = 0; i < bt->len; i++) {
mrb_gc_mark(mrb, (struct RBasic*)bt->locations[i].proc);
}
}
break;
default:
break;
}
@@ -835,6 +826,9 @@ obj_free(mrb_state *mrb, struct RBasic *obj, int end)
case MRB_TT_BACKTRACE:
{
struct RBacktrace *bt = (struct RBacktrace*)obj;
for (size_t i = 0; i < bt->len; i++) {
mrb_irep_decref(mrb, (mrb_irep*)bt->locations[i].irep);
}
mrb_free(mrb, bt->locations);
}