Skip to content
Merged
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
39 changes: 39 additions & 0 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,41 @@ rb_gc_impl_zjit_writebarrier_required_offset(void)
return -1;
}

/*
* call-seq:
* GC::MMTk.harness_begin
*
* A hook to be called before a benchmark begins.
*
* MMTk will do necessary preparations (such as triggering a full-heap GC)
* and start collecting statistic data, such as the number of GC triggered,
* time spent in GC, time spent in mutator, etc.
*/
static VALUE
rb_mmtk_harness_begin(VALUE _)
{
mmtk_harness_begin(rb_gc_get_ractor_newobj_cache());

return Qnil;
}

/*
* call-seq:
* GC::MMTk.harness_end
*
* A hook to be called after a benchmark ends.
*
* When this method is called, MMTk will stop collecting statistic data and
* print out the data already collected.
*/
VALUE
rb_mmtk_harness_end(VALUE _)
{
mmtk_harness_end();

return Qnil;
}

void
rb_gc_impl_init(void)
{
Expand All @@ -771,6 +806,10 @@ rb_gc_impl_init(void)
rb_define_singleton_method(rb_mGC, "auto_compact=", rb_f_notimplement, 1);
rb_define_singleton_method(rb_mGC, "latest_compact_info", rb_f_notimplement, 0);
rb_define_singleton_method(rb_mGC, "verify_compaction_references", rb_f_notimplement, -1);

VALUE rb_mMMTk = rb_define_module_under(rb_mGC, "MMTk");
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);
}

int
Expand Down
4 changes: 4 additions & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ size_t mmtk_heap_min(void);

size_t mmtk_heap_max(void);

void mmtk_harness_begin(MMTk_VMMutatorThread tls);

void mmtk_harness_end(void);

bool mmtk_is_mmtk_object(MMTk_Address addr);

extern void rb_mmtk_init_gc_worker_thread(struct MMTk_GCThreadTLS *gc_worker_tls);
Expand Down
12 changes: 12 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,18 @@ pub extern "C" fn mmtk_heap_max() -> usize {
}
}

// =============== Measurement ===============

#[unsafe(no_mangle)]
pub extern "C" fn mmtk_harness_begin(tls: VMMutatorThread) {
memory_manager::harness_begin::<Ruby>(crate::BINDING.get().unwrap().mmtk, tls);
}

#[unsafe(no_mangle)]
pub extern "C" fn mmtk_harness_end() {
memory_manager::harness_end::<Ruby>(crate::BINDING.get().unwrap().mmtk);
}

// =============== Miscellaneous ===============

#[unsafe(no_mangle)]
Expand Down
17 changes: 17 additions & 0 deletions test/mmtk/test_mmtk_harness.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require_relative "helper"

module MMTk
class TestMMTkHarness < TestCase
def test_harness_begin_end_output
assert_in_out_err([], <<~RUBY) do |out, _err|
GC::MMTk.harness_begin
GC.start
GC::MMTk.harness_end
RUBY
assert_match(/MMTk Statistics Totals/, out.join)
end
end
end
end
Loading