Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a secondary heap #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion class.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ rb_class_detach_module_subclasses(VALUE klass)
static VALUE
class_alloc(VALUE flags, VALUE klass)
{
NEWOBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | FL_PROMOTED1 /* start from age == 2 */ | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0));
NEW_TCLASS_OBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | FL_PROMOTED1 /* start from age == 2 */ | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0));
obj->ptr = ZALLOC(rb_classext_t);
/* ZALLOC
RCLASS_IV_TBL(obj) = 0;
Expand Down
39 changes: 37 additions & 2 deletions ext/objspace/objspace_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "objspace.h"

static VALUE sym_output, sym_stdout, sym_string, sym_file;
static VALUE sym_include_pages, sym_include_none;

struct dump_config {
VALUE type;
Expand All @@ -31,6 +32,9 @@ struct dump_config {
VALUE cur_obj;
VALUE cur_obj_klass;
size_t cur_obj_references;
int include_pages;
int include_none;
int pages_seen;
};

PRINTF_ARGS(static void dump_append(struct dump_config *, const char *, ...), 2, 3);
Expand Down Expand Up @@ -190,6 +194,18 @@ dump_append_string_content(struct dump_config *dc, VALUE obj)
}
}

static void
dump_empty(VALUE obj, struct dump_config *dc)
{
dump_append(dc, "{\"address\":\"%p\", ", (void *)obj);
dump_append(dc, "\"type\":\"NONE\"");

if (dc->include_pages)
dump_append(dc, ", \"page_number\":%d", dc->pages_seen);
dump_append(dc, "}\n");
return;
}

static void
dump_object(VALUE obj, struct dump_config *dc)
{
Expand All @@ -215,6 +231,8 @@ dump_object(VALUE obj, struct dump_config *dc)

if (dc->cur_obj_klass)
dump_append(dc, ", \"class\":\"%p\"", (void *)dc->cur_obj_klass);
if (dc->include_pages)
dump_append(dc, ", \"page_number\":%d", dc->pages_seen);
if (rb_obj_frozen_p(obj))
dump_append(dc, ", \"frozen\":true");

Expand Down Expand Up @@ -318,11 +336,15 @@ dump_object(VALUE obj, struct dump_config *dc)
static int
heap_i(void *vstart, void *vend, size_t stride, void *data)
{
struct dump_config *dc = (struct dump_config *)data;
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
if (RBASIC(v)->flags)
dump_object(v, data);
dump_object(v, dc);
else if (dc->include_none && T_NONE == BUILTIN_TYPE(v))
dump_empty(v, dc);
}
dc->pages_seen++;
return 0;
}

Expand All @@ -347,9 +369,20 @@ dump_output(struct dump_config *dc, VALUE opts, VALUE output, const char *filena
{
VALUE tmp;

if (RTEST(opts))
dc->pages_seen = 0;
dc->include_pages = 0;
dc->include_none = 0;

if (RTEST(opts)) {
output = rb_hash_aref(opts, sym_output);

if (Qtrue == rb_hash_lookup2(opts, sym_include_pages, Qfalse))
dc->include_pages = 1;

if (Qtrue == rb_hash_lookup2(opts, sym_include_none, Qfalse))
dc->include_none = 1;
}

if (output == sym_stdout) {
dc->stream = stdout;
dc->string = Qnil;
Expand Down Expand Up @@ -474,6 +507,8 @@ Init_objspace_dump(VALUE rb_mObjSpace)
sym_stdout = ID2SYM(rb_intern("stdout"));
sym_string = ID2SYM(rb_intern("string"));
sym_file = ID2SYM(rb_intern("file"));
sym_include_pages = ID2SYM(rb_intern("include_pages"));
sym_include_none = ID2SYM(rb_intern("include_none"));

/* force create static IDs */
rb_obj_gc_flags(rb_mObjSpace, 0, 0);
Expand Down
Loading