From 32fc4906ae73f641d140ba00e5b82cf766805b95 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Tue, 8 Oct 2019 23:51:18 +0000 Subject: [PATCH] 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 --- js/src/builtin/TestingFunctions.cpp | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 90082868bb18..5105cc2c0b9a 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -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])",