Overhaul MallocSizeOf and related things.

This patch makes the MallocSizeOf stuff in Stylo work more like the HeapSizeOf
stuff already in Servo, except better. In particular, it adds deriving support
for MallocSizeOf, which will make it easier to improve coverage.

The patch does the following.

- Combines servo/components/style/stylesheets/memory.rs and the heapsize crate
  into a new crate, malloc_size_of.

- Forks the heapsize_derive crate, calling it malloc_size_of, so that
  MallocSizeOf can be derived.

- Both the new crates have MIT/Apache licenses, like heapsize, in case they are
  incorporated into heapsize in the future.

- Renames the methods within MallocSizeOf and the related traits so they are
  more concise.

- Removes MallocSizeOfWithGuard.

- Adds `derive(MallocSizeOf)` to a lot of types, in some cases replacing an
  equivalent or almost-equivalent hand-written implementation.

- Adds stuff so that Rc/Arc can be handled properly.
This commit is contained in:
Nicholas Nethercote 2017-09-12 12:03:01 +10:00
parent 24b2d8d9cf
commit 32548e5312
44 changed files with 1188 additions and 486 deletions

View file

@ -29,6 +29,7 @@ use font_metrics::FontMetricsProvider;
#[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID};
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
use logical_geometry::WritingMode;
#[cfg(feature = "gecko")] use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps};
use media_queries::Device;
use parser::ParserContext;
use properties::animated_properties::AnimatableLonghand;
@ -39,8 +40,7 @@ use selectors::parser::SelectorParseError;
use shared_lock::StylesheetGuards;
use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError};
use style_traits::{PropertyDeclarationParseError, StyleParseError, ValueParseError};
use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfBox, MallocSizeOfFn, MallocSizeOfVec};
use stylesheets::{Origin, UrlExtraData};
use stylesheets::{CssRuleType, Origin, UrlExtraData};
#[cfg(feature = "servo")] use values::Either;
use values::generics::text::LineHeight;
use values::computed;
@ -292,6 +292,7 @@ static ${name}: LonghandIdSet = LonghandIdSet {
</%def>
/// A set of longhand properties
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, PartialEq)]
pub struct LonghandIdSet {
storage: [u32; (${len(data.longhands)} - 1 + 32) / 32]
@ -1329,19 +1330,20 @@ impl ToCss for PropertyDeclaration {
}
}
#[cfg(feature = "gecko")]
impl MallocSizeOf for PropertyDeclaration {
fn malloc_size_of_children(&self, malloc_size_of: MallocSizeOfFn) -> usize {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
match *self {
% for property in data.longhands:
% if property.boxed and property.is_vector:
<% raise Exception("this should not happen! not smart to box a vector here") %>
% elif property.boxed:
PropertyDeclaration::${property.camel_case}(ref sv_box) => {
sv_box.malloc_shallow_size_of_box(malloc_size_of)
<Box<_> as MallocShallowSizeOf>::shallow_size_of(sv_box, ops)
}
% elif property.is_vector:
PropertyDeclaration::${property.camel_case}(ref sv_vec) => {
sv_vec.0.malloc_shallow_size_of_vec(malloc_size_of)
sv_vec.0.shallow_size_of(ops)
}
% endif
% endfor