From 14760651617a8e2c85bf0fb7993b4baeb8db61e4 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Oct 2019 01:40:48 +0000 Subject: [PATCH] =?UTF-8?q?servo:=20Merge=20#18944=20-=20Stop=20relying=20?= =?UTF-8?q?on=20linking=20details=20of=20std=E2=80=99s=20default=20allocat?= =?UTF-8?q?or=20(from=20servo:jemallocator2);=20r=3Dnox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve been bitten before by symbol names changing: https://github.com/servo/heapsize/pull/46, and upstream is planning to stop using jemalloc by default: https://github.com/rust-lang/rust/issues/33082#issuecomment-309781465 So use the (relatively) new `#[global_allocator]` attribute to explicitly select the system allocator on Windows and jemalloc (now in an external crate) on other platforms. This choice matches current defaults. Source-Repo: https://github.com/servo/servo Source-Revision: 07e9794306d597afe5d90d192fd32a99572c3cc3 UltraBlame original commit: 921526150768f9a2e9ba1586a350583f9ad025c9 --- servo/Cargo.lock | 459 ++++++++++++++++-- servo/components/allocator/Cargo.toml | 125 +++++ servo/components/allocator/lib.rs | 331 +++++++++++++ servo/components/gfx/Cargo.toml | 12 + servo/components/gfx/lib.rs | 23 + .../gfx/platform/freetype/font_context.rs | 28 +- servo/components/layout_thread/Cargo.toml | 12 + servo/components/layout_thread/lib.rs | 12 +- servo/components/malloc_size_of/Cargo.toml | 23 - servo/components/malloc_size_of/lib.rs | 201 -------- servo/components/profile/Cargo.toml | 23 + servo/components/profile/lib.rs | 60 +-- servo/components/profile/mem.rs | 64 +-- servo/components/script/Cargo.toml | 17 + servo/components/script/lib.rs | 4 + servo/components/script/script_thread.rs | 10 +- servo/ports/servo/Cargo.toml | 5 + servo/python/tidy/servo_tidy/tidy.py | 35 ++ servo/tests/unit/profile/Cargo.toml | 50 ++ servo/tests/unit/profile/lib.rs | 4 + 20 files changed, 1121 insertions(+), 377 deletions(-) create mode 100644 servo/components/allocator/Cargo.toml create mode 100644 servo/components/allocator/lib.rs diff --git a/servo/Cargo.lock b/servo/Cargo.lock index 30f808693f16a..93dd584f52198 100644 --- a/servo/Cargo.lock +++ b/servo/Cargo.lock @@ -14119,6 +14119,14 @@ index ) " " +servo_allocator +0 +. +0 +. +1 +" +" servo_arc 0 . @@ -18727,6 +18735,218 @@ package name = " +jemalloc +- +sys +" +version += +" +0 +. +1 +. +3 +" +source += +" +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +" +dependencies += +[ +" +cc +1 +. +0 +. +1 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +" +libc +0 +. +2 +. +23 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +] +[ +[ +package +] +] +name += +" +jemallocator +" +version += +" +0 +. +1 +. +3 +" +source += +" +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +" +dependencies += +[ +" +jemalloc +- +sys +0 +. +1 +. +3 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +" +libc +0 +. +2 +. +23 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +] +[ +[ +package +] +] +name += +" jpeg - decoder @@ -20595,6 +20815,14 @@ index ) " " +servo_allocator +0 +. +0 +. +1 +" +" servo_arc 0 . @@ -22283,37 +22511,6 @@ mozjs ) " " -kernel32 -- -sys -0 -. -2 -. -2 -( -registry -+ -https -: -/ -/ -github -. -com -/ -rust -- -lang -/ -crates -. -io -- -index -) -" -" servo_arc 0 . @@ -30561,6 +30758,37 @@ index ) " " +jemalloc +- +sys +0 +. +1 +. +3 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +" libc 0 . @@ -30828,6 +31056,14 @@ profile_traits . 1 " +" +servo_allocator +0 +. +0 +. +1 +" ] [ [ @@ -34443,6 +34679,14 @@ index ) " " +servo_allocator +0 +. +0 +. +1 +" +" servo_arc 0 . @@ -38774,6 +39018,89 @@ package name = " +servo_allocator +" +version += +" +0 +. +0 +. +1 +" +dependencies += +[ +" +jemallocator +0 +. +1 +. +3 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +" +kernel32 +- +sys +0 +. +2 +. +2 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" +] +[ +[ +package +] +] +name += +" servo_arc " version @@ -54249,6 +54576,76 @@ eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c " " checksum +jemalloc +- +sys +0 +. +1 +. +3 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" += +" +94fb624d7e8345e5c42caab8d1db6ec925fdadff3fd0cb7dd781b41be8442828 +" +" +checksum +jemallocator +0 +. +1 +. +3 +( +registry ++ +https +: +/ +/ +github +. +com +/ +rust +- +lang +/ +crates +. +io +- +index +) +" += +" +1850725977c344d63af66e8fd00857646e3ec936c490cd63667860b7b03ab5c1 +" +" +checksum jpeg - decoder diff --git a/servo/components/allocator/Cargo.toml b/servo/components/allocator/Cargo.toml new file mode 100644 index 0000000000000..8ecf79f775b13 --- /dev/null +++ b/servo/components/allocator/Cargo.toml @@ -0,0 +1,125 @@ +[ +package +] +name += +" +servo_allocator +" +version += +" +0 +. +0 +. +1 +" +authors += +[ +" +The +Servo +Project +Developers +" +] +license += +" +MPL +- +2 +. +0 +" +publish += +false +[ +lib +] +path += +" +lib +. +rs +" +[ +features +] +unstable += +[ +" +kernel32 +- +sys +" +" +jemallocator +" +] +[ +target +. +' +cfg +( +not +( +windows +) +) +' +. +dependencies +] +jemallocator += +{ +version += +" +0 +. +1 +. +3 +" +optional += +true +} +[ +target +. +' +cfg +( +windows +) +' +. +dependencies +] +kernel32 +- +sys += +{ +version += +" +0 +. +2 +. +1 +" +optional += +true +} diff --git a/servo/components/allocator/lib.rs b/servo/components/allocator/lib.rs new file mode 100644 index 0000000000000..4e39065fabd25 --- /dev/null +++ b/servo/components/allocator/lib.rs @@ -0,0 +1,331 @@ +# +! +[ +cfg_attr +( +all +( +feature += +" +unstable +" +windows +) +feature +( +alloc_system +allocator_api +) +) +] +# +! +[ +cfg_attr +( +feature += +" +unstable +" +feature +( +global_allocator +) +) +] +# +[ +cfg +( +feature += +" +unstable +" +) +] +# +[ +global_allocator +] +static +ALLOC +: +platform +: +: +Allocator += +platform +: +: +Allocator +; +pub +use +platform +: +: +usable_size +; +# +[ +cfg +( +all +( +feature += +" +unstable +" +not +( +windows +) +) +) +] +mod +platform +{ +extern +crate +jemallocator +; +pub +use +self +: +: +jemallocator +: +: +Jemalloc +as +Allocator +; +use +std +: +: +os +: +: +raw +: +: +c_void +; +pub +unsafe +extern +" +C +" +fn +usable_size +( +ptr +: +* +const +c_void +) +- +> +usize +{ +jemallocator +: +: +usable_size +( +ptr +) +} +} +# +[ +cfg +( +all +( +feature += +" +unstable +" +windows +) +) +] +mod +platform +{ +extern +crate +alloc_system +; +extern +crate +kernel32 +; +pub +use +self +: +: +alloc_system +: +: +System +as +Allocator +; +use +self +: +: +kernel32 +: +: +{ +GetProcessHeap +HeapSize +HeapValidate +} +; +use +std +: +: +os +: +: +raw +: +: +c_void +; +pub +unsafe +extern +" +C +" +fn +usable_size +( +mut +ptr +: +* +const +c_void +) +- +> +usize +{ +let +heap += +GetProcessHeap +( +) +; +if +HeapValidate +( +heap +0 +ptr +) += += +0 +{ +ptr += +* +( +ptr +as +* +const +* +const +c_void +) +. +offset +( +- +1 +) +; +} +HeapSize +( +heap +0 +ptr +) +as +usize +} +} +# +[ +cfg +( +not +( +feature += +" +unstable +" +) +) +] +mod +platform +{ +use +std +: +: +os +: +: +raw +: +: +c_void +; +pub +unsafe +extern +" +C +" +fn +usable_size +( +_ptr +: +* +const +c_void +) +- +> +usize +{ +0 +} +} diff --git a/servo/components/gfx/Cargo.toml b/servo/components/gfx/Cargo.toml index ed304073e7736..70bc0b2dae872 100644 --- a/servo/components/gfx/Cargo.toml +++ b/servo/components/gfx/Cargo.toml @@ -487,6 +487,18 @@ freetype . 3 " +servo_allocator += +{ +path += +" +. +. +/ +allocator +" +} [ target . diff --git a/servo/components/gfx/lib.rs b/servo/components/gfx/lib.rs index 4c2425eb12afb..57375ec16d8e1 100644 --- a/servo/components/gfx/lib.rs +++ b/servo/components/gfx/lib.rs @@ -174,6 +174,29 @@ extern crate freetype ; +# +[ +cfg +( +any +( +target_os += +" +linux +" +target_os += +" +android +" +) +) +] +extern +crate +servo_allocator +; extern crate gfx_traits diff --git a/servo/components/gfx/platform/freetype/font_context.rs b/servo/components/gfx/platform/freetype/font_context.rs index 92a4b8b708d19..eca517ac8ad60 100644 --- a/servo/components/gfx/platform/freetype/font_context.rs +++ b/servo/components/gfx/platform/freetype/font_context.rs @@ -57,12 +57,17 @@ malloc_size_of : : { -malloc_size_of MallocSizeOf MallocSizeOfOps } ; use +servo_allocator +: +: +usable_size +; +use std : : @@ -184,7 +189,7 @@ unsafe let actual_size = -malloc_size_of +usable_size ( ptr as @@ -239,7 +244,7 @@ unsafe let actual_size = -malloc_size_of +usable_size ( ptr as @@ -314,7 +319,7 @@ ft_realloc mem : FT_Memory -_cur_size +old_size : c_long new_req_size @@ -343,7 +348,7 @@ unsafe { old_actual_size = -malloc_size_of +usable_size ( old_ptr as @@ -352,6 +357,13 @@ const _ ) ; +let +old_size += +old_size +as +usize +; vec = Vec @@ -369,8 +381,8 @@ as * mut u8 -old_actual_size -old_actual_size +old_size +old_size ) ; } @@ -441,7 +453,7 @@ unsafe let new_actual_size = -malloc_size_of +usable_size ( new_ptr as diff --git a/servo/components/layout_thread/Cargo.toml b/servo/components/layout_thread/Cargo.toml index fa728d8172623..94478c9bc769a 100644 --- a/servo/components/layout_thread/Cargo.toml +++ b/servo/components/layout_thread/Cargo.toml @@ -342,6 +342,18 @@ serde_json . 0 " +servo_allocator += +{ +path += +" +. +. +/ +allocator +" +} servo_arc = { diff --git a/servo/components/layout_thread/lib.rs b/servo/components/layout_thread/lib.rs index f4b4cce9306f7..594a80a67e190 100644 --- a/servo/components/layout_thread/lib.rs +++ b/servo/components/layout_thread/lib.rs @@ -136,6 +136,10 @@ serde_json ; extern crate +servo_allocator +; +extern +crate servo_arc ; extern @@ -486,7 +490,6 @@ malloc_size_of : : { -malloc_size_of MallocSizeOf MallocSizeOfOps } @@ -4325,7 +4328,12 @@ MallocSizeOfOps : new ( -malloc_size_of +: +: +servo_allocator +: +: +usable_size None None ) diff --git a/servo/components/malloc_size_of/Cargo.toml b/servo/components/malloc_size_of/Cargo.toml index 0f80d18938cc0..fbe285fa032e7 100644 --- a/servo/components/malloc_size_of/Cargo.toml +++ b/servo/components/malloc_size_of/Cargo.toml @@ -50,29 +50,6 @@ lib rs " [ -target -. -' -cfg -( -windows -) -' -. -dependencies -] -kernel32 -- -sys -= -" -0 -. -2 -. -1 -" -[ features ] servo diff --git a/servo/components/malloc_size_of/lib.rs b/servo/components/malloc_size_of/lib.rs index aa6ad2401cb8f..d7e8eb531383e 100644 --- a/servo/components/malloc_size_of/lib.rs +++ b/servo/components/malloc_size_of/lib.rs @@ -29,21 +29,6 @@ extern crate js ; -# -[ -cfg -( -target_os -= -" -windows -" -) -] -extern -crate -kernel32 -; extern crate servo_arc @@ -116,27 +101,6 @@ extern crate xml5ever ; -# -[ -cfg -( -target_os -= -" -windows -" -) -] -use -kernel32 -: -: -{ -GetProcessHeap -HeapSize -HeapValidate -} -; use std : @@ -477,171 +441,6 @@ c_void ) } } -# -[ -cfg -( -not -( -target_os -= -" -windows -" -) -) -] -pub -unsafe -extern -" -C -" -fn -malloc_size_of -( -ptr -: -* -const -c_void -) -- -> -usize -{ -extern -" -C -" -{ -# -[ -cfg_attr -( -any -( -prefixed_jemalloc -target_os -= -" -macos -" -target_os -= -" -ios -" -target_os -= -" -android -" -) -link_name -= -" -je_malloc_usable_size -" -) -] -fn -malloc_usable_size -( -ptr -: -* -const -c_void -) -- -> -usize -; -} -malloc_usable_size -( -ptr -) -} -# -[ -cfg -( -target_os -= -" -windows -" -) -] -pub -unsafe -extern -" -C -" -fn -malloc_size_of -( -mut -ptr -: -* -const -c_void -) -- -> -usize -{ -let -heap -= -GetProcessHeap -( -) -; -if -HeapValidate -( -heap -0 -ptr -) -= -= -0 -{ -ptr -= -* -( -ptr -as -* -const -* -const -c_void -) -. -offset -( -- -1 -) -; -} -HeapSize -( -heap -0 -ptr -) -as -usize -} pub trait MallocSizeOf diff --git a/servo/components/profile/Cargo.toml b/servo/components/profile/Cargo.toml index a3524e1793dff..b480f29c837ed 100644 --- a/servo/components/profile/Cargo.toml +++ b/servo/components/profile/Cargo.toml @@ -58,6 +58,11 @@ features unstable = [ +" +jemalloc +- +sys +" ] [ dependencies @@ -227,3 +232,21 @@ libc . 2 " +jemalloc +- +sys += +{ +version += +" +0 +. +1 +. +3 +" +optional += +true +} diff --git a/servo/components/profile/lib.rs b/servo/components/profile/lib.rs index 67880bd0bed21..18105beeeebdb 100644 --- a/servo/components/profile/lib.rs +++ b/servo/components/profile/lib.rs @@ -1,33 +1,6 @@ # ! [ -cfg_attr -( -all -( -feature -= -" -unstable -" -not -( -target_os -= -" -windows -" -) -) -feature -( -alloc_jemalloc -) -) -] -# -! -[ deny ( unsafe_code @@ -40,6 +13,18 @@ allow unused_extern_crates ) ] +extern +crate +heartbeats_simple +; +extern +crate +influent +; +extern +crate +ipc_channel +; # [ cfg @@ -64,29 +49,10 @@ windows ] extern crate -alloc_jemalloc -; -extern -crate -heartbeats_simple -; -extern -crate -influent -; -extern -crate -ipc_channel +jemalloc_sys ; # [ -allow -( -unused_extern_crates -) -] -# -[ cfg ( not diff --git a/servo/components/profile/mem.rs b/servo/components/profile/mem.rs index 684a05ed6085f..075eaac181b6c 100644 --- a/servo/components/profile/mem.rs +++ b/servo/components/profile/mem.rs @@ -1858,7 +1858,6 @@ libc : : { -c_char c_void size_t } @@ -2419,69 +2418,12 @@ windows ) ) ] -extern -{ -# -[ -cfg_attr -( -any -( -target_os -= -" -macos -" -target_os -= -" -android -" -) -link_name -= -" -je_mallctl -" -) -] -fn -mallctl -( -name -: -* -const -c_char -oldp -: -* -mut -c_void -oldlenp -: -* -mut -size_t -newp -: -* -mut -c_void -newlen -: -size_t -) -- -> -: -: -libc +use +jemalloc_sys : : -c_int +mallctl ; -} # [ cfg diff --git a/servo/components/script/Cargo.toml b/servo/components/script/Cargo.toml index ce453bf5b2b07..ef88c8fdf8ef3 100644 --- a/servo/components/script/Cargo.toml +++ b/servo/components/script/Cargo.toml @@ -74,6 +74,11 @@ debugmozjs unstable = [ +" +servo_allocator +/ +unstable +" ] [ build @@ -669,6 +674,18 @@ serde . 0 " +servo_allocator += +{ +path += +" +. +. +/ +allocator +" +} servo_arc = { diff --git a/servo/components/script/lib.rs b/servo/components/script/lib.rs index 245616c6ddc97..992e2cad11a6a 100644 --- a/servo/components/script/lib.rs +++ b/servo/components/script/lib.rs @@ -378,6 +378,10 @@ serde ; extern crate +servo_allocator +; +extern +crate servo_arc ; # diff --git a/servo/components/script/script_thread.rs b/servo/components/script/script_thread.rs index 5388823067d18..46225f915a5f2 100644 --- a/servo/components/script/script_thread.rs +++ b/servo/components/script/script_thread.rs @@ -632,10 +632,7 @@ use malloc_size_of : : -{ -malloc_size_of MallocSizeOfOps -} ; use mem @@ -9589,7 +9586,12 @@ MallocSizeOfOps : new ( -malloc_size_of +: +: +servo_allocator +: +: +usable_size None None ) diff --git a/servo/ports/servo/Cargo.toml b/servo/ports/servo/Cargo.toml index 8041bf945b428..cc97100414570 100644 --- a/servo/ports/servo/Cargo.toml +++ b/servo/ports/servo/Cargo.toml @@ -416,6 +416,11 @@ libservo / unstable " +" +profile_tests +/ +unstable +" ] [ dependencies diff --git a/servo/python/tidy/servo_tidy/tidy.py b/servo/python/tidy/servo_tidy/tidy.py index f31f91e64dcf0..c0ce4ffceeede 100644 --- a/servo/python/tidy/servo_tidy/tidy.py +++ b/servo/python/tidy/servo_tidy/tidy.py @@ -5679,6 +5679,41 @@ = crate_name +if +line += += +" +} +" +: + +for +i +in +[ +i +for +i +in +prev_crate +. +keys +( +) +if +i +> +indent +] +: + +del +prev_crate +[ +i +] + if is_lib_rs_file : diff --git a/servo/tests/unit/profile/Cargo.toml b/servo/tests/unit/profile/Cargo.toml index acd5eed20e1d9..b6235d5979345 100644 --- a/servo/tests/unit/profile/Cargo.toml +++ b/servo/tests/unit/profile/Cargo.toml @@ -53,6 +53,18 @@ doctest = false [ +features +] +unstable += +[ +" +servo_allocator +/ +unstable +" +] +[ dependencies ] ipc @@ -104,3 +116,41 @@ components profile_traits " } +# +Work +around +https +: +/ +/ +github +. +com +/ +alexcrichton +/ +jemallocator +/ +issues +/ +19 +servo_allocator += +{ +path += +" +. +. +/ +. +. +/ +. +. +/ +components +/ +allocator +" +} diff --git a/servo/tests/unit/profile/lib.rs b/servo/tests/unit/profile/lib.rs index 641a6a915dd8b..b3243e6473cf4 100644 --- a/servo/tests/unit/profile/lib.rs +++ b/servo/tests/unit/profile/lib.rs @@ -10,6 +10,10 @@ extern crate profile_traits ; +extern +crate +servo_allocator +; # [ cfg