Skip to content

Commit

Permalink
Warn when we cannot parse capacities
Browse files Browse the repository at this point in the history
  • Loading branch information
eightbitraptor committed Oct 18, 2024
1 parent 2539ce8 commit 80d4492
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,24 @@ pub extern "C" fn mmtk_builder_default() -> *mut MMTKBuilder {
const DEFAULT_HEAP_MIN: usize = 1 << 20;

let mut mmtk_heap_min = match std::env::var("MMTK_HEAP_MIN") {
Ok(min) => parse_capacity(min, DEFAULT_HEAP_MIN),
Ok(min) => {
let capa = parse_capacity(&min, DEFAULT_HEAP_MIN);
if capa == DEFAULT_HEAP_MIN {
eprintln!("MMTK_HEAP_MIN: value ({}) unusable, Using default.", min)
};
capa
},
Err(_) => DEFAULT_HEAP_MIN
};

let mut mmtk_heap_max = match std::env::var("MMTK_HEAP_MAX") {
Ok(max) => parse_capacity(max, default_heap_max()),
Ok(max) => {
let capa = parse_capacity(&max, default_heap_max());
if capa == default_heap_max() {
eprintln!("MMTK_HEAP_MAX: value ({}) unusable, Using default.", max)
};
capa
},
Err(_) => default_heap_max()
};

Expand Down
2 changes: 1 addition & 1 deletion gc/mmtk/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn default_heap_max() -> usize {
.expect("Invalid Memory size") as usize
}

pub fn parse_capacity(input: String, default: usize) -> usize {
pub fn parse_capacity(input: &String, default: usize) -> usize {
let trimmed = input.trim();

const KIBIBYTE: usize = 1024;
Expand Down

0 comments on commit 80d4492

Please sign in to comment.