Skip to content

Commit 2310eba

Browse files
authored
Adding stock gc trigger and set it as default (#222)
This PR implements Julia's Stock GC heuristics for triggering GC and resizing the heap. It also updates `mmtk-core` to the latest version.
1 parent 2b52b85 commit 2310eba

File tree

6 files changed

+396
-7
lines changed

6 files changed

+396
-7
lines changed

mmtk/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mmtk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lazy_static = "1.1"
2727
# - change branch
2828
# - change repo name
2929
# But other changes including adding/removing whitespaces in commented lines may break the CI
30-
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "ec745353a8de72b645613e0fef3ab7f5f1ad9bd1" }
30+
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "051bc7470feef915c445305301e6113f86d3957b" }
3131
# Uncomment the following to build locally
3232
# mmtk = { path = "../repos/mmtk-core" }
3333
log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"] }

mmtk/src/api.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ pub extern "C" fn mmtk_gc_init(
5353

5454
// Set heap size
5555
let success =
56-
if min_heap_size != 0 {
56+
// By default min and max heap size are 0, and we use the Stock GC heuristics
57+
if min_heap_size == 0 && max_heap_size == 0 {
58+
info!(
59+
"Setting mmtk heap size to use Stock GC heuristics as defined in gc_trigger.rs",
60+
);
61+
builder
62+
.options
63+
.gc_trigger
64+
.set(mmtk::util::options::GCTriggerSelector::Delegated)
65+
} else if min_heap_size != 0 {
5766
info!(
5867
"Setting mmtk heap size to a variable size with min-max of {}-{} (in bytes)",
5968
min_heap_size, max_heap_size

mmtk/src/collection.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
use crate::SINGLETON;
22
use crate::{
3-
jl_gc_prepare_to_collect, jl_gc_update_stats, jl_get_gc_disable_counter, jl_hrtime,
4-
jl_throw_out_of_memory_error,
3+
jl_gc_get_max_memory, jl_gc_prepare_to_collect, jl_gc_update_stats, jl_get_gc_disable_counter,
4+
jl_hrtime, jl_throw_out_of_memory_error,
55
};
66
use crate::{JuliaVM, USER_TRIGGERED_GC};
77
use log::{info, trace};
88
use mmtk::util::alloc::AllocationError;
9+
use mmtk::util::heap::GCTriggerPolicy;
910
use mmtk::util::opaque_pointer::*;
1011
use mmtk::vm::{Collection, GCThreadContext};
1112
use mmtk::Mutator;
1213
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicU64, Ordering};
1314

1415
use crate::{BLOCK_FOR_GC, STW_COND, WORLD_HAS_STOPPED};
1516

16-
static GC_START: AtomicU64 = AtomicU64::new(0);
17+
pub static GC_START: AtomicU64 = AtomicU64::new(0);
1718

1819
pub struct VMCollection {}
1920

@@ -111,6 +112,12 @@ impl Collection<JuliaVM> for VMCollection {
111112
fn is_collection_enabled() -> bool {
112113
unsafe { jl_get_gc_disable_counter() == 0 }
113114
}
115+
116+
fn create_gc_trigger() -> Box<dyn GCTriggerPolicy<JuliaVM>> {
117+
use crate::gc_trigger::*;
118+
let max_memory = unsafe { jl_gc_get_max_memory() };
119+
Box::new(JuliaGCTrigger::new(max_memory))
120+
}
114121
}
115122

116123
pub fn is_current_gc_nursery() -> bool {

0 commit comments

Comments
 (0)