Skip to content

Commit 936a9aa

Browse files
authored
Update to MMTk core PR #817 (#58)
Update for mmtk/mmtk-core#817.
1 parent 3bc50c7 commit 936a9aa

File tree

6 files changed

+110
-73
lines changed

6 files changed

+110
-73
lines changed

.github/scripts/ci-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cur=$(realpath $(dirname "$0"))
88

99
# Build release
1010
cd $cur
11-
./ci-build.sh release
11+
./ci-build.sh release immix
1212

1313
# Use release build to run tests
1414
cd $cur

julia/mmtk_julia.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ extern int64_t perm_scanned_bytes;
88
extern void run_finalizer(jl_task_t *ct, void *o, void *ff);
99
extern int gc_n_threads;
1010
extern jl_ptls_t* gc_all_tls_states;
11-
extern jl_ptls_t get_next_mutator_tls(void);
1211
extern jl_value_t *cmpswap_names JL_GLOBALLY_ROOTED;
1312
extern jl_array_t *jl_global_roots_table JL_GLOBALLY_ROOTED;
1413
extern jl_typename_t *jl_array_typename JL_GLOBALLY_ROOTED;
@@ -18,11 +17,14 @@ extern void gc_premark(jl_ptls_t ptls2);
1817
extern uint64_t finalizer_rngState[4];
1918
extern const unsigned pool_sizes[];
2019
extern void store_obj_size_c(void* obj, size_t size);
21-
extern void reset_count_tls(void);
2220
extern void jl_gc_free_array(jl_array_t *a);
2321
extern size_t get_obj_size(void* obj);
2422
extern void jl_rng_split(uint64_t to[4], uint64_t from[4]);
2523

24+
extern void* new_mutator_iterator(void);
25+
extern jl_ptls_t get_next_mutator_tls(void*);
26+
extern void* close_mutator_iterator(void*);
27+
2628
JL_DLLEXPORT void (jl_mmtk_harness_begin)(void)
2729
{
2830
jl_ptls_t ptls = jl_current_task->ptls;
@@ -112,8 +114,8 @@ JL_DLLEXPORT jl_value_t *jl_mmtk_gc_alloc_big(jl_ptls_t ptls, size_t sz)
112114

113115
static void mmtk_sweep_malloced_arrays(void) JL_NOTSAFEPOINT
114116
{
115-
reset_count_tls();
116-
jl_ptls_t ptls2 = (jl_ptls_t) get_next_mutator_tls();
117+
void* iter = new_mutator_iterator();
118+
jl_ptls_t ptls2 = get_next_mutator_tls(iter);
117119
while(ptls2 != NULL) {
118120
mallocarray_t *ma = ptls2->heap.mallocarrays;
119121
mallocarray_t **pma = &ptls2->heap.mallocarrays;
@@ -136,9 +138,10 @@ static void mmtk_sweep_malloced_arrays(void) JL_NOTSAFEPOINT
136138
}
137139
ma = nxt;
138140
}
139-
ptls2 = get_next_mutator_tls();
141+
ptls2 = get_next_mutator_tls(iter);
140142
}
141143
gc_sweep_sysimg();
144+
close_mutator_iterator(iter);
142145
}
143146

144147
extern void mark_metadata_scanned(jl_value_t* obj);

mmtk/Cargo.lock

Lines changed: 43 additions & 7 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
@@ -29,7 +29,7 @@ lazy_static = "1.1"
2929
# - change branch
3030
# - change repo name
3131
# But other changes including adding/removing whitespaces in commented lines may break the CI
32-
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "7b06ead8bffc8a33b059919d440cb0b9812359b9" }
32+
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "de8bbfe623eee5e915f32870de8f81128df8ad41" }
3333
# Uncomment the following to build locally
3434
# mmtk = { path = "../repos/mmtk-core" }
3535
log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"] }

mmtk/runtime/runtime_gc_x64.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ void* get_mutator_from_ref(void* mutator) {
1313
return mutator;
1414
}
1515

16-
int mutator_cursor = 0;
17-
18-
void reset_mutator_count() {
19-
mutator_cursor = 0;
20-
}
21-
22-
int get_next_julia_mutator() {
23-
return mutator_cursor++;
24-
}
25-
2616
extern void start_spawned_worker_thread(void*, void*);
2717
extern void start_spawned_controller_thread(void*, void*);
2818

mmtk/src/active_plan.rs

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
use crate::JuliaVM;
2-
use crate::{
3-
get_mutator_from_ref, get_next_julia_mutator, reset_mutator_count, MUTATORS, MUTATOR_TLS,
4-
SINGLETON,
5-
};
2+
use crate::{get_mutator_from_ref, MUTATORS, MUTATOR_TLS, SINGLETON};
63
use mmtk::util::opaque_pointer::*;
74
use mmtk::util::Address;
85
use mmtk::vm::ActivePlan;
96
use mmtk::Mutator;
107
use mmtk::Plan;
118
use mmtk::{plan::ObjectQueue, scheduler::GCWorker, util::ObjectReference};
129

10+
use std::sync::RwLockReadGuard;
11+
12+
pub struct JuliaMutatorIterator<'a> {
13+
guard: RwLockReadGuard<'a, Vec<ObjectReference>>,
14+
cursor: usize,
15+
}
16+
17+
impl<'a> JuliaMutatorIterator<'a> {
18+
fn new(guard: RwLockReadGuard<'a, Vec<ObjectReference>>) -> Self {
19+
Self {
20+
guard: guard,
21+
cursor: 0,
22+
}
23+
}
24+
}
25+
26+
impl<'a> Iterator for JuliaMutatorIterator<'a> {
27+
type Item = &'a mut Mutator<JuliaVM>;
28+
29+
fn next(&mut self) -> Option<Self::Item> {
30+
let ref mutators = self.guard;
31+
32+
let mutator_idx = self.cursor;
33+
self.cursor += 1;
34+
35+
let mutator = mutators.get(mutator_idx);
36+
37+
match mutator {
38+
Some(m) => {
39+
let mutator = unsafe { get_mutator_from_ref(*m) };
40+
Some(unsafe { &mut *mutator })
41+
}
42+
None => None,
43+
}
44+
}
45+
}
46+
1347
pub struct VMActivePlan {}
1448

1549
impl ActivePlan<JuliaVM> for VMActivePlan {
@@ -18,7 +52,7 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
1852
}
1953

2054
fn number_of_mutators() -> usize {
21-
unimplemented!()
55+
Self::mutators().count()
2256
}
2357

2458
fn is_mutator(tls: VMThread) -> bool {
@@ -35,30 +69,9 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
3569
unimplemented!()
3670
}
3771

38-
fn reset_mutator_iterator() {
39-
unsafe { reset_mutator_count() }
40-
}
41-
42-
fn get_next_mutator() -> Option<&'static mut Mutator<JuliaVM>> {
43-
let mutators = MUTATORS.read().unwrap();
44-
// println!("All mutators: {:?}", mutators.iter());
45-
46-
let mutator_idx = unsafe { get_next_julia_mutator() };
47-
48-
// println!("Next mutator is: {:?}", mutator_idx);
49-
50-
let mutator = mutators.get(mutator_idx);
51-
52-
let res = match mutator {
53-
Some(m) => {
54-
let mutator = unsafe { get_mutator_from_ref(*m) };
55-
// println!("Next mutator is: {:?}", mutator);
56-
Some(unsafe { &mut *mutator })
57-
}
58-
None => None,
59-
};
60-
61-
res
72+
fn mutators<'a>() -> Box<dyn Iterator<Item = &'a mut Mutator<JuliaVM>> + 'a> {
73+
let guard = MUTATORS.read().unwrap();
74+
Box::new(JuliaMutatorIterator::new(guard))
6275
}
6376

6477
fn vm_trace_object<Q: ObjectQueue>(
@@ -71,29 +84,24 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
7184
}
7285
}
7386

74-
#[no_mangle]
75-
pub extern "C" fn get_next_mutator_tls() -> OpaquePointer {
76-
let mutators = MUTATORS.read().unwrap();
77-
78-
let mutator_idx = unsafe { get_next_julia_mutator() };
79-
let mutator = mutators.get(mutator_idx);
80-
81-
let res = match mutator {
82-
Some(m) => {
83-
let mutator = unsafe { get_mutator_from_ref(*m) };
87+
// Expose the mutator iterator so they can be used in C.
8488

85-
unsafe { (*mutator).mutator_tls.0 .0 }
86-
}
87-
None => {
88-
unsafe { reset_mutator_count() }
89-
OpaquePointer::from_address(unsafe { Address::zero() })
90-
}
91-
};
89+
#[no_mangle]
90+
pub extern "C" fn new_mutator_iterator() -> *mut JuliaMutatorIterator<'static> {
91+
let guard = MUTATORS.read().unwrap();
92+
Box::into_raw(Box::new(JuliaMutatorIterator::new(guard)))
93+
}
9294

93-
res
95+
#[no_mangle]
96+
pub extern "C" fn get_next_mutator_tls(iter: *mut JuliaMutatorIterator<'static>) -> OpaquePointer {
97+
match unsafe { iter.as_mut() }.unwrap().next() {
98+
Some(m) => m.mutator_tls.0 .0,
99+
None => OpaquePointer::from_address(Address::ZERO),
100+
}
94101
}
95102

96103
#[no_mangle]
97-
pub extern "C" fn reset_count_tls() {
98-
unsafe { reset_mutator_count() }
104+
pub extern "C" fn close_mutator_iterator(iter: *mut JuliaMutatorIterator<'static>) {
105+
// The boxed pointer will get dropped
106+
let _to_drop = unsafe { Box::from_raw(iter) };
99107
}

0 commit comments

Comments
 (0)