Skip to content

Experimental support for heap traversal #82

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 1 commit 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
4 changes: 4 additions & 0 deletions internal/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,8 @@ bool mmtk_is_object_wb_unprotected(MMTk_ObjectReference object);

void mmtk_object_reference_write_post(MMTk_Mutator *mutator, MMTk_ObjectReference object);

void mmtk_print_all_objects(void);

void mmtk_enumerate_objects(void (*callback)(MMTk_ObjectReference, void*), void *data);

#endif /* MMTK_H */
1 change: 1 addition & 0 deletions internal/mmtk_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ VALUE rb_mmtk_plan_name(VALUE _);
VALUE rb_mmtk_enabled(VALUE _);
VALUE rb_mmtk_harness_begin(VALUE _);
VALUE rb_mmtk_harness_end(VALUE _);
VALUE rb_mmtk_print_all_objects(VALUE _);

// Debugging
bool rb_mmtk_is_mmtk_worker(void);
Expand Down
25 changes: 25 additions & 0 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#include "insns.inc"
#include "insns_info.inc"

// MMTk conditional compilation macros
#include "internal/mmtk_macros.h"

VALUE rb_cISeq;
static VALUE iseqw_new(const rb_iseq_t *iseq);
static const rb_iseq_t *iseqw_check(VALUE iseqw);
Expand Down Expand Up @@ -3989,6 +3992,23 @@ rb_clear_bf_ccs(void)
rb_objspace_each_objects(clear_bf_ccs_i, NULL);
}

#if USE_MMTK
static void
rb_mmtk_trace_set_i(MMTk_ObjectReference objref, void *data)
{
rb_event_flag_t turnon_events = *(rb_event_flag_t *)data;
VALUE v = (VALUE) objref;

if (rb_obj_is_iseq(v)) {
rb_iseq_trace_set(rb_iseq_check((rb_iseq_t *)v), turnon_events);
}
else if (clear_attr_cc(v)) {
}
else if (clear_bf_cc(v)) {
}
}
#endif

static int
trace_set_i(void *vstart, void *vend, size_t stride, void *data)
{
Expand All @@ -4015,6 +4035,11 @@ trace_set_i(void *vstart, void *vend, size_t stride, void *data)
void
rb_iseq_trace_set_all(rb_event_flag_t turnon_events)
{
WHEN_USING_MMTK({
mmtk_enumerate_objects(rb_mmtk_trace_set_i, &turnon_events);
return;
});

rb_objspace_each_objects(trace_set_i, &turnon_events);
}

Expand Down
14 changes: 14 additions & 0 deletions mmtk_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ rb_mmtk_define_gc_mmtk_module(void)
rb_define_singleton_method(rb_mMMTk, "enabled?", rb_mmtk_enabled, 0);
rb_define_singleton_method(rb_mMMTk, "harness_begin", rb_mmtk_harness_begin, 0);
rb_define_singleton_method(rb_mMMTk, "harness_end", rb_mmtk_harness_end, 0);
rb_define_singleton_method(rb_mMMTk, "print_all_objects", rb_mmtk_print_all_objects, 0);
}

/*
Expand Down Expand Up @@ -1303,6 +1304,19 @@ rb_mmtk_harness_end(VALUE _)
return Qnil;
}

/*
* call-seq:
* GC::MMTk.print_all_objects
*
* Traverse the heap and print the addresses of all objects.
*/
VALUE
rb_mmtk_print_all_objects(VALUE _)
{
mmtk_print_all_objects();
return Qnil;
}

////////////////////////////////////////////////////////////////////////////////
// Debugging
////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading