Bug 1201057 - Move AutoEnterOOMUnsafeRegion to Utility.h with the other OOM simulation infrastructure r=terrence

This commit is contained in:
Jon Coppeard 2015-09-21 14:31:51 +01:00
parent c5b4b99e86
commit b07921aacc
3 changed files with 39 additions and 30 deletions

View File

@ -181,6 +181,45 @@ static inline bool ShouldFailWithOOM() { return false; }
# endif /* DEBUG || JS_OOM_BREAKPOINT */
namespace js {
MOZ_NORETURN MOZ_COLD void
CrashAtUnhandlableOOM(const char* reason);
/* Disable OOM testing in sections which are not OOM safe. */
struct MOZ_RAII AutoEnterOOMUnsafeRegion
{
void crash(const char* reason) {
CrashAtUnhandlableOOM(reason);
}
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
AutoEnterOOMUnsafeRegion()
: oomEnabled_(OOM_maxAllocations != UINT32_MAX), oomAfter_(0)
{
if (oomEnabled_) {
oomAfter_ = int64_t(OOM_maxAllocations) - OOM_counter;
OOM_maxAllocations = UINT32_MAX;
}
}
~AutoEnterOOMUnsafeRegion() {
MOZ_ASSERT(OOM_maxAllocations == UINT32_MAX);
if (oomEnabled_) {
int64_t maxAllocations = OOM_counter + oomAfter_;
MOZ_ASSERT(maxAllocations >= 0 && maxAllocations < UINT32_MAX);
OOM_maxAllocations = uint32_t(maxAllocations);
}
}
private:
bool oomEnabled_;
int64_t oomAfter_;
#endif
};
} /* namespace js */
static inline void* js_malloc(size_t bytes)
{
JS_OOM_POSSIBLY_FAIL();

View File

@ -1312,33 +1312,6 @@ class MOZ_RAII AutoSuppressGC
}
};
#ifdef DEBUG
/* Disable OOM testing in sections which are not OOM safe. */
class MOZ_RAII AutoEnterOOMUnsafeRegion
{
bool oomEnabled_;
int64_t oomAfter_;
public:
AutoEnterOOMUnsafeRegion()
: oomEnabled_(OOM_maxAllocations != UINT32_MAX), oomAfter_(0)
{
if (oomEnabled_) {
oomAfter_ = OOM_maxAllocations - OOM_counter;
OOM_maxAllocations = UINT32_MAX;
}
}
~AutoEnterOOMUnsafeRegion() {
MOZ_ASSERT(OOM_maxAllocations == UINT32_MAX);
if (oomEnabled_)
OOM_maxAllocations = OOM_counter + oomAfter_;
}
};
#else
class MOZ_RAII AutoEnterOOMUnsafeRegion {};
#endif /* DEBUG */
// A singly linked list of zones.
class ZoneList
{

View File

@ -45,9 +45,6 @@ js_memcpy(void* dst_, const void* src_, size_t len)
namespace js {
MOZ_NORETURN MOZ_COLD void
CrashAtUnhandlableOOM(const char* reason);
template <class T>
struct AlignmentTestStruct
{