Bug 1200642 - Add checkSimulatedOOM() to AllocPolicy r=Waldo

This commit is contained in:
Jon Coppeard 2015-09-30 11:34:44 +01:00
parent 47aef61183
commit d36da99d53
7 changed files with 47 additions and 0 deletions

View File

@ -559,6 +559,9 @@ class LifoAllocPolicy
}
void reportAllocOverflow() const {
}
bool checkSimulatedOOM() const {
return fb == Infallible || !js::oom::ShouldFailWithOOM();
}
};
} // namespace js

View File

@ -103,6 +103,9 @@ class JitAllocPolicy
}
void reportAllocOverflow() const {
}
bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
}
};
class OldJitAllocPolicy
@ -120,6 +123,9 @@ class OldJitAllocPolicy
}
void reportAllocOverflow() const {
}
bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
}
};
class AutoJitContextAlloc

View File

@ -38,8 +38,14 @@ class SystemAllocPolicy
}
void free_(void* p) { js_free(p); }
void reportAllocOverflow() const {}
bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
}
};
class ExclusiveContext;
void ReportOutOfMemory(ExclusiveContext* cxArg);
/*
* Allocation policy that calls the system memory functions and reports errors
* to the context. Since the JSContext given on construction is stored for
@ -93,6 +99,15 @@ class TempAllocPolicy
}
JS_FRIEND_API(void) reportAllocOverflow() const;
bool checkSimulatedOOM() const {
if (js::oom::ShouldFailWithOOM()) {
js::ReportOutOfMemory(reinterpret_cast<ExclusiveContext*>(cx_));
return false;
}
return true;
}
};
} /* namespace js */

View File

@ -2087,6 +2087,10 @@ class RuntimeAllocPolicy
void free_(void* p) { js_free(p); }
void reportAllocOverflow() const {}
bool checkSimulatedOOM() const {
return !js::oom::ShouldFailWithOOM();
}
};
extern const JSSecurityCallbacks NullSecurityCallbacks;

View File

@ -70,6 +70,7 @@ private:
void *realloc_(void *p, size_t bytes) { return ::realloc(p, bytes); }
void free_(void *p) { ::free(p); }
void reportAllocOverflow() const {}
bool checkSimulatedOOM() const { return true; }
};
typedef js::HashMap<nsIContent*, CacheEntry, js::DefaultHasher<nsIContent*>,

View File

@ -225,6 +225,7 @@ public:
}
static void reportAllocOverflow() { ExitOnFailure(nullptr); }
bool checkSimulatedOOM() const { return true; }
};
// This is only needed because of the |const void*| vs |void*| arg mismatch.

View File

@ -39,6 +39,18 @@ namespace mozilla {
* to allocate more than the available memory space -- think allocating an
* array of large-size objects, where N * size overflows) before null is
* returned.
* - bool checkSimulatedOOM() const
* Some clients generally allocate memory yet in some circumstances won't
* need to do so. For example, appending to a vector with a small amount of
* inline storage generally allocates memory, but no allocation occurs
* unless appending exceeds inline storage. But for testing purposes, it
* can be useful to treat *every* operation as allocating.
* Clients (such as this hypothetical append method implementation) should
* call this method in situations that don't allocate, but could generally,
* to support this. The default behavior should return true; more
* complicated behavior might be to return false only after a certain
* number of allocations-or-check-simulated-OOMs (coordinating with the
* other AllocPolicy methods) have occurred.
*
* mfbt provides (and typically uses by default) only MallocAllocPolicy, which
* does nothing more than delegate to the malloc/alloc/free functions.
@ -83,6 +95,11 @@ public:
void reportAllocOverflow() const
{
}
bool checkSimulatedOOM() const
{
return true;
}
};
} // namespace mozilla