Closed Bug 654369 Opened 14 years ago Closed 14 years ago

Remove OOM checks from layout

Categories

(Core :: Layout, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla7

People

(Reporter: craig.topper, Assigned: craig.topper)

Details

Attachments

(7 files, 13 obsolete files)

2.96 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
2.48 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
2.06 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
4.81 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
3.27 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
17.46 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
27.21 KB, patch
bzbarsky
: review+
Details | Diff | Splinter Review
No description provided.
Attached patch Part 1: Remove NS_NewCaret (obsolete) — Splinter Review
Attachment #529631 - Flags: review?(bzbarsky)
Attachment #529632 - Flags: review?(bzbarsky)
Attachment #529633 - Flags: review?(bzbarsky)
Attachment #529634 - Flags: review?(bzbarsky)
Attachment #529635 - Flags: review?(bzbarsky)
Attachment #529643 - Flags: review?(bzbarsky)
Attachment #529644 - Flags: review?(bzbarsky)
Comment on attachment 529631 [details] [diff] [review] Part 1: Remove NS_NewCaret r=me
Attachment #529631 - Flags: review?(bzbarsky) → review+
Comment on attachment 529632 [details] [diff] [review] Part 2: Remove oom check and outparam from PresShell::CloneStyleSet r=me
Attachment #529632 - Flags: review?(bzbarsky) → review+
Comment on attachment 529633 [details] [diff] [review] Part 3: Make nsCSSRendering::Init return void r=me
Attachment #529633 - Flags: review?(bzbarsky) → review+
Comment on attachment 529634 [details] [diff] [review] Part 4: Make nsContainerFrame::SetOverflowFrames return void r=me
Attachment #529634 - Flags: review?(bzbarsky) → review+
Comment on attachment 529635 [details] [diff] [review] Part 5: Make nsFrameList::Init return void r=me
Attachment #529635 - Flags: review?(bzbarsky) → review+
Comment on attachment 529643 [details] [diff] [review] Part 6: Remove OOM checks from nsImageMap This one I'm not convinced about; the page controls |cnt|, right? These allocations would make more sense being fallible, perhaps.
Comment on attachment 529644 [details] [diff] [review] Part 7: Remove OOM checks from nsTextFrameThebes r=me
Attachment #529644 - Flags: review?(bzbarsky) → review+
(In reply to comment #13) > Comment on attachment 529643 [details] [diff] [review] [review] > Part 6: Remove OOM checks from nsImageMap > > This one I'm not convinced about; the page controls |cnt|, right? These > allocations would make more sense being fallible, perhaps. Oops. I missed that that was actually a call to new[] rather than just new. I'll undo that.
It's not just the new[]; the other allocation here are under content control too, I think. We should have a followup bug to make that new[] fallible, at least.
(In reply to comment #16) > It's not just the new[]; the other allocation here are under content control > too, I think. > > We should have a followup bug to make that new[] fallible, at least. The only other allocation is for the different kinds of Area. How can that one fail except in the case of the NOT_REACHED path. But since "area" isn't initialized at all before the switch there's no guarantee that it will be null on the NOT_REACHED path anyway. Maybe that was a bug in itself?
My point is that the number of calls to AddArea is under content control. We should probably make the |new| in AddArea fallible and just do nothing if it fails.
Attachment #529643 - Attachment is obsolete: true
Attachment #529643 - Flags: review?(bzbarsky)
Attachment #530930 - Flags: review?(bzbarsky)
Attachment #530930 - Attachment is obsolete: true
Attachment #530930 - Flags: review?(bzbarsky)
Attachment #530931 - Flags: review?(bzbarsky)
Attachment #530931 - Attachment is obsolete: true
Attachment #530931 - Flags: review?(bzbarsky)
Attachment #530932 - Flags: review?(bzbarsky)
Attachment #530933 - Flags: review?(bzbarsky)
Attachment #530934 - Flags: review?(bzbarsky)
Attachment #530936 - Flags: review?(bzbarsky)
Comment on attachment 530932 [details] [diff] [review] Part 8: Make nsLineIterator::Init return void >diff --git a/layout/generic/nsFloatManager.cpp b/layout/generic/nsFloatManager.cpp >--- a/layout/generic/nsFloatManager.cpp >+++ b/layout/generic/nsFloatManager.cpp >@@ -570,17 +570,17 @@ > mOld->List(stdout); > } > #endif > > delete mNew; > } > } > >-nsresult >+void > nsAutoFloatManager::CreateFloatManager(nsPresContext *aPresContext) > { > // Create a new float manager and install it in the reflow > // state. `Remember' the old float manager so we can restore it > // later. > mNew = new nsFloatManager(aPresContext->PresShell()); > if (! mNew) > return NS_ERROR_OUT_OF_MEMORY; You should remove that check in this patch, not in part 9.
Comment on attachment 530933 [details] [diff] [review] Part 9: Remove OOM checks from layout/generic >diff --git a/layout/generic/nsFrameUtil.cpp b/layout/generic/nsFrameUtil.cpp >--- a/layout/generic/nsFrameUtil.cpp >+++ b/layout/generic/nsFrameUtil.cpp >@@ -503,31 +498,28 @@ > if (type == openClose) { > aResult.Append(PRUnichar('/')); > } > aResult.Append(PRUnichar('>')); > } > > //---------------------------------------------------------------------- > >-nsresult NS_NewFrameUtil(nsIFrameUtil** aResult); > nsresult > NS_NewFrameUtil(nsIFrameUtil** aResult) > { > NS_PRECONDITION(nsnull != aResult, "null pointer"); > if (nsnull == aResult) { > return NS_ERROR_NULL_POINTER; > } >- *aResult = nsnull; > > nsFrameUtil* it = new nsFrameUtil(); >- if (nsnull == it) { >- return NS_ERROR_OUT_OF_MEMORY; >- } >- return it->QueryInterface(NS_GET_IID(nsIFrameUtil), (void**) aResult); >+ >+ NS_ADDREF(*aResult = it); >+ return NS_OK; > } This can just return nsFrameUtil* or already_AddRefed<nsFrameUtil>. >diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp >--- a/layout/generic/nsGfxScrollFrame.cpp >+++ b/layout/generic/nsGfxScrollFrame.cpp >@@ -1564,22 +1564,20 @@ > > if (mAsyncScroll) { > if (mAsyncScroll->mIsSmoothScroll) { > currentPosition = mAsyncScroll->PositionAt(now); > currentVelocity = mAsyncScroll->VelocityAt(now); > } > } else { > mAsyncScroll = new AsyncScroll; >- if (mAsyncScroll) { >- mAsyncScroll->mScrollTimer = do_CreateInstance("@mozilla.org/timer;1"); >- if (!mAsyncScroll->mScrollTimer) { >- delete mAsyncScroll; >- mAsyncScroll = nsnull; >- } >+ mAsyncScroll->mScrollTimer = do_CreateInstance("@mozilla.org/timer;1"); >+ if (!mAsyncScroll->mScrollTimer) { >+ delete mAsyncScroll; >+ mAsyncScroll = nsnull; > } > if (!mAsyncScroll) { > // some allocation failed. Scroll the normal way. > ScrollToImpl(mDestination); > return; > } I think this would read more easily as mAsyncScroll->mScrollTimer = do_CreateInstance("@mozilla.org/timer;1"); if (!mAsyncScroll->mScrollTimer) { delete mAsyncScroll; mAsyncScroll = nsnull; ScrollToImpl(mDestination); return; } >diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp >--- a/layout/generic/nsSelection.cpp >+++ b/layout/generic/nsSelection.cpp >@@ -501,28 +501,24 @@ > PRUint32 mDelay; > }; > > NS_IMPL_ISUPPORTS1(nsAutoScrollTimer, nsITimerCallback) > > nsresult NS_NewSelection(nsFrameSelection **aFrameSelection) > { > nsFrameSelection *rlist = new nsFrameSelection; >- if (!rlist) >- return NS_ERROR_OUT_OF_MEMORY; > *aFrameSelection = rlist; > NS_ADDREF(rlist); > return NS_OK; > } > > nsresult NS_NewDomSelection(nsISelection **aDomSelection) > { > nsTypedSelection *rlist = new nsTypedSelection; >- if (!rlist) >- return NS_ERROR_OUT_OF_MEMORY; > *aDomSelection = (nsISelection *)rlist; > NS_ADDREF(rlist); > return NS_OK; > } These two can return the pointer as well. >@@ -4745,17 +4726,17 @@ > return NS_OK; > } > > NS_IMETHODIMP > nsTypedSelection::GetEnumerator(nsIEnumerator **aIterator) > { > nsresult status = NS_ERROR_OUT_OF_MEMORY; > nsSelectionIterator *iterator = new nsSelectionIterator(this); >- if (iterator && NS_FAILED(status = CallQueryInterface(iterator, aIterator)) ) >+ if (NS_FAILED(status = CallQueryInterface(iterator, aIterator)) ) > delete iterator; > return status; > } { NS_ADDREF(*aIterator = new nsSelectionIterator(this)); return NS_OK; }
Comment on attachment 530936 [details] [diff] [review] Part 11: Remove OOM checks from layout/base >diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp >--- a/layout/base/nsDocumentViewer.cpp >+++ b/layout/base/nsDocumentViewer.cpp >@@ -517,19 +517,16 @@ > // Class IDs > static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); > > //------------------------------------------------------------------ > nsresult > NS_NewDocumentViewer(nsIDocumentViewer** aResult) > { > *aResult = new DocumentViewerImpl(); >- if (!*aResult) { >- return NS_ERROR_OUT_OF_MEMORY; >- } > > NS_ADDREF(*aResult); > > return NS_OK; > } Can return a pointer. >diff --git a/layout/base/nsFrameTraversal.cpp b/layout/base/nsFrameTraversal.cpp >--- a/layout/base/nsFrameTraversal.cpp >+++ b/layout/base/nsFrameTraversal.cpp >@@ -146,18 +146,16 @@ > /************IMPLEMENTATIONS**************/ > > nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult) > { > NS_ENSURE_ARG_POINTER(aResult); > *aResult = nsnull; > > nsCOMPtr<nsIFrameTraversal> t(new nsFrameTraversal()); >- if (!t) >- return NS_ERROR_OUT_OF_MEMORY; > > *aResult = t; > NS_ADDREF(*aResult); > > return NS_OK; > } > > nsresult >@@ -174,18 +172,16 @@ > nsCOMPtr<nsIFrameEnumerator> trav; > if (aVisual) { > trav = new nsVisualIterator(aPresContext, aStart, aType, > aLockInScrollView, aFollowOOFs); > } else { > trav = new nsFrameIterator(aPresContext, aStart, aType, > aLockInScrollView, aFollowOOFs); > } >- if (!trav) >- return NS_ERROR_OUT_OF_MEMORY; > *aEnumerator = trav; > NS_ADDREF(trav); > return NS_OK; > } Same for these, but if you don't, can you please do - *aEnumerator = trav; - NS_ADDREF(trav); + trav.forget(aEnumerator); >diff --git a/layout/base/nsLayoutDebugger.cpp b/layout/base/nsLayoutDebugger.cpp >--- a/layout/base/nsLayoutDebugger.cpp >+++ b/layout/base/nsLayoutDebugger.cpp >@@ -79,19 +79,16 @@ > nsresult > NS_NewLayoutDebugger(nsILayoutDebugger** aResult) > { > NS_PRECONDITION(aResult, "null OUT ptr"); > if (!aResult) { > return NS_ERROR_NULL_POINTER; > } > nsLayoutDebugger* it = new nsLayoutDebugger(); >- if (!it) { >- return NS_ERROR_OUT_OF_MEMORY; >- } > return it->QueryInterface(NS_GET_IID(nsILayoutDebugger), (void**)aResult); > } Here, too. >diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp >--- a/layout/base/nsPresShell.cpp >+++ b/layout/base/nsPresShell.cpp >@@ -1631,18 +1625,16 @@ > NS_NewPresShell(nsIPresShell** aInstancePtrResult) > { > NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); > > if (!aInstancePtrResult) > return NS_ERROR_NULL_POINTER; > > *aInstancePtrResult = new PresShell(); >- if (!*aInstancePtrResult) >- return NS_ERROR_OUT_OF_MEMORY; > > NS_ADDREF(*aInstancePtrResult); > return NS_OK; > } And here. Of course, all of these can be done in followup bugs / patches and only apply if bz doesn't disagree.
(In reply to comment #25) > Comment on attachment 530932 [details] [diff] [review] [review] > Part 8: Make nsLineIterator::Init return void > > >diff --git a/layout/generic/nsFloatManager.cpp b/layout/generic/nsFloatManager.cpp > >--- a/layout/generic/nsFloatManager.cpp > >+++ b/layout/generic/nsFloatManager.cpp > >@@ -570,17 +570,17 @@ > > mOld->List(stdout); > > } > > #endif > > > > delete mNew; > > } > > } > > > >-nsresult > >+void > > nsAutoFloatManager::CreateFloatManager(nsPresContext *aPresContext) > > { > > // Create a new float manager and install it in the reflow > > // state. `Remember' the old float manager so we can restore it > > // later. > > mNew = new nsFloatManager(aPresContext->PresShell()); > > if (! mNew) > > return NS_ERROR_OUT_OF_MEMORY; > > You should remove that check in this patch, not in part 9. Thanks. That must have happened when I fractured the patches and I didn't build with only a subset applied.
Attachment #530932 - Attachment is obsolete: true
Attachment #530932 - Flags: review?(bzbarsky)
Attachment #530933 - Attachment is obsolete: true
Attachment #530933 - Flags: review?(bzbarsky)
Attachment #530936 - Attachment is obsolete: true
Attachment #530936 - Flags: review?(bzbarsky)
(In reply to comment #32) > And because I like what you're doing so much: > > http://mxr.mozilla.org/mozilla-central/source/layout/style/nsRuleNode. > cpp#1934 Aren't those all Arena allocations? Are those infallible?
Attachment #530940 - Flags: review?(bzbarsky)
Attachment #530941 - Flags: review?(bzbarsky)
Attachment #530944 - Flags: review?(bzbarsky)
Attachment #530947 - Flags: review?(bzbarsky)
Rulenode allocations are fallible, last I checked. We can consider fixing that, but not in this bug! Ms2ger, can I suggest not overquoting? ;) Craig, I'll try to get to these in the next 2 days. Once we do these, I'd say push the patches and file a followup for any further work just to keep the bugs sane length.
Comment on attachment 530940 [details] [diff] [review] Part 8: Make nsLineIterator::Init return void Just nix init entirely in favor of constructor arguments.
Attachment #530940 - Flags: review?(bzbarsky) → review-
Comment on attachment 530941 [details] [diff] [review] Part 8b: Make nsAutoFloatManager::CreateFloatManager return void r=me
Attachment #530941 - Flags: review?(bzbarsky) → review+
Comment on attachment 530934 [details] [diff] [review] Part 10: Make nsFloatManager::StoreRegionFor return void r=me
Attachment #530934 - Flags: review?(bzbarsky) → review+
Comment on attachment 530941 [details] [diff] [review] Part 8b: Make nsAutoFloatManager::CreateFloatManager return void Actually, sorry. This operator new doesn't seem to be infallible. Perhaps that should be changed.
Attachment #530941 - Flags: review+ → review-
Comment on attachment 530944 [details] [diff] [review] Part 9: Remove OOM checks from layout/generic The frameset frame code should use fallible allocations for all of that stuff since it's under content control. The rest of the changes here look fine; maybe you want to split out the frameset changes into a separate patch...
Attachment #530944 - Flags: review?(bzbarsky) → review-
For that layout/base patch, there are some more new[] uses that may need to be fallible... Do you want me to review anyway?
Attachment #529631 - Attachment is obsolete: true
Attachment #530941 - Attachment is obsolete: true
Attachment #530940 - Attachment is obsolete: true
Attachment #530944 - Attachment is obsolete: true
Attachment #530947 - Attachment is obsolete: true
Attachment #530947 - Flags: review?(bzbarsky)
Attachment #536233 - Flags: review?(bzbarsky)
Attachment #536234 - Flags: review?(bzbarsky)
Attachment #536235 - Flags: review?(bzbarsky)
Comment on attachment 536233 [details] [diff] [review] Part 8: Remove nsLineIterator::Init by moving code to constructor Hmm. So I just realized that this is doing an allocation that should probably in fact be fallible. In particular, mLines.....
Attachment #536233 - Flags: review?(bzbarsky) → review-
Comment on attachment 536234 [details] [diff] [review] Part 9: Remove OOM checks from layout/generic r=me
Attachment #536234 - Flags: review?(bzbarsky) → review+
Comment on attachment 536235 [details] [diff] [review] Part 11: Remove OOM checks from layout/base r=me
Attachment #536235 - Flags: review?(bzbarsky) → review+
Attachment #536233 - Attachment is obsolete: true
Attachment #529633 - Attachment is obsolete: true
Whiteboard: [inbound]
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Whiteboard: [inbound]
Target Milestone: --- → mozilla7
(In reply to comment #39) > Comment on attachment 530941 [details] [diff] [review] > Part 8b: Make nsAutoFloatManager::CreateFloatManager return void > > Actually, sorry. This operator new doesn't seem to be infallible. Perhaps > that should be changed. What makes this particular operator new fallible?
> What makes this particular operator new fallible? It's a custom operator new that allocates memory via the presshell arena, not via global ::new.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: