diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 07ba217f3189..6f0703a90d5c 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -541,9 +541,6 @@ struct JSRuntime : js::RuntimeFriendFields /* The gcNumber at the time of the most recent GC's first slice. */ uint64_t gcStartNumber; - /* Whether the currently running GC can finish in multiple slices. */ - int gcIsIncremental; - /* Whether all compartments are being collected in first GC slice. */ bool gcIsFull; diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 23acfb04c574..a182d413d566 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -776,12 +776,6 @@ SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback) return old; } -JS_FRIEND_API(bool) -WasIncrementalGC(JSRuntime *rt) -{ - return rt->gcIsIncremental; -} - jschar * GCDescription::formatMessage(JSRuntime *rt) const { diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 3faf48ccba86..9a57851fed38 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -745,10 +745,6 @@ typedef void extern JS_FRIEND_API(GCSliceCallback) SetGCSliceCallback(JSRuntime *rt, GCSliceCallback callback); -/* Was the most recent GC run incrementally? */ -extern JS_FRIEND_API(bool) -WasIncrementalGC(JSRuntime *rt); - /* * Signals a good place to do an incremental slice, because the browser is * drawing a frame. diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index edf611c1866f..e123047ce063 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -3186,7 +3186,7 @@ ShouldPreserveJITCode(JSCompartment *c, int64_t currentTime) } static void -BeginMarkPhase(JSRuntime *rt) +BeginMarkPhase(JSRuntime *rt, bool isIncremental) { int64_t currentTime = PRMJ_Now(); @@ -3197,7 +3197,7 @@ BeginMarkPhase(JSRuntime *rt) * arenas. This purge call ensures that we only mark arenas that have had * allocations after the incremental GC started. */ - if (rt->gcIsIncremental) { + if (isIncremental) { for (GCCompartmentsIter c(rt); !c.done(); c.next()) c->arenas.purge(); } @@ -3221,7 +3221,7 @@ BeginMarkPhase(JSRuntime *rt) JS_ASSERT(IS_GC_MARKING_TRACER(&rt->gcMarker)); /* For non-incremental GC the following sweep discards the jit code. */ - if (rt->gcIsIncremental) { + if (isIncremental) { for (GCCompartmentsIter c(rt); !c.done(); c.next()) { gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_MARK_DISCARD_CODE); c->discardJitCode(rt->defaultFreeOp()); @@ -3314,7 +3314,7 @@ ValidateIncrementalMarking(JSRuntime *rt); #endif static void -EndMarkPhase(JSRuntime *rt) +EndMarkPhase(JSRuntime *rt, bool isIncremental) { { gcstats::AutoPhase ap1(rt->gcStats, gcstats::PHASE_MARK); @@ -3324,7 +3324,7 @@ EndMarkPhase(JSRuntime *rt) JS_ASSERT(rt->gcMarker.isDrained()); #ifdef DEBUG - if (rt->gcIsIncremental) + if (isIncremental) ValidateIncrementalMarking(rt); #endif @@ -3891,10 +3891,10 @@ IncrementalCollectSlice(JSRuntime *rt, } #endif - rt->gcIsIncremental = rt->gcIncrementalState != NO_INCREMENTAL || - budget != SliceBudget::Unlimited || - zeal == ZealIncrementalRootsThenFinish || - zeal == ZealIncrementalMarkAllThenFinish; + bool isIncremental = rt->gcIncrementalState != NO_INCREMENTAL || + budget != SliceBudget::Unlimited || + zeal == ZealIncrementalRootsThenFinish || + zeal == ZealIncrementalMarkAllThenFinish; if (rt->gcIncrementalState == NO_INCREMENTAL) { rt->gcIncrementalState = MARK_ROOTS; @@ -3904,7 +3904,7 @@ IncrementalCollectSlice(JSRuntime *rt, switch (rt->gcIncrementalState) { case MARK_ROOTS: - BeginMarkPhase(rt); + BeginMarkPhase(rt, isIncremental); PushZealSelectedObjects(rt); rt->gcIncrementalState = MARK; @@ -3939,7 +3939,7 @@ IncrementalCollectSlice(JSRuntime *rt, break; } - EndMarkPhase(rt); + EndMarkPhase(rt, isIncremental); rt->gcIncrementalState = SWEEP; diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index a6baed73774b..1cc7a44e8548 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -22,7 +22,6 @@ #include "mozilla/Preferences.h" #include "mozilla/Telemetry.h" -#include "nsLayoutStatics.h" #include "nsContentUtils.h" #include "nsCCUncollectableMarker.h" #include "jsfriendapi.h" @@ -553,7 +552,7 @@ xpc_UnmarkSkippableJSHolders() template static void DoDeferredRelease(nsTArray &array) { - while (true) { + while (1) { PRUint32 count = array.Length(); if (!count) { array.Compact(); @@ -565,74 +564,6 @@ DoDeferredRelease(nsTArray &array) } } -class IncrementalReleaseRunnable : public nsRunnable -{ - nsTArray items; - - static const PRTime SliceMillis = 10; /* ms */ - - public: - IncrementalReleaseRunnable(nsTArray &items); - virtual ~IncrementalReleaseRunnable(); - - NS_DECL_NSIRUNNABLE -}; - -IncrementalReleaseRunnable::IncrementalReleaseRunnable(nsTArray &items) -{ - nsLayoutStatics::AddRef(); - this->items.SwapElements(items); -} - -IncrementalReleaseRunnable::~IncrementalReleaseRunnable() -{ - nsLayoutStatics::Release(); -} - -NS_IMETHODIMP -IncrementalReleaseRunnable::Run() -{ - MOZ_ASSERT(NS_IsMainThread()); - - TimeDuration sliceTime = TimeDuration::FromMilliseconds(SliceMillis); - TimeStamp started = TimeStamp::Now(); - PRUint32 counter = 0; - while (true) { - PRUint32 count = items.Length(); - if (!count) - break; - - nsISupports *wrapper = items[count - 1]; - items.RemoveElementAt(count - 1); - NS_RELEASE(wrapper); - - /* We don't want to read the clock too often. */ - counter++; - if (counter == 100) { - counter = 0; - if (TimeStamp::Now() - started >= sliceTime) - break; - } - } - - if (items.Length()) { - nsresult rv = NS_DispatchToMainThread(this); - if (NS_FAILED(rv)) - Run(); - } - - return NS_OK; -} - -static void -ReleaseIncrementally(nsTArray &array) -{ - nsRefPtr runnable = new IncrementalReleaseRunnable(array); - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) - runnable->Run(); -} - /* static */ void XPCJSRuntime::GCCallback(JSRuntime *rt, JSGCStatus status) { @@ -655,10 +586,14 @@ XPCJSRuntime::GCCallback(JSRuntime *rt, JSGCStatus status) case JSGC_END: { // Do any deferred releases of native objects. - if (js::WasIncrementalGC(rt)) - ReleaseIncrementally(self->mNativesToReleaseArray); - else - DoDeferredRelease(self->mNativesToReleaseArray); +#ifdef XPC_TRACK_DEFERRED_RELEASES + printf("XPC - Begin deferred Release of %d nsISupports pointers\n", + self->mNativesToReleaseArray.Length()); +#endif + DoDeferredRelease(self->mNativesToReleaseArray); +#ifdef XPC_TRACK_DEFERRED_RELEASES + printf("XPC - End deferred Releases\n"); +#endif self->GetXPConnect()->ClearGCBeforeCC(); break;