Commit 86819838 authored by qinsoon's avatar qinsoon

check_alignment agains min alignment before allocate

parent a247e2b2
......@@ -2764,12 +2764,12 @@ pub fn emit_context(vm: &VM) {
// global_cell_name:
let global_cell_name = symbol(global_value.name().unwrap());
file.write_fmt(format_args!("\t{}\n", directive_globl(global_cell_name.clone()))).unwrap();
file.write_fmt(format_args!("\t{}:\n", global_cell_name)).unwrap();
file.write_fmt(format_args!("{}:\n", global_cell_name)).unwrap();
// .globl dump_label
// dump_label:
let dump_label = symbol(global_dump.relocatable_refs.get(&obj_dump.reference_addr).unwrap().clone());
file.write_fmt(format_args!("\t{}\n", directive_globl(dump_label.clone()))).unwrap();
file.write_fmt(format_args!("\t{}:\n", dump_label)).unwrap();
file.write_fmt(format_args!("{}:\n", dump_label)).unwrap();
let base = obj_dump.reference_addr;
let mut cursor = obj_dump.reference_addr;
......
......@@ -128,16 +128,15 @@ pub fn resolve_backend_type_info (ty: &MuType, vm: &VM) -> BackendTypeInfo {
size : ele_ty.size * len,
alignment : ele_ty.alignment,
struct_layout: None,
gc_type : mm::add_gc_type(GCType {
id : GCTYPE_INIT_ID,
size : ele_ty.size * len,
alignment: ele_ty.alignment,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern{
pattern: RefPattern::NestedType(vec![ele_ty.gc_type]),
count : len
})
})
gc_type : mm::add_gc_type(GCType::new(GCTYPE_INIT_ID,
ele_ty.size * len,
ele_ty.alignment,
None,
Some(RepeatingRefPattern{
pattern: RefPattern::NestedType(vec![ele_ty.gc_type]),
count : len
})
))
}
}
// struct
......@@ -247,20 +246,18 @@ fn layout_struct(tys: &Vec<P<MuType>>, vm: &VM) -> BackendTypeInfo {
size : size,
alignment : struct_align,
struct_layout: Some(offsets),
gc_type : mm::add_gc_type(GCType {
id : GCTYPE_INIT_ID,
size : size,
alignment: struct_align,
non_repeat_refs: Some(if use_ref_offsets {
RefPattern::Map {
offsets: ref_offsets,
size: size
}
} else {
RefPattern::NestedType(gc_types)
}),
repeat_refs : None
})
gc_type : mm::add_gc_type(GCType::new(GCTYPE_INIT_ID,
size,
struct_align,
Some(if use_ref_offsets {
RefPattern::Map {
offsets: ref_offsets,
size: size
}
} else {
RefPattern::NestedType(gc_types)
}),
None))
}
}
......
......@@ -3,6 +3,7 @@
use std::sync::Arc;
use utils::POINTER_SIZE;
use utils::ByteSize;
use objectmodel;
use std::u32;
pub const GCTYPE_INIT_ID: u32 = u32::MAX;
......@@ -11,12 +12,22 @@ pub const GCTYPE_INIT_ID: u32 = u32::MAX;
pub struct GCType {
pub id: u32,
pub size: ByteSize,
pub alignment: ByteSize,
alignment: ByteSize,
pub non_repeat_refs: Option<RefPattern>,
pub repeat_refs : Option<RepeatingRefPattern>,
}
impl GCType {
pub fn new(id: u32, size: ByteSize, alignment: ByteSize, non_repeat_refs: Option<RefPattern>, repeat_refs: Option<RepeatingRefPattern>) -> GCType {
GCType {
id: id,
size: size,
alignment: objectmodel::check_alignment(alignment),
non_repeat_refs: non_repeat_refs,
repeat_refs: repeat_refs
}
}
pub fn new_noreftype(size: ByteSize, align: ByteSize) -> GCType {
GCType {
id: GCTYPE_INIT_ID,
......
......@@ -140,7 +140,10 @@ impl ImmixMutatorLocal {
#[inline(always)]
pub fn alloc(&mut self, size: usize, align: usize) -> Address {
// this part of code will slow down allocation
let align = objectmodel::check_alignment(align);
let size = size + objectmodel::OBJECT_HEADER_SIZE;
// end
let start = self.cursor.align_up(align);
let end = start.plus(size);
......@@ -155,7 +158,8 @@ impl ImmixMutatorLocal {
process::exit(102);
}
}
// this offset should be removed as well (for performance)
ret.offset(-objectmodel::OBJECT_HEADER_OFFSET)
} else {
if cfg!(debug_assertions) {
......
......@@ -34,6 +34,8 @@ use utils::{Address, ObjectReference};
use utils::POINTER_SIZE;
use utils::LOG_POINTER_SIZE;
pub const MINIMAL_ALIGNMENT : ByteSize = 8;
pub const OBJECT_HEADER_SIZE : ByteSize = 8;
pub const OBJECT_HEADER_OFFSET : ByteOffset = - (OBJECT_HEADER_SIZE as ByteOffset);
......@@ -270,16 +272,14 @@ mod tests {
#[test]
fn gctype_to_encode1() {
// linked list: struct {ref, int64}
let a = GCType{
id: 0,
size: 16,
alignment: 8,
non_repeat_refs: Some(RefPattern::Map{
offsets: vec![0],
size: 16
}),
repeat_refs : None
};
let a = GCType::new(0,
16,
8,
Some(RefPattern::Map{
offsets: vec![0],
size: 16
}),
None);
println!("gctype: {:?}", a);
let encode = gen_gctype_encode(&a);
......@@ -293,16 +293,14 @@ mod tests {
#[test]
fn gctype_to_encode2() {
// doubly linked list: struct {ref, ref, int64, int64}
let a = GCType{
id: 0,
size: 32,
alignment: 8,
non_repeat_refs: Some(RefPattern::Map{
offsets: vec![0, 8],
size: 32
}),
repeat_refs : None
};
let a = GCType::new(0,
32,
8,
Some(RefPattern::Map{
offsets: vec![0, 8],
size: 32
}),
None);
println!("gctype: {:?}", a);
let encode = gen_gctype_encode(&a);
......@@ -317,16 +315,15 @@ mod tests {
fn gctype_to_encode3() {
// a struct of 64 references
const N_REF : usize = 64;
let a = GCType{
id: 999,
alignment: 8,
size: N_REF * POINTER_SIZE,
non_repeat_refs: Some(RefPattern::Map{
offsets: (0..N_REF).map(|x| x * POINTER_SIZE).collect(),
size: N_REF * POINTER_SIZE
}),
repeat_refs : None
};
let a = GCType::new(999,
N_REF * POINTER_SIZE,
8,
Some(RefPattern::Map{
offsets: (0..N_REF).map(|x| x * POINTER_SIZE).collect(),
size: N_REF * POINTER_SIZE
}),
None
);
println!("gctype: {:?}", a);
let encode = gen_gctype_encode(&a);
......@@ -339,19 +336,17 @@ mod tests {
#[test]
fn gctype_to_encode4() {
// array of struct {ref, int64} with length 10
let a = GCType {
id: 1,
size: 160,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::Map{
offsets: vec![0],
size : 16
},
count : 10
}),
};
let a = GCType::new(1,
160,
8,
None,
Some(RepeatingRefPattern {
pattern: RefPattern::Map{
offsets: vec![0],
size : 16
},
count : 10
}));
println!("gctype: {:?}", a);
let encode = gen_gctype_encode(&a);
......@@ -365,31 +360,27 @@ mod tests {
#[test]
fn gctype_to_encode5() {
// array of struct {ref, int64} with length 10
let b = GCType {
id: 1,
size: 160,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::Map{
offsets: vec![0],
size : 16
},
count : 10
}),
};
let b = GCType::new(1,
160,
8,
None,
Some(RepeatingRefPattern {
pattern: RefPattern::Map{
offsets: vec![0],
size : 16
},
count : 10
}));
// array(10) of array(10) of struct {ref, int64}
let a = GCType {
id: 2,
size: 1600,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::NestedType(vec![Arc::new(b.clone()).clone()]),
count : 10
})
};
let a = GCType::new(2,
1600,
8,
None,
Some(RepeatingRefPattern {
pattern: RefPattern::NestedType(vec![Arc::new(b.clone()).clone()]),
count : 10
}));
println!("gctype: {:?}", a);
let encode = gen_gctype_encode(&a);
......
use std::sync::atomic;
use utils::ByteSize;
#[cfg(feature = "use-sidemap")]
mod sidemap;
......@@ -27,11 +28,22 @@ pub fn flip(mark: u8) -> u8 {
mark ^ 1
}
#[inline(always)]
pub fn check_alignment(align: ByteSize) -> ByteSize {
if align < MINIMAL_ALIGNMENT {
MINIMAL_ALIGNMENT
} else {
align
}
}
// --- sidemap object model ---
#[cfg(feature = "use-sidemap")]
pub use self::sidemap::gen_gctype_encode;
#[cfg(feature = "use-sidemap")]
pub use self::sidemap::MINIMAL_ALIGNMENT;
#[cfg(feature = "use-sidemap")]
pub use self::sidemap::OBJECT_HEADER_SIZE;
#[cfg(feature = "use-sidemap")]
......@@ -81,6 +93,8 @@ pub use self::header::SHR_HYBRID_LENGTH;
// header location/size
#[cfg(not(feature = "use-sidemap"))]
pub use self::header::MINIMAL_ALIGNMENT;
#[cfg(not(feature = "use-sidemap"))]
pub use self::header::OBJECT_HEADER_SIZE;
#[cfg(not(feature = "use-sidemap"))]
pub use self::header::OBJECT_HEADER_OFFSET;
......
......@@ -5,6 +5,8 @@ use utils::{LOG_POINTER_SIZE, POINTER_SIZE};
use utils::bit_utils;
use utils::{ByteSize, ByteOffset};
pub const MINIMAL_ALIGNMENT : ByteSize = 1;
pub const OBJECT_HEADER_SIZE : ByteSize = 0;
pub const OBJECT_HEADER_OFFSET : ByteOffset = 0;
......
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