Commit 439221f2 authored by qinsoon's avatar qinsoon

seperate crates for ast/utils/gc

parent cf276acb
target/*
**/target/*
emit/*
Cargo.lock
*.log
......
File added
......@@ -11,17 +11,17 @@ crate-type = ["staticlib", "rlib"]
gcc = "0.3"
[dependencies]
ast = {path = "src/ast"}
utils = {path = "src/utils"}
gc = {path = "src/gc"}
libloading = "0.3"
lazy_static = "0.1.15"
log = "0.3.5"
simple_logger = "0.4.0"
nalgebra = "0.8.2"
linked-hash-map = "0.0.10"
hprof = "0.1.3"
memmap = "0.4.0"
memsec = "0.1.9"
rustc-serialize = "*"
time = "0.1.34"
aligned_alloc = "0.1.2"
crossbeam = "0.2.8"
byteorder = "0.5.3"
time = "0.1.34"
\ No newline at end of file
......@@ -4,7 +4,6 @@ extern crate gcc;
#[cfg(target_arch = "x86_64")]
fn main() {
gcc::compile_library("libruntime.a", &["src/runtime/runtime_x64_macos.c"]);
gcc::compile_library("libgc_clib_x64.a", &["src/runtime/mm/heap/gc/clib_x64.c"]);
gcc::Config::new().flag("-O3")
.file("src/runtime/swap_stack_x64_macos.s")
......
[package]
name = "ast"
version = "0.0.1"
authors = ["qinsoon <qinsoon@gmail.com>"]
[lib]
crate-type = ["rlib"]
[dependencies]
utils = {path = "../utils"}
lazy_static = "0.1.15"
log = "0.3.5"
simple_logger = "0.4.0"
rustc-serialize = "*"
\ No newline at end of file
#[macro_use]
pub mod ir;
pub mod inst;
pub mod types;
pub mod ir_semantics;
pub mod ptr;
pub mod op;
\ No newline at end of file
use ast::ir::*;
use ast::ptr::*;
use ast::types::*;
use ast::op::*;
use utils::vec_utils::as_str as vector_as_str;
use ir::*;
use ptr::*;
use types::*;
use op::*;
use utils::vec_utils;
use std::fmt;
......@@ -69,7 +69,7 @@ impl fmt::Display for Instruction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ops = &self.ops.read().unwrap();
if self.value.is_some() {
write!(f, "{} = {}", vector_as_str(self.value.as_ref().unwrap()), self.v.debug_str(ops))
write!(f, "{} = {}", vec_utils::as_str(self.value.as_ref().unwrap()), self.v.debug_str(ops))
} else {
write!(f, "{}", self.v.debug_str(ops))
}
......@@ -434,4 +434,4 @@ impl DestArg {
&DestArg::Freshbound(n) => format!("${}", n)
}
}
}
}
\ No newline at end of file
use ast::ptr::P;
use ast::types::*;
use ast::inst::*;
use ast::op::*;
use utils::vec_utils::as_str as vector_as_str;
use ptr::P;
use types::*;
use inst::*;
use op::*;
use utils::vec_utils;
use std::collections::HashMap;
......@@ -272,8 +272,8 @@ impl ControlFlow {
impl fmt::Display for ControlFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "preds: [{}], ", vector_as_str(&self.preds)).unwrap();
write!(f, "succs: [{}]", vector_as_str(&self.succs))
write!(f, "preds: [{}], ", vec_utils::as_str(&self.preds)).unwrap();
write!(f, "succs: [{}]", vec_utils::as_str(&self.succs))
}
}
......@@ -764,25 +764,6 @@ pub trait MuEntity {
fn as_entity(&self) -> &MuEntity;
}
macro_rules! impl_mu_entity {
($entity: ty) => {
impl MuEntity for $entity {
#[inline(always)]
fn id(&self) -> MuID {self.hdr.id}
#[inline(always)]
fn name(&self) -> Option<MuName> {self.hdr.name()}
fn set_name(&self, name: MuName) {
let mut write_guard = self.hdr.name.write().unwrap();
*write_guard = Some(name);
}
fn as_entity(&self) -> &MuEntity {
let ref_ty : &$entity = self;
ref_ty as &MuEntity
}
}
}
}
impl_mu_entity!(MuFunction);
impl_mu_entity!(MuFunctionVersion);
impl_mu_entity!(Block);
......@@ -801,4 +782,4 @@ pub fn op_vector_str(vec: &Vec<OpIndex>, ops: &Vec<P<TreeNode>>) -> String {
}
}
ret
}
}
\ No newline at end of file
use ast::inst::*;
use ast::inst::Instruction_::*;
use inst::*;
use inst::Instruction_::*;
pub fn is_terminal_inst(inst: &Instruction_) -> bool {
match inst {
......
#[macro_use]
extern crate log;
extern crate simple_logger;
#[macro_use]
extern crate lazy_static;
extern crate rustc_serialize;
extern crate utils;
#[macro_export]
macro_rules! impl_mu_entity {
($entity: ty) => {
impl MuEntity for $entity {
#[inline(always)]
fn id(&self) -> MuID {self.hdr.id}
#[inline(always)]
fn name(&self) -> Option<MuName> {self.hdr.name()}
fn set_name(&self, name: MuName) {
let mut write_guard = self.hdr.name.write().unwrap();
*write_guard = Some(name);
}
fn as_entity(&self) -> &MuEntity {
let ref_ty : &$entity = self;
ref_ty as &MuEntity
}
}
}
}
macro_rules! select_value {
($cond: expr, $res1 : expr, $res2 : expr) => {
if $cond {
$res1
} else {
$res2
}
}
}
#[macro_use]
pub mod ir;
pub mod inst;
pub mod types;
pub mod ir_semantics;
pub mod ptr;
pub mod op;
\ No newline at end of file
use ast::ptr::P;
use ast::types::*;
use ast::inst::*;
use ptr::P;
use types::*;
use inst::*;
use types::MuType_::*;
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
pub enum OpCode {
......@@ -55,7 +56,6 @@ pub enum OpCode {
}
pub fn pick_op_code_for_ssa(ty: &P<MuType>) -> OpCode {
use ast::types::MuType_::*;
let a : &MuType = ty;
match a.v {
// currently use i64 for all ints
......@@ -84,7 +84,6 @@ pub fn pick_op_code_for_ssa(ty: &P<MuType>) -> OpCode {
}
pub fn pick_op_code_for_value(ty: &P<MuType>) -> OpCode {
use ast::types::MuType_::*;
let a : &MuType = ty;
match a.v {
// currently use i64 for all ints
......
......@@ -43,7 +43,7 @@
use std::sync::Arc;
use ast::ir::MuEntity;
use ir::MuEntity;
pub type P<T> = Arc<T>;
//pub struct P<T: MuEntity> {
......
use ast::ptr::P;
use ast::ir::*;
use utils::vec_utils::as_str as vector_as_str;
use ptr::P;
use ir::*;
use utils::vec_utils;
use std::fmt;
use std::collections::HashMap;
......@@ -87,7 +88,7 @@ impl fmt::Display for MuType_ {
&MuType_::WeakRef(ref ty) => write!(f, "weakref<{}>", ty),
&MuType_::UPtr(ref ty) => write!(f, "uptr<{}>", ty),
&MuType_::Array(ref ty, size) => write!(f, "array<{} {}>", ty, size),
&MuType_::Hybrid(ref fix_tys, ref var_ty) => write!(f, "hybrid<[{}] {}>", vector_as_str(fix_tys), var_ty),
&MuType_::Hybrid(ref fix_tys, ref var_ty) => write!(f, "hybrid<[{}] {}>", vec_utils::as_str(fix_tys), var_ty),
&MuType_::Void => write!(f, "void"),
&MuType_::ThreadRef => write!(f, "threadref"),
&MuType_::StackRef => write!(f, "stackref"),
......@@ -334,6 +335,6 @@ pub struct MuFuncSig {
impl fmt::Display for MuFuncSig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}] -> [{}]", vector_as_str(&self.ret_tys), vector_as_str(&self.arg_tys))
write!(f, "[{}] -> [{}]", vec_utils::as_str(&self.ret_tys), vec_utils::as_str(&self.arg_tys))
}
}
[package]
name = "gc"
version = "0.0.1"
authors = ["qinsoon <qinsoon@gmail.com>"]
build = "build.rs"
[lib]
crate-type = ["rlib"]
[build-dependencies]
gcc = "0.3"
[dependencies]
utils = {path = "../utils"}
lazy_static = "0.1.15"
log = "0.3.5"
simple_logger = "0.4.0"
aligned_alloc = "0.1.2"
crossbeam = "0.2.8"
\ No newline at end of file
extern crate gcc;
#[cfg(target_os = "macos")]
#[cfg(target_arch = "x86_64")]
fn main() {
gcc::compile_library("libgc_clib_x64.a", &["src/heap/gc/clib_x64.c"]);
}
\ No newline at end of file
use runtime::mm::common::LOG_POINTER_SIZE;
use runtime::mm::common::Address;
use runtime::mm::common::bitmap::Bitmap;
use utils::LOG_POINTER_SIZE;
use utils::Address;
use common::bitmap::Bitmap;
#[derive(Clone)]
pub struct AddressBitmap {
......
use std::mem;
use runtime::mm::common::LOG_POINTER_SIZE;
use runtime::mm::common::Address;
use runtime::mm::heap::gc::malloc_zero;
use utils::LOG_POINTER_SIZE;
use utils::Address;
use heap::gc::malloc_zero;
#[derive(Clone)]
pub struct AddressMap<T: Copy> {
......
use std::mem;
use runtime::mm::heap::gc::malloc_zero;
use heap::gc::malloc_zero;
#[derive(Clone)]
pub struct Bitmap {
......
mod bitmap;
mod address_bitmap;
mod address_map;
pub use self::address_bitmap::AddressBitmap;
pub use self::address_map::AddressMap;
\ No newline at end of file
use runtime::mm::common::Address;
use runtime::mm::heap::immix;
extern crate aligned_alloc;
use utils::Address;
use heap::immix;
use heap::gc;
use aligned_alloc;
use std::collections::LinkedList;
use std::sync::Arc;
......@@ -35,7 +35,7 @@ impl FreeListSpace {
if self.used_bytes + size > self.size {
None
} else {
let ret = self::aligned_alloc::aligned_alloc(size, align);
let ret = aligned_alloc::aligned_alloc(size, align);
let addr = Address::from_ptr::<()>(ret);
......@@ -64,7 +64,7 @@ impl FreeListSpace {
NodeMark::PrevLive | NodeMark::FreshAlloc => {
let ptr = node.start.to_ptr::<()>() as *mut ();
// free the memory
unsafe {self::aligned_alloc::aligned_free(ptr);}
unsafe {aligned_alloc::aligned_free(ptr);}
// do not add this node into new linked list
}
}
......@@ -121,7 +121,6 @@ pub fn alloc_large(size: usize, align: usize, mutator: &mut immix::ImmixMutatorL
return addr;
},
None => {
use runtime::mm::heap::gc;
gc::trigger_gc();
}
}
......
use runtime::mm::heap::immix::MUTATORS;
use runtime::mm::heap::immix::N_MUTATORS;
use runtime::mm::heap::immix::ImmixMutatorLocal;
use runtime::mm::heap::immix::ImmixSpace;
use runtime::mm::heap::immix::ImmixLineMarkTable;
use runtime::mm::heap::freelist::FreeListSpace;
use runtime::mm::objectmodel;
use runtime::mm::common;
use runtime::mm::common::{Address, ObjectReference};
use runtime::mm::common::AddressMap;
use heap::immix::MUTATORS;
use heap::immix::N_MUTATORS;
use heap::immix::ImmixMutatorLocal;
use heap::immix::ImmixSpace;
use heap::immix::ImmixLineMarkTable;
use heap::freelist::FreeListSpace;
use objectmodel;
use common::AddressMap;
use utils::{Address, ObjectReference};
use utils::POINTER_SIZE;
use utils::bit_utils;
use std::sync::atomic::{AtomicIsize, Ordering};
use std::sync::{Arc, Mutex, Condvar, RwLock};
extern crate crossbeam;
#[cfg(feature = "mt-trace")]
use self::crossbeam::sync::chase_lev::*;
use crossbeam::sync::chase_lev::*;
#[cfg(feature = "mt-trace")]
use std::sync::mpsc;
#[cfg(feature = "mt-trace")]
......@@ -89,7 +88,7 @@ pub fn is_valid_object(addr: Address, start: Address, end: Address, live_map: &A
return false;
}
common::test_nth_bit(live_map.get(addr), objectmodel::OBJ_START_BIT)
bit_utils::test_nth_bit(live_map.get(addr), objectmodel::OBJ_START_BIT)
}
pub fn stack_scan() -> Vec<ObjectReference> {
......@@ -109,7 +108,7 @@ pub fn stack_scan() -> Vec<ObjectReference> {
ret.push(unsafe {value.to_object_reference()});
}
cursor = cursor.plus(common::POINTER_SIZE);
cursor = cursor.plus(POINTER_SIZE);
}
let roots_from_stack = ret.len();
......@@ -298,7 +297,6 @@ pub fn start_trace(work_stack: &mut Vec<ObjectReference>, immix_space: Arc<Immix
#[inline(never)]
#[cfg(not(feature = "mt-trace"))]
pub fn start_trace(local_queue: &mut Vec<ObjectReference>, immix_space: Arc<ImmixSpace>, lo_space: Arc<RwLock<FreeListSpace>>) {
use runtime::mm::objectmodel;
let mark_state = objectmodel::MARK_STATE.load(Ordering::SeqCst) as u8;
while !local_queue.is_empty() {
......@@ -401,8 +399,6 @@ pub fn steal_process_edge(addr: Address, local_queue:&mut Vec<ObjectReference>,
#[inline(always)]
pub fn trace_object(obj: ObjectReference, local_queue: &mut Vec<ObjectReference>, alloc_map: *mut u8, trace_map: *mut u8, line_mark_table: &ImmixLineMarkTable, immix_start: Address, immix_end: Address, mark_state: u8) {
use runtime::mm::objectmodel;
objectmodel::mark_as_traced(trace_map, immix_start, obj, mark_state);
let addr = obj.to_address();
......@@ -416,7 +412,7 @@ pub fn trace_object(obj: ObjectReference, local_queue: &mut Vec<ObjectReference>
let mut base = addr;
loop {
let value = objectmodel::get_ref_byte(alloc_map, immix_start, obj);
let (ref_bits, short_encode) = (common::lower_bits(value, objectmodel::REF_BITS_LEN), common::test_nth_bit(value, objectmodel::SHORT_ENCODE_BIT));
let (ref_bits, short_encode) = (bit_utils::lower_bits(value, objectmodel::REF_BITS_LEN), bit_utils::test_nth_bit(value, objectmodel::SHORT_ENCODE_BIT));
match ref_bits {
0b0000_0001 => {
......@@ -448,8 +444,6 @@ pub fn trace_object(obj: ObjectReference, local_queue: &mut Vec<ObjectReference>
#[inline(always)]
pub fn process_edge(addr: Address, local_queue:&mut Vec<ObjectReference>, trace_map: *mut u8, space_start: Address, mark_state: u8) {
use runtime::mm::objectmodel;
let obj_addr : ObjectReference = unsafe{addr.load()};
if !obj_addr.to_address().is_zero() && !objectmodel::is_traced(trace_map, space_start, obj_addr, mark_state) {
......
use runtime::mm::heap::immix;
use runtime::mm::heap::immix::ImmixSpace;
use runtime::mm::heap::immix::immix_space::ImmixBlock;
use runtime::mm::heap::gc;
use heap::immix;
use heap::immix::ImmixSpace;
use heap::immix::immix_space::ImmixBlock;
use heap::gc;
use runtime::mm::common::LOG_POINTER_SIZE;
use runtime::mm::common::Address;
use utils::LOG_POINTER_SIZE;
use utils::Address;
use std::*;
use std::sync::Arc;
......
use runtime::mm::heap::immix;
use runtime::mm::heap::gc;
use runtime::mm::common::Address;
use runtime::mm::common::AddressMap;
use runtime::mm::heap::gc::malloc_zero;
use heap::immix;
use heap::gc;
use utils::Address;
use common::AddressMap;
use heap::gc::malloc_zero;
extern crate std;
extern crate memmap;
use utils::mem::memmap;
use std::*;
use std::collections::LinkedList;
......@@ -267,7 +266,7 @@ impl ImmixSpace {
if full_blocks == self.total_blocks {
println!("Out of memory in Immix Space");
std::process::exit(1);
process::exit(1);
}
debug_assert!(full_blocks + usable_blocks == self.total_blocks);
......
use runtime::mm::common::Address;
use utils::Address;
use std::sync::atomic::AtomicUsize;
pub mod immix;
......
extern crate utils;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate simple_logger;
extern crate aligned_alloc;
extern crate crossbeam;
use std::sync::atomic::Ordering;
pub mod common;
pub mod objectmodel;
pub mod heap;
pub use runtime::mm::heap::immix::ImmixMutatorLocal as Mutator;
use runtime::mm::common::ObjectReference;
use runtime::mm::heap::immix::ImmixSpace;
use runtime::mm::heap::immix::ImmixMutatorLocal;
use runtime::mm::heap::freelist;
use runtime::mm::heap::freelist::FreeListSpace;
pub use heap::immix::ImmixMutatorLocal as Mutator;
use utils::ObjectReference;
use heap::immix::ImmixSpace;
use heap::immix::ImmixMutatorLocal;
use heap::freelist;
use heap::freelist::FreeListSpace;
use std::fmt;
use std::sync::Arc;
......
use std::sync::atomic;
pub static MARK_STATE : atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT;
use runtime::mm::common::ObjectReference;
use runtime::mm::common::Address;
use runtime::mm::common::LOG_POINTER_SIZE;
use utils::{Address, ObjectReference};
use utils::LOG_POINTER_SIZE;
pub fn init() {
MARK_STATE.store(1, atomic::Ordering::SeqCst);
......
......@@ -3,13 +3,12 @@ extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate rustc_serialize;
extern crate byteorder;
extern crate simple_logger;
#[macro_use]
pub mod utils;
pub extern crate ast;
#[macro_use]
pub mod ast;
pub extern crate utils;
pub mod vm;
pub mod compiler;
pub mod runtime;
pub mod mm;
pub mod thread;
pub mod entrypoints;
pub use runtime::mm::common::Address;
pub use runtime::mm::common::ObjectReference;
use log;
use simple_logger;
use utils;
......@@ -16,14 +9,18 @@ use ast::ir::*;
use vm::VM;
use compiler::backend::Word;
use compiler::backend::RegGroup;
use utils::Address;
use std::os::raw::c_char;
use std::os::raw::c_void;
use std::ffi::CString;
use std::ffi::CStr;
use std::sync::Arc;
pub extern crate gc as mm;
pub mod thread;
pub mod entrypoints;
lazy_static! {
pub static ref ADDRESS_TYPE : P<MuType> = P(
MuType::new(ir::new_internal_id(), MuType_::int(64))
......
[package]
name = "utils"
version = "0.0.1"
authors = ["qinsoon <qinsoon@gmail.com>"]
[lib]
crate-type = ["rlib"]
[dependencies]
memmap = "0.4.0"
memsec = "0.1.9"
linked-hash-map = "0.0.10"
byteorder = "0.5.3"
\ No newline at end of file
......@@ -2,15 +2,6 @@ use std::cmp;
use std::fmt;
use std::mem;
mod bitmap;
mod address_bitmap;
mod address_map;
pub use self::address_bitmap::AddressBitmap;
pub use self::address_map::AddressMap;
pub const LOG_POINTER_SIZE : usize = 3;
pub const POINTER_SIZE : usize = 1 << LOG_POINTER_SIZE;
#[repr(C)]
#[derive(Copy, Clone, Eq, Hash)]
pub struct Address(usize);
......@@ -191,28 +182,4 @@ impl fmt::Debug for ObjectReference {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "0x{:X}", self.0)
}
}
#[inline(always)]
pub fn test_nth_bit(value: u8, index: usize) -> bool {
value & (1 << index) != 0
}
#[inline(always)]
pub fn lower_bits(value: u8, len: usize) -> u8 {
value & ((1 << len) - 1)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
pub fn test_u8_bits() {
let value : u8 = 0b1100_0011;
assert_eq!(test_nth_bit(value, 6), true);
assert_eq!(lower_bits(value, 6), 0b00_0011);
}
}
\ No newline at end of file
#[inline(always)]
pub fn test_nth_bit(value: u8, index: usize) -> bool {
value & (1 << index) != 0
}
#[inline(always)]
pub fn lower_bits(value: u8, len: usize) -> u8 {
value & ((1 << len) - 1)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
pub fn test_u8_bits() {
let value : u8 = 0b1100_0011;
assert_eq!(test_nth_bit(value, 6), true);
assert_eq!(lower_bits(value, 6), 0b00_0011);
}
}
\ No newline at end of file
extern crate byteorder;
pub type ByteSize = usize;
pub type Word = usize;
#[cfg(target_arch = "x86_64")]
pub const LOG_POINTER_SIZE : usize = 3;
pub const POINTER_SIZE : ByteSize = 1 << LOG_POINTER_SIZE;
pub const WORD_SIZE : ByteSize = 1 << LOG_POINTER_SIZE;
pub mod mem;
mod linked_hashset;
pub use linked_hashset::LinkedHashSet;
pub use linked_hashset::LinkedHashMap;