mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Replace all uses of the heapsize
crate with malloc_size_of
.
Servo currently uses `heapsize`, but Stylo/Gecko use `malloc_size_of`. `malloc_size_of` is better -- it handles various cases that `heapsize` does not -- so this patch changes Servo to use `malloc_size_of`. This patch makes the following changes to the `malloc_size_of` crate. - Adds `MallocSizeOf` trait implementations for numerous types, some built-in (e.g. `VecDeque`), some external and Servo-only (e.g. `string_cache`). - Makes `enclosing_size_of_op` optional, because vanilla jemalloc doesn't support that operation. - For `HashSet`/`HashMap`, falls back to a computed estimate when `enclosing_size_of_op` isn't available. - Adds an extern "C" `malloc_size_of` function that does the actual heap measurement; this is based on the same functions from the `heapsize` crate. This patch makes the following changes elsewhere. - Converts all the uses of `heapsize` to instead use `malloc_size_of`. - Disables the "heapsize"/"heap_size" feature for the external crates that provide it. - Removes the `HeapSizeOf` implementation from `hashglobe`. - Adds `ignore` annotations to a few `Rc`/`Arc`, because `malloc_size_of` doesn't derive those types, unlike `heapsize`.
This commit is contained in:
parent
421baa854e
commit
4506f0d30c
269 changed files with 1418 additions and 1521 deletions
|
@ -8,7 +8,7 @@ use freetype::freetype::FT_Library;
|
|||
use freetype::freetype::FT_Memory;
|
||||
use freetype::freetype::FT_MemoryRec_;
|
||||
use freetype::freetype::FT_New_Library;
|
||||
use heapsize::{HeapSizeOf, heap_size_of};
|
||||
use malloc_size_of::{malloc_size_of, MallocSizeOf, MallocSizeOfOps};
|
||||
use std::mem;
|
||||
use std::os::raw::{c_long, c_void};
|
||||
use std::ptr;
|
||||
|
@ -31,7 +31,7 @@ extern fn ft_alloc(mem: FT_Memory, req_size: c_long) -> *mut c_void {
|
|||
mem::forget(vec);
|
||||
|
||||
unsafe {
|
||||
let actual_size = heap_size_of(ptr as *const _);
|
||||
let actual_size = malloc_size_of(ptr as *const _);
|
||||
let user = (*mem).user as *mut User;
|
||||
(*user).size += actual_size;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ extern fn ft_alloc(mem: FT_Memory, req_size: c_long) -> *mut c_void {
|
|||
|
||||
extern fn ft_free(mem: FT_Memory, ptr: *mut c_void) {
|
||||
unsafe {
|
||||
let actual_size = heap_size_of(ptr as *const _);
|
||||
let actual_size = malloc_size_of(ptr as *const _);
|
||||
let user = (*mem).user as *mut User;
|
||||
(*user).size -= actual_size;
|
||||
|
||||
|
@ -55,7 +55,7 @@ extern fn ft_realloc(mem: FT_Memory, _cur_size: c_long, new_req_size: c_long,
|
|||
let old_actual_size;
|
||||
let mut vec;
|
||||
unsafe {
|
||||
old_actual_size = heap_size_of(old_ptr as *const _);
|
||||
old_actual_size = malloc_size_of(old_ptr as *const _);
|
||||
vec = Vec::<u8>::from_raw_parts(old_ptr as *mut u8, old_actual_size, old_actual_size);
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,7 @@ extern fn ft_realloc(mem: FT_Memory, _cur_size: c_long, new_req_size: c_long,
|
|||
mem::forget(vec);
|
||||
|
||||
unsafe {
|
||||
let new_actual_size = heap_size_of(new_ptr as *const _);
|
||||
let new_actual_size = malloc_size_of(new_ptr as *const _);
|
||||
let user = (*mem).user as *mut User;
|
||||
(*user).size += new_actual_size;
|
||||
(*user).size -= old_actual_size;
|
||||
|
@ -104,13 +104,13 @@ impl Drop for FreeTypeLibraryHandle {
|
|||
}
|
||||
}
|
||||
|
||||
impl HeapSizeOf for FreeTypeLibraryHandle {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
impl MallocSizeOf for FreeTypeLibraryHandle {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
unsafe {
|
||||
(*self.user).size +
|
||||
heap_size_of(self.ctx as *const _) +
|
||||
heap_size_of(self.mem as *const _) +
|
||||
heap_size_of(self.user as *const _)
|
||||
ops.malloc_size_of(self.ctx as *const _) +
|
||||
ops.malloc_size_of(self.mem as *const _) +
|
||||
ops.malloc_size_of(self.user as *const _)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,9 +123,9 @@ pub struct FontContextHandle {
|
|||
pub ctx: Rc<FreeTypeLibraryHandle>,
|
||||
}
|
||||
|
||||
impl HeapSizeOf for FontContextHandle {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
self.ctx.heap_size_of_children()
|
||||
impl MallocSizeOf for FontContextHandle {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
self.ctx.size_of(ops)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use heapsize::HeapSizeOf;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, MallocSizeOf)]
|
||||
pub struct FontContextHandle {
|
||||
ctx: ()
|
||||
}
|
||||
|
@ -15,9 +13,3 @@ impl FontContextHandle {
|
|||
FontContextHandle { ctx: () }
|
||||
}
|
||||
}
|
||||
|
||||
impl HeapSizeOf for FontContextHandle {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
* 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/. */
|
||||
|
||||
use heapsize::HeapSizeOf;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FontContextHandle;
|
||||
|
||||
|
@ -14,8 +12,4 @@ impl FontContextHandle {
|
|||
}
|
||||
}
|
||||
|
||||
impl HeapSizeOf for FontContextHandle {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
malloc_size_of_is_0!(FontContextHandle);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue