Skip to content

Commit 72fc4a5

Browse files
committed
auto merge of #14119 : thestinger/rust/heap, r=cmr
2 parents b40c3e9 + f1735ce commit 72fc4a5

File tree

11 files changed

+44
-34
lines changed

11 files changed

+44
-34
lines changed

Diff for: .gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
src/etc/pkg/rust-logo.ico binary
88
src/etc/pkg/rust-logo.png binary
99
src/rt/msvc/* -whitespace
10-
src/rt/vg/* -whitespace
10+
src/rt/valgrind/* -whitespace

Diff for: mk/dist.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ LICENSE.txt: $(S)COPYRIGHT $(S)LICENSE-APACHE $(S)LICENSE-MIT
3636
PKG_TAR = dist/$(PKG_NAME).tar.gz
3737

3838
PKG_GITMODULES := $(S)src/libuv $(S)src/llvm $(S)src/gyp $(S)src/compiler-rt \
39-
$(S)src/rt/hoedown
39+
$(S)src/rt/hoedown $(S)src/jemalloc
4040
PKG_FILES := \
4141
$(S)COPYRIGHT \
4242
$(S)LICENSE-APACHE \

Diff for: mk/rt.mk

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ $$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS)
260260
CC="$$(CC_$(1))" \
261261
AR="$$(AR_$(1))" \
262262
RANLIB="$$(AR_$(1)) s" \
263+
CPPFLAGS="-I $(S)src/rt/" \
263264
EXTRA_CFLAGS="$$(CFG_CFLAGS_$(1))"
264265
$$(Q)$$(MAKE) -C "$$(JEMALLOC_BUILD_DIR_$(1))" build_lib_static
265266
$$(Q)cp $$(JEMALLOC_BUILD_DIR_$(1))/lib/$$(JEMALLOC_REAL_NAME_$(1)) $$(JEMALLOC_LIB_$(1))

Diff for: mk/tests.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ ALL_HS := $(wildcard $(S)src/rt/*.h \
227227
$(S)src/rt/*/*.h \
228228
$(S)src/rt/*/*/*.h \
229229
$(S)src/rustllvm/*.h)
230-
ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
231-
$(S)src/rt/vg/memcheck.h \
230+
ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
231+
$(S)src/rt/valgrind/memcheck.h \
232232
$(S)src/rt/msvc/typeof.h \
233233
$(S)src/rt/msvc/stdint.h \
234234
$(S)src/rt/msvc/inttypes.h \

Diff for: src/libstd/rc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use option::{Option, Some, None};
3333
use ptr;
3434
use ptr::RawPtr;
3535
use mem::{min_align_of, size_of};
36-
use rt::heap::exchange_free;
36+
use rt::heap::deallocate;
3737

3838
struct RcBox<T> {
3939
value: T,
@@ -105,8 +105,8 @@ impl<T> Drop for Rc<T> {
105105
self.dec_weak();
106106

107107
if self.weak() == 0 {
108-
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(),
109-
min_align_of::<RcBox<T>>())
108+
deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
109+
min_align_of::<RcBox<T>>())
110110
}
111111
}
112112
}
@@ -179,8 +179,8 @@ impl<T> Drop for Weak<T> {
179179
// the weak count starts at 1, and will only go to
180180
// zero if all the strong pointers have disappeared.
181181
if self.weak() == 0 {
182-
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(),
183-
min_align_of::<RcBox<T>>())
182+
deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
183+
min_align_of::<RcBox<T>>())
184184
}
185185
}
186186
}

Diff for: src/libstd/rt/heap.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
// FIXME: #13996: need a way to mark the `allocate` and `reallocate` return values as `noalias`
1313

1414
use intrinsics::{abort, cttz32};
15-
use libc::{c_int, c_void, size_t};
16-
use ptr::RawPtr;
15+
use libc::{c_char, c_int, c_void, size_t};
16+
use ptr::{RawPtr, mut_null, null};
17+
use option::{None, Option};
1718

1819
#[link(name = "jemalloc", kind = "static")]
1920
extern {
@@ -22,6 +23,9 @@ extern {
2223
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
2324
fn je_dallocx(ptr: *mut c_void, flags: c_int);
2425
fn je_nallocx(size: size_t, flags: c_int) -> size_t;
26+
fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void, *c_char)>,
27+
cbopaque: *mut c_void,
28+
opts: *c_char);
2529
}
2630

2731
// -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 {
99103
unsafe { je_nallocx(size as size_t, mallocx_align(align)) as uint }
100104
}
101105

106+
/// Print implementation-defined allocator statistics.
107+
///
108+
/// These statistics may be inconsistent if other threads use the allocator during the call.
109+
#[unstable]
110+
pub fn stats_print() {
111+
unsafe {
112+
je_malloc_stats_print(None, mut_null(), null())
113+
}
114+
}
115+
102116
/// The allocator for unique pointers.
103117
#[cfg(stage0)]
104118
#[lang="exchange_malloc"]
@@ -151,13 +165,8 @@ pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
151165
#[lang="exchange_free"]
152166
#[inline]
153167
// FIXME: #13994 (rustc should pass align and size here)
154-
pub unsafe fn exchange_free_(ptr: *mut u8) {
155-
exchange_free(ptr, 0, 8)
156-
}
157-
158-
#[inline]
159-
pub unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
160-
deallocate(ptr, size, align);
168+
unsafe fn exchange_free(ptr: *mut u8) {
169+
deallocate(ptr, 0, 8);
161170
}
162171

163172
// FIXME: #7496
@@ -179,26 +188,26 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uin
179188
#[doc(hidden)]
180189
#[deprecated]
181190
#[cfg(stage0, not(test))]
182-
pub extern "C" fn rust_malloc(size: uint) -> *mut u8 {
183-
unsafe { exchange_malloc(size) }
191+
pub unsafe extern "C" fn rust_malloc(size: uint) -> *mut u8 {
192+
exchange_malloc(size)
184193
}
185194

186195
// hack for libcore
187196
#[no_mangle]
188197
#[doc(hidden)]
189198
#[deprecated]
190199
#[cfg(not(stage0), not(test))]
191-
pub extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
192-
unsafe { exchange_malloc(size, align) }
200+
pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
201+
exchange_malloc(size, align)
193202
}
194203

195204
// hack for libcore
196205
#[no_mangle]
197206
#[doc(hidden)]
198207
#[deprecated]
199208
#[cfg(not(test))]
200-
pub extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
201-
unsafe { exchange_free(ptr, size, align) }
209+
pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
210+
deallocate(ptr, size, align)
202211
}
203212

204213
#[cfg(test)]

Diff for: src/libstd/slice.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use ops::Drop;
109109
use option::{None, Option, Some};
110110
use ptr::RawPtr;
111111
use ptr;
112-
use rt::heap::{exchange_malloc, exchange_free};
112+
use rt::heap::{exchange_malloc, deallocate};
113113
use unstable::finally::try_finally;
114114
use vec::Vec;
115115

@@ -330,7 +330,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
330330
ptr::read(&*p.offset(j));
331331
}
332332
// FIXME: #13994 (should pass align and size here)
333-
exchange_free(ret as *mut u8, 0, 8);
333+
deallocate(ret as *mut u8, 0, 8);
334334
});
335335
mem::transmute(ret)
336336
}
@@ -377,7 +377,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
377377
ptr::read(&*p.offset(j));
378378
}
379379
// FIXME: #13994 (should pass align and size here)
380-
exchange_free(ret as *mut u8, 0, 8);
380+
deallocate(ret as *mut u8, 0, 8);
381381
});
382382
mem::transmute(ret)
383383
}
@@ -817,7 +817,7 @@ impl<T> Drop for MoveItems<T> {
817817
for _x in *self {}
818818
unsafe {
819819
// FIXME: #13994 (should pass align and size here)
820-
exchange_free(self.allocation, 0, 8)
820+
deallocate(self.allocation, 0, 8)
821821
}
822822
}
823823
}

Diff for: src/libsync/arc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use std::mem;
1717
use std::ptr;
18-
use std::rt::heap::exchange_free;
18+
use std::rt::heap::deallocate;
1919
use std::sync::atomics;
2020
use std::mem::{min_align_of, size_of};
2121

@@ -191,8 +191,8 @@ impl<T: Share + Send> Drop for Arc<T> {
191191

192192
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
193193
atomics::fence(atomics::Acquire);
194-
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(),
195-
min_align_of::<ArcInner<T>>()) }
194+
unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
195+
min_align_of::<ArcInner<T>>()) }
196196
}
197197
}
198198
}
@@ -242,8 +242,8 @@ impl<T: Share + Send> Drop for Weak<T> {
242242
// the memory orderings
243243
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
244244
atomics::fence(atomics::Acquire);
245-
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(),
246-
min_align_of::<ArcInner<T>>()) }
245+
unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
246+
min_align_of::<ArcInner<T>>()) }
247247
}
248248
}
249249
}

Diff for: src/rt/rust_builtin.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/* Foreign builtins. */
1212

13-
#include "vg/valgrind.h"
13+
#include "valgrind/valgrind.h"
1414

1515
#include <stdint.h>
1616
#include <time.h>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)