1
Fork 0

auto merge of #14119 : thestinger/rust/heap, r=cmr

This commit is contained in:
bors 2014-05-11 17:51:41 -07:00
commit 72fc4a5eb7
11 changed files with 44 additions and 34 deletions

2
.gitattributes vendored
View file

@ -7,4 +7,4 @@
src/etc/pkg/rust-logo.ico binary src/etc/pkg/rust-logo.ico binary
src/etc/pkg/rust-logo.png binary src/etc/pkg/rust-logo.png binary
src/rt/msvc/* -whitespace src/rt/msvc/* -whitespace
src/rt/vg/* -whitespace src/rt/valgrind/* -whitespace

View file

@ -36,7 +36,7 @@ LICENSE.txt: $(S)COPYRIGHT $(S)LICENSE-APACHE $(S)LICENSE-MIT
PKG_TAR = dist/$(PKG_NAME).tar.gz PKG_TAR = dist/$(PKG_NAME).tar.gz
PKG_GITMODULES := $(S)src/libuv $(S)src/llvm $(S)src/gyp $(S)src/compiler-rt \ PKG_GITMODULES := $(S)src/libuv $(S)src/llvm $(S)src/gyp $(S)src/compiler-rt \
$(S)src/rt/hoedown $(S)src/rt/hoedown $(S)src/jemalloc
PKG_FILES := \ PKG_FILES := \
$(S)COPYRIGHT \ $(S)COPYRIGHT \
$(S)LICENSE-APACHE \ $(S)LICENSE-APACHE \

View file

@ -260,6 +260,7 @@ $$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS)
CC="$$(CC_$(1))" \ CC="$$(CC_$(1))" \
AR="$$(AR_$(1))" \ AR="$$(AR_$(1))" \
RANLIB="$$(AR_$(1)) s" \ RANLIB="$$(AR_$(1)) s" \
CPPFLAGS="-I $(S)src/rt/" \
EXTRA_CFLAGS="$$(CFG_CFLAGS_$(1))" EXTRA_CFLAGS="$$(CFG_CFLAGS_$(1))"
$$(Q)$$(MAKE) -C "$$(JEMALLOC_BUILD_DIR_$(1))" build_lib_static $$(Q)$$(MAKE) -C "$$(JEMALLOC_BUILD_DIR_$(1))" build_lib_static
$$(Q)cp $$(JEMALLOC_BUILD_DIR_$(1))/lib/$$(JEMALLOC_REAL_NAME_$(1)) $$(JEMALLOC_LIB_$(1)) $$(Q)cp $$(JEMALLOC_BUILD_DIR_$(1))/lib/$$(JEMALLOC_REAL_NAME_$(1)) $$(JEMALLOC_LIB_$(1))

View file

@ -227,8 +227,8 @@ ALL_HS := $(wildcard $(S)src/rt/*.h \
$(S)src/rt/*/*.h \ $(S)src/rt/*/*.h \
$(S)src/rt/*/*/*.h \ $(S)src/rt/*/*/*.h \
$(S)src/rustllvm/*.h) $(S)src/rustllvm/*.h)
ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \ ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
$(S)src/rt/vg/memcheck.h \ $(S)src/rt/valgrind/memcheck.h \
$(S)src/rt/msvc/typeof.h \ $(S)src/rt/msvc/typeof.h \
$(S)src/rt/msvc/stdint.h \ $(S)src/rt/msvc/stdint.h \
$(S)src/rt/msvc/inttypes.h \ $(S)src/rt/msvc/inttypes.h \

View file

@ -33,7 +33,7 @@ use option::{Option, Some, None};
use ptr; use ptr;
use ptr::RawPtr; use ptr::RawPtr;
use mem::{min_align_of, size_of}; use mem::{min_align_of, size_of};
use rt::heap::exchange_free; use rt::heap::deallocate;
struct RcBox<T> { struct RcBox<T> {
value: T, value: T,
@ -105,7 +105,7 @@ impl<T> Drop for Rc<T> {
self.dec_weak(); self.dec_weak();
if self.weak() == 0 { if self.weak() == 0 {
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(), deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
min_align_of::<RcBox<T>>()) min_align_of::<RcBox<T>>())
} }
} }
@ -179,7 +179,7 @@ impl<T> Drop for Weak<T> {
// the weak count starts at 1, and will only go to // the weak count starts at 1, and will only go to
// zero if all the strong pointers have disappeared. // zero if all the strong pointers have disappeared.
if self.weak() == 0 { if self.weak() == 0 {
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(), deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
min_align_of::<RcBox<T>>()) min_align_of::<RcBox<T>>())
} }
} }

View file

@ -12,8 +12,9 @@
// FIXME: #13996: need a way to mark the `allocate` and `reallocate` return values as `noalias` // FIXME: #13996: need a way to mark the `allocate` and `reallocate` return values as `noalias`
use intrinsics::{abort, cttz32}; use intrinsics::{abort, cttz32};
use libc::{c_int, c_void, size_t}; use libc::{c_char, c_int, c_void, size_t};
use ptr::RawPtr; use ptr::{RawPtr, mut_null, null};
use option::{None, Option};
#[link(name = "jemalloc", kind = "static")] #[link(name = "jemalloc", kind = "static")]
extern { extern {
@ -22,6 +23,9 @@ extern {
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t; fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
fn je_dallocx(ptr: *mut c_void, flags: c_int); fn je_dallocx(ptr: *mut c_void, flags: c_int);
fn je_nallocx(size: size_t, flags: c_int) -> size_t; fn je_nallocx(size: size_t, flags: c_int) -> size_t;
fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void, *c_char)>,
cbopaque: *mut c_void,
opts: *c_char);
} }
// -lpthread needs to occur after -ljemalloc, the earlier argument isn't enough // -lpthread needs to occur after -ljemalloc, the earlier argument isn't enough
@ -99,6 +103,16 @@ pub fn usable_size(size: uint, align: uint) -> uint {
unsafe { je_nallocx(size as size_t, mallocx_align(align)) as uint } unsafe { je_nallocx(size as size_t, mallocx_align(align)) as uint }
} }
/// Print implementation-defined allocator statistics.
///
/// These statistics may be inconsistent if other threads use the allocator during the call.
#[unstable]
pub fn stats_print() {
unsafe {
je_malloc_stats_print(None, mut_null(), null())
}
}
/// The allocator for unique pointers. /// The allocator for unique pointers.
#[cfg(stage0)] #[cfg(stage0)]
#[lang="exchange_malloc"] #[lang="exchange_malloc"]
@ -151,13 +165,8 @@ pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
#[lang="exchange_free"] #[lang="exchange_free"]
#[inline] #[inline]
// FIXME: #13994 (rustc should pass align and size here) // FIXME: #13994 (rustc should pass align and size here)
pub unsafe fn exchange_free_(ptr: *mut u8) { unsafe fn exchange_free(ptr: *mut u8) {
exchange_free(ptr, 0, 8) deallocate(ptr, 0, 8);
}
#[inline]
pub unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
deallocate(ptr, size, align);
} }
// FIXME: #7496 // FIXME: #7496
@ -179,8 +188,8 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uin
#[doc(hidden)] #[doc(hidden)]
#[deprecated] #[deprecated]
#[cfg(stage0, not(test))] #[cfg(stage0, not(test))]
pub extern "C" fn rust_malloc(size: uint) -> *mut u8 { pub unsafe extern "C" fn rust_malloc(size: uint) -> *mut u8 {
unsafe { exchange_malloc(size) } exchange_malloc(size)
} }
// hack for libcore // hack for libcore
@ -188,8 +197,8 @@ pub extern "C" fn rust_malloc(size: uint) -> *mut u8 {
#[doc(hidden)] #[doc(hidden)]
#[deprecated] #[deprecated]
#[cfg(not(stage0), not(test))] #[cfg(not(stage0), not(test))]
pub extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 { pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
unsafe { exchange_malloc(size, align) } exchange_malloc(size, align)
} }
// hack for libcore // hack for libcore
@ -197,8 +206,8 @@ pub extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
#[doc(hidden)] #[doc(hidden)]
#[deprecated] #[deprecated]
#[cfg(not(test))] #[cfg(not(test))]
pub extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) { pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
unsafe { exchange_free(ptr, size, align) } deallocate(ptr, size, align)
} }
#[cfg(test)] #[cfg(test)]

View file

@ -109,7 +109,7 @@ use ops::Drop;
use option::{None, Option, Some}; use option::{None, Option, Some};
use ptr::RawPtr; use ptr::RawPtr;
use ptr; use ptr;
use rt::heap::{exchange_malloc, exchange_free}; use rt::heap::{exchange_malloc, deallocate};
use unstable::finally::try_finally; use unstable::finally::try_finally;
use vec::Vec; use vec::Vec;
@ -330,7 +330,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
ptr::read(&*p.offset(j)); ptr::read(&*p.offset(j));
} }
// FIXME: #13994 (should pass align and size here) // FIXME: #13994 (should pass align and size here)
exchange_free(ret as *mut u8, 0, 8); deallocate(ret as *mut u8, 0, 8);
}); });
mem::transmute(ret) mem::transmute(ret)
} }
@ -377,7 +377,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
ptr::read(&*p.offset(j)); ptr::read(&*p.offset(j));
} }
// FIXME: #13994 (should pass align and size here) // FIXME: #13994 (should pass align and size here)
exchange_free(ret as *mut u8, 0, 8); deallocate(ret as *mut u8, 0, 8);
}); });
mem::transmute(ret) mem::transmute(ret)
} }
@ -817,7 +817,7 @@ impl<T> Drop for MoveItems<T> {
for _x in *self {} for _x in *self {}
unsafe { unsafe {
// FIXME: #13994 (should pass align and size here) // FIXME: #13994 (should pass align and size here)
exchange_free(self.allocation, 0, 8) deallocate(self.allocation, 0, 8)
} }
} }
} }

View file

@ -15,7 +15,7 @@
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::rt::heap::exchange_free; use std::rt::heap::deallocate;
use std::sync::atomics; use std::sync::atomics;
use std::mem::{min_align_of, size_of}; use std::mem::{min_align_of, size_of};
@ -191,7 +191,7 @@ impl<T: Share + Send> Drop for Arc<T> {
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 { if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
atomics::fence(atomics::Acquire); atomics::fence(atomics::Acquire);
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(), unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
min_align_of::<ArcInner<T>>()) } min_align_of::<ArcInner<T>>()) }
} }
} }
@ -242,7 +242,7 @@ impl<T: Share + Send> Drop for Weak<T> {
// the memory orderings // the memory orderings
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 { if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
atomics::fence(atomics::Acquire); atomics::fence(atomics::Acquire);
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(), unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
min_align_of::<ArcInner<T>>()) } min_align_of::<ArcInner<T>>()) }
} }
} }

View file

@ -10,7 +10,7 @@
/* Foreign builtins. */ /* Foreign builtins. */
#include "vg/valgrind.h" #include "valgrind/valgrind.h"
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>