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

@ -12,12 +12,12 @@ use gecko_bindings::structs::{StyleSheetInfo, ServoStyleSheetInner};
use gecko_bindings::structs::nsIDocument;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use media_queries::{Device, MediaList};
use properties::ComputedValues;
use servo_arc::Arc;
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
use stylesheets::{MallocEnclosingSizeOfFn, MallocSizeOfFn, PerOrigin, StylesheetContents};
use stylesheets::StylesheetInDocument;
use stylesheets::{PerOrigin, StylesheetContents, StylesheetInDocument};
use stylist::{ExtraStyleData, Stylist};
/// Little wrapper to a Gecko style sheet.
@ -186,19 +186,10 @@ impl PerDocumentStyleDataImpl {
self.visited_links_enabled() && !self.is_private_browsing_enabled()
}
/// Measures heap usage.
pub fn malloc_add_size_of_children(&self, malloc_size_of: MallocSizeOfFn,
malloc_enclosing_size_of: MallocEnclosingSizeOfFn,
sizes: &mut ServoStyleSetSizes) {
self.stylist.malloc_add_size_of_children(malloc_size_of, malloc_enclosing_size_of, sizes);
let data = &self.extra_style_data;
sizes.mStylistOther +=
data.user_agent.malloc_size_of_children(malloc_size_of, malloc_enclosing_size_of);
sizes.mStylistOther +=
data.user.malloc_size_of_children(malloc_size_of, malloc_enclosing_size_of);
sizes.mStylistOther +=
data.author.malloc_size_of_children(malloc_size_of, malloc_enclosing_size_of);
/// Measure heap usage.
pub fn add_size_of_children(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) {
self.stylist.add_size_of_children(ops, sizes);
sizes.mStylistOther += self.extra_style_data.size_of(ops);
}
}