Skip to content

Commit

Permalink
Bug 1383977 - stylo: Measure Elements and ComputedValues. r=manishearth.
Browse files Browse the repository at this point in the history
The patch provides FFI access to Gecko's SeenPtrs type from Rust, in order to
record what has already been measured when measuring Arcs. (The SeenPtrs must
be initialized on the Gecko side because the same table is reused for measuring
all Elements within a window, because Elements can share ComputedValues.) I
have confirmed with DMD that this is working correctly.

The patch also introduces MallocSizeOfRepeats, which is like MallocSizeOf but
takes a SizeOfState, which holds a SeenPtrs table.

MozReview-Commit-ID: DHS8zvCsEdQ

--HG--
extra : rebase_source : acf4d7909abf6ceb1719331ccf2e33137eb6dc91
  • Loading branch information
nnethercote committed Jul 19, 2017
1 parent 5340159 commit cc91dee
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4138,13 +4138,20 @@ Element::SetCustomElementData(CustomElementData* aData)
slots->mCustomElementData = aData;
}

MOZ_DEFINE_MALLOC_SIZE_OF(ServoElementMallocSizeOf)

size_t
Element::SizeOfExcludingThis(SizeOfState& aState) const
{
size_t n = FragmentOrElement::SizeOfExcludingThis(aState);

// XXX: measure mServoData.

// Measure mServoData. We use ServoElementMallocSizeOf rather than
// |aState.mMallocSizeOf| to distinguish in DMD's output the memory
// measured within Servo code.
if (mServoData.Get()) {
n += Servo_Element_SizeOfExcludingThis(ServoElementMallocSizeOf,
&aState.mSeenPtrs, this);
}
return n;
}

2 changes: 2 additions & 0 deletions layout/style/ServoBindingList.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// Element data
SERVO_BINDING_FUNC(Servo_Element_ClearData, void, RawGeckoElementBorrowed node)
SERVO_BINDING_FUNC(Servo_Element_SizeOfExcludingThis, size_t, mozilla::MallocSizeOf,
mozilla::SeenPtrs* seen_ptrs, RawGeckoElementBorrowed node)

// Styleset and Stylesheet management
SERVO_BINDING_FUNC(Servo_StyleSheet_FromUTF8Bytes, RawServoStyleSheetContentsStrong,
Expand Down
13 changes: 13 additions & 0 deletions layout/style/ServoBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "mozilla/Mutex.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/ServoRestyleManager.h"
#include "mozilla/SizeOfState.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/SystemGroup.h"
#include "mozilla/ServoMediaList.h"
Expand Down Expand Up @@ -452,6 +453,18 @@ Gecko_GetElementSnapshot(const ServoElementSnapshotTable* aTable,
return aTable->Get(const_cast<Element*>(aElement));
}

bool
Gecko_HaveSeenPtr(SeenPtrs* aTable, const void* aPtr)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aTable);
// Empty Rust allocations are indicated by small values up to the alignment
// of the relevant type. We shouldn't see anything like that here.
MOZ_ASSERT(uintptr_t(aPtr) > 16);

return aTable->HaveSeenPtr(aPtr);
}

RawServoDeclarationBlockStrongBorrowedOrNull
Gecko_GetStyleAttrDeclarationBlock(RawGeckoElementBorrowed aElement)
{
Expand Down
5 changes: 5 additions & 0 deletions layout/style/ServoBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace mozilla {
};
enum class UpdateAnimationsTasks : uint8_t;
struct LangGroupFontPrefs;
class SeenPtrs;
class ServoStyleContext;
class ServoStyleSheet;
class ServoElementSnapshotTable;
Expand Down Expand Up @@ -397,6 +398,10 @@ Gecko_GetElementSnapshot(const mozilla::ServoElementSnapshotTable* table,

void Gecko_DropElementSnapshot(ServoElementSnapshotOwned snapshot);

// Have we seen this pointer before?
bool
Gecko_HaveSeenPtr(mozilla::SeenPtrs* table, const void* ptr);

// `array` must be an nsTArray
// If changing this signature, please update the
// friend function declaration in nsTArray.h
Expand Down
4 changes: 4 additions & 0 deletions layout/style/ServoBindings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ headers = [
"mozilla/ServoBindings.h",
"mozilla/ServoMediaList.h",
"mozilla/ServoStyleContext.h",
"mozilla/SizeOfState.h",
"nsCSSCounterStyleRule.h",
"nsCSSFontFaceRule.h",
"nsMediaFeatures.h",
Expand Down Expand Up @@ -123,6 +124,7 @@ whitelist-types = [
"mozilla::ComputedTiming",
"mozilla::ComputedTimingFunction",
"mozilla::ComputedTimingFunction::BeforeFlag",
"mozilla::SeenPtrs",
"mozilla::ServoElementSnapshot.*",
"mozilla::ServoStyleContext",
"mozilla::ServoStyleSheetInner",
Expand Down Expand Up @@ -297,6 +299,7 @@ opaque-types = [
"nsAutoPtr_Proxy_member_function",
"mozilla::detail::PointerType",
"mozilla::Pair_Base",
"mozilla::SeenPtrs",
"mozilla::SupportsWeakPtr",
"SupportsWeakPtr",
"mozilla::detail::WeakReference",
Expand Down Expand Up @@ -403,6 +406,7 @@ structs-types = [
"IterationCompositeOperation",
"Keyframe",
"PropertyValuePair",
"SeenPtrs",
"ServoBundledURI",
"ServoElementSnapshot",
"ServoElementSnapshotTable",
Expand Down

0 comments on commit cc91dee

Please sign in to comment.