Commit 9bea1c6c authored by qinsoon's avatar qinsoon

use offset_of! macro from field_offset

parent 60a4f0c2
...@@ -21,6 +21,7 @@ ast = {path = "src/ast"} ...@@ -21,6 +21,7 @@ ast = {path = "src/ast"}
utils = {path = "src/utils"} utils = {path = "src/utils"}
gc = {path = "src/gc"} gc = {path = "src/gc"}
field-offset = "0.1.1"
libloading = "0.3" libloading = "0.3"
lazy_static = "0.1.15" lazy_static = "0.1.15"
log = "0.3.5" log = "0.3.5"
......
...@@ -23,4 +23,5 @@ log = "0.3.5" ...@@ -23,4 +23,5 @@ log = "0.3.5"
simple_logger = "0.4.0" simple_logger = "0.4.0"
aligned_alloc = "0.1.2" aligned_alloc = "0.1.2"
crossbeam = "0.2.8" crossbeam = "0.2.8"
rustc-serialize = "*" rustc-serialize = "*"
\ No newline at end of file field-offset = "0.1.1"
\ No newline at end of file
...@@ -26,7 +26,6 @@ lazy_static! { ...@@ -26,7 +26,6 @@ lazy_static! {
const TRACE_ALLOC_FASTPATH : bool = true; const TRACE_ALLOC_FASTPATH : bool = true;
#[repr(C)] #[repr(C)]
// do not change the layout (unless change the offset of fields correspondingly)
pub struct ImmixMutatorLocal { pub struct ImmixMutatorLocal {
id : usize, id : usize,
...@@ -53,12 +52,8 @@ pub struct ImmixMutatorLocal { ...@@ -53,12 +52,8 @@ pub struct ImmixMutatorLocal {
} }
lazy_static! { lazy_static! {
pub static ref CURSOR_OFFSET : usize = mem::size_of::<usize>() pub static ref CURSOR_OFFSET : usize = offset_of!(ImmixMutatorLocal=>cursor).get_byte_offset();
+ mem::size_of::<*mut u8>() * 2 pub static ref LIMIT_OFFSET : usize = offset_of!(ImmixMutatorLocal=>limit).get_byte_offset();
+ mem::size_of::<Address>();
pub static ref LIMIT_OFFSET : usize = *CURSOR_OFFSET
+ mem::size_of::<Address>();
} }
pub struct ImmixMutatorGlobal { pub struct ImmixMutatorGlobal {
......
...@@ -7,6 +7,8 @@ extern crate simple_logger; ...@@ -7,6 +7,8 @@ extern crate simple_logger;
extern crate aligned_alloc; extern crate aligned_alloc;
extern crate crossbeam; extern crate crossbeam;
extern crate rustc_serialize; extern crate rustc_serialize;
#[macro_use]
extern crate field_offset;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
......
...@@ -6,6 +6,8 @@ extern crate rustc_serialize; ...@@ -6,6 +6,8 @@ extern crate rustc_serialize;
extern crate stderrlog; extern crate stderrlog;
#[macro_use] #[macro_use]
extern crate maplit; extern crate maplit;
#[macro_use]
extern crate field_offset;
#[macro_use] #[macro_use]
pub extern crate ast; pub extern crate ast;
......
...@@ -197,8 +197,6 @@ pub enum MuStackState { ...@@ -197,8 +197,6 @@ pub enum MuStackState {
} }
#[repr(C)] #[repr(C)]
#[allow(improper_ctypes)]
// do not change the layout (unless change the offset of fields correspondingly)
pub struct MuThread { pub struct MuThread {
pub hdr: MuEntityHeader, pub hdr: MuEntityHeader,
pub allocator: mm::Mutator, pub allocator: mm::Mutator,
...@@ -213,15 +211,10 @@ pub struct MuThread { ...@@ -213,15 +211,10 @@ pub struct MuThread {
// this depends on the layout of MuThread // this depends on the layout of MuThread
lazy_static! { lazy_static! {
pub static ref ALLOCATOR_OFFSET : usize = mem::size_of::<MuEntityHeader>(); pub static ref ALLOCATOR_OFFSET : usize = offset_of!(MuThread=>allocator).get_byte_offset();
pub static ref NATIVE_SP_LOC_OFFSET : usize = offset_of!(MuThread=>native_sp_loc).get_byte_offset();
pub static ref NATIVE_SP_LOC_OFFSET : usize = *ALLOCATOR_OFFSET pub static ref USER_TLS_OFFSET : usize = offset_of!(MuThread=>user_tls).get_byte_offset();
+ mem::size_of::<mm::Mutator>() pub static ref EXCEPTION_OBJ_OFFSET : usize = offset_of!(MuThread=>exception_obj).get_byte_offset();
+ mem::size_of::<Option<Box<MuStack>>>();
pub static ref USER_TLS_OFFSET : usize = *NATIVE_SP_LOC_OFFSET + mem::size_of::<Address>();
pub static ref EXCEPTION_OBJ_OFFSET : usize = *USER_TLS_OFFSET + mem::size_of::<Address>();
} }
impl fmt::Display for MuThread { impl fmt::Display for MuThread {
......
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