Skip to content

Commit

Permalink
Add mmtk_plan to GC.config
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 15, 2025
1 parent 22ceb28 commit 67da9ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ rb_gc_impl_config_get(void *objspace_ptr)
VALUE hash = rb_hash_new();

rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_worker_count")), RB_ULONG2NUM(mmtk_worker_count()));
rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_plan")), rb_str_new_cstr((const char *)mmtk_plan()));

return hash;
}
Expand Down
2 changes: 2 additions & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ MMTk_Address mmtk_last_heap_address(void);

size_t mmtk_worker_count(void);

const uint8_t *mmtk_plan(void);

bool mmtk_is_mmtk_object(MMTk_Address addr);

#endif /* MMTK_H */
14 changes: 14 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,20 @@ pub extern "C" fn mmtk_worker_count() -> usize {
memory_manager::num_of_workers(mmtk())
}

#[no_mangle]
pub extern "C" fn mmtk_plan() -> *const u8 {
static NO_GC: &[u8] = b"NoGC\0";
static MARK_SWEEP: &[u8] = b"MarkSweep\0";
static IMMIX: &[u8] = b"Immix\0";

match *crate::BINDING.get().unwrap().mmtk.get_options().plan {
PlanSelector::NoGC => NO_GC.as_ptr(),
PlanSelector::MarkSweep => MARK_SWEEP.as_ptr(),
PlanSelector::Immix => IMMIX.as_ptr(),
_ => panic!("Unknown plan")
}
}

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

#[no_mangle]
Expand Down
9 changes: 9 additions & 0 deletions test/mmtk/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def test_MMTK_THREADS
RUBY
end

# TODO: Add NoGC once this is fixed: https://github.com/mmtk/mmtk-core/pull/1263
%w(MarkSweep Immix).each do |plan|
define_method(:"test_MMTK_PLAN_#{plan}") do
assert_separately([{ "MMTK_PLAN" => plan }], <<~RUBY)
assert_equal("#{plan}", GC.config[:mmtk_plan])
RUBY
end
end

%w(MMTK_THREADS MMTK_HEAP_MIN MMTK_HEAP_MAX MMTK_HEAP_MODE MMTK_PLAN).each do |var|
define_method(:"test_invalid_#{var}") do
exit_code = assert_in_out_err(
Expand Down

0 comments on commit 67da9ea

Please sign in to comment.