Bug 1155618 - Don't retry memory allocation if we're simulating OOM r=terrence

This commit is contained in:
Jon Coppeard 2015-07-01 18:53:04 +01:00
parent 47cc82c456
commit 57d849ede0
2 changed files with 35 additions and 24 deletions

View File

@ -82,17 +82,25 @@ static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); }
namespace js {
namespace oom {
static inline bool ShouldFailWithOOM()
static inline bool
IsSimulatedOOMAllocation()
{
return OOM_counter == OOM_maxAllocations ||
(OOM_counter > OOM_maxAllocations && OOM_failAlways);
}
static inline bool
ShouldFailWithOOM()
{
OOM_counter++;
if (OOM_counter == OOM_maxAllocations ||
(OOM_counter > OOM_maxAllocations && OOM_failAlways))
{
if (IsSimulatedOOMAllocation()) {
JS_OOM_CALL_BP_FUNC();
return true;
}
return false;
}
} /* namespace oom */
} /* namespace js */
@ -114,6 +122,7 @@ static inline bool ShouldFailWithOOM()
# define JS_OOM_POSSIBLY_FAIL_BOOL() do {} while(0)
namespace js {
namespace oom {
static inline bool IsSimulatedOOMAllocation() { return false; }
static inline bool ShouldFailWithOOM() { return false; }
} /* namespace oom */
} /* namespace js */

View File

@ -744,27 +744,29 @@ JSRuntime::onOutOfMemory(AllocFunction allocFunc, size_t nbytes, void* reallocPt
if (isHeapBusy())
return nullptr;
/*
* Retry when we are done with the background sweeping and have stopped
* all the allocations and released the empty GC chunks.
*/
gc.onOutOfMallocMemory();
void* p;
switch (allocFunc) {
case AllocFunction::Malloc:
p = js_malloc(nbytes);
break;
case AllocFunction::Calloc:
p = js_calloc(nbytes);
break;
case AllocFunction::Realloc:
p = js_realloc(reallocPtr, nbytes);
break;
default:
MOZ_CRASH();
if (!oom::IsSimulatedOOMAllocation()) {
/*
* Retry when we are done with the background sweeping and have stopped
* all the allocations and released the empty GC chunks.
*/
gc.onOutOfMallocMemory();
void* p;
switch (allocFunc) {
case AllocFunction::Malloc:
p = js_malloc(nbytes);
break;
case AllocFunction::Calloc:
p = js_calloc(nbytes);
break;
case AllocFunction::Realloc:
p = js_realloc(reallocPtr, nbytes);
break;
default:
MOZ_CRASH();
}
if (p)
return p;
}
if (p)
return p;
if (maybecx)
ReportOutOfMemory(maybecx);