зеркало из 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(uint64_t) counter;
|
||||||
extern JS_PUBLIC_DATA(bool) failAlways;
|
extern JS_PUBLIC_DATA(bool) failAlways;
|
||||||
|
|
||||||
static inline void
|
extern void
|
||||||
SimulateOOMAfter(uint64_t allocations, uint32_t thread, bool always) {
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
extern void
|
||||||
ResetSimulatedOOM() {
|
ResetSimulatedOOM();
|
||||||
targetThread = THREAD_TYPE_NONE;
|
|
||||||
maxAllocations = UINT64_MAX;
|
|
||||||
failAlways = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool
|
inline bool
|
||||||
IsThreadSimulatingOOM()
|
IsThreadSimulatingOOM()
|
||||||
{
|
{
|
||||||
return js::oom::targetThread && js::oom::targetThread == js::oom::GetThreadType();
|
return js::oom::targetThread && js::oom::targetThread == js::oom::GetThreadType();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
inline bool
|
||||||
IsSimulatedOOMAllocation()
|
IsSimulatedOOMAllocation()
|
||||||
{
|
{
|
||||||
return IsThreadSimulatingOOM() &&
|
return IsThreadSimulatingOOM() &&
|
||||||
(counter == maxAllocations || (counter > maxAllocations && failAlways));
|
(counter == maxAllocations || (counter > maxAllocations && failAlways));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
inline bool
|
||||||
ShouldFailWithOOM()
|
ShouldFailWithOOM()
|
||||||
{
|
{
|
||||||
if (!IsThreadSimulatingOOM())
|
if (!IsThreadSimulatingOOM())
|
||||||
|
@ -167,7 +157,7 @@ ShouldFailWithOOM()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
inline bool
|
||||||
HadSimulatedOOM() {
|
HadSimulatedOOM() {
|
||||||
return counter >= maxAllocations;
|
return counter >= maxAllocations;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1225,7 +1225,6 @@ ResetOOMFailure(JSContext* cx, unsigned argc, Value* vp)
|
||||||
{
|
{
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
args.rval().setBoolean(js::oom::HadSimulatedOOM());
|
args.rval().setBoolean(js::oom::HadSimulatedOOM());
|
||||||
HelperThreadState().waitForAllThreads();
|
|
||||||
js::oom::ResetSimulatedOOM();
|
js::oom::ResetSimulatedOOM();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "jstypes.h"
|
#include "jstypes.h"
|
||||||
|
|
||||||
|
#include "vm/HelperThreads.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# include "jswin.h"
|
# include "jswin.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +59,25 @@ GetThreadType(void) {
|
||||||
return threadType.get();
|
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 oom
|
||||||
} // namespace js
|
} // namespace js
|
||||||
#endif // defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
#endif // defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче