From 7a4e1969f202e2e0b1f3a84b66e1b29ac373717f Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Tue, 17 Sep 2013 09:46:32 -0700 Subject: [PATCH] Bug 905926 - Move rambo GC to runtime destruction. r=jonco --- js/public/GCAPI.h | 2 +- js/src/jsapi.cpp | 2 +- js/src/jscntxt.cpp | 39 +++----------------------- js/src/jsgc.cpp | 2 +- js/src/vm/Runtime.cpp | 36 ++++++++++++++++++++++++ xpcom/base/CycleCollectedJSRuntime.cpp | 2 +- 6 files changed, 44 insertions(+), 39 deletions(-) diff --git a/js/public/GCAPI.h b/js/public/GCAPI.h index 61598a0d457f..d24b56a35a4e 100644 --- a/js/public/GCAPI.h +++ b/js/public/GCAPI.h @@ -17,7 +17,7 @@ namespace JS { /* Reasons internal to the JS engine */ \ D(API) \ D(MAYBEGC) \ - D(LAST_CONTEXT) \ + D(DESTROY_RUNTIME) \ D(DESTROY_CONTEXT) \ D(LAST_DITCH) \ D(TOO_MUCH_MALLOC) \ diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index bab37bded57b..31831c308169 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -38,6 +38,7 @@ #include "jsstr.h" #include "jstypes.h" #include "jsutil.h" +#include "jswatchpoint.h" #include "jsweakmap.h" #ifdef JS_THREADSAFE #include "jsworkers.h" @@ -716,7 +717,6 @@ JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads) JS_PUBLIC_API(void) JS_DestroyRuntime(JSRuntime *rt) { - js_free(rt->defaultLocale); js_delete(rt); } diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 07bae64e8364..d8108fdd718f 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -251,44 +251,13 @@ js::DestroyContext(JSContext *cx, DestroyContextMode mode) JS_ASSERT(!rt->isHeapBusy()); /* - * Dump remaining type inference results first. This printing - * depends on atoms still existing. + * Dump remaining type inference results while we still have a context. + * This printing depends on atoms still existing. */ for (CompartmentsIter c(rt); !c.done(); c.next()) c->types.print(cx, false); - - /* Off thread compilation and parsing depend on atoms still existing. */ - for (CompartmentsIter c(rt); !c.done(); c.next()) - CancelOffThreadIonCompile(c, NULL); - WaitForOffThreadParsingToFinish(rt); - -#ifdef JS_WORKER_THREADS - if (rt->workerThreadState) - rt->workerThreadState->cleanup(rt); -#endif - - /* Unpin all common names before final GC. */ - FinishCommonNames(rt); - - /* Clear debugging state to remove GC roots. */ - for (CompartmentsIter c(rt); !c.done(); c.next()) { - c->clearTraps(rt->defaultFreeOp()); - if (WatchpointMap *wpmap = c->watchpointMap) - wpmap->clear(); - } - - /* Clear the statics table to remove GC roots. */ - rt->staticStrings.finish(); - - JS::PrepareForFullGC(rt); - GC(rt, GC_NORMAL, JS::gcreason::LAST_CONTEXT); - - /* - * Clear the self-hosted global and delete self-hosted classes *after* - * GC, as finalizers for objects check for clasp->finalize during GC. - */ - rt->finishSelfHosting(); - } else if (mode == DCM_FORCE_GC) { + } + if (mode == DCM_FORCE_GC) { JS_ASSERT(!rt->isHeapBusy()); JS::PrepareForFullGC(rt); GC(rt, GC_NORMAL, JS::gcreason::DESTROY_CONTEXT); diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 73fe7dfaab5c..ce1ede1248b1 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -4380,7 +4380,7 @@ IncrementalCollectSlice(JSRuntime *rt, if (!finished) break; - EndSweepPhase(rt, gckind, reason == JS::gcreason::LAST_CONTEXT); + EndSweepPhase(rt, gckind, reason == JS::gcreason::DESTROY_RUNTIME); if (rt->gcSweepOnBackgroundThread) rt->gcHelperThread.startBackgroundSweep(gckind == GC_SHRINK); diff --git a/js/src/vm/Runtime.cpp b/js/src/vm/Runtime.cpp index 66b77008b7b7..4bbe980680df 100644 --- a/js/src/vm/Runtime.cpp +++ b/js/src/vm/Runtime.cpp @@ -22,6 +22,7 @@ #include "jsnativestack.h" #include "jsobj.h" #include "jsscript.h" +#include "jswatchpoint.h" #include "jswrapper.h" #include "jit/AsmJSSignalHandlers.h" @@ -393,6 +394,40 @@ JSRuntime::init(uint32_t maxbytes) JSRuntime::~JSRuntime() { + JS_ASSERT(!isHeapBusy()); + + /* Off thread compilation and parsing depend on atoms still existing. */ + for (CompartmentsIter comp(this); !comp.done(); comp.next()) + CancelOffThreadIonCompile(comp, NULL); + WaitForOffThreadParsingToFinish(this); + +#ifdef JS_WORKER_THREADS + if (workerThreadState) + workerThreadState->cleanup(this); +#endif + + /* Poison common names before final GC. */ + FinishCommonNames(this); + + /* Clear debugging state to remove GC roots. */ + for (CompartmentsIter comp(this); !comp.done(); comp.next()) { + comp->clearTraps(defaultFreeOp()); + if (WatchpointMap *wpmap = comp->watchpointMap) + wpmap->clear(); + } + + /* Clear the statics table to remove GC roots. */ + staticStrings.finish(); + + JS::PrepareForFullGC(this); + GC(this, GC_NORMAL, JS::gcreason::DESTROY_RUNTIME); + + /* + * Clear the self-hosted global and delete self-hosted classes *after* + * GC, as finalizers for objects check for clasp->finalize during GC. + */ + finishSelfHosting(); + mainThread.removeFromThreadList(); #ifdef JS_WORKER_THREADS @@ -449,6 +484,7 @@ JSRuntime::~JSRuntime() PR_DestroyLock(gcLock); #endif + js_free(defaultLocale); js_delete(bumpAlloc_); js_delete(mathCache_); #ifdef JS_ION diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index ca8fc369449e..1db9dea13253 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -471,10 +471,10 @@ CycleCollectedJSRuntime::DestroyRuntime() // Clear mPendingException first, since it might be cycle collected. mPendingException = nullptr; - nsCycleCollector_forgetJSRuntime(); JS_DestroyRuntime(mJSRuntime); mJSRuntime = nullptr; + nsCycleCollector_forgetJSRuntime(); } CycleCollectedJSRuntime::~CycleCollectedJSRuntime()