зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1263218 - Fix possbile race under oomTest involving background threads r=terrence
--HG-- extra : rebase_source : 89e57d0d85029caf301f63e8409bffbbd9fd9073
This commit is contained in:
Родитель
1ab12b024b
Коммит
c20538fdb8
|
@ -124,36 +124,26 @@ extern JS_PUBLIC_DATA(uint64_t) maxAllocations;
|
|||
extern JS_PUBLIC_DATA(uint64_t) counter;
|
||||
extern JS_PUBLIC_DATA(bool) failAlways;
|
||||
|
||||
static inline void
|
||||
SimulateOOMAfter(uint64_t allocations, uint32_t thread, bool always) {
|
||||
MOZ_ASSERT(counter + allocations > counter);
|
||||
MOZ_ASSERT(thread > js::oom::THREAD_TYPE_NONE && thread < js::oom::THREAD_TYPE_MAX);
|
||||
targetThread = thread;
|
||||
maxAllocations = counter + allocations;
|
||||
failAlways = always;
|
||||
}
|
||||
extern void
|
||||
SimulateOOMAfter(uint64_t allocations, uint32_t thread, bool always);
|
||||
|
||||
static inline void
|
||||
ResetSimulatedOOM() {
|
||||
targetThread = THREAD_TYPE_NONE;
|
||||
maxAllocations = UINT64_MAX;
|
||||
failAlways = false;
|
||||
}
|
||||
extern void
|
||||
ResetSimulatedOOM();
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
IsThreadSimulatingOOM()
|
||||
{
|
||||
return js::oom::targetThread && js::oom::targetThread == js::oom::GetThreadType();
|
||||
}
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
IsSimulatedOOMAllocation()
|
||||
{
|
||||
return IsThreadSimulatingOOM() &&
|
||||
(counter == maxAllocations || (counter > maxAllocations && failAlways));
|
||||
}
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
ShouldFailWithOOM()
|
||||
{
|
||||
if (!IsThreadSimulatingOOM())
|
||||
|
@ -167,7 +157,7 @@ ShouldFailWithOOM()
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
HadSimulatedOOM() {
|
||||
return counter >= maxAllocations;
|
||||
}
|
||||
|
|
|
@ -1225,7 +1225,6 @@ ResetOOMFailure(JSContext* cx, unsigned argc, Value* vp)
|
|||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
args.rval().setBoolean(js::oom::HadSimulatedOOM());
|
||||
HelperThreadState().waitForAllThreads();
|
||||
js::oom::ResetSimulatedOOM();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include "jstypes.h"
|
||||
|
||||
#include "vm/HelperThreads.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "jswin.h"
|
||||
#endif
|
||||
|
@ -57,6 +59,25 @@ GetThreadType(void) {
|
|||
return threadType.get();
|
||||
}
|
||||
|
||||
void
|
||||
SimulateOOMAfter(uint64_t allocations, uint32_t thread, bool always) {
|
||||
MOZ_ASSERT(counter + allocations > counter);
|
||||
MOZ_ASSERT(thread > js::oom::THREAD_TYPE_NONE && thread < js::oom::THREAD_TYPE_MAX);
|
||||
targetThread = thread;
|
||||
maxAllocations = counter + allocations;
|
||||
failAlways = always;
|
||||
}
|
||||
|
||||
void
|
||||
ResetSimulatedOOM() {
|
||||
if (targetThread != THREAD_TYPE_NONE && targetThread != THREAD_TYPE_MAIN)
|
||||
HelperThreadState().waitForAllThreads();
|
||||
targetThread = THREAD_TYPE_NONE;
|
||||
maxAllocations = UINT64_MAX;
|
||||
failAlways = false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace oom
|
||||
} // namespace js
|
||||
#endif // defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
||||
|
|
Загрузка…
Ссылка в новой задаче