Commit 01136bf7 authored by Yi Lin's avatar Yi Lin

Merge branch 'issue83-memory-leak' into 'develop'

Issue83 memory leak

See merge request !24
parents 2ad245a8 eb0e9514
......@@ -16,7 +16,8 @@ use std::mem;
use utils::POINTER_SIZE;
use utils::LOG_POINTER_SIZE;
use utils::Address;
use heap::gc::malloc_zero;
use utils::mem::malloc_zero;
use utils::mem::memsec::free;
#[derive(Clone)]
pub struct AddressMap<T: Copy> {
......@@ -64,3 +65,12 @@ where
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 @@
// limitations under the License.
use std::mem;
use heap::gc::malloc_zero;
use utils::mem::malloc_zero;
use utils::mem::memsec::free;
#[derive(Clone)]
pub struct Bitmap {
......@@ -136,6 +136,12 @@ impl Bitmap {
}
}
impl Drop for Bitmap {
fn drop(&mut self) {
unsafe { free(self.bitmap) }
}
}
#[cfg(test)]
mod test {
use super::*;
......
......@@ -25,14 +25,6 @@ low_water_mark:
.xword 0
.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
# X0
begin_func immmix_get_stack_ptr
......
......@@ -16,12 +16,6 @@
#include <stdlib.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 rsp;
// get current rsp, rbp (this C func frame)
......
......@@ -19,12 +19,6 @@
#include <assert.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 rsp;
// get current rsp, rbp (this C func frame)
......
......@@ -64,11 +64,9 @@ pub fn trigger_gc() {
}
}
use std::os::raw::c_void;
#[cfg(target_arch = "x86_64")]
#[link(name = "gc_clib_x64")]
extern "C" {
pub fn malloc_zero(size: usize) -> *const c_void;
fn immmix_get_stack_ptr() -> Address;
pub fn set_low_water_mark();
fn get_low_water_mark() -> Address;
......@@ -79,7 +77,6 @@ extern "C" {
#[cfg(target_arch = "aarch64")]
#[link(name = "gc_clib_aarch64")]
extern "C" {
pub fn malloc_zero(size: usize) -> *const c_void;
fn immmix_get_stack_ptr() -> Address;
pub fn set_low_water_mark();
fn get_low_water_mark() -> Address;
......
......@@ -16,8 +16,7 @@ use heap::immix;
use heap::gc;
use utils::Address;
use common::AddressMap;
use heap::gc::malloc_zero;
use utils::mem::malloc_zero;
use utils::mem::memmap;
use utils::mem::memsec;
......@@ -118,6 +117,12 @@ impl LineMarkTable {
}
}
impl Drop for LineMarkTable {
fn drop(&mut self) {
unsafe { memsec::free(self.ptr) }
}
}
impl LineMarkTableSlice {
#[inline(always)]
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,
}
}
/// destroys current GC instance
#[no_mangle]
pub extern "C" fn gc_destoy() {
*MY_GC.write().unwrap() = None;
}
/// creates a mutator
#[no_mangle]
pub extern "C" fn new_mutator() -> ImmixMutatorLocal {
......
......@@ -21,6 +21,18 @@ use Word;
#[allow(unused_imports)] // import both endianness (we may not use big endian though)
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
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub fn u64_to_raw(val: u64) -> Word {
......
......@@ -193,6 +193,12 @@ macro_rules! gen_handle_int {
}
}
impl Drop for VM {
fn drop(&mut self) {
self.destroy();
}
}
impl<'a> VM {
/// creates a VM with default options
pub fn new() -> VM {
......@@ -370,6 +376,11 @@ impl<'a> VM {
}
}
/// cleans up currenet VM
fn destroy(&mut self) {
gc::gc_destoy();
}
/// adds an exception callsite and catch block
/// (later we will use this info to build an exception table for unwinding use)
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