Commit 75d70254 authored by Eduardo Souza's avatar Eduardo Souza

Scanning for global roots.

parent 665eaf74
......@@ -1437,7 +1437,7 @@ pub unsafe fn gen_instr_new(
size,
alignment,
LLVMConstInt(LLVMInt64Type(), 0, false as i32),
// LLVMConstInt(LLVMInt32Type(), mu_type as u64, 0),
LLVMConstInt(LLVMInt32Type(), mu_type as u64, 0),
];
let ptr = LLVMBuildCall(
llvm_internal_context.builder,
......
......@@ -267,10 +267,14 @@ fn visit_inst_custom(
let arg_type = Arc::new(MuType::new(0, MuType_::Int(64)));
let llvm_arg_type =
gen_llvm_type(llvm_internal_context, &arg_type);
let arg_type_i32 = Arc::new(MuType::new(0, MuType_::Int(32)));
let llvm_arg_type_i32 =
gen_llvm_type(llvm_internal_context, &arg_type_i32);
let llvm_arg_types = vec![
llvm_arg_type.clone(),
llvm_arg_type.clone(),
llvm_arg_type.clone(),
llvm_arg_type_i32,
];
add_function_to_module(
......
......@@ -24,6 +24,10 @@ use self::mu::utils::LinkedHashMap;
use self::mu::vm::*;
use crate::aot_mu;
use std::path::PathBuf;
use crate::tests::test_call::gen_ccall_exit;
use mu::linkutils;
use self::mu::utils::Address;
use self::mu::runtime::thread::MuThread;
use crate::tests::create_dyn_lib;
use std::sync::Arc;
......@@ -536,6 +540,192 @@ fn gc_mult_call_single_obj_with_gc() -> VM {
vm
}
#[test]
fn test_global_pointer_gc() {
VM::start_logging_trace();
let vm = Arc::new(VM::new_with_opts("init_mu --generate-llvm"));
// unsafe {
// MuThread::current_thread_as_mu_thread(Address::zero(), vm.clone());
// }
global_pointer_gc(&vm);
let mut whitelist = vec![];
let func_id = vm.id_of("foo");
whitelist.push(func_id);
let func_id = vm.id_of("global_pointer_gc");
whitelist.push(func_id);
let primordial_func = vm.handle_from_func(func_id);
// set global by api here
// {
let global_id = vm.id_of("my_global");
let global_handle = vm.handle_from_global(global_id);
// let uint64_10_handle = vm.handle_from_uint64(10, 64);
//
//
//
// debug!(
// "write {:?} to location {:?}",
// uint64_10_handle, global_handle
// );
//
// vm.handle_store(
// MemoryOrder::Relaxed,
// &global_handle,
// &uint64_10_handle
// );
// }
// then emit context (global will be put into context.s
vm.set_primordial_thread(func_id, true, vec![]);
let image_name = String::from("global_access");
aot_mu::make_boot_image_for_testing(
&vm,
whitelist,
Some(&*primordial_func),
None,
None,
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
image_name.clone()
);
// link
let image_location = format!("emit/{}", image_name);
let executable = PathBuf::from(image_location);
let output = linkutils::exec_path_nocheck(executable);
assert!(output.status.code().is_some());
let ret_code = output.status.code().unwrap();
info!("return code: {} (i.e. the value set before)", ret_code);
info!("{:?}", global_handle.v.as_address());
assert!(ret_code == 10);
}
fn global_pointer_gc(vm: &VM) {
typedef! ((vm) int64 = mu_int(64));
typedef! ((vm) ref_int64 = mu_ref(int64));
typedef! ((vm) ref_ref_int64 = mu_ref(ref_int64));
globaldef! ((vm) <ref_int64> my_global);
funcsig! ((vm) foo_sig = () -> ());
funcdecl! ((vm) <foo_sig> foo);
{
// add
funcdef! ((vm) <foo_sig> foo VERSION foo_v1);
block! ((vm, foo_v1) blk_entry);
global! ((vm, foo_v1) blk_entry_my_global = my_global);
// ssa! ((vm, foo_v1) <ref_int64> x);
// inst! ((vm, foo_v1) blk_entry_load:
// x = LOAD blk_entry_my_global (is_ptr: false, order: MemoryOrder::SeqCst)
// );
ssa! ((vm, foo_v1) <int64> i);
inst! ((vm, foo_v1) blk_entry_convop:
i = CONVOP (ConvOp::PTRCAST) <ref_ref_int64 int64> blk_entry_my_global
);
inst! ((vm, foo_v1) blk_entry_print1:
PRINTHEX i
);
inst! ((vm, foo_v1) blk_entry_ret:
RET
);
define_block! ((vm, foo_v1) blk_entry() {
// blk_entry_load,
blk_entry_convop, blk_entry_print1, blk_entry_ret
});
define_func_ver!((vm) foo_v1 (entry: blk_entry) {blk_entry});
}
funcsig! ((vm) sig = () -> (int64));
funcdecl! ((vm) <sig> global_pointer_gc);
funcdef! ((vm) <sig> global_pointer_gc VERSION global_pointer_gc_v1);
// blk entry
block! ((vm, global_pointer_gc_v1) blk_entry);
global! ((vm, global_pointer_gc_v1) blk_entry_my_global = my_global);
ssa! ((vm, global_pointer_gc_v1) <ref_int64> a);
inst! ((vm, global_pointer_gc_v1) blk_entry_new:
a = NEW <int64>
);
inst! ((vm, global_pointer_gc_v1) blk_entry_write:
STORE blk_entry_my_global a (is_ptr: true, order: MemoryOrder::Relaxed)
);
// call trigger gc
funcsig! ((vm) trigger_gc_sig = () -> ());
typedef!((vm) ufp_trigger_gc = mu_ufuncptr(trigger_gc_sig));
constdef!((vm) <ufp_trigger_gc> const_trigger_gc = Constant::ExternSym(C ("trigger_gc_void")));
consta!((vm, global_pointer_gc_v1) const_trigger_gc_local = const_trigger_gc);
inst!((vm, global_pointer_gc_v1) blk_entry_ccall:
EXPRCCALL (CallConvention::Foreign(ForeignFFI::C), is_abort: false) const_trigger_gc_local ()
);
typedef! ((vm) funcref_to_sig = mu_funcref(foo_sig));
constdef! ((vm) <funcref_to_sig> funcref_foo = Constant::FuncRef(foo));
consta! ((vm, global_pointer_gc_v1) funcref_foo_local = funcref_foo);
inst! ((vm, global_pointer_gc_v1) blk_entry_call:
EXPRCALL (CallConvention::Mu, is_abort: false) funcref_foo_local ()
);
ssa! ((vm, global_pointer_gc_v1) <ref_int64> val_ptr);
inst! ((vm, global_pointer_gc_v1) blk_entry_load:
val_ptr = LOAD blk_entry_my_global (is_ptr: false, order: MemoryOrder::SeqCst)
);
ssa! ((vm, global_pointer_gc_v1) <int64> val);
inst! ((vm, global_pointer_gc_v1) blk_entry_load_2:
val = LOAD val_ptr (is_ptr: false, order: MemoryOrder::SeqCst)
);
ssa! ((vm, global_pointer_gc_v1) <ref_int64> b);
inst! ((vm, global_pointer_gc_v1) blk_entry_new_b:
b = NEW <int64>
);
let blk_entry_exit =
gen_ccall_exit(val.clone(), &mut global_pointer_gc_v1, &vm);
// won't execute this inst
inst! ((vm, global_pointer_gc_v1) blk_entry_ret:
RET (val)
);
define_block! ((vm, global_pointer_gc_v1) blk_entry() {
blk_entry_new,
blk_entry_write,
blk_entry_ccall,
blk_entry_call,
blk_entry_load,
blk_entry_load_2,
blk_entry_new_b,
blk_entry_exit, blk_entry_ret
});
define_func_ver!((vm) global_pointer_gc_v1 (entry: blk_entry) {
blk_entry
});
}
#[test]
fn test_gc_mult_call_mult_obj() {
build_and_run_llvm_test!(
......
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