Bug 872823 - implement oomAfterAllocations testing function

--HG--
extra : rebase_source : 9baca68d56f8b15e691f2154bd8aa6b6cea45845
This commit is contained in:
Steve Fink 2013-05-20 12:59:55 -07:00
Родитель 3c9dc008ee
Коммит 255134ac6f
4 изменённых файлов: 36 добавлений и 6 удалений

Просмотреть файл

@ -84,10 +84,11 @@ extern JS_PUBLIC_API(void) JS_Abort(void);
#else
# ifdef DEBUG
/*
* In order to test OOM conditions, when the shell command-line option
* |-A NUM| is passed, we fail continuously after the NUM'th allocation.
* In order to test OOM conditions, when the testing function
* oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th
* allocation from now.
*/
extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set from shell/js.cpp */
extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */
extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */
#ifdef JS_OOM_DO_BACKTRACES

Просмотреть файл

@ -731,6 +731,29 @@ CountHeap(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
#ifdef DEBUG
static JSBool
OOMAfterAllocations(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() != 1) {
JS_ReportError(cx, "count argument required");
return false;
}
int32_t count;
if (!JS_ValueToInt32(cx, args[0], &count))
return false;
if (count <= 0) {
JS_ReportError(cx, "count argument must be positive");
return false;
}
OOM_maxAllocations = OOM_counter + count;
return true;
}
#endif
static unsigned finalizeCount = 0;
static void
@ -919,6 +942,13 @@ static JSFunctionSpecWithHelp TestingFunctions[] = {
" count all things or one of 'object', 'double', 'string', 'function'\n"
" to count only things of that kind."),
#ifdef DEBUG
JS_FN_HELP("oomAfterAllocations", OOMAfterAllocations, 1, 0,
"oomAfterAllocations(count)",
" After 'count' js_malloc memory allocations, fail every following allocation\n"
" (return NULL)."),
#endif
JS_FN_HELP("makeFinalizeObserver", MakeFinalizeObserver, 0, 0,
"makeFinalizeObserver()",
" Get a special object whose finalization increases the counter returned\n"

Просмотреть файл

@ -1738,6 +1738,8 @@ class TypedArrayTemplate
? UseNewTypeForInitializer(cx, script, pc, fastClass())
: GenericObject;
RootedObject obj(cx, NewBuiltinClassInstance(cx, fastClass(), newKind));
if (!obj)
return NULL;
if (script) {
if (!types::SetInitializerObjectType(cx, script, pc, obj, newKind))

Просмотреть файл

@ -5262,7 +5262,6 @@ main(int argc, char **argv, char **envp)
|| !op.addBoolOption('D', "dump-bytecode", "Dump bytecode with exec count for all scripts")
|| !op.addBoolOption('b', "print-timing", "Print sub-ms runtime for each file that's run")
#ifdef DEBUG
|| !op.addIntOption('A', "oom-after", "COUNT", "Trigger OOM after COUNT allocations", -1)
|| !op.addBoolOption('O', "print-alloc", "Print the number of allocations at exit")
#endif
|| !op.addOptionalStringArg("script", "A script to execute (after all options)")
@ -5344,8 +5343,6 @@ main(int argc, char **argv, char **envp)
* Process OOM options as early as possible so that we can observe as many
* allocations as possible.
*/
if (op.getIntOption('A') >= 0)
OOM_maxAllocations = op.getIntOption('A');
if (op.getBoolOption('O'))
OOM_printAllocationCount = true;