Bug 1141234 - Part 1: Abstract PossiblyFail into the OOM testing machinery; r=sfink

This commit is contained in:
Terrence Cole 2015-03-11 11:06:20 -07:00
parent 74500c29ee
commit 180d3adfed
2 changed files with 14 additions and 8 deletions

View File

@ -95,9 +95,22 @@ static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); }
} \
} while (0)
namespace js {
namespace oom {
static inline bool ShouldFailWithOOM()
{
if (++OOM_counter > OOM_maxAllocations) {
JS_OOM_CALL_BP_FUNC();
return true;
}
return false;
}
}
}
# else
# define JS_OOM_POSSIBLY_FAIL() do {} while(0)
# define JS_OOM_POSSIBLY_FAIL_BOOL() do {} while(0)
namespace js { namespace oom { static inline bool ShouldFailWithOOM() { return false; } } }
# endif /* DEBUG || JS_OOM_BREAKPOINT */
static inline void* js_malloc(size_t bytes)

View File

@ -53,13 +53,6 @@ TryNewNurseryObject(JSContext *cx, size_t thingSize, size_t nDynamicSlots, const
return nullptr;
}
static inline bool
PossiblyFail()
{
JS_OOM_POSSIBLY_FAIL_BOOL();
return true;
}
static inline bool
GCIfNeeded(ExclusiveContext *cx)
{
@ -121,7 +114,7 @@ CheckAllocatorState(ExclusiveContext *cx, AllocKind kind)
JS::AutoAssertOnGC::VerifyIsSafeToGC(rt);
// For testing out of memory conditions
if (!PossiblyFail()) {
if (js::oom::ShouldFailWithOOM()) {
ReportOutOfMemory(ncx);
return false;
}