Bug 1316556 - Remove zeroing allocation in class nsIPresShell. r=dbaron.
authorJulian Seward <jseward@acm.org>
Thu, 01 Dec 2016 09:06:50 +0100
changeset 324990 db70aca765dc6400864e16701f4c9d42866ad713
parent 324989 c63c761e089c36a9065c9ca5f019c87dddabd816
child 324991 3245e69aa698265f4ff511fda5fccaa35b112f90
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersdbaron
bugs1316556
milestone53.0a1
Bug 1316556 - Remove zeroing allocation in class nsIPresShell. r=dbaron.
layout/base/nsIPresShell.h
layout/forms/nsTextControlFrame.cpp
layout/generic/nsBulletFrame.h
layout/generic/nsIFrame.h
layout/generic/nsLineBox.cpp
layout/generic/nsPluginFrame.cpp
layout/generic/nsSplittableFrame.h
layout/generic/nsSubDocumentFrame.cpp
layout/generic/nsTextFrame.h
layout/mathml/nsMathMLmfencedFrame.h
layout/mathml/nsMathMLmfracFrame.h
layout/mathml/nsMathMLmpaddedFrame.h
layout/svg/SVGTextFrame.h
layout/svg/nsSVGOuterSVGFrame.cpp
layout/tables/nsTableColFrame.cpp
layout/tables/nsTableRowFrame.cpp
layout/xul/nsMenuBarFrame.cpp
layout/xul/nsSliderFrame.cpp
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -204,45 +204,43 @@ public:
   virtual void Destroy() = 0;
 
   bool IsDestroying() { return mIsDestroying; }
 
   /**
    * All frames owned by the shell are allocated from an arena.  They
    * are also recycled using free lists.  Separate free lists are
    * maintained for each frame type (aID), which must always correspond
-   * to the same aSize value.  AllocateFrame returns zero-filled memory.
-   * AllocateFrame is infallible and will abort on out-of-memory.
+   * to the same aSize value.  AllocateFrame is infallible and will abort
+   * on out-of-memory.
    */
   void* AllocateFrame(nsQueryFrame::FrameIID aID, size_t aSize)
   {
     void* result = mFrameArena.AllocateByFrameID(aID, aSize);
     RecordAlloc(result);
-    memset(result, 0, aSize);
     return result;
   }
 
   void FreeFrame(nsQueryFrame::FrameIID aID, void* aPtr)
   {
     RecordFree(aPtr);
     if (!mIsDestroying)
       mFrameArena.FreeByFrameID(aID, aPtr);
   }
 
   /**
    * This is for allocating other types of objects (not frames).  Separate free
    * lists are maintained for each type (aID), which must always correspond to
-   * the same aSize value.  AllocateByObjectID returns zero-filled memory.
-   * AllocateByObjectID is infallible and will abort on out-of-memory.
+   * the same aSize value.  AllocateByObjectID is infallible and will abort on
+   * out-of-memory.
    */
   void* AllocateByObjectID(mozilla::ArenaObjectID aID, size_t aSize)
   {
     void* result = mFrameArena.AllocateByObjectID(aID, aSize);
     RecordAlloc(result);
-    memset(result, 0, aSize);
     return result;
   }
 
   void FreeByObjectID(mozilla::ArenaObjectID aID, void* aPtr)
   {
     RecordFree(aPtr);
     if (!mIsDestroying)
       mFrameArena.FreeByObjectID(aID, aPtr);
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -103,16 +103,17 @@ private:
   bool mFirstEntry;
 };
 #endif
 
 nsTextControlFrame::nsTextControlFrame(nsStyleContext* aContext)
   : nsContainerFrame(aContext)
   , mEditorHasBeenInitialized(false)
   , mIsProcessing(false)
+  , mUsePlaceholder(false)
 #ifdef DEBUG
   , mInEditorInitialization(false)
 #endif
 {
 }
 
 nsTextControlFrame::~nsTextControlFrame()
 {
--- a/layout/generic/nsBulletFrame.h
+++ b/layout/generic/nsBulletFrame.h
@@ -51,16 +51,17 @@ public:
   NS_DECL_QUERYFRAME_TARGET(nsBulletFrame)
   NS_DECL_QUERYFRAME
 #endif
 
   explicit nsBulletFrame(nsStyleContext* aContext)
     : nsFrame(aContext)
     , mPadding(GetWritingMode())
     , mIntrinsicSize(GetWritingMode())
+    , mOrdinal(0)
     , mRequestRegistered(false)
     , mBlockingOnload(false)
   { }
   virtual ~nsBulletFrame();
 
   NS_IMETHOD Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aData);
   NS_IMETHOD BlockOnload(imgIRequest* aRequest);
   NS_IMETHOD UnblockOnload(imgIRequest* aRequest);
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -518,16 +518,27 @@ public:
   typedef mozilla::gfx::DrawTarget DrawTarget;
   typedef mozilla::gfx::Matrix Matrix;
   typedef mozilla::gfx::Matrix4x4 Matrix4x4;
   typedef mozilla::Sides Sides;
   typedef mozilla::LogicalSides LogicalSides;
 
   NS_DECL_QUERYFRAME_TARGET(nsIFrame)
 
+  nsIFrame()
+    : mRect()
+    , mContent(nullptr)
+    , mStyleContext(nullptr)
+    , mParent(nullptr)
+    , mNextSibling(nullptr)
+    , mPrevSibling(nullptr)
+  {
+    mozilla::PodZero(&mOverflow);
+  }
+
   nsPresContext* PresContext() const {
     return StyleContext()->PresContext();
   }
 
   /**
    * Called to initialize the frame. This is called immediately after creating
    * the frame.
    *
--- a/layout/generic/nsLineBox.cpp
+++ b/layout/generic/nsLineBox.cpp
@@ -28,21 +28,33 @@ int32_t nsLineBox::GetCtorCount() { retu
 // static nsLineBox constant; initialized in the header file.
 const uint32_t nsLineBox::kMinChildCountForHashtable;
 #endif
 
 using namespace mozilla;
 
 nsLineBox::nsLineBox(nsIFrame* aFrame, int32_t aCount, bool aIsBlock)
   : mFirstChild(aFrame)
+  , mWritingMode()
   , mContainerSize(-1, -1)
   , mBounds(WritingMode()) // mBounds will be initialized with the correct
                            // writing mode when it is set
-// NOTE: memory is already zeroed since we allocate with AllocateByObjectID.
+  , mFrames()
+  , mAscent()
+  , mAllFlags(0)
+  , mData(nullptr)
 {
+  // Assert that the union elements chosen for initialisation are at
+  // least as large as all other elements in their respective unions, so
+  // as to ensure that no parts are missed.
+  static_assert(sizeof(mFrames) >= sizeof(mChildCount), "nsLineBox init #1");
+  static_assert(sizeof(mAllFlags) >= sizeof(mFlags), "nsLineBox init #2");
+  static_assert(sizeof(mData) >= sizeof(mBlockData), "nsLineBox init #3");
+  static_assert(sizeof(mData) >= sizeof(mInlineData), "nsLineBox init #4");
+
   MOZ_COUNT_CTOR(nsLineBox);
 #ifdef DEBUG
   ++ctorCount;
   NS_ASSERTION(!aIsBlock || aCount == 1, "Blocks must have exactly one child");
   nsIFrame* f = aFrame;
   for (int32_t n = aCount; n > 0; f = f->GetNextSibling(), --n) {
     NS_ASSERTION(aIsBlock == f->IsBlockOutside(),
                  "wrong kind of child frame");
--- a/layout/generic/nsPluginFrame.cpp
+++ b/layout/generic/nsPluginFrame.cpp
@@ -147,16 +147,18 @@ protected:
 
   uint64_t mLastSequenceNumber;
   nsPluginFrame* mFrame;
 };
 
 nsPluginFrame::nsPluginFrame(nsStyleContext* aContext)
   : nsFrame(aContext)
   , mInstanceOwner(nullptr)
+  , mInnerView(nullptr)
+  , mBackgroundSink(nullptr)
   , mReflowCallbackPosted(false)
 {
   MOZ_LOG(sPluginFrameLog, LogLevel::Debug,
          ("Created new nsPluginFrame %p\n", this));
 }
 
 nsPluginFrame::~nsPluginFrame()
 {
--- a/layout/generic/nsSplittableFrame.h
+++ b/layout/generic/nsSplittableFrame.h
@@ -69,17 +69,21 @@ public:
   virtual nsIFrame* FirstInFlow() const override;
   virtual nsIFrame* LastInFlow() const override;
 
   // Remove the frame from the flow. Connects the frame's prev-in-flow
   // and its next-in-flow. This should only be called in frame Destroy() methods.
   static void RemoveFromFlow(nsIFrame* aFrame);
 
 protected:
-  explicit nsSplittableFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
+  explicit nsSplittableFrame(nsStyleContext* aContext)
+    : nsFrame(aContext)
+    , mPrevContinuation(nullptr)
+    , mNextContinuation(nullptr)
+  {}
 
   /**
    * Determine the height consumed by our previous-in-flows.
    *
    * @note (bz) This makes laying out a splittable frame with N in-flows
    *       O(N^2)! So, use this function with caution and minimize the number
    *       of calls to this method.
    */
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -55,16 +55,17 @@ GetDocumentFromView(nsView* aView)
 
   nsViewManager* vm = aView->GetViewManager();
   nsIPresShell* ps =  vm ? vm->GetPresShell() : nullptr;
   return ps ? ps->GetDocument() : nullptr;
 }
 
 nsSubDocumentFrame::nsSubDocumentFrame(nsStyleContext* aContext)
   : nsAtomicContainerFrame(aContext)
+  , mInnerView(nullptr)
   , mIsInline(false)
   , mPostedReflowCallback(false)
   , mDidCreateDoc(false)
   , mCallingShow(false)
 {
 }
 
 #ifdef ACCESSIBILITY
--- a/layout/generic/nsTextFrame.h
+++ b/layout/generic/nsTextFrame.h
@@ -51,16 +51,20 @@ public:
   NS_DECL_FRAMEARENA_HELPERS
 
   friend class nsContinuingTextFrame;
   friend class nsDisplayTextGeometry;
   friend class nsDisplayText;
 
   explicit nsTextFrame(nsStyleContext* aContext)
     : nsFrame(aContext)
+    , mNextContinuation(nullptr)
+    , mContentOffset(0)
+    , mContentLengthHint(0)
+    , mAscent(0)
   {
     NS_ASSERTION(mContentOffset == 0, "Bogus content offset");
   }
   
   // nsQueryFrame
   NS_DECL_QUERYFRAME
 
   // nsIFrame
--- a/layout/mathml/nsMathMLmfencedFrame.h
+++ b/layout/mathml/nsMathMLmfencedFrame.h
@@ -91,17 +91,24 @@ public:
     // <mfenced> <mo>%</mo> </mfenced>
     // renders equivalently to
     // <mrow> <mo> ( </mo> <mo>%</mo> <mo> ) </mo> </mrow>
     // This also holds with multiple children.  (MathML3 3.3.8.1)
     return true;
   }
 
 protected:
-  explicit nsMathMLmfencedFrame(nsStyleContext* aContext) : nsMathMLContainerFrame(aContext) {}
+  explicit nsMathMLmfencedFrame(nsStyleContext* aContext)
+    : nsMathMLContainerFrame(aContext)
+    , mOpenChar(nullptr)
+    , mCloseChar(nullptr)
+    , mSeparatorsChar(nullptr)
+    , mSeparatorsCount(0)
+  {}
+
   virtual ~nsMathMLmfencedFrame();
   
   nsMathMLChar* mOpenChar;
   nsMathMLChar* mCloseChar;
   nsMathMLChar* mSeparatorsChar;
   int32_t       mSeparatorsCount;
 
   // clean up
--- a/layout/mathml/nsMathMLmfracFrame.h
+++ b/layout/mathml/nsMathMLmfracFrame.h
@@ -90,17 +90,23 @@ public:
                     nscoord          onePixel,
                     nscoord          aDefaultRuleThickness,
                     float            aFontSizeInflation);
 
   uint8_t
   ScriptIncrement(nsIFrame* aFrame) override;
 
 protected:
-  explicit nsMathMLmfracFrame(nsStyleContext* aContext) : nsMathMLContainerFrame(aContext) {}
+  explicit nsMathMLmfracFrame(nsStyleContext* aContext)
+    : nsMathMLContainerFrame(aContext)
+    , mLineRect()
+    , mSlashChar(nullptr)
+    , mLineThickness(0)
+    , mIsBevelled(false)
+  {}
   virtual ~nsMathMLmfracFrame();
 
   nsresult PlaceInternal(DrawTarget*          aDrawTarget,
                          bool                 aPlaceOrigin,
                          ReflowOutput& aDesiredSize,
                          bool                 aWidthOnly);
 
   // Display a slash
--- a/layout/mathml/nsMathMLmpaddedFrame.h
+++ b/layout/mathml/nsMathMLmpaddedFrame.h
@@ -40,17 +40,30 @@ public:
 
   bool
   IsMrowLike() override {
     return mFrames.FirstChild() != mFrames.LastChild() ||
            !mFrames.FirstChild();
   }
 
 protected:
-  explicit nsMathMLmpaddedFrame(nsStyleContext* aContext) : nsMathMLContainerFrame(aContext) {}
+  explicit nsMathMLmpaddedFrame(nsStyleContext* aContext)
+    : nsMathMLContainerFrame(aContext)
+    , mWidthSign(0)
+    , mHeightSign(0)
+    , mDepthSign(0)
+    , mLeadingSpaceSign(0)
+    , mVerticalOffsetSign(0)
+    , mWidthPseudoUnit(0)
+    , mHeightPseudoUnit(0)
+    , mDepthPseudoUnit(0)
+    , mLeadingSpacePseudoUnit(0)
+    , mVerticalOffsetPseudoUnit(0)
+  {}
+
   virtual ~nsMathMLmpaddedFrame();
 
   virtual nsresult
   MeasureForWidth(DrawTarget* aDrawTarget,
                   ReflowOutput& aDesiredSize) override;
 
 private:
   nsCSSValue mWidth;
--- a/layout/svg/SVGTextFrame.h
+++ b/layout/svg/SVGTextFrame.h
@@ -190,16 +190,17 @@ class SVGTextFrame final : public nsSVGD
   typedef mozilla::gfx::DrawTarget DrawTarget;
   typedef mozilla::gfx::Path Path;
   typedef mozilla::gfx::Point Point;
   typedef mozilla::image::DrawResult DrawResult;
 
 protected:
   explicit SVGTextFrame(nsStyleContext* aContext)
     : nsSVGDisplayContainerFrame(aContext)
+    , mTrailingUndisplayedCharacters(0)
     , mFontSizeScaleFactor(1.0f)
     , mLastContextScale(1.0f)
     , mLengthAdjustScaleFactor(1.0f)
   {
     AddStateBits(NS_STATE_SVG_POSITIONING_DIRTY);
   }
 
   ~SVGTextFrame() {}
--- a/layout/svg/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/nsSVGOuterSVGFrame.cpp
@@ -60,16 +60,17 @@ NS_NewSVGOuterSVGFrame(nsIPresShell* aPr
 {
   return new (aPresShell) nsSVGOuterSVGFrame(aContext);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGOuterSVGFrame)
 
 nsSVGOuterSVGFrame::nsSVGOuterSVGFrame(nsStyleContext* aContext)
     : nsSVGDisplayContainerFrame(aContext)
+    , mCallingReflowSVG(false)
     , mFullZoom(aContext->PresContext()->GetFullZoom())
     , mViewportInitialized(false)
     , mIsRootContent(false)
 {
   // Outer-<svg> has CSS layout, so remove this bit:
   RemoveStateBits(NS_FRAME_SVG_LAYOUT);
 }
 
--- a/layout/tables/nsTableColFrame.cpp
+++ b/layout/tables/nsTableColFrame.cpp
@@ -18,18 +18,32 @@ using namespace mozilla;
 #define COL_TYPE_BITS                 (NS_FRAME_STATE_BIT(28) | \
                                        NS_FRAME_STATE_BIT(29) | \
                                        NS_FRAME_STATE_BIT(30) | \
                                        NS_FRAME_STATE_BIT(31))
 #define COL_TYPE_OFFSET               28
 
 using namespace mozilla;
 
-nsTableColFrame::nsTableColFrame(nsStyleContext* aContext) :
-  nsSplittableFrame(aContext)
+nsTableColFrame::nsTableColFrame(nsStyleContext* aContext)
+  : nsSplittableFrame(aContext)
+  , mMinCoord(0)
+  , mPrefCoord(0)
+  , mSpanMinCoord(0)
+  , mSpanPrefCoord(0)
+  , mPrefPercent(0.0f)
+  , mSpanPrefPercent(0.0f)
+  , mFinalISize(0)
+  , mColIndex(0)
+  , mIStartBorderWidth(0)
+  , mIEndBorderWidth(0)
+  , mBStartContBorderWidth(0)
+  , mIEndContBorderWidth(0)
+  , mBEndContBorderWidth(0)
+  , mHasSpecifiedCoord(false)
 {
   SetColType(eColContent);
   ResetIntrinsics();
   ResetSpanIntrinsics();
   ResetFinalISize();
 }
 
 nsTableColFrame::~nsTableColFrame()
--- a/layout/tables/nsTableRowFrame.cpp
+++ b/layout/tables/nsTableRowFrame.cpp
@@ -126,18 +126,31 @@ nsTableRowFrame::SetPctBSize(float aPctV
 /* ----------- nsTableRowFrame ---------- */
 
 NS_QUERYFRAME_HEAD(nsTableRowFrame)
   NS_QUERYFRAME_ENTRY(nsTableRowFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
 
 nsTableRowFrame::nsTableRowFrame(nsStyleContext* aContext)
   : nsContainerFrame(aContext)
+  , mContentBSize(0)
+  , mStylePctBSize(0)
+  , mStyleFixedBSize(0)
+  , mMaxCellAscent(0)
+  , mMaxCellDescent(0)
+  , mBStartBorderWidth(0)
+  , mBEndBorderWidth(0)
+  , mIEndContBorderWidth(0)
+  , mBStartContBorderWidth(0)
+  , mIStartContBorderWidth(0)
 {
-  mBits.mRowIndex = mBits.mFirstInserted = 0;
+  mBits.mRowIndex = 0;
+  mBits.mHasFixedBSize = 0;
+  mBits.mHasPctBSize = 0;
+  mBits.mFirstInserted = 0;
   ResetBSize(0);
 }
 
 nsTableRowFrame::~nsTableRowFrame()
 {
 }
 
 void
--- a/layout/xul/nsMenuBarFrame.cpp
+++ b/layout/xul/nsMenuBarFrame.cpp
@@ -49,16 +49,17 @@ NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame
 
 //
 // nsMenuBarFrame cntr
 //
 nsMenuBarFrame::nsMenuBarFrame(nsStyleContext* aContext):
   nsBoxFrame(aContext),
     mStayActive(false),
     mIsActive(false),
+    mActiveByKeyboard(false),
     mCurrentMenu(nullptr),
     mTarget(nullptr)
 {
 } // cntr
 
 void
 nsMenuBarFrame::Init(nsIContent*       aContent,
                      nsContainerFrame* aParent,
--- a/layout/xul/nsSliderFrame.cpp
+++ b/layout/xul/nsSliderFrame.cpp
@@ -76,16 +76,17 @@ NS_NewSliderFrame (nsIPresShell* aPresSh
 NS_IMPL_FRAMEARENA_HELPERS(nsSliderFrame)
 
 NS_QUERYFRAME_HEAD(nsSliderFrame)
   NS_QUERYFRAME_ENTRY(nsSliderFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
 
 nsSliderFrame::nsSliderFrame(nsStyleContext* aContext):
   nsBoxFrame(aContext),
+  mRatio(0.0f),
   mCurPos(0),
   mChange(0),
   mDragFinished(true),
   mUserChanged(false),
   mScrollingWithAPZ(false),
   mSuppressionActive(false)
 {
 }