Commit 2d522d20 authored by qinsoon's avatar qinsoon

[wip] gcbench. it doesnt run, disable it for now

parent 69d76617
......@@ -97,7 +97,7 @@ pub extern fn alloc_slow(mutator: &mut Box<ImmixMutatorLocal>, size: usize, alig
}
#[no_mangle]
pub extern fn alloc_large(mutator: &mut Box<ImmixMutatorLocal>, size: usize) -> ObjectReference {
let ret = freelist::alloc_large(size, 8, mutator, MY_GC.read().unwrap().as_ref().unwrap().lo_space.clone());
pub extern fn alloc_large(mutator: &mut Box<ImmixMutatorLocal>, size: usize, align: usize) -> ObjectReference {
let ret = freelist::alloc_large(size, align, mutator, MY_GC.read().unwrap().as_ref().unwrap().lo_space.clone());
unsafe {ret.to_object_reference()}
}
\ No newline at end of file
mod test_thread;
mod test_gc;
\ No newline at end of file
mod test_gc;
//disable this for now - it doesnt run
//mod test_gcbench;
\ No newline at end of file
......@@ -22,18 +22,6 @@ const LO_SPACE_SIZE : usize = 500 << 20;
#[test]
fn test_exhaust_alloc() {
mem::gc_init(IMMIX_SPACE_SIZE, LO_SPACE_SIZE, 8);
let shared_space : Arc<ImmixSpace> = {
let space : ImmixSpace = ImmixSpace::new(heap::IMMIX_SPACE_SIZE.load(Ordering::SeqCst));
Arc::new(space)
};
let lo_space : Arc<RwLock<FreeListSpace>> = {
let space : FreeListSpace = FreeListSpace::new(heap::LO_SPACE_SIZE.load(Ordering::SeqCst));
Arc::new(RwLock::new(space))
};
heap::gc::init(shared_space.clone(), lo_space.clone());
let mut mutator = mem::new_mutator();
println!("Trying to allocate {} objects of (size {}, align {}). ", WORK_LOAD, OBJECT_SIZE, OBJECT_ALIGN);
......@@ -101,6 +89,7 @@ fn test_alloc_mark() {
}
}
#[allow(dead_code)]
struct Node<'a> {
hdr : u64,
next : &'a Node<'a>,
......
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]
use mu::runtime::mem;
use mu::runtime::mem::heap;
use mu::runtime::mem::heap::immix::ImmixMutatorLocal;
use mu::runtime::mem::heap::immix::ImmixSpace;
use mu::runtime::mem::heap::freelist;
use mu::runtime::mem::heap::freelist::FreeListSpace;
use std::mem::size_of;
use std::sync::atomic::Ordering;
extern crate time;
const IMMIX_SPACE_SIZE : usize = 40 << 20;
const LO_SPACE_SIZE : usize = 40 << 20;
const kStretchTreeDepth : i32 = 18;
const kLongLivedTreeDepth : i32 = 16;
const kArraySize : i32 = 500000;
const kMinTreeDepth : i32 = 4;
const kMaxTreeDepth : i32 = 16;
struct Node {
left : *mut Node,
right : *mut Node,
i : i32,
j : i32
}
struct Array {
value : [f64; kArraySize as usize]
}
fn init_Node(me: *mut Node, l: *mut Node, r: *mut Node) {
unsafe {
(*me).left = l;
(*me).right = r;
}
}
fn TreeSize(i: i32) -> i32{
(1 << (i + 1)) - 1
}
fn NumIters(i: i32) -> i32 {
2 * TreeSize(kStretchTreeDepth) / TreeSize(i)
}
fn Populate(iDepth: i32, thisNode: *mut Node, mutator: &mut ImmixMutatorLocal) {
if iDepth <= 0 {
return;
} else {
unsafe {
(*thisNode).left = alloc(mutator);
(*thisNode).right = alloc(mutator);
Populate(iDepth - 1, (*thisNode).left, mutator);
Populate(iDepth - 1, (*thisNode).right, mutator);
}
}
}
fn MakeTree(iDepth: i32, mutator: &mut ImmixMutatorLocal) -> *mut Node {
if iDepth <= 0 {
alloc(mutator)
} else {
let left = MakeTree(iDepth - 1, mutator);
let right = MakeTree(iDepth - 1, mutator);
let result = alloc(mutator);
init_Node(result, left, right);
result
}
}
fn PrintDiagnostics() {
}
fn TimeConstruction(depth: i32, mutator: &mut ImmixMutatorLocal) {
let iNumIters = NumIters(depth);
println!("creating {} trees of depth {}", iNumIters, depth);
let tStart = time::now_utc();
for _ in 0..iNumIters {
let tempTree = alloc(mutator);
Populate(depth, tempTree, mutator);
// destroy tempTree
}
let tFinish = time::now_utc();
println!("\tTop down construction took {} msec", (tFinish - tStart).num_milliseconds());
let tStart = time::now_utc();
for _ in 0..iNumIters {
let tempTree = MakeTree(depth, mutator);
}
let tFinish = time::now_utc();
println!("\tButtom up construction took {} msec", (tFinish - tStart).num_milliseconds());
}
#[inline(always)]
fn alloc(mutator: &mut ImmixMutatorLocal) -> *mut Node {
let addr = mutator.alloc(size_of::<Node>(), 8);
mutator.init_object(addr, 0b1100_0011);
// objectmodel::init_header(unsafe{addr.to_object_reference()}, HEADER_INIT_U64);
addr.to_ptr_mut::<Node>()
}
#[test]
fn start() {
unsafe {heap::gc::set_low_water_mark();}
mem::gc_init(IMMIX_SPACE_SIZE, LO_SPACE_SIZE, 8);
let mut mutator = mem::new_mutator();
println!("Garbage Collector Test");
println!(" Live storage will peak at {} bytes.\n",
2 * (size_of::<Node>() as i32) * TreeSize(kLongLivedTreeDepth) +
(size_of::<Array>() as i32));
println!(" Stretching memory with a binary tree or depth {}", kStretchTreeDepth);
PrintDiagnostics();
let tStart = time::now_utc();
// Stretch the memory space quickly
let tempTree = MakeTree(kStretchTreeDepth, &mut mutator);
// destroy tree
// Create a long lived object
println!(" Creating a long-lived binary tree of depth {}", kLongLivedTreeDepth);
let longLivedTree = alloc(&mut mutator);
Populate(kLongLivedTreeDepth, longLivedTree, &mut mutator);
println!(" Creating a long-lived array of {} doubles", kArraySize);
mem::alloc_large(&mut mutator, size_of::<Array>(), 8);
PrintDiagnostics();
let mut d = kMinTreeDepth;
while d <= kMaxTreeDepth {
TimeConstruction(d, &mut mutator);
d += 2;
}
if longLivedTree.is_null() {
println!("Failed(long lived tree wrong)");
}
// if array.array[1000] != 1.0f64 / (1000 as f64) {
// println!("Failed(array element wrong)");
// }
let tFinish = time::now_utc();
let tElapsed = (tFinish - tStart).num_milliseconds();
PrintDiagnostics();
println!("Completed in {} msec", tElapsed);
println!("Finished with {} collections", heap::gc::GC_COUNT.load(Ordering::SeqCst));
}
\ No newline at end of file
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