Commit cea4c431 authored by qinsoon's avatar qinsoon

[wip] cannot persist heap into a shared lib (need to use PIC code)

parent ff556adc
......@@ -10,7 +10,6 @@ use ast::types::*;
use utils::Address;
use compiler::backend::RegGroup;
use compiler::backend::BackendTypeInfo;
use vm::VM;
use runtime::ValueLocation;
use runtime::thread::MuThread;
......
......@@ -274,12 +274,14 @@ impl MuThread {
#[allow(unused_unsafe)]
// pieces of this function are not safe (we want to mark it unsafe)
// this function is exposed as unsafe because it is not always safe to call it
pub unsafe fn current_thread_as_mu_thread(threadlocal: Address, vm: Arc<VM>) {
/// returns true if we have created MuThread on this call
/// (false means we had MuThread for current thread before)
pub unsafe fn current_thread_as_mu_thread(threadlocal: Address, vm: Arc<VM>) -> bool {
use std::usize;
if ! unsafe{muentry_get_thread_local()}.is_zero() {
warn!("current thread has a thread local (has a muthread to it)");
return;
return false;
}
// fake a stack for current thread
......@@ -333,17 +335,20 @@ impl MuThread {
// unsafe {
// fake_swap_mu_thread(sp_threadlocal_loc);
// }
true
}
/// turn this current mu thread back as normal thread
#[allow(unused_variables)]
pub unsafe fn cleanup_current_mu_thread() {
let mu_thread_addr = unsafe {muentry_get_thread_local()};
let mu_thread_addr = muentry_get_thread_local();
if !mu_thread_addr.is_zero() {
let mu_thread : *mut MuThread = mu_thread_addr.to_ptr_mut();
mm::drop_mutator(&mut (*mu_thread).allocator as *mut mm::Mutator);
let mu_thread : Box<MuThread> = unsafe {Box::from_raw(mu_thread)};
let mu_thread : Box<MuThread> = Box::from_raw(mu_thread);
// drop mu_thread here
}
......
......@@ -54,6 +54,11 @@ impl MuIRBuilder {
unsafe { & *self.mvm }
}
#[inline(always)]
fn get_mvm_immutable<'a, 'b>(&'a self) -> &'b MuVM {
unsafe { & *self.mvm }
}
#[inline(always)]
fn get_vm<'a, 'b>(&'a mut self) -> &'b VM {
&self.get_mvm().vm
......@@ -1859,7 +1864,8 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
fn add_everything_to_vm(&mut self) {
let vm = self.vm;
let vm = self.b.get_mvm_immutable().vm.clone();
let arc_vm = vm.clone();
trace!("Loading bundle to the VM...");
......@@ -1871,6 +1877,7 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
&mut self.built_globals,
&mut self.built_funcs,
&mut self.built_funcvers,
arc_vm
);
trace!("Bundle loaded to the VM!");
......
......@@ -100,7 +100,7 @@ impl MuVM {
thread::MuThread::current_thread_as_mu_thread(
transmute::<CMuCPtr, Address>(threadlocal),
self.vm.clone()
)
);
}
}
......
......@@ -20,6 +20,7 @@ use vm::vm_options::MuLogLevel;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
use log::LogLevel;
use std::sync::Arc;
use std::path;
use std::sync::RwLock;
use std::sync::RwLockWriteGuard;
......@@ -757,7 +758,8 @@ impl <'a> VM {
new_constants: &mut HashMap<MuID, P<Value>>,
new_globals: &mut HashMap<MuID, P<Value>>,
new_funcs: &mut HashMap<MuID, Box<MuFunction>>,
new_func_vers: &mut HashMap<MuID, Box<MuFunctionVersion>>
new_func_vers: &mut HashMap<MuID, Box<MuFunctionVersion>>,
arc_vm: Arc<VM>
) {
// Make sure other components, if ever acquiring multiple locks at the same time, acquire
// them in this order, to prevent deadlock.
......@@ -817,11 +819,15 @@ impl <'a> VM {
let mut global_locs = self.global_locations.write().unwrap();
// make sure current thread has allocator
// MuThread::current_thread_as_mu_thread(unsafe {Address::zero()}, self);
let created = unsafe {MuThread::current_thread_as_mu_thread(Address::zero(), arc_vm.clone())};
for (id, global) in globals.iter() {
self.alloc_global(&mut global_locs, *id, global.clone());
}
if created {
unsafe {MuThread::cleanup_current_mu_thread()};
}
}
}
......@@ -1135,7 +1141,7 @@ impl <'a> VM {
v : APIHandleValue::Double(val)
}
}
Value_::Constant(Constant::FuncRef(id)) => {
Value_::Constant(Constant::FuncRef(_)) => {
unimplemented!()
}
Value_::Constant(Constant::NullRef) => {
......
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