mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Embed Backtrace objects
rb_backtrace_t is 32B, so it fits well in a 80B slot. There is some unused spaces but given Backtrace objects are rarely held onto it should be inconsequential and avoid the malloc churn. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
This commit is contained in:
parent
a9f45aac6e
commit
3b69637eba
1 changed files with 10 additions and 11 deletions
|
@ -478,7 +478,6 @@ backtrace_free(void *ptr)
|
|||
{
|
||||
rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
|
||||
ruby_xfree(bt->backtrace);
|
||||
ruby_xfree(bt);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -515,13 +514,13 @@ static size_t
|
|||
backtrace_memsize(const void *ptr)
|
||||
{
|
||||
rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
|
||||
return sizeof(rb_backtrace_t) + sizeof(rb_backtrace_location_t) * bt->backtrace_size;
|
||||
return sizeof(rb_backtrace_location_t) * bt->backtrace_size;
|
||||
}
|
||||
|
||||
static const rb_data_type_t backtrace_data_type = {
|
||||
"backtrace",
|
||||
{backtrace_mark, backtrace_free, backtrace_memsize, backtrace_update},
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
|
||||
};
|
||||
|
||||
int
|
||||
|
@ -595,9 +594,9 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
|
|||
ptrdiff_t size;
|
||||
rb_backtrace_t *bt;
|
||||
VALUE btobj = backtrace_alloc(rb_cBacktrace);
|
||||
TypedData_Get_Struct(btobj, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
rb_backtrace_location_t *loc = NULL;
|
||||
unsigned long cfunc_counter = 0;
|
||||
GetCoreDataFromValue(btobj, rb_backtrace_t, bt);
|
||||
|
||||
// In the case the thread vm_stack or cfp is not initialized, there is no backtrace.
|
||||
if (end_cfp == NULL) {
|
||||
|
@ -625,8 +624,8 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
|
|||
}
|
||||
}
|
||||
|
||||
bt->backtrace = ZALLOC_N(rb_backtrace_location_t, num_frames);
|
||||
bt->backtrace_size = 0;
|
||||
bt->backtrace = ZALLOC_N(rb_backtrace_location_t, num_frames);
|
||||
if (num_frames == 0) {
|
||||
if (start_too_large) *start_too_large = 0;
|
||||
return btobj;
|
||||
|
@ -719,7 +718,7 @@ backtrace_to_str_ary(VALUE self)
|
|||
{
|
||||
VALUE r;
|
||||
rb_backtrace_t *bt;
|
||||
GetCoreDataFromValue(self, rb_backtrace_t, bt);
|
||||
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
r = backtrace_collect(bt, location_to_str_dmyarg, 0);
|
||||
RB_GC_GUARD(self);
|
||||
return r;
|
||||
|
@ -729,7 +728,7 @@ VALUE
|
|||
rb_backtrace_to_str_ary(VALUE self)
|
||||
{
|
||||
rb_backtrace_t *bt;
|
||||
GetCoreDataFromValue(self, rb_backtrace_t, bt);
|
||||
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
|
||||
if (!bt->strary) {
|
||||
RB_OBJ_WRITE(self, &bt->strary, backtrace_to_str_ary(self));
|
||||
|
@ -743,7 +742,7 @@ rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self)
|
|||
const rb_backtrace_t *bt;
|
||||
rb_backtrace_location_t *loc;
|
||||
|
||||
GetCoreDataFromValue(self, rb_backtrace_t, bt);
|
||||
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
VM_ASSERT(bt->backtrace_size > 0);
|
||||
|
||||
loc = &bt->backtrace[0];
|
||||
|
@ -771,7 +770,7 @@ backtrace_to_location_ary(VALUE self)
|
|||
{
|
||||
VALUE r;
|
||||
rb_backtrace_t *bt;
|
||||
GetCoreDataFromValue(self, rb_backtrace_t, bt);
|
||||
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
r = backtrace_collect(bt, location_create, (void *)self);
|
||||
RB_GC_GUARD(self);
|
||||
return r;
|
||||
|
@ -781,7 +780,7 @@ VALUE
|
|||
rb_backtrace_to_location_ary(VALUE self)
|
||||
{
|
||||
rb_backtrace_t *bt;
|
||||
GetCoreDataFromValue(self, rb_backtrace_t, bt);
|
||||
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
|
||||
if (!bt->locary) {
|
||||
RB_OBJ_WRITE(self, &bt->locary, backtrace_to_location_ary(self));
|
||||
|
@ -800,7 +799,7 @@ static VALUE
|
|||
backtrace_load_data(VALUE self, VALUE str)
|
||||
{
|
||||
rb_backtrace_t *bt;
|
||||
GetCoreDataFromValue(self, rb_backtrace_t, bt);
|
||||
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
|
||||
RB_OBJ_WRITE(self, &bt->strary, str);
|
||||
return self;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue