Bug 1560931 - Add low memory state API and use it to restrict max nursery size r=sfink

Add a lowMemoryState field to GCRuntime and an API set set it.  Use it to restict the nursery size when resizing the nursery.

Differential Revision: https://phabricator.services.mozilla.com/D35680
This commit is contained in:
Jon Coppeard 2019-06-24 18:23:52 +01:00
parent ace8608f82
commit ca04a00e08
3 changed files with 13 additions and 3 deletions

View File

@ -1038,6 +1038,7 @@ GCRuntime::GCRuntime(JSRuntime* rt)
fullCompartmentChecks(false),
gcCallbackDepth(0),
alwaysPreserveCode(false),
lowMemoryState(false),
#ifdef DEBUG
arenasEmptyAtShutdown(true),
#endif
@ -8918,6 +8919,10 @@ JS::SetGCNurseryCollectionCallback(JSContext* cx,
return cx->runtime()->gc.setNurseryCollectionCallback(callback);
}
JS_PUBLIC_API void JS::SetLowMemoryState(JSContext* cx, bool newState) {
return cx->runtime()->gc.setLowMemoryState(newState);
}
JS_PUBLIC_API void JS::DisableIncrementalGC(JSContext* cx) {
cx->runtime()->gc.disallowIncrementalGC();
}

View File

@ -317,6 +317,9 @@ class GCRuntime {
return uid;
}
void setLowMemoryState(bool newState) { lowMemoryState = newState; }
bool systemHasLowMemory() const { return lowMemoryState; }
#ifdef DEBUG
bool shutdownCollectedEverything() const { return arenasEmptyAtShutdown; }
#endif
@ -408,7 +411,6 @@ class GCRuntime {
JS::GCNurseryCollectionCallback callback);
JS::DoCycleCollectionCallback setDoCycleCollectionCallback(
JS::DoCycleCollectionCallback callback);
void callDoCycleCollectionCallback(JSContext* cx);
void setFullCompartmentChecks(bool enable);
@ -705,6 +707,7 @@ class GCRuntime {
void callFinalizeCallbacks(FreeOp* fop, JSFinalizeStatus status) const;
void callWeakPointerZonesCallbacks() const;
void callWeakPointerCompartmentCallbacks(JS::Compartment* comp) const;
void callDoCycleCollectionCallback(JSContext* cx);
public:
JSRuntime* const rt;
@ -1015,6 +1018,8 @@ class GCRuntime {
/* Always preserve JIT code during GCs, for testing. */
MainThreadData<bool> alwaysPreserveCode;
MainThreadData<bool> lowMemoryState;
#ifdef DEBUG
MainThreadData<bool> arenasEmptyAtShutdown;
#endif

View File

@ -1303,9 +1303,9 @@ bool js::Nursery::maybeResizeExact(JS::GCReason reason) {
return true;
}
// Shrink the nursery to its minimum size of we ran out of memory or
// Shrink the nursery to its minimum size if we ran out of memory or
// received a memory pressure event.
if (gc::IsOOMReason(reason)) {
if (gc::IsOOMReason(reason) || runtime()->gc.systemHasLowMemory()) {
minimizeAllocableSpace();
return true;
}