Skip to content

Commit

Permalink
Add mmtk_heap_max to GC.config
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 17, 2025
1 parent 5bbac70 commit 6a78ffa
Show file tree
Hide file tree
Showing 4 changed files with 18 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 @@ -637,6 +637,7 @@ rb_gc_impl_config_get(void *objspace_ptr)
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));
rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_heap_max")), RB_ULONG2NUM(mmtk_heap_max()));

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

size_t mmtk_heap_min(void);

size_t mmtk_heap_max(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 @@ -368,6 +368,15 @@ pub extern "C" fn mmtk_heap_min() -> usize {
}
}

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

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

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

def test_MMTK_HEAP_MAX
assert_separately([{ "MMTK_HEAP_MODE" => "fixed", "MMTK_HEAP_MAX" => "100MiB" }], <<~RUBY)
assert_equal(100 * 1024 * 1024, GC.config[:mmtk_heap_max])
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 6a78ffa

Please sign in to comment.