Bug 1703443 - pt 11. Move the shrinking GC fields and logic into CCGCScheduler r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D118696
This commit is contained in:
Paul Bone 2021-07-09 07:14:14 +00:00
Родитель d0325267c2
Коммит b8ae31be26
3 изменённых файлов: 31 добавлений и 20 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "mozilla/StaticPrefs_javascript.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/dom/ScriptSettings.h"
namespace mozilla {
@ -45,9 +46,9 @@ void CCGCScheduler::ShrinkingGCTimerFired(nsITimer* aTimer) {
if (mbPromise) {
mbPromise->Then(
GetMainThreadSerialEventTarget(), __func__,
[](bool aIgnored) {
if (!sUserIsActive) {
sIsCompactingOnUserInactive = true;
[this](bool aIgnored) {
if (!mUserIsActive) {
mIsCompactingOnUserInactive = true;
nsJSContext::GarbageCollectNow(JS::GCReason::USER_INACTIVE,
nsJSContext::IncrementalGC,
nsJSContext::ShrinkingGC);
@ -275,6 +276,24 @@ void CCGCScheduler::EnsureGCRunner(uint32_t aDelay) {
[this] { return mDidShutdown; });
}
void CCGCScheduler::UserIsInactive() {
mUserIsActive = false;
if (StaticPrefs::javascript_options_compact_on_user_inactive()) {
PokeShrinkingGC();
}
}
void CCGCScheduler::UserIsActive() {
mUserIsActive = true;
KillShrinkingGCTimer();
if (mIsCompactingOnUserInactive) {
mozilla::dom::AutoJSAPI jsapi;
jsapi.Init();
JS::AbortIncrementalGC(jsapi.cx());
}
MOZ_ASSERT(!mIsCompactingOnUserInactive);
}
void CCGCScheduler::KillShrinkingGCTimer() {
if (mShrinkingGCTimer) {
mShrinkingGCTimer->Cancel();

Просмотреть файл

@ -153,6 +153,9 @@ class CCGCScheduler {
void PokeFullGC();
void MaybePokeCC();
void UserIsInactive();
void UserIsActive();
void KillShrinkingGCTimer();
void KillFullGCTimer();
void KillGCRunner();
@ -215,6 +218,7 @@ class CCGCScheduler {
mReadyForMajorGC = false;
mNeedsFullCC = true;
mHasRunGC = true;
mIsCompactingOnUserInactive = false;
mCleanupsSinceLastGC = 0;
mCCollectedWaitingForGC = 0;
@ -443,6 +447,9 @@ class CCGCScheduler {
JS::GCReason mMajorGCReason = JS::GCReason::NO_REASON;
bool mIsCompactingOnUserInactive = false;
bool mUserIsActive = true;
public:
uint32_t mCCollectedWaitingForGC = 0;
uint32_t mCCollectedZonesWaitingForGC = 0;
@ -453,10 +460,6 @@ class CCGCScheduler {
TimeDuration mActiveIntersliceGCBudget = TimeDuration::FromMilliseconds(5);
};
// XXX Move into class
static bool sIsCompactingOnUserInactive = false;
static bool sUserIsActive = true;
js::SliceBudget CCGCScheduler::ComputeCCSliceBudget(
TimeStamp aDeadline, TimeStamp aCCBeginTime, TimeStamp aPrevSliceEndTime,
bool* aPreferShorterSlices) const {

Просмотреть файл

@ -310,19 +310,9 @@ nsJSEnvironmentObserver::Observe(nsISupports* aSubject, const char* aTopic,
} else if (!nsCRT::strcmp(aTopic, "memory-pressure-stop")) {
nsJSContext::SetLowMemoryState(false);
} else if (!nsCRT::strcmp(aTopic, "user-interaction-inactive")) {
sUserIsActive = false;
if (StaticPrefs::javascript_options_compact_on_user_inactive()) {
sScheduler.PokeShrinkingGC();
}
sScheduler.UserIsInactive();
} else if (!nsCRT::strcmp(aTopic, "user-interaction-active")) {
sUserIsActive = true;
sScheduler.KillShrinkingGCTimer();
if (sIsCompactingOnUserInactive) {
AutoJSAPI jsapi;
jsapi.Init();
JS::AbortIncrementalGC(jsapi.cx());
}
MOZ_ASSERT(!sIsCompactingOnUserInactive);
sScheduler.UserIsActive();
} else if (!nsCRT::strcmp(aTopic, "quit-application") ||
!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) ||
!nsCRT::strcmp(aTopic, "content-child-will-shutdown")) {
@ -1717,7 +1707,6 @@ static void DOMGCSliceCallback(JSContext* aCx, JS::GCProgress aProgress,
}
sScheduler.NoteGCEnd();
sIsCompactingOnUserInactive = false;
using mozilla::ipc::IdleSchedulerChild;
IdleSchedulerChild* child =