1212// FIXME: #13996: need a way to mark the `allocate` and `reallocate` return values as `noalias`
1313
1414use 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" ) ]
1920extern {
@@ -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) ]
0 commit comments