Commit 0b181a27 authored by qinsoon's avatar qinsoon

Merge branch 'develop' into swapstack

parents 49cf6e58 8a1a2d3f
// Copyright 2017 The Australian National University // Copyright 2017 The Australian National University
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -17,20 +17,32 @@ extern crate gcc; ...@@ -17,20 +17,32 @@ extern crate gcc;
#[cfg(any(target_os = "macos", target_os = "linux"))] #[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
fn build_libgc() { fn build_libgc() {
gcc::Build::new().flag("-O3").flag("-c").file("src/heap/gc/clib_x64.c").compile("libgc_clib_x64.a"); gcc::Build::new()
.flag("-O3")
.flag("-c")
.file("src/heap/gc/clib_x64.c")
.compile("libgc_clib_x64.a");
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
fn build_libgc() { fn build_libgc() {
gcc::Build::new().flag("-O3").flag("-c").file("src/heap/gc/clib_aarch64.S").compile("libgc_clib_aarch64.a"); gcc::Build::new()
.flag("-O3")
.flag("-c")
.file("src/heap/gc/clib_aarch64.S")
.compile("libgc_clib_aarch64.a");
} }
// This is here to enable cross compiling from windows/x86_64 to linux/aarch64 // This is here to enable cross compiling from windows/x86_64 to linux/aarch64
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
fn build_libgc() { fn build_libgc() {
gcc::Build::new().flag("-O3").flag("-c").file("src/heap/gc/clib_aarch64.S").compile("libgc_clib_aarch64.a"); gcc::Build::new()
.flag("-O3")
.flag("-c")
.file("src/heap/gc/clib_aarch64.S")
.compile("libgc_clib_aarch64.a");
} }
// Due to bugs, it is currently not possible to use conditional compilation \ // Due to bugs, it is currently not possible to use conditional compilation \
...@@ -56,9 +68,13 @@ fn main() { ...@@ -56,9 +68,13 @@ fn main() {
use std::path::Path; use std::path::Path;
let mut compiler_name = String::new(); let mut compiler_name = String::new();
compiler_name.push_str("x86_64-rumprun-netbsd-gcc"); compiler_name.push_str("x86_64-rumprun-netbsd-gcc");
gcc::Build::new().flag("-O3").flag("-c") gcc::Build::new()
.flag("-O3")
.flag("-c")
.compiler(Path::new(compiler_name.as_str())) .compiler(Path::new(compiler_name.as_str()))
.file("src/heap/gc/clib_x64_sel4_rumprun.c") .file("src/heap/gc/clib_x64_sel4_rumprun.c")
.compile("libgc_clib_x64.a"); .compile("libgc_clib_x64.a");
} else { build_libgc(); } } else {
build_libgc();
}
} }
...@@ -16,7 +16,8 @@ use std::mem; ...@@ -16,7 +16,8 @@ use std::mem;
use utils::POINTER_SIZE; use utils::POINTER_SIZE;
use utils::LOG_POINTER_SIZE; use utils::LOG_POINTER_SIZE;
use utils::Address; use utils::Address;
use heap::gc::malloc_zero; use utils::mem::malloc_zero;
use utils::mem::memsec::free;
#[derive(Clone)] #[derive(Clone)]
pub struct AddressMap<T: Copy> { pub struct AddressMap<T: Copy> {
...@@ -64,3 +65,12 @@ where ...@@ -64,3 +65,12 @@ where
unsafe { *self.ptr.offset(index) } unsafe { *self.ptr.offset(index) }
} }
} }
impl<T> Drop for AddressMap<T>
where
T: Copy
{
fn drop(&mut self) {
unsafe { free(self.ptr) }
}
}
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
// limitations under the License. // limitations under the License.
use std::mem; use std::mem;
use utils::mem::malloc_zero;
use heap::gc::malloc_zero; use utils::mem::memsec::free;
#[derive(Clone)] #[derive(Clone)]
pub struct Bitmap { pub struct Bitmap {
...@@ -136,6 +136,12 @@ impl Bitmap { ...@@ -136,6 +136,12 @@ impl Bitmap {
} }
} }
impl Drop for Bitmap {
fn drop(&mut self) {
unsafe { free(self.bitmap) }
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
......
...@@ -25,14 +25,6 @@ low_water_mark: ...@@ -25,14 +25,6 @@ low_water_mark:
.xword 0 .xword 0
.size low_water_mark, 8 .size low_water_mark, 8
#malloc_zero(size_t size) -> void*
# X0 X0
begin_func malloc_zero
MOV X1, X0 // X1 = size
MOV X0, #1
B calloc // tail call calloc(1, size)
end_func malloc_zero
#immmix_get_stack_ptr() -> uintptr_t #immmix_get_stack_ptr() -> uintptr_t
# X0 # X0
begin_func immmix_get_stack_ptr begin_func immmix_get_stack_ptr
......
...@@ -16,12 +16,6 @@ ...@@ -16,12 +16,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
void* malloc_zero(size_t size) {
void* ret = malloc(size);
memset(ret, 0, size);
return ret;
}
uintptr_t immmix_get_stack_ptr() { uintptr_t immmix_get_stack_ptr() {
uintptr_t rsp; uintptr_t rsp;
// get current rsp, rbp (this C func frame) // get current rsp, rbp (this C func frame)
......
...@@ -19,12 +19,6 @@ ...@@ -19,12 +19,6 @@
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
void* malloc_zero(size_t size) {
void* ret = malloc(size);
memset(ret, 0, size);
return ret;
}
uintptr_t immmix_get_stack_ptr() { uintptr_t immmix_get_stack_ptr() {
uintptr_t rsp; uintptr_t rsp;
// get current rsp, rbp (this C func frame) // get current rsp, rbp (this C func frame)
......
...@@ -64,11 +64,9 @@ pub fn trigger_gc() { ...@@ -64,11 +64,9 @@ pub fn trigger_gc() {
} }
} }
use std::os::raw::c_void;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[link(name = "gc_clib_x64")] #[link(name = "gc_clib_x64")]
extern "C" { extern "C" {
pub fn malloc_zero(size: usize) -> *const c_void;
fn immmix_get_stack_ptr() -> Address; fn immmix_get_stack_ptr() -> Address;
pub fn set_low_water_mark(); pub fn set_low_water_mark();
fn get_low_water_mark() -> Address; fn get_low_water_mark() -> Address;
...@@ -79,7 +77,6 @@ extern "C" { ...@@ -79,7 +77,6 @@ extern "C" {
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
#[link(name = "gc_clib_aarch64")] #[link(name = "gc_clib_aarch64")]
extern "C" { extern "C" {
pub fn malloc_zero(size: usize) -> *const c_void;
fn immmix_get_stack_ptr() -> Address; fn immmix_get_stack_ptr() -> Address;
pub fn set_low_water_mark(); pub fn set_low_water_mark();
fn get_low_water_mark() -> Address; fn get_low_water_mark() -> Address;
......
...@@ -16,8 +16,7 @@ use heap::immix; ...@@ -16,8 +16,7 @@ use heap::immix;
use heap::gc; use heap::gc;
use utils::Address; use utils::Address;
use common::AddressMap; use common::AddressMap;
use heap::gc::malloc_zero; use utils::mem::malloc_zero;
use utils::mem::memmap; use utils::mem::memmap;
use utils::mem::memsec; use utils::mem::memsec;
...@@ -118,6 +117,12 @@ impl LineMarkTable { ...@@ -118,6 +117,12 @@ impl LineMarkTable {
} }
} }
impl Drop for LineMarkTable {
fn drop(&mut self) {
unsafe { memsec::free(self.ptr) }
}
}
impl LineMarkTableSlice { impl LineMarkTableSlice {
#[inline(always)] #[inline(always)]
pub fn get(&self, index: usize) -> immix::LineMark { pub fn get(&self, index: usize) -> immix::LineMark {
......
...@@ -182,6 +182,12 @@ pub extern "C" fn gc_init(immix_size: usize, lo_size: usize, n_gcthreads: usize, ...@@ -182,6 +182,12 @@ pub extern "C" fn gc_init(immix_size: usize, lo_size: usize, n_gcthreads: usize,
} }
} }
/// destroys current GC instance
#[no_mangle]
pub extern "C" fn gc_destoy() {
*MY_GC.write().unwrap() = None;
}
/// creates a mutator /// creates a mutator
#[no_mangle] #[no_mangle]
pub extern "C" fn new_mutator() -> ImmixMutatorLocal { pub extern "C" fn new_mutator() -> ImmixMutatorLocal {
......
...@@ -20,6 +20,18 @@ pub extern crate memsec; ...@@ -20,6 +20,18 @@ pub extern crate memsec;
#[allow(unused_imports)] // import both endianness (we may not use big endian though) #[allow(unused_imports)] // import both endianness (we may not use big endian though)
use byteorder::{LittleEndian, BigEndian, ReadBytesExt, WriteBytesExt, ByteOrder}; use byteorder::{LittleEndian, BigEndian, ReadBytesExt, WriteBytesExt, ByteOrder};
/// malloc's and zeroes the memory
pub unsafe fn malloc_zero(size: usize) -> *mut u8 {
use self::memsec;
match memsec::malloc(size) {
Some(ptr) => {
memsec::memzero(ptr, size);
ptr
}
None => panic!("failed to malloc_zero() {} bytes", size)
}
}
/// returns bit representations for u64 /// returns bit representations for u64
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub fn u64_to_raw(val: u64) -> u64 { pub fn u64_to_raw(val: u64) -> u64 {
......
...@@ -202,6 +202,12 @@ macro_rules! gen_handle_int { ...@@ -202,6 +202,12 @@ macro_rules! gen_handle_int {
} }
} }
impl Drop for VM {
fn drop(&mut self) {
self.destroy();
}
}
impl<'a> VM { impl<'a> VM {
/// creates a VM with default options /// creates a VM with default options
pub fn new() -> VM { pub fn new() -> VM {
...@@ -380,6 +386,11 @@ impl<'a> VM { ...@@ -380,6 +386,11 @@ impl<'a> VM {
} }
} }
/// cleans up currenet VM
fn destroy(&mut self) {
gc::gc_destoy();
}
/// adds an exception callsite and catch block /// adds an exception callsite and catch block
/// (later we will use this info to build an exception table for unwinding use) /// (later we will use this info to build an exception table for unwinding use)
pub fn add_exception_callsite(&self, callsite: Callsite, fv: MuID) { pub fn add_exception_callsite(&self, callsite: Callsite, fv: MuID) {
......
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