Closed
Bug 645646
Opened 15 years ago
Closed 15 years ago
AvmCore::presweep must allow kCanFail (e.g. OOM handling)
Categories
(Tamarin Graveyard :: Virtual Machine, defect, P2)
Tamarin Graveyard
Virtual Machine
Tracking
(Not tracked)
RESOLVED
FIXED
Q2 11 - Wasabi
People
(Reporter: pnkfelix, Assigned: pnkfelix)
References
Details
(Whiteboard: WE:2833668)
Attachments
(2 files)
|
257 bytes,
text/plain
|
Details | |
|
3.17 KB,
patch
|
stejohns
:
review+
|
Details | Diff | Splinter Review |
When we run out of memory to allocate, we perform a last-ditch collection effort.
This collection effort follows the standard collector control flow; in particular, it invokes the presweep callbacks before sweeping.
One of the presweep handlers is AvmCore::presweep. In part, it attempts to remove unreachable interned-strings and namespaces from their respective internal tables.
If it finds something to remove from the tables [1], it also rehashes the table [2].
But the rehash attempts to allocate a new table. We are OOM'ing, so the allocation can't happen. The rehash is invoking a non-kCanFail Alloc call, and so when that allocation is denied, we Abort.
This is no good. We know in this case that the rehash is to shrink, not to grow, and so it would be safe to delay the rehash for later (or simply not do it at all). This code should be generalized to do so.
[1] For some reason it applies the rehashing logic only to the namespaces table, not to the intern table. But (1) that's not what the comments say, and (2) I don't see why it is not applied to the intern table.
[2] There's a TODO note about making this less aggressive; presumably that's just talking about not rehashing unless we removed a significant amount; right now "significant" in this context is "any entries at all."
Assignee: nobody → fklockii
Flags: flashplayer-qrb+
Flags: flashplayer-injection-
Priority: -- → P2
Whiteboard: WE:2833668
Target Milestone: --- → Q2 11 - Wasabi
| Assignee | ||
Comment 1•15 years ago
|
||
| Assignee | ||
Comment 2•15 years ago
|
||
(In reply to comment #1)
> Created attachment 522376 [details]
> test case (run with "-memlimit 600")
The reason I *think* this is a test case is the stack trace I get when I set a breakpoint on GCHeap::Abort:
#0 0x0005c5ef in MMgc::GCHeap::Abort ()
#1 0x00063a8b in MMgc::GCHeap::Alloc ()
#2 0x0004e3e9 in MMgc::FixedMalloc::LargeAlloc ()
#3 0x0004ead5 in MMgc::FixedMalloc::OutOfLineAlloc ()
#4 0x0006e5db in MMgc::NewTaggedArray ()
#5 0x0008c7eb in avmplus::AvmCore::rehashStrings ()
#6 0x0008cc0e in avmplus::AvmCore::findStringUTF16 ()
#7 0x0008ce6b in avmplus::AvmCore::findInternedString ()
#8 0x00113fdd in avmplus::Sampler::getFakeFunctionName ()
#9 0x0006dc05 in MMgc::ZCT::Reap ()
#10 0x00057465 in MMgc::GC::memoryStatusChange ()
#11 0x000630d4 in MMgc::GCHeap::SendFreeMemorySignal ()
#12 0x000636e4 in MMgc::GCHeap::AllocHelper ()
#13 0x0006385c in MMgc::GCHeap::Alloc ()
#14 0x0004e3e9 in MMgc::FixedMalloc::LargeAlloc ()
#15 0x0004ead5 in MMgc::FixedMalloc::OutOfLineAlloc ()
#16 0x0006e5db in MMgc::NewTaggedArray ()
#17 0x0008c7eb in avmplus::AvmCore::rehashStrings ()
#18 0x0008d06e in avmplus::AvmCore::findString ()
#19 0x00094479 in avmplus::AvmCore::intern ()
| Assignee | ||
Comment 3•15 years ago
|
||
Oh, wait, I did not look at that stack trace carefully enough. This is Abort is happening in the context of a Reap, not a presweep, and its due to the Sampler running (I was using a debugger build).
This is probably what Lars meant when he mentioned that allocations in presence of OOM are scary; I cannot trust that it is enough to just modify the control path during presweep. . .
Comment 4•15 years ago
|
||
That stack trace looks like an infinite loop to me. The Sampler calls findInternedString with the expectation that nothing will be allocated and that appears broken.
| Assignee | ||
Comment 5•15 years ago
|
||
(In reply to comment #4)
> That stack trace looks like an infinite loop to me. The Sampler calls
> findInternedString with the expectation that nothing will be allocated and that
> appears broken.
Do you mean it would be an infinite loop if it were not for the OOM Abort short-cutting it?
(I'm ignorant of the Sampler code logic.)
Comment 6•15 years ago
|
||
I said that because I saw rehashStrings on the stack twice. I'm sure that code wasn't intended to be re-entered. There is a separate bug here that findInternedString isn't honoring its documented contract:
/**
* intern without allocating memory, returns NULL if its not already interned
*/
Fixing that may or may not fix this bug.
| Assignee | ||
Comment 7•15 years ago
|
||
(In reply to comment #6)
> I said that because I saw rehashStrings on the stack twice. I'm sure that
> code wasn't intended to be re-entered. There is a separate bug here that
> findInternedString isn't honoring its documented contract:
>
> /**
> * intern without allocating memory, returns NULL if its not already
> interned
> */
>
> Fixing that may or may not fix this bug.
Filed as Bug 645748.
| Assignee | ||
Comment 8•15 years ago
|
||
Uh oh, rathole alert.
I'm trying this change in AvmCore::rehashNamespaces:
@@ -3740,7 +3746,13 @@
DRC(Namespacep) *old = namespaces;
int oldCount = numNamespaces;
- namespaces = mmfx_new_array(DRC(Namespacep), newlen);
+ if (newlen <= oldCount) {
+ namespaces = mmfx_new_array_opt(DRC(Namespacep), newlen, kCanFail);
+ if (namespaces == NULL)
+ return;
+ } else {
+ namespaces = mmfx_new_array(DRC(Namespacep), newlen);
+ }
numNamespaces = newlen;
for (int i=0; i < oldCount; i++)
But now I'm hitting a new problem: MMgcConstructTaggedArray (which is what mmfx_new_array_opt expands into) seems to be written in a manner that assumes its opts parameter never includes kCanFail.
| Assignee | ||
Comment 9•15 years ago
|
||
(In reply to comment #8)
> But now I'm hitting a new problem: MMgcConstructTaggedArray (which is what
> mmfx_new_array_opt expands into) seems to be written in a manner that assumes
> its opts parameter never includes kCanFail.
I'm talking here about the MMgcConstructedTaggedArray template function on line 273 of GCGlobalNew.h. The variant that consumes a void* just delegates to NewTaggedArray, so that one might be fine.
Comment 10•15 years ago
|
||
(In reply to comment #8)
>
> But now I'm hitting a new problem: MMgcConstructTaggedArray (which is what
> mmfx_new_array_opt expands into) seems to be written in a manner that assumes
> its opts parameter never includes kCanFail.
Related bug# 642539?
| Assignee | ||
Comment 11•15 years ago
|
||
(In reply to comment #10)
> (In reply to comment #8)
> >
> > But now I'm hitting a new problem: MMgcConstructTaggedArray (which is what
> > mmfx_new_array_opt expands into) seems to be written in a manner that assumes
> > its opts parameter never includes kCanFail.
>
> Related bug# 642539?
Yes, I think so.
I think Lars complaint in his note is about the test case being used that exposes the problem, but clearly there are other cases (i.e., this bug) that do not involve allocation size overflow.
| Assignee | ||
Comment 12•15 years ago
|
||
I have "fixes" for the namespace hashtable resizing and for Bug 642539, but I'm still running into OOM conditions under the 50 MB memory limit (in a totally different place, AFAICT).
I'm going to try analyzing the memory profile, and also check if varying the gc-load policy modifies things, but I'm no longer certain I can remove the OOM scenario entirely for Wasabi without entirely reverting the gc-load policy (which I'm pretty sure is not a step we want to take).
| Assignee | ||
Comment 13•15 years ago
|
||
Steven: The other obvious approach here is to just change rehashNamespaces itself to pass kCanFail conditionally whenever newlen <= oldCount.
I did not take that approach here because I am trying to keep the scope of the change minimal for Wasabi.
I would be curious to hear your thoughts on what we should do for the mainline in general. But in any case this seems like a step in the right direction to me.
Also Steven: I'm planning on pushing an analogue of this to Wasabi if I get an R+ on this patch. If you want to review the corresponding patch for Wasabi, I can post it; its the obvious analogue that uses DRC() instead of GCMember<> in all the appropriate spots.
Attachment #523512 -
Flags: review?(stejohns)
Comment 14•15 years ago
|
||
Comment on attachment 523512 [details] [diff] [review]
conservative change: kCanFail for alloc in presweep alone
Dumb question: if the table isn't growing, why bother allocating a new table -- can't we just rehash in place?
Attachment #523512 -
Flags: review?(stejohns) → review+
| Assignee | ||
Comment 15•15 years ago
|
||
(In reply to comment #14)
> Comment on attachment 523512 [details] [diff] [review]
> conservative change: kCanFail for alloc in presweep alone
>
> Dumb question: if the table isn't growing, why bother allocating a new table --
> can't we just rehash in place?
Not a dumb question. I'd have to review the code.
Naive guesses before I take on such a review:
-- If we're shrinking, then you want to allocate a new table so that you can not waste the space for the larger-than-necessary table.
-- If we're staying the same size, then doesn't the rehashing algorithm need to be clever to avoid overwriting an element that remains to be rehashed? (I'm assuming that the rehashing uses the old table as the work-queue.)
Comment 16•15 years ago
|
||
changeset: 6153:974f98886318
user: Felix S Klock II <fklockii>
summary: Bug 645646: AvmCore::presweep table alloc must allow kCanFail (r=stejohns).
http://hg.mozilla.org/tamarin-redux/rev/974f98886318
| Assignee | ||
Comment 17•15 years ago
|
||
(In reply to comment #15)
> (In reply to comment #14)
> > Comment on attachment 523512 [details] [diff] [review]
> > conservative change: kCanFail for alloc in presweep alone
> >
> > Dumb question: if the table isn't growing, why bother allocating a new table --
> > can't we just rehash in place?
>
> Not a dumb question. I'd have to review the code.
Filed as Bug 647696.
| Assignee | ||
Comment 18•15 years ago
|
||
Pushed to Wasabi as part of p4 CL 878813.
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Comment 19•15 years ago
|
||
Fix submitted to Wasabi with P4 CL: 878813, Verified fixed/UTR by player qe with player 10.3.180.77
Talking with Felix it does not appear that this would be easily testable.
You need to log in
before you can comment on or make changes to this bug.
Description
•