Bug 1209911 - Remove option to simulate OOM on all threads r=terrence

--HG--
extra : rebase_source : c03694b314165446ffa3a6ab4d70fea02c202055
This commit is contained in:
Jon Coppeard 2015-10-06 14:50:50 +01:00
parent f3fb1958bf
commit a758f19926
2 changed files with 24 additions and 48 deletions

View File

@ -73,7 +73,7 @@ namespace oom {
* without causing an OOM in the main thread first.
*/
enum ThreadType {
THREAD_TYPE_NONE, // 0
THREAD_TYPE_NONE = 0, // 0
THREAD_TYPE_MAIN, // 1
THREAD_TYPE_ASMJS, // 2
THREAD_TYPE_ION, // 3
@ -127,7 +127,7 @@ extern JS_PUBLIC_DATA(uint32_t) targetThread;
static inline bool
IsThreadSimulatingOOM()
{
return !js::oom::targetThread || js::oom::targetThread == js::oom::GetThreadType();
return js::oom::targetThread && js::oom::targetThread == js::oom::GetThreadType();
}
static inline bool
@ -203,11 +203,8 @@ struct MOZ_RAII AutoEnterOOMUnsafeRegion
}
~AutoEnterOOMUnsafeRegion() {
// TODO: This class is not thread safe. If another thread has modified
// OOM_maxAllocations, don't try to restore it.
if (OOM_maxAllocations != UINT32_MAX)
return;
if (oomEnabled_) {
MOZ_ASSERT(OOM_maxAllocations == UINT32_MAX);
int64_t maxAllocations = OOM_counter + oomAfter_;
MOZ_ASSERT(maxAllocations >= 0 && maxAllocations < UINT32_MAX);
OOM_maxAllocations = uint32_t(maxAllocations);

View File

@ -993,25 +993,16 @@ OOMThreadTypes(JSContext* cx, unsigned argc, Value* vp)
}
static bool
OOMAfterAllocations(JSContext* cx, unsigned argc, Value* vp)
SetupOOMFailure(JSContext* cx, bool failAlways, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() < 1) {
JS_ReportError(cx, "count argument required");
JS_ReportError(cx, "Count argument required");
return false;
}
if (args.length() > 2) {
JS_ReportError(cx, "too many arguments");
return false;
}
uint32_t targetThread = 0;
if (!ToUint32(cx, args.get(1), &targetThread))
return false;
if (targetThread >= js::oom::THREAD_TYPE_MAX) {
JS_ReportError(cx, "invalid thread type specified");
JS_ReportError(cx, "Too many arguments");
return false;
}
@ -1019,45 +1010,32 @@ OOMAfterAllocations(JSContext* cx, unsigned argc, Value* vp)
if (!JS::ToUint32(cx, args.get(0), &count))
return false;
uint32_t targetThread = js::oom::THREAD_TYPE_MAIN;
if (args.length() > 1 && !ToUint32(cx, args[1], &targetThread))
return false;
if (targetThread == js::oom::THREAD_TYPE_NONE || targetThread >= js::oom::THREAD_TYPE_MAX) {
JS_ReportError(cx, "Invalid thread type specified");
return false;
}
HelperThreadState().waitForAllThreads();
js::oom::targetThread = targetThread;
OOM_maxAllocations = OOM_counter + count;
OOM_failAlways = true;
OOM_failAlways = failAlways;
return true;
}
static bool
OOMAfterAllocations(JSContext* cx, unsigned argc, Value* vp)
{
return SetupOOMFailure(cx, true, argc, vp);
}
static bool
OOMAtAllocation(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() < 1) {
JS_ReportError(cx, "count argument required");
return false;
}
if (args.length() > 2) {
JS_ReportError(cx, "too many arguments");
return false;
}
uint32_t targetThread = 0;
if (!ToUint32(cx, args.get(1), &targetThread))
return false;
if (targetThread >= js::oom::THREAD_TYPE_MAX) {
JS_ReportError(cx, "invalid thread type specified");
return false;
}
uint32_t count;
if (!JS::ToUint32(cx, args.get(0), &count))
return false;
HelperThreadState().waitForAllThreads();
js::oom::targetThread = targetThread;
OOM_maxAllocations = OOM_counter + count;
OOM_failAlways = false;
return true;
return SetupOOMFailure(cx, false, argc, vp);
}
static bool
@ -1065,6 +1043,7 @@ ResetOOMFailure(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setBoolean(OOM_counter >= OOM_maxAllocations);
js::oom::targetThread = js::oom::THREAD_TYPE_NONE;
OOM_maxAllocations = UINT32_MAX;
return true;
}