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..cfdb0bd13f72d --- /dev/null +++ b/servo/components/allocator/lib.rs @@ -0,0 +1,458 @@ +/ +* +This +Source +Code +Form +is +subject +to +the +terms +of +the +Mozilla +Public +* +License +v +. +2 +. +0 +. +If +a +copy +of +the +MPL +was +not +distributed +with +this +* +file +You +can +obtain +one +at +http +: +/ +/ +mozilla +. +org +/ +MPL +/ +2 +. +0 +/ +. +* +/ +/ +/ +! +Selecting +the +default +global +allocator +for +Servo +# +! +[ +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 +; +/ +/ +/ +Get +the +size +of +a +heap +block +. +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 +; +/ +/ +/ +Get +the +size +of +a +heap +block +. +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 +; +/ +/ +/ +Without +# +[ +global_allocator +] +we +cannot +be +certain +of +what +allocator +is +used +/ +/ +/ +or +how +it +is +linked +. +We +therefore +disable +memory +reporting +. +( +Return +zero +. +) +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 1a0a9001c25ad..baf9bbc09cc37 100644 --- a/servo/components/gfx/lib.rs +++ b/servo/components/gfx/lib.rs @@ -251,6 +251,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 1ad544bf6e78f..ea9fff25afee7 100644 --- a/servo/components/gfx/platform/freetype/font_context.rs +++ b/servo/components/gfx/platform/freetype/font_context.rs @@ -115,12 +115,17 @@ malloc_size_of : : { -malloc_size_of MallocSizeOf MallocSizeOfOps } ; use +servo_allocator +: +: +usable_size +; +use std : : @@ -315,7 +320,7 @@ unsafe let actual_size = -malloc_size_of +usable_size ( ptr as @@ -370,7 +375,7 @@ unsafe let actual_size = -malloc_size_of +usable_size ( ptr as @@ -445,7 +450,7 @@ ft_realloc mem : FT_Memory -_cur_size +old_size : c_long new_req_size @@ -474,7 +479,7 @@ unsafe { old_actual_size = -malloc_size_of +usable_size ( old_ptr as @@ -483,6 +488,13 @@ const _ ) ; +let +old_size += +old_size +as +usize +; vec = Vec @@ -500,8 +512,8 @@ as * mut u8 -old_actual_size -old_actual_size +old_size +old_size ) ; } @@ -572,7 +584,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 17567d0aee510..380bc79e1152c 100644 --- a/servo/components/layout_thread/lib.rs +++ b/servo/components/layout_thread/lib.rs @@ -219,6 +219,10 @@ serde_json ; extern crate +servo_allocator +; +extern +crate servo_arc ; extern @@ -569,7 +573,6 @@ malloc_size_of : : { -malloc_size_of MallocSizeOf MallocSizeOfOps } @@ -5328,7 +5331,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 b6cbd2c9a03b5..029909ccf8f48 100644 --- a/servo/components/malloc_size_of/lib.rs +++ b/servo/components/malloc_size_of/lib.rs @@ -644,21 +644,6 @@ extern crate js ; -# -[ -cfg -( -target_os -= -" -windows -" -) -] -extern -crate -kernel32 -; extern crate servo_arc @@ -731,27 +716,6 @@ extern crate xml5ever ; -# -[ -cfg -( -target_os -= -" -windows -" -) -] -use -kernel32 -: -: -{ -GetProcessHeap -HeapSize -HeapValidate -} -; use std : @@ -1442,252 +1406,6 @@ c_void / / / -Get -the -size -of -a -heap -block -. -# -[ -cfg -( -not -( -target_os -= -" -windows -" -) -) -] -pub -unsafe -extern -" -C -" -fn -malloc_size_of -( -ptr -: -* -const -c_void -) -- -> -usize -{ -/ -/ -The -C -prototype -is -je_malloc_usable_size -( -JEMALLOC_USABLE_SIZE_CONST -void -* -ptr -) -. -On -some -/ -/ -platforms -JEMALLOC_USABLE_SIZE_CONST -is -const -and -on -some -it -is -empty -. -But -in -practice -/ -/ -this -function -doesn -' -t -modify -the -contents -of -the -block -that -ptr -points -to -so -we -use -/ -/ -* -const -c_void -here -. -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 -) -} -/ -/ -/ -Get -the -size -of -a -heap -block -. -# -[ -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 -} -/ -/ -/ Trait for measuring 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 48a651dc9ff2b..72d455f1372a0 100644 --- a/servo/components/profile/lib.rs +++ b/servo/components/profile/lib.rs @@ -59,33 +59,6 @@ MPL # ! [ -cfg_attr -( -all -( -feature -= -" -unstable -" -not -( -target_os -= -" -windows -" -) -) -feature -( -alloc_jemalloc -) -) -] -# -! -[ deny ( unsafe_code @@ -98,6 +71,18 @@ allow unused_extern_crates ) ] +extern +crate +heartbeats_simple +; +extern +crate +influent +; +extern +crate +ipc_channel +; # [ cfg @@ -122,29 +107,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 cbdd4fed2c19c..76e088635e414 100644 --- a/servo/components/profile/mem.rs +++ b/servo/components/profile/mem.rs @@ -2711,7 +2711,6 @@ libc : : { -c_char c_void size_t } @@ -3568,69 +3567,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 6c90741bb6609..a4e9238ec6121 100644 --- a/servo/components/script/lib.rs +++ b/servo/components/script/lib.rs @@ -436,6 +436,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 ae70340b8f83c..7bdabc4a7d7f4 100644 --- a/servo/components/script/script_thread.rs +++ b/servo/components/script/script_thread.rs @@ -923,10 +923,7 @@ use malloc_size_of : : -{ -malloc_size_of MallocSizeOfOps -} ; use mem @@ -11531,7 +11528,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 4ac43b91f8946..ed6e32412ce95 100644 --- a/servo/python/tidy/servo_tidy/tidy.py +++ b/servo/python/tidy/servo_tidy/tidy.py @@ -6398,6 +6398,41 @@ = crate_name +if +line += += +" +} +" +: + +for +i +in +[ +i +for +i +in +prev_crate +. +keys +( +) +if +i +> +indent +] +: + +del +prev_crate +[ +i +] + # check alphabetical 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 5604c26a9afb6..ad6392c04ee33 100644 --- a/servo/tests/unit/profile/lib.rs +++ b/servo/tests/unit/profile/lib.rs @@ -68,6 +68,10 @@ extern crate profile_traits ; +extern +crate +servo_allocator +; # [ cfg