Commit 3ed935e1 authored by qinsoon's avatar qinsoon

interface to add gc types

parent c1a463d7
......@@ -4,10 +4,10 @@ use utils::ByteSize;
#[derive(Clone, Debug)]
pub struct GCType {
id: usize,
size: ByteSize,
non_repeat_refs: Option<RefPattern>,
repeat_refs : Option<RepeatingRefPattern>
pub id: usize,
pub size: ByteSize,
pub non_repeat_refs: Option<RefPattern>,
pub repeat_refs : Option<RepeatingRefPattern>
}
impl GCType {
......@@ -73,8 +73,8 @@ impl RefPattern {
#[derive(Clone, Debug)]
pub struct RepeatingRefPattern {
pattern: RefPattern,
count: usize
pub pattern: RefPattern,
pub count: usize
}
impl RepeatingRefPattern {
......
mod bitmap;
mod address_bitmap;
mod address_map;
mod gctype;
pub mod gctype;
pub use self::address_bitmap::AddressBitmap;
pub use self::address_map::AddressMap;
\ No newline at end of file
......@@ -5,6 +5,7 @@ use heap::immix::ImmixSpace;
use heap::freelist::FreeListSpace;
use objectmodel;
use heap::Space;
use MY_GC;
use utils::{Address, ObjectReference};
use utils::POINTER_SIZE;
......@@ -24,8 +25,6 @@ lazy_static! {
static ref STW_COND : Arc<(Mutex<usize>, Condvar)> = {
Arc::new((Mutex::new(0), Condvar::new()))
};
static ref GC_CONTEXT : RwLock<GCContext> = RwLock::new(GCContext{immix_space: None, lo_space: None});
static ref ROOTS : RwLock<Vec<ObjectReference>> = RwLock::new(vec![]);
}
......@@ -33,16 +32,10 @@ lazy_static! {
static CONTROLLER : AtomicIsize = atomic::ATOMIC_ISIZE_INIT;
const NO_CONTROLLER : isize = -1;
pub struct GCContext {
immix_space : Option<Arc<ImmixSpace>>,
lo_space : Option<Arc<FreeListSpace>>
}
pub fn init(immix_space: Arc<ImmixSpace>, lo_space: Arc<FreeListSpace>) {
pub fn init(n_gcthreads: usize) {
CONTROLLER.store(NO_CONTROLLER, Ordering::SeqCst);
let mut gccontext = GC_CONTEXT.write().unwrap();
gccontext.immix_space = Some(immix_space);
gccontext.lo_space = Some(lo_space);
GC_THREADS.store(n_gcthreads, Ordering::SeqCst);
}
pub fn trigger_gc() {
......@@ -83,11 +76,12 @@ pub fn stack_scan() -> Vec<ObjectReference> {
let mut cursor = stack_ptr;
let mut ret = vec![];
let gccontext = GC_CONTEXT.read().unwrap();
let immix_space = gccontext.immix_space.as_ref().unwrap();
let lo_space = gccontext.lo_space.as_ref().unwrap();
let gccontext_guard = MY_GC.read().unwrap();
let gccontext = gccontext_guard.as_ref().unwrap();
let immix_space = gccontext.immix_space.clone();
let lo_space = gccontext.lo_space.clone();
while cursor < low_water_mark {
let value : Address = unsafe {cursor.load::<Address>()};
......@@ -212,8 +206,9 @@ fn gc() {
// mark & trace
{
let gccontext = GC_CONTEXT.read().unwrap();
let (immix_space, lo_space) = (gccontext.immix_space.as_ref().unwrap(), gccontext.lo_space.as_ref().unwrap());
let gccontext_guard = MY_GC.read().unwrap();
let gccontext = gccontext_guard.as_ref().unwrap();
let (immix_space, lo_space) = (&gccontext.immix_space, &gccontext.lo_space);
start_trace(&mut roots, immix_space.clone(), lo_space.clone());
}
......@@ -222,12 +217,13 @@ fn gc() {
// sweep
{
let gccontext = GC_CONTEXT.read().unwrap();
let gccontext_guard = MY_GC.read().unwrap();
let gccontext = gccontext_guard.as_ref().unwrap();
let immix_space = gccontext.immix_space.as_ref().unwrap();
let ref immix_space = gccontext.immix_space;
immix_space.sweep();
let lo_space = gccontext.lo_space.as_ref().unwrap();
let ref lo_space = gccontext.lo_space;
lo_space.sweep();
}
......
......@@ -13,6 +13,7 @@ pub mod common;
pub mod objectmodel;
pub mod heap;
use common::gctype::GCType;
use utils::ObjectReference;
use heap::immix::BYTES_IN_LINE;
use heap::immix::ImmixSpace;
......@@ -33,7 +34,9 @@ pub use heap::immix::LIMIT_OFFSET as ALLOCATOR_LIMIT_OFFSET;
#[repr(C)]
pub struct GC {
immix_space: Arc<ImmixSpace>,
lo_space : Arc<FreeListSpace>
lo_space : Arc<FreeListSpace>,
gc_types : Vec<GCType>
}
impl fmt::Debug for GC {
......@@ -62,6 +65,19 @@ pub extern fn get_spaces() -> (Arc<ImmixSpace>, Arc<FreeListSpace>) {
(space.immix_space.clone(), space.lo_space.clone())
}
#[no_mangle]
pub extern fn add_gc_type(mut ty: GCType) -> usize {
let mut gc_guard = MY_GC.write().unwrap();
let mut gc = gc_guard.as_mut().unwrap();
let index = gc.gc_types.len();
ty.id = index;
gc.gc_types.push(ty);
index
}
#[no_mangle]
pub extern fn gc_init(immix_size: usize, lo_size: usize, n_gcthreads: usize) {
// set this line to turn on certain level of debugging info
......@@ -78,16 +94,19 @@ pub extern fn gc_init(immix_size: usize, lo_size: usize, n_gcthreads: usize) {
let immix_space = Arc::new(ImmixSpace::new(immix_size));
let lo_space = Arc::new(FreeListSpace::new(lo_size));
heap::gc::init(immix_space.clone(), lo_space.clone());
heap::gc::init(n_gcthreads);
(immix_space, lo_space)
};
*MY_GC.write().unwrap() = Some(GC {immix_space: immix_space, lo_space: lo_space});
*MY_GC.write().unwrap() = Some(GC {
immix_space: immix_space,
lo_space: lo_space,
gc_types: vec![]
});
info!("heap is {} bytes (immix: {} bytes, lo: {} bytes) . ", immix_size + lo_size, immix_size, lo_size);
// gc threads
heap::gc::GC_THREADS.store(n_gcthreads, Ordering::SeqCst);
info!("{} gc threads", n_gcthreads);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment