mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-06 12:43:53 +00:00
Bug 987995, part 3 - Move memory pressure callbacks from nsJSEnvironment/XPCJSRuntime to CycleCollectedJSRuntime. r=mccr8.
This commit is contained in:
parent
9f145037d7
commit
6f2b5025bf
@ -2912,16 +2912,6 @@ AsmJSCacheOpenEntryForWrite(JS::Handle<JSObject*> aGlobal,
|
||||
aSize, aMemory, aHandle);
|
||||
}
|
||||
|
||||
static void
|
||||
OnLargeAllocationFailure(void* data)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> os =
|
||||
mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nullptr, "memory-pressure", MOZ_UTF16("heap-minimize"));
|
||||
}
|
||||
}
|
||||
|
||||
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
||||
|
||||
void
|
||||
@ -2981,8 +2971,6 @@ nsJSContext::EnsureStatics()
|
||||
};
|
||||
JS::SetAsmJSCacheOps(sRuntime, &asmJSCacheOps);
|
||||
|
||||
JS::SetLargeAllocationFailureCallback(sRuntime, OnLargeAllocationFailure, nullptr);
|
||||
|
||||
// Set these global xpconnect options...
|
||||
Preferences::RegisterCallbackAndCall(ReportAllJSExceptionsPrefChangedCallback,
|
||||
"dom.report_all_js_exceptions");
|
||||
|
@ -1436,8 +1436,8 @@ XPCJSRuntime::InterruptCallback(JSContext *cx)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
XPCJSRuntime::OutOfMemoryCallback(JSContext *cx, void *data)
|
||||
void
|
||||
XPCJSRuntime::CustomOutOfMemoryCallback()
|
||||
{
|
||||
if (!Preferences::GetBool("memory.dump_reports_on_oom")) {
|
||||
return;
|
||||
@ -1454,6 +1454,15 @@ XPCJSRuntime::OutOfMemoryCallback(JSContext *cx, void *data)
|
||||
/* minimizeMemoryUsage = */ false);
|
||||
}
|
||||
|
||||
void
|
||||
XPCJSRuntime::CustomLargeAllocationFailureCallback()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nullptr, "memory-pressure", MOZ_UTF16("heap-minimize"));
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
XPCJSRuntime::SizeOfIncludingThis(MallocSizeOf mallocSizeOf)
|
||||
{
|
||||
@ -3178,7 +3187,6 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
|
||||
js::SetActivityCallback(runtime, ActivityCallback, this);
|
||||
js::SetCTypesActivityCallback(runtime, CTypesActivityCallback);
|
||||
JS_SetInterruptCallback(runtime, InterruptCallback);
|
||||
JS::SetOutOfMemoryCallback(runtime, OutOfMemoryCallback, nullptr);
|
||||
|
||||
// The JS engine needs to keep the source code around in order to implement
|
||||
// Function.prototype.toSource(). It'd be nice to not have to do this for
|
||||
|
@ -510,6 +510,8 @@ public:
|
||||
void DispatchDeferredDeletion(bool continuation) MOZ_OVERRIDE;
|
||||
|
||||
void CustomGCCallback(JSGCStatus status) MOZ_OVERRIDE;
|
||||
void CustomOutOfMemoryCallback() MOZ_OVERRIDE;
|
||||
void CustomLargeAllocationFailureCallback() MOZ_OVERRIDE;
|
||||
bool CustomContextCallback(JSContext *cx, unsigned operation) MOZ_OVERRIDE;
|
||||
static void GCSliceCallback(JSRuntime *rt,
|
||||
JS::GCProgress progress,
|
||||
@ -547,7 +549,6 @@ public:
|
||||
static void CTypesActivityCallback(JSContext *cx,
|
||||
js::CTypesActivityType type);
|
||||
static bool InterruptCallback(JSContext *cx);
|
||||
static void OutOfMemoryCallback(JSContext *cx, void *data);
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
|
||||
|
||||
|
@ -480,6 +480,8 @@ CycleCollectedJSRuntime::CycleCollectedJSRuntime(JSRuntime* aParentRuntime,
|
||||
}
|
||||
JS_SetGrayGCRootsTracer(mJSRuntime, TraceGrayJS, this);
|
||||
JS_SetGCCallback(mJSRuntime, GCCallback, this);
|
||||
JS::SetOutOfMemoryCallback(mJSRuntime, OutOfMemoryCallback, this);
|
||||
JS::SetLargeAllocationFailureCallback(mJSRuntime, LargeAllocationFailureCallback, this);
|
||||
JS_SetContextCallback(mJSRuntime, ContextCallback, this);
|
||||
JS_SetDestroyZoneCallback(mJSRuntime, XPCStringConvert::FreeZoneCache);
|
||||
JS_SetSweepZoneCallback(mJSRuntime, XPCStringConvert::ClearZoneCache);
|
||||
@ -745,6 +747,25 @@ CycleCollectedJSRuntime::GCCallback(JSRuntime* aRuntime,
|
||||
self->OnGC(aStatus);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
CycleCollectedJSRuntime::OutOfMemoryCallback(JSContext *aContext,
|
||||
void* aData)
|
||||
{
|
||||
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
||||
|
||||
MOZ_ASSERT(JS_GetRuntime(aContext) == self->Runtime());
|
||||
|
||||
self->OnOutOfMemory();
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
CycleCollectedJSRuntime::LargeAllocationFailureCallback(void* aData)
|
||||
{
|
||||
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
|
||||
|
||||
self->OnLargeAllocationFailure();
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
CycleCollectedJSRuntime::ContextCallback(JSContext* aContext,
|
||||
unsigned aOperation,
|
||||
@ -1185,3 +1206,15 @@ CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
|
||||
|
||||
CustomGCCallback(aStatus);
|
||||
}
|
||||
|
||||
void
|
||||
CycleCollectedJSRuntime::OnOutOfMemory()
|
||||
{
|
||||
CustomOutOfMemoryCallback();
|
||||
}
|
||||
|
||||
void
|
||||
CycleCollectedJSRuntime::OnLargeAllocationFailure()
|
||||
{
|
||||
CustomLargeAllocationFailureCallback();
|
||||
}
|
||||
|
@ -131,6 +131,12 @@ protected:
|
||||
virtual void CustomGCCallback(JSGCStatus aStatus)
|
||||
{
|
||||
}
|
||||
virtual void CustomOutOfMemoryCallback()
|
||||
{
|
||||
}
|
||||
virtual void CustomLargeAllocationFailureCallback()
|
||||
{
|
||||
}
|
||||
virtual bool CustomContextCallback(JSContext* aCx, unsigned aOperation)
|
||||
{
|
||||
return true; // Don't block context creation.
|
||||
@ -185,6 +191,8 @@ private:
|
||||
static void TraceBlackJS(JSTracer* aTracer, void* aData);
|
||||
static void TraceGrayJS(JSTracer* aTracer, void* aData);
|
||||
static void GCCallback(JSRuntime* aRuntime, JSGCStatus aStatus, void* aData);
|
||||
static void OutOfMemoryCallback(JSContext *aContext, void *aData);
|
||||
static void LargeAllocationFailureCallback(void *aData);
|
||||
static bool ContextCallback(JSContext* aCx, unsigned aOperation,
|
||||
void* aData);
|
||||
|
||||
@ -199,6 +207,8 @@ private:
|
||||
void FinalizeDeferredThings(DeferredFinalizeType aType);
|
||||
|
||||
void OnGC(JSGCStatus aStatus);
|
||||
void OnOutOfMemory();
|
||||
void OnLargeAllocationFailure();
|
||||
|
||||
public:
|
||||
void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
|
||||
|
Loading…
Reference in New Issue
Block a user