Skip to content

Commit

Permalink
Add mmtk_heap_min to GC.config
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 16, 2025
1 parent 89f8b8b commit 5bbac70
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ rb_gc_impl_config_get(void *objspace_ptr)
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()));
rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_heap_mode")), rb_str_new_cstr((const char *)mmtk_heap_mode()));
size_t heap_min = mmtk_heap_min();
if (heap_min > 0) rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_heap_min")), RB_ULONG2NUM(heap_min));

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 @@ -151,6 +151,8 @@ const uint8_t *mmtk_plan(void);

const uint8_t *mmtk_heap_mode(void);

size_t mmtk_heap_min(void);

bool mmtk_is_mmtk_object(MMTk_Address addr);

#endif /* MMTK_H */
9 changes: 9 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ pub extern "C" fn mmtk_heap_mode() -> *const u8 {
}
}

#[no_mangle]
pub extern "C" fn mmtk_heap_min() -> usize {
match *crate::BINDING.get().unwrap().mmtk.get_options().gc_trigger {
GCTriggerSelector::FixedHeapSize(_) => 0,
GCTriggerSelector::DynamicHeapSize(min_size, _) => min_size,
_ => panic!("Unknown heap mode")
}
}

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

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

def test_MMTK_HEAP_MIN
# TODO: uncomment this test when the infinite loop is fixed
# assert_separately([{ "MMTK_HEAP_MODE" => "dynamic", "MMTK_HEAP_MIN" => "1" }], <<~RUBY)
# assert_equal(1, GC.config[:mmtk_heap_min])
# RUBY

assert_separately([{ "MMTK_HEAP_MODE" => "dynamic", "MMTK_HEAP_MIN" => "10MiB", "MMTK_HEAP_MAX" => "1GiB" }], <<~RUBY)
assert_equal(10 * 1024 * 1024, GC.config[:mmtk_heap_min])
RUBY
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 5bbac70

Please sign in to comment.