mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +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
|
@ -32,7 +32,6 @@ use dom::virtualmethods::VirtualMethods;
|
|||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use fnv::FnvHasher;
|
||||
use heapsize::HeapSizeOf;
|
||||
use js::jsapi::{CompileFunction, JS_GetFunctionObject, JSAutoCompartment};
|
||||
use js::rust::{AutoObjectVectorWrapper, CompileOptionsWrapper};
|
||||
use libc::{c_char, size_t};
|
||||
|
@ -48,11 +47,19 @@ use std::ops::{Deref, DerefMut};
|
|||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Clone, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
pub enum CommonEventHandler {
|
||||
EventHandler(Rc<EventHandlerNonNull>),
|
||||
ErrorEventHandler(Rc<OnErrorEventHandlerNonNull>),
|
||||
BeforeUnloadEventHandler(Rc<OnBeforeUnloadEventHandlerNonNull>),
|
||||
EventHandler(
|
||||
#[ignore_malloc_size_of = "Rc"]
|
||||
Rc<EventHandlerNonNull>),
|
||||
|
||||
ErrorEventHandler(
|
||||
#[ignore_malloc_size_of = "Rc"]
|
||||
Rc<OnErrorEventHandlerNonNull>),
|
||||
|
||||
BeforeUnloadEventHandler(
|
||||
#[ignore_malloc_size_of = "Rc"]
|
||||
Rc<OnBeforeUnloadEventHandlerNonNull>),
|
||||
}
|
||||
|
||||
impl CommonEventHandler {
|
||||
|
@ -65,14 +72,14 @@ impl CommonEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, HeapSizeOf, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
pub enum ListenerPhase {
|
||||
Capturing,
|
||||
Bubbling,
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#internal-raw-uncompiled-handler>
|
||||
#[derive(Clone, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
struct InternalRawUncompiledHandler {
|
||||
source: DOMString,
|
||||
url: ServoUrl,
|
||||
|
@ -80,7 +87,7 @@ struct InternalRawUncompiledHandler {
|
|||
}
|
||||
|
||||
/// A representation of an event handler, either compiled or uncompiled raw source, or null.
|
||||
#[derive(Clone, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
enum InlineEventListener {
|
||||
Uncompiled(InternalRawUncompiledHandler),
|
||||
Compiled(CommonEventHandler),
|
||||
|
@ -110,19 +117,12 @@ impl InlineEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
enum EventListenerType {
|
||||
Additive(Rc<EventListener>),
|
||||
Additive(#[ignore_malloc_size_of = "Rc"] Rc<EventListener>),
|
||||
Inline(InlineEventListener),
|
||||
}
|
||||
|
||||
impl HeapSizeOf for EventListenerType {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
// FIXME: Rc<T> isn't HeapSizeOf and we can't ignore it due to #6870 and #6871
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl EventListenerType {
|
||||
fn get_compiled_listener(&mut self, owner: &EventTarget, ty: &Atom)
|
||||
-> Option<CompiledEventListener> {
|
||||
|
@ -225,14 +225,14 @@ impl CompiledEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, DenyPublicFields, HeapSizeOf, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, DenyPublicFields, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
/// A listener in a collection of event listeners.
|
||||
struct EventListenerEntry {
|
||||
phase: ListenerPhase,
|
||||
listener: EventListenerType
|
||||
}
|
||||
|
||||
#[derive(HeapSizeOf, JSTraceable)]
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
/// A mix of potentially uncompiled and compiled event listeners of the same type.
|
||||
struct EventListeners(Vec<EventListenerEntry>);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue