Commit 81d6c0b6 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Implemented primordial threadlocals

parent fad24db1
......@@ -3578,7 +3578,8 @@ use std::collections::HashMap;
pub fn emit_context_with_reloc(
vm: &VM,
symbols: HashMap<Address, MuName>,
fields: HashMap<Address, MuName>
fields: HashMap<Address, MuName>,
primordial_threadlocal: Option<Address>
) {
use std::path;
use std::io::prelude::*;
......@@ -3604,7 +3605,7 @@ pub fn emit_context_with_reloc(
// data
writeln!(file, ".data").unwrap();
{
let primordial_threadlocal = {
use runtime::mm;
// persist globals
......@@ -3720,6 +3721,11 @@ pub fn emit_context_with_reloc(
offset += POINTER_SIZE;
}
}
primordial_threadlocal.map(|a| relocatable_refs.get(&a).unwrap().clone())
};
{
let mut lock = vm.primordial_threadlocal.write().unwrap();
*lock = primordial_threadlocal;
}
// serialize vm
......@@ -3752,7 +3758,7 @@ pub fn emit_context_with_reloc(
}
pub fn emit_context(vm: &VM) {
emit_context_with_reloc(vm, hashmap!{}, hashmap!{});
emit_context_with_reloc(vm, hashmap!{}, hashmap!{}, None);
}
fn write_data_bytes(f: &mut File, from: Address, to: Address) {
......
......@@ -4097,7 +4097,8 @@ use compiler::backend::code_emission::emit_mu_types;
pub fn emit_context_with_reloc(
vm: &VM,
symbols: HashMap<Address, MuName>,
fields: HashMap<Address, MuName>
fields: HashMap<Address, MuName>,
primordial_threadlocal: Option<Address>
) {
use std::path;
use std::io::prelude::*;
......@@ -4129,7 +4130,7 @@ pub fn emit_context_with_reloc(
file.write("\t.data\n".as_bytes()).unwrap();
// persist heap - we traverse the heap from globals
{
let primordial_threadlocal = {
use runtime::mm;
let global_locs_lock = vm.global_locations().read().unwrap();
......@@ -4257,8 +4258,13 @@ pub fn emit_context_with_reloc(
offset += POINTER_SIZE;
}
}
}
primordial_threadlocal.map(|a| relocatable_refs.get(&a).unwrap().clone())
};
{
let mut lock = vm.primordial_threadlocal.write().unwrap();
*lock = primordial_threadlocal;
}
// serialize vm, and put it to boot image
// currently using rustc_serialize to persist vm as json string.
// Deserializing from this is extremely slow, we need to fix this. See Issue #41
......@@ -4289,7 +4295,7 @@ pub fn emit_context_with_reloc(
/// emit vm context for current session,
/// without consideration about relocation symbols/fields from the client
pub fn emit_context(vm: &VM) {
emit_context_with_reloc(vm, hashmap!{}, hashmap!{});
emit_context_with_reloc(vm, hashmap!{}, hashmap!{}, None);
}
/// writes raw bytes from memory between from_address (inclusive) to to_address (exclusive)
......
......@@ -305,8 +305,13 @@ pub extern "C" fn mu_main(
args
};
// FIXME: currently assumes no user defined thread local - See Issue #48
thread::MuThread::new_thread_normal(stack, unsafe { Address::zero() }, args, vm.clone());
let threadlocal = vm.primordial_threadlocal
.read()
.unwrap()
.as_ref()
.map(|name| resolve_symbol(Arc::new(name.clone())))
.unwrap_or(unsafe { Address::zero() });
thread::MuThread::new_thread_normal(stack, threadlocal, args, vm.clone());
loop {
let thread = vm.pop_join_handle();
......
......@@ -121,6 +121,7 @@ pub struct VM {
/// a map from callsite address to CompiledCallsite
compiled_callsite_table: RwLock<HashMap<Address, CompiledCallsite>>, // 896
pub primordial_threadlocal: RwLock<Option<String>>,
/// Nnmber of callsites in the callsite tables
callsite_count: AtomicUsize,
......@@ -169,6 +170,7 @@ unsafe impl rodal::Dump for VM {
RwLock::new(rodal::EmptyHashMap::<Address, CompiledCallsite>::new());
dumper.dump_object_here(&compiled_callsite_table);
dumper.dump_object(&self.primordial_threadlocal);
dumper.dump_object(&self.callsite_count);
dumper.dump_padding(&self.pending_joins);
......@@ -244,6 +246,7 @@ impl<'a> VM {
primordial: RwLock::new(None),
aot_pending_funcref_store: RwLock::new(HashMap::new()),
compiled_callsite_table: RwLock::new(HashMap::new()),
primordial_threadlocal: RwLock::new(None),
callsite_count: ATOMIC_USIZE_INIT,
pending_joins: Mutex::new(LinkedList::new())
};
......@@ -1160,11 +1163,6 @@ impl<'a> VM {
whitelist_funcs
};
if primordial_threadlocal.is_some() {
// we are going to need to persist this threadlocal
unimplemented!()
}
let has_primordial_func = primordial_func.is_some();
let has_primordial_stack = primordial_stack.is_some();
......@@ -1217,7 +1215,12 @@ impl<'a> VM {
};
// emit context (persist vm, etc)
backend::emit_context_with_reloc(self, symbols, fields);
backend::emit_context_with_reloc(
self,
symbols,
fields,
primordial_threadlocal.map(|x| x.v.as_ref().1)
);
// link
self.link_boot_image(whitelist_funcs, extra_sources_to_link, output_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