зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1209911 - Add oomThreadTypes() test function to report the number of thread types we can simulate OOM on r=terrence
--HG-- extra : rebase_source : facfa7ff892375e7c5999cd9310948866542e2f9
This commit is contained in:
Родитель
810fbfb206
Коммит
298b347ff4
|
@ -984,6 +984,14 @@ DisableTrackAllocations(JSContext* cx, unsigned argc, Value* vp)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
||||||
|
static bool
|
||||||
|
OOMThreadTypes(JSContext* cx, unsigned argc, Value* vp)
|
||||||
|
{
|
||||||
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
args.rval().setInt32(js::oom::THREAD_TYPE_MAX);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
OOMAfterAllocations(JSContext* cx, unsigned argc, Value* vp)
|
OOMAfterAllocations(JSContext* cx, unsigned argc, Value* vp)
|
||||||
{
|
{
|
||||||
|
@ -2928,6 +2936,11 @@ static const JSFunctionSpecWithHelp TestingFunctions[] = {
|
||||||
" Stop capturing the JS stack at every allocation."),
|
" Stop capturing the JS stack at every allocation."),
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
|
||||||
|
JS_FN_HELP("oomThreadTypes", OOMThreadTypes, 0, 0,
|
||||||
|
"oomThreadTypes()",
|
||||||
|
" Get the number of thread types that can be used as an argument for\n"
|
||||||
|
"oomAfterAllocations() and oomAtAllocation()."),
|
||||||
|
|
||||||
JS_FN_HELP("oomAfterAllocations", OOMAfterAllocations, 2, 0,
|
JS_FN_HELP("oomAfterAllocations", OOMAfterAllocations, 2, 0,
|
||||||
"oomAfterAllocations(count [,threadType])",
|
"oomAfterAllocations(count [,threadType])",
|
||||||
" After 'count' js_malloc memory allocations, fail every following allocation\n"
|
" After 'count' js_malloc memory allocations, fail every following allocation\n"
|
||||||
|
|
|
@ -1,34 +1,39 @@
|
||||||
// Function to test OOM handling by repeatedly calling a function and failing
|
// Function to test OOM handling by repeatedly calling a function and failing
|
||||||
// successive allocations.
|
// successive allocations.
|
||||||
|
|
||||||
const verbose = false;
|
if (!("oomAtAllocation" in this && "resetOOMFailure" in this && "oomThreadTypes" in this))
|
||||||
|
|
||||||
if (!("oomAtAllocation" in this && "resetOOMFailure" in this))
|
|
||||||
quit();
|
quit();
|
||||||
|
|
||||||
if ("gczeal" in this)
|
if ("gczeal" in this)
|
||||||
gczeal(0);
|
gczeal(0);
|
||||||
|
|
||||||
|
const verbose = ("os" in this) && os.getenv("OOM_VERBOSE");
|
||||||
|
|
||||||
// Test out of memory handing by calling a function f() while causing successive
|
// Test out of memory handing by calling a function f() while causing successive
|
||||||
// memory allocations to fail. Repeat until f() finishes without reaching the
|
// memory allocations to fail. Repeat until f() finishes without reaching the
|
||||||
// failing allocation.
|
// failing allocation.
|
||||||
function oomTest(f) {
|
function oomTest(f) {
|
||||||
var i = 1;
|
for (let thread = 1; thread < oomThreadTypes(); thread++) {
|
||||||
var more;
|
|
||||||
do {
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
print("fail at " + i);
|
print("testing thread " + thread);
|
||||||
try {
|
|
||||||
oomAtAllocation(i);
|
|
||||||
f();
|
|
||||||
more = resetOOMFailure();
|
|
||||||
} catch (e) {
|
|
||||||
// Ignore exceptions.
|
|
||||||
more = resetOOMFailure();
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
} while(more);
|
|
||||||
|
|
||||||
if (verbose)
|
var i = 1;
|
||||||
print("finished after " + i);
|
var more;
|
||||||
|
do {
|
||||||
|
if (verbose)
|
||||||
|
print("fail at " + i);
|
||||||
|
try {
|
||||||
|
oomAtAllocation(i, thread);
|
||||||
|
f();
|
||||||
|
more = resetOOMFailure();
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore exceptions.
|
||||||
|
more = resetOOMFailure();
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
} while(more);
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
print("finished after " + (i - 2) + " failures");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче