From 92430894eee925c58cb94919256c3efff08dcdf9 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 22 May 2018 17:33:55 +0200 Subject: [PATCH 1/5] Update to latest jemallocator and jemalloc-sys --- Cargo.lock | 14 +++++- components/allocator/Cargo.toml | 4 +- components/allocator/lib.rs | 81 ++------------------------------- 3 files changed, 19 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c72223c03857..412d02fc482e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1328,10 +1328,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "jemalloc-sys" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "jemallocator" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "jemalloc-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/components/allocator/Cargo.toml b/components/allocator/Cargo.toml index c3c27357cbfd..4f97162269fa 100644 --- a/components/allocator/Cargo.toml +++ b/components/allocator/Cargo.toml @@ -9,13 +9,13 @@ publish = false path = "lib.rs" [features] -unstable = ["kernel32-sys", "jemalloc-sys"] +unstable = ["kernel32-sys", "jemallocator"] [dependencies] libc = "0.2" # Only used when 'unstable' is disabled, but looks like Cargo cannot express that. [target.'cfg(not(windows))'.dependencies] -jemalloc-sys = { version = "0.1.4", optional = true } +jemallocator = { version = "0.1.8", optional = true } [target.'cfg(windows)'.dependencies] kernel32-sys = { version = "0.2.1", optional = true } diff --git a/components/allocator/lib.rs b/components/allocator/lib.rs index 3d933599688a..10379e04dd3e 100644 --- a/components/allocator/lib.rs +++ b/components/allocator/lib.rs @@ -12,93 +12,22 @@ static ALLOC: Allocator = Allocator; pub use platform::*; - #[cfg(all(feature = "unstable", not(windows)))] mod platform { - extern crate jemalloc_sys as ffi; + extern crate jemallocator; + pub use self::jemallocator::Jemalloc as Allocator; use std::alloc::{GlobalAlloc, Layout, Opaque, System}; - use std::os::raw::{c_int, c_void}; + use std::os::raw::{void}; /// Get the size of a heap block. pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize { - ffi::malloc_usable_size(ptr as *const _) + jemallocator::usable_size(ptr as *const _) } /// Memory allocation APIs compatible with libc pub mod libc_compat { - pub use super::ffi::{malloc, realloc, free}; - } - - pub struct Allocator; - - // The minimum alignment guaranteed by the architecture. This value is used to - // add fast paths for low alignment values. - #[cfg(all(any(target_arch = "arm", - target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc")))] - const MIN_ALIGN: usize = 8; - #[cfg(all(any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "powerpc64", - target_arch = "powerpc64le", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")))] - const MIN_ALIGN: usize = 16; - - fn layout_to_flags(align: usize, size: usize) -> c_int { - // If our alignment is less than the minimum alignment they we may not - // have to pass special flags asking for a higher alignment. If the - // alignment is greater than the size, however, then this hits a sort of odd - // case where we still need to ask for a custom alignment. See #25 for more - // info. - if align <= MIN_ALIGN && align <= size { - 0 - } else { - // Equivalent to the MALLOCX_ALIGN(a) macro. - align.trailing_zeros() as _ - } - } - - unsafe impl GlobalAlloc for Allocator { - #[inline] - unsafe fn alloc(&self, layout: Layout) -> *mut Opaque { - let flags = layout_to_flags(layout.align(), layout.size()); - ffi::mallocx(layout.size(), flags) as *mut Opaque - } - - #[inline] - unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque { - if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { - ffi::calloc(1, layout.size()) as *mut Opaque - } else { - let flags = layout_to_flags(layout.align(), layout.size()) | ffi::MALLOCX_ZERO; - ffi::mallocx(layout.size(), flags) as *mut Opaque - } - } - - #[inline] - unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) { - let flags = layout_to_flags(layout.align(), layout.size()); - ffi::sdallocx(ptr as *mut _, layout.size(), flags) - } - - #[inline] - unsafe fn realloc(&self, - ptr: *mut Opaque, - layout: Layout, - new_size: usize) -> *mut Opaque { - let flags = layout_to_flags(layout.align(), new_size); - ffi::rallocx(ptr as *mut _, new_size, flags) as *mut Opaque - } - - #[inline] - fn oom(&self) -> ! { - System.oom() - } + pub use super::jemallocator::ffi::{malloc, realloc, free}; } } From 7610232ce6fb862dc98931e9d83507164785a6b6 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 22 May 2018 19:00:54 +0200 Subject: [PATCH 2/5] properly update the Cargo.lock --- Cargo.lock | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 412d02fc482e..38ceee8557a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,7 +110,7 @@ name = "backtrace-sys" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -312,7 +312,7 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.5" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -395,7 +395,7 @@ name = "cmake" version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -923,6 +923,11 @@ dependencies = [ "servo-freetype-sys 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "fs_extra" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -1526,7 +1531,7 @@ name = "libloading" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1577,7 +1582,7 @@ name = "libz-sys" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1757,7 +1762,7 @@ name = "miniz-sys" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1800,7 +1805,7 @@ name = "mozangle" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2087,7 +2092,7 @@ name = "openssl-sys" version = "0.9.27" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2245,7 +2250,7 @@ dependencies = [ "heartbeats-simple 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "influent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jemalloc-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "jemalloc-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "profile_traits 0.0.1", @@ -2802,7 +2807,7 @@ dependencies = [ name = "servo_allocator" version = "0.0.1" dependencies = [ - "jemalloc-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "jemallocator 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3136,7 +3141,7 @@ dependencies = [ name = "task_info" version = "0.0.1" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3231,7 +3236,7 @@ name = "tinyfiledialogs" version = "3.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3788,7 +3793,7 @@ dependencies = [ "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1b7db437d718977f6dc9b2e3fd6fc343c02ac6b899b73fdd2179163447bd9ce9" "checksum caseless 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3261638034d9db4f94a666ebb16494846341ae5a8456c05c1616d66980cf39a" -"checksum cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9be26b24e988625409b19736d130f0c7d224f01d06454b5f81d8d23d6c1a618f" +"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba" "checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum cgl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "80f05e25f9631fdee56693110feda284a49308ca1e768857a0ad3906cfc1502a" @@ -3840,6 +3845,7 @@ dependencies = [ "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b659e75b7a7338fe75afd7f909fc2b71937845cffb6ebe54ba2e50f13d8e903d" +"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futf 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "51f93f3de6ba1794dcd5810b3546d004600a59a98266487c8407bc4b24e398f3" @@ -3877,7 +3883,8 @@ dependencies = [ "checksum itertools 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b07332223953b5051bceb67e8c4700aa65291535568e1f12408c43c4a42c0394" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" -"checksum jemalloc-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "479294d130502fada93c7a957e8d059b632b03d6204aca37af557dee947f30a9" +"checksum jemalloc-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "982f9c2b89a08b6fba50b3b5cbe2bc764a40a67ce6301d3d6ab10c4d8c9332cc" +"checksum jemallocator 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b9df699f98eb274d8d20a8f7082b8a694eb45b93609fcb5c2965e8c8f2ceb26" "checksum jpeg-decoder 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0dfe27a6c0dabd772d0f9b9f8701c4ca12c4d1eebcadf2be1f6f70396f6a1434" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum khronos_api 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9ef23fcc4059260c5936f638c9805ebfc87cb172fa6661d130cba7f97d58f55" From 7c514e888971d93e01dc8f4fa3cdb32a41582091 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 22 May 2018 19:32:48 +0200 Subject: [PATCH 3/5] fix style --- components/allocator/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/allocator/lib.rs b/components/allocator/lib.rs index 10379e04dd3e..8e44a27e45c7 100644 --- a/components/allocator/lib.rs +++ b/components/allocator/lib.rs @@ -18,7 +18,7 @@ mod platform { pub use self::jemallocator::Jemalloc as Allocator; use std::alloc::{GlobalAlloc, Layout, Opaque, System}; - use std::os::raw::{void}; + use std::os::raw::c_void; /// Get the size of a heap block. pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize { From 023eebd1049d15c606a52e6696061ce2a0a03f5d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 30 May 2018 12:48:04 +0200 Subject: [PATCH 4/5] disable jemallocator default features (bg_thread) on all targets --- components/allocator/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/allocator/Cargo.toml b/components/allocator/Cargo.toml index 4f97162269fa..7fb9785de5eb 100644 --- a/components/allocator/Cargo.toml +++ b/components/allocator/Cargo.toml @@ -15,7 +15,7 @@ unstable = ["kernel32-sys", "jemallocator"] libc = "0.2" # Only used when 'unstable' is disabled, but looks like Cargo cannot express that. [target.'cfg(not(windows))'.dependencies] -jemallocator = { version = "0.1.8", optional = true } +jemallocator = { version = "0.1.8", default-features = false, optional = true } [target.'cfg(windows)'.dependencies] kernel32-sys = { version = "0.2.1", optional = true } From 68f67504adc49f154f3763c102df450008145a83 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 30 May 2018 13:18:15 +0200 Subject: [PATCH 5/5] fixup --- components/allocator/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/components/allocator/lib.rs b/components/allocator/lib.rs index 8e44a27e45c7..262e302e6be7 100644 --- a/components/allocator/lib.rs +++ b/components/allocator/lib.rs @@ -17,7 +17,6 @@ mod platform { extern crate jemallocator; pub use self::jemallocator::Jemalloc as Allocator; - use std::alloc::{GlobalAlloc, Layout, Opaque, System}; use std::os::raw::c_void; /// Get the size of a heap block.