From a758f199260b97654afb432834360dbee8c618dd Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Tue, 6 Oct 2015 14:50:50 +0100 Subject: [PATCH] Bug 1209911 - Remove option to simulate OOM on all threads r=terrence --HG-- extra : rebase_source : c03694b314165446ffa3a6ab4d70fea02c202055 --- js/public/Utility.h | 9 ++--- js/src/builtin/TestingFunctions.cpp | 63 ++++++++++------------------- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/js/public/Utility.h b/js/public/Utility.h index 6e635201e476..5b36e5eec0b0 100644 --- a/js/public/Utility.h +++ b/js/public/Utility.h @@ -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); diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 35133f06e24f..edf6e318309f 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -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; }