Bug 1585159 - Allow the shell to invoke a last-ditch GC r=jonco

I want to add this option to the gc() shell builtin to write a test case for
this bug.

Differential Revision: https://phabricator.services.mozilla.com/D48291

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Bone 2019-10-08 23:51:18 +00:00
Родитель 13f15730a5
Коммит 32fc4906ae
1 изменённых файлов: 22 добавлений и 9 удалений

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

@ -468,14 +468,27 @@ static bool GC(JSContext* cx, unsigned argc, Value* vp) {
}
}
bool shrinking = false;
JSGCInvocationKind gckind = GC_NORMAL;
JS::GCReason reason = JS::GCReason::API;
if (args.length() >= 2) {
Value arg = args[1];
if (arg.isString()) {
bool shrinking = false;
bool last_ditch = false;
if (!JS_StringEqualsLiteral(cx, arg.toString(), "shrinking",
&shrinking)) {
return false;
}
if (!JS_StringEqualsLiteral(cx, arg.toString(), "last-ditch",
&last_ditch)) {
return false;
}
if (shrinking) {
gckind = GC_SHRINK;
} else if (last_ditch) {
gckind = GC_SHRINK;
reason = JS::GCReason::LAST_DITCH;
}
}
}
@ -489,8 +502,7 @@ static bool GC(JSContext* cx, unsigned argc, Value* vp) {
JS::PrepareForFullGC(cx);
}
JSGCInvocationKind gckind = shrinking ? GC_SHRINK : GC_NORMAL;
JS::NonIncrementalGC(cx, gckind, JS::GCReason::API);
JS::NonIncrementalGC(cx, gckind, reason);
char buf[256] = {'\0'};
#ifndef JS_MORE_DETERMINISTIC
@ -6155,12 +6167,13 @@ static bool PCCountProfiling_ScriptContents(JSContext* cx, unsigned argc,
// clang-format off
static const JSFunctionSpecWithHelp TestingFunctions[] = {
JS_FN_HELP("gc", ::GC, 0, 0,
"gc([obj] | 'zone' [, 'shrinking'])",
" Run the garbage collector. When obj is given, GC only its zone.\n"
" If 'zone' is given, GC any zones that were scheduled for\n"
" GC via schedulegc.\n"
" If 'shrinking' is passed as the optional second argument, perform a\n"
" shrinking GC rather than a normal GC."),
"gc([obj] | 'zone' [, ('shrinking' | 'last-ditch') ])",
" Run the garbage collector.\n"
" The first parameter describes which zones to collect: if an object is\n"
" given, GC only its zone. If 'zone' is given, GC any zones that were\n"
" scheduled via schedulegc.\n"
" The second parameter is optional and may be 'shrinking' to perform a\n"
" shrinking GC or 'last-ditch' for a shrinking, last-ditch GC."),
JS_FN_HELP("minorgc", ::MinorGC, 0, 0,
"minorgc([aboutToOverflow])",