Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cur=$(realpath $(dirname "$0"))

# Build release
cd $cur
./ci-build.sh release
./ci-build.sh release immix

# Use release build to run tests
cd $cur
Expand Down
13 changes: 8 additions & 5 deletions julia/mmtk_julia.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern int64_t perm_scanned_bytes;
extern void run_finalizer(jl_task_t *ct, void *o, void *ff);
extern int gc_n_threads;
extern jl_ptls_t* gc_all_tls_states;
extern jl_ptls_t get_next_mutator_tls(void);
extern jl_value_t *cmpswap_names JL_GLOBALLY_ROOTED;
extern jl_array_t *jl_global_roots_table JL_GLOBALLY_ROOTED;
extern jl_typename_t *jl_array_typename JL_GLOBALLY_ROOTED;
Expand All @@ -18,11 +17,14 @@ extern void gc_premark(jl_ptls_t ptls2);
extern uint64_t finalizer_rngState[4];
extern const unsigned pool_sizes[];
extern void store_obj_size_c(void* obj, size_t size);
extern void reset_count_tls(void);
extern void jl_gc_free_array(jl_array_t *a);
extern size_t get_obj_size(void* obj);
extern void jl_rng_split(uint64_t to[4], uint64_t from[4]);

extern void* new_mutator_iterator(void);
extern jl_ptls_t get_next_mutator_tls(void*);
extern void* close_mutator_iterator(void*);

JL_DLLEXPORT void (jl_mmtk_harness_begin)(void)
{
jl_ptls_t ptls = jl_current_task->ptls;
Expand Down Expand Up @@ -112,8 +114,8 @@ JL_DLLEXPORT jl_value_t *jl_mmtk_gc_alloc_big(jl_ptls_t ptls, size_t sz)

static void mmtk_sweep_malloced_arrays(void) JL_NOTSAFEPOINT
{
reset_count_tls();
jl_ptls_t ptls2 = (jl_ptls_t) get_next_mutator_tls();
void* iter = new_mutator_iterator();
jl_ptls_t ptls2 = get_next_mutator_tls(iter);
while(ptls2 != NULL) {
mallocarray_t *ma = ptls2->heap.mallocarrays;
mallocarray_t **pma = &ptls2->heap.mallocarrays;
Expand All @@ -136,9 +138,10 @@ static void mmtk_sweep_malloced_arrays(void) JL_NOTSAFEPOINT
}
ma = nxt;
}
ptls2 = get_next_mutator_tls();
ptls2 = get_next_mutator_tls(iter);
}
gc_sweep_sysimg();
close_mutator_iterator(iter);
}

extern void mark_metadata_scanned(jl_value_t* obj);
Expand Down
50 changes: 43 additions & 7 deletions mmtk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lazy_static = "1.1"
# - change branch
# - change repo name
# But other changes including adding/removing whitespaces in commented lines may break the CI
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "7b06ead8bffc8a33b059919d440cb0b9812359b9" }
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "de8bbfe623eee5e915f32870de8f81128df8ad41" }
# Uncomment the following to build locally
# mmtk = { path = "../repos/mmtk-core" }
log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"] }
Expand Down
10 changes: 0 additions & 10 deletions mmtk/runtime/runtime_gc_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ void* get_mutator_from_ref(void* mutator) {
return mutator;
}

int mutator_cursor = 0;

void reset_mutator_count() {
mutator_cursor = 0;
}

int get_next_julia_mutator() {
return mutator_cursor++;
}

extern void start_spawned_worker_thread(void*, void*);
extern void start_spawned_controller_thread(void*, void*);

Expand Down
106 changes: 57 additions & 49 deletions mmtk/src/active_plan.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
use crate::JuliaVM;
use crate::{
get_mutator_from_ref, get_next_julia_mutator, reset_mutator_count, MUTATORS, MUTATOR_TLS,
SINGLETON,
};
use crate::{get_mutator_from_ref, MUTATORS, MUTATOR_TLS, SINGLETON};
use mmtk::util::opaque_pointer::*;
use mmtk::util::Address;
use mmtk::vm::ActivePlan;
use mmtk::Mutator;
use mmtk::Plan;
use mmtk::{plan::ObjectQueue, scheduler::GCWorker, util::ObjectReference};

use std::sync::RwLockReadGuard;

pub struct JuliaMutatorIterator<'a> {
guard: RwLockReadGuard<'a, Vec<ObjectReference>>,
cursor: usize,
}

impl<'a> JuliaMutatorIterator<'a> {
fn new(guard: RwLockReadGuard<'a, Vec<ObjectReference>>) -> Self {
Self {
guard: guard,
cursor: 0,
}
}
}

impl<'a> Iterator for JuliaMutatorIterator<'a> {
type Item = &'a mut Mutator<JuliaVM>;

fn next(&mut self) -> Option<Self::Item> {
let ref mutators = self.guard;

let mutator_idx = self.cursor;
self.cursor += 1;

let mutator = mutators.get(mutator_idx);

match mutator {
Some(m) => {
let mutator = unsafe { get_mutator_from_ref(*m) };
Some(unsafe { &mut *mutator })
}
None => None,
}
}
}

pub struct VMActivePlan {}

impl ActivePlan<JuliaVM> for VMActivePlan {
Expand All @@ -18,7 +52,7 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
}

fn number_of_mutators() -> usize {
unimplemented!()
Self::mutators().count()
}

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

fn reset_mutator_iterator() {
unsafe { reset_mutator_count() }
}

fn get_next_mutator() -> Option<&'static mut Mutator<JuliaVM>> {
let mutators = MUTATORS.read().unwrap();
// println!("All mutators: {:?}", mutators.iter());

let mutator_idx = unsafe { get_next_julia_mutator() };

// println!("Next mutator is: {:?}", mutator_idx);

let mutator = mutators.get(mutator_idx);

let res = match mutator {
Some(m) => {
let mutator = unsafe { get_mutator_from_ref(*m) };
// println!("Next mutator is: {:?}", mutator);
Some(unsafe { &mut *mutator })
}
None => None,
};

res
fn mutators<'a>() -> Box<dyn Iterator<Item = &'a mut Mutator<JuliaVM>> + 'a> {
let guard = MUTATORS.read().unwrap();
Box::new(JuliaMutatorIterator::new(guard))
}

fn vm_trace_object<Q: ObjectQueue>(
Expand All @@ -71,29 +84,24 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
}
}

#[no_mangle]
pub extern "C" fn get_next_mutator_tls() -> OpaquePointer {
let mutators = MUTATORS.read().unwrap();

let mutator_idx = unsafe { get_next_julia_mutator() };
let mutator = mutators.get(mutator_idx);

let res = match mutator {
Some(m) => {
let mutator = unsafe { get_mutator_from_ref(*m) };
// Expose the mutator iterator so they can be used in C.

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

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

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