mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* gc.c (rb_raw_obj_info): separated from rb_obj_info().
Fill internal object information into passed buffer. * gc.h: declare rb_raw_obj_info(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5a2b77ff4a
commit
771fceba59
3 changed files with 71 additions and 59 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Thu Jul 2 18:34:26 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* gc.c (rb_raw_obj_info): separated from rb_obj_info().
|
||||||
|
Fill internal object information into passed buffer.
|
||||||
|
|
||||||
|
* gc.h: declare rb_raw_obj_info().
|
||||||
|
|
||||||
Thu Jul 2 16:15:04 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Jul 2 16:15:04 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* dir.c (replace_real_basename): update path type by the target
|
* dir.c (replace_real_basename): update path type by the target
|
||||||
|
|
60
gc.c
60
gc.c
|
@ -8839,8 +8839,6 @@ obj_type_name(VALUE obj)
|
||||||
return type_name(TYPE(obj), obj);
|
return type_name(TYPE(obj), obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RGENGC_OBJ_INFO
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
method_type_name(rb_method_type_t type)
|
method_type_name(rb_method_type_t type)
|
||||||
{
|
{
|
||||||
|
@ -8861,12 +8859,6 @@ method_type_name(rb_method_type_t type)
|
||||||
rb_bug("method_type_name: unreachable (type: %d)", type);
|
rb_bug("method_type_name: unreachable (type: %d)", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define OBJ_INFO_BUFFERS_NUM 10
|
|
||||||
#define OBJ_INFO_BUFFERS_SIZE 0x100
|
|
||||||
static int obj_info_buffers_index = 0;
|
|
||||||
static char obj_info_buffers[OBJ_INFO_BUFFERS_NUM][OBJ_INFO_BUFFERS_SIZE];
|
|
||||||
|
|
||||||
/* from array.c */
|
/* from array.c */
|
||||||
# define ARY_SHARED_P(ary) \
|
# define ARY_SHARED_P(ary) \
|
||||||
(assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
|
(assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
|
||||||
|
@ -8875,21 +8867,15 @@ static char obj_info_buffers[OBJ_INFO_BUFFERS_NUM][OBJ_INFO_BUFFERS_SIZE];
|
||||||
(assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
|
(assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
|
||||||
FL_TEST((ary), RARRAY_EMBED_FLAG)!=0)
|
FL_TEST((ary), RARRAY_EMBED_FLAG)!=0)
|
||||||
|
|
||||||
static const char *
|
const char *
|
||||||
obj_info(VALUE obj)
|
rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
|
||||||
{
|
{
|
||||||
const int index = obj_info_buffers_index++;
|
|
||||||
char *const buff = &obj_info_buffers[index][0];
|
|
||||||
const int age = RVALUE_FLAGS_AGE(RBASIC(obj)->flags);
|
const int age = RVALUE_FLAGS_AGE(RBASIC(obj)->flags);
|
||||||
const int type = BUILTIN_TYPE(obj);
|
const int type = BUILTIN_TYPE(obj);
|
||||||
|
|
||||||
if (obj_info_buffers_index >= OBJ_INFO_BUFFERS_NUM) {
|
|
||||||
obj_info_buffers_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TF(c) ((c) != 0 ? "true" : "false")
|
#define TF(c) ((c) != 0 ? "true" : "false")
|
||||||
#define C(c, s) ((c) != 0 ? (s) : " ")
|
#define C(c, s) ((c) != 0 ? (s) : " ")
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%p [%d%s%s%s%s] %s",
|
snprintf(buff, buff_size, "%p [%d%s%s%s%s] %s",
|
||||||
(void *)obj, age,
|
(void *)obj, age,
|
||||||
C(RVALUE_UNCOLLECTIBLE_BITMAP(obj), "L"),
|
C(RVALUE_UNCOLLECTIBLE_BITMAP(obj), "L"),
|
||||||
C(RVALUE_MARK_BITMAP(obj), "M"),
|
C(RVALUE_MARK_BITMAP(obj), "M"),
|
||||||
|
@ -8901,38 +8887,38 @@ obj_info(VALUE obj)
|
||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
else if (RBASIC(obj)->klass == 0) {
|
else if (RBASIC(obj)->klass == 0) {
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (temporary internal)", buff);
|
snprintf(buff, buff_size, "%s (temporary internal)", buff);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE class_path = rb_class_path_cached(RBASIC(obj)->klass);
|
VALUE class_path = rb_class_path_cached(RBASIC(obj)->klass);
|
||||||
if (!NIL_P(class_path)) {
|
if (!NIL_P(class_path)) {
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (%s)", buff, RSTRING_PTR(class_path));
|
snprintf(buff, buff_size, "%s (%s)", buff, RSTRING_PTR(class_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GC_DEBUG
|
#if GC_DEBUG
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s @%s:%d", buff, RANY(obj)->file, RANY(obj)->line);
|
snprintf(buff, buff_size, "%s @%s:%d", buff, RANY(obj)->file, RANY(obj)->line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case T_NODE:
|
case T_NODE:
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (%s)", buff,
|
snprintf(buff, buff_size, "%s (%s)", buff,
|
||||||
ruby_node_name(nd_type(obj)));
|
ruby_node_name(nd_type(obj)));
|
||||||
break;
|
break;
|
||||||
case T_ARRAY:
|
case T_ARRAY:
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s [%s%s] len: %d", buff,
|
snprintf(buff, buff_size, "%s [%s%s] len: %d", buff,
|
||||||
C(ARY_EMBED_P(obj), "E"),
|
C(ARY_EMBED_P(obj), "E"),
|
||||||
C(ARY_SHARED_P(obj), "S"),
|
C(ARY_SHARED_P(obj), "S"),
|
||||||
(int)RARRAY_LEN(obj));
|
(int)RARRAY_LEN(obj));
|
||||||
break;
|
break;
|
||||||
case T_STRING: {
|
case T_STRING: {
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, RSTRING_PTR(obj));
|
snprintf(buff, buff_size, "%s %s", buff, RSTRING_PTR(obj));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case T_CLASS: {
|
case T_CLASS: {
|
||||||
VALUE class_path = rb_class_path_cached(obj);
|
VALUE class_path = rb_class_path_cached(obj);
|
||||||
if (!NIL_P(class_path)) {
|
if (!NIL_P(class_path)) {
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, RSTRING_PTR(class_path));
|
snprintf(buff, buff_size, "%s %s", buff, RSTRING_PTR(class_path));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -8942,12 +8928,12 @@ obj_info(VALUE obj)
|
||||||
rb_iseq_t *iseq;
|
rb_iseq_t *iseq;
|
||||||
GetISeqPtr(obj, iseq);
|
GetISeqPtr(obj, iseq);
|
||||||
if (iseq->location.label) {
|
if (iseq->location.label) {
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s@%s:%d", buff,
|
snprintf(buff, buff_size, "%s %s@%s:%d", buff,
|
||||||
RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path), (int)iseq->location.first_lineno);
|
RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path), (int)iseq->location.first_lineno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type_name) {
|
else if (type_name) {
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, type_name);
|
snprintf(buff, buff_size, "%s %s", buff, type_name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -8965,10 +8951,10 @@ obj_info(VALUE obj)
|
||||||
default: rb_bug("unknown IMEMO");
|
default: rb_bug("unknown IMEMO");
|
||||||
#undef IMEMO_NAME
|
#undef IMEMO_NAME
|
||||||
}
|
}
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, imemo_name);
|
snprintf(buff, buff_size, "%s %s", buff, imemo_name);
|
||||||
if (imemo_type(obj) == imemo_ment) {
|
if (imemo_type(obj) == imemo_ment) {
|
||||||
const rb_method_entry_t *me = &RANY(obj)->as.imemo.ment;
|
const rb_method_entry_t *me = &RANY(obj)->as.imemo.ment;
|
||||||
snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (called_id: %s, type: %s, alias: %d, class: %s)", buff,
|
snprintf(buff, buff_size, "%s (called_id: %s, type: %s, alias: %d, class: %s)", buff,
|
||||||
rb_id2name(me->called_id), method_type_name(me->def->type), me->def->alias_count, obj_info(me->klass));
|
rb_id2name(me->called_id), method_type_name(me->def->type), me->def->alias_count, obj_info(me->klass));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8981,6 +8967,24 @@ obj_info(VALUE obj)
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if RGENGC_OBJ_INFO
|
||||||
|
#define OBJ_INFO_BUFFERS_NUM 10
|
||||||
|
#define OBJ_INFO_BUFFERS_SIZE 0x100
|
||||||
|
static int obj_info_buffers_index = 0;
|
||||||
|
static char obj_info_buffers[OBJ_INFO_BUFFERS_NUM][OBJ_INFO_BUFFERS_SIZE];
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
obj_info(VALUE obj)
|
||||||
|
{
|
||||||
|
const int index = obj_info_buffers_index++;
|
||||||
|
char *const buff = &obj_info_buffers[index][0];
|
||||||
|
|
||||||
|
if (obj_info_buffers_index >= OBJ_INFO_BUFFERS_NUM) {
|
||||||
|
obj_info_buffers_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rb_raw_obj_info(buff, OBJ_INFO_BUFFERS_SIZE, obj);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static const char *
|
static const char *
|
||||||
obj_info(VALUE obj)
|
obj_info(VALUE obj)
|
||||||
|
|
1
gc.h
1
gc.h
|
@ -84,6 +84,7 @@ int ruby_get_stack_grow_direction(volatile VALUE *addr);
|
||||||
#define IS_STACK_DIR_UPPER() STACK_DIR_UPPER(1,0)
|
#define IS_STACK_DIR_UPPER() STACK_DIR_UPPER(1,0)
|
||||||
|
|
||||||
const char *rb_obj_info(VALUE obj);
|
const char *rb_obj_info(VALUE obj);
|
||||||
|
const char *rb_raw_obj_info(char *buff, const int buff_size, VALUE obj);
|
||||||
|
|
||||||
RUBY_SYMBOL_EXPORT_BEGIN
|
RUBY_SYMBOL_EXPORT_BEGIN
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue