From c24a94277644fad55d98d017e7b03d2693ef3ac0 Mon Sep 17 00:00:00 2001 From: Norisz Fay Date: Fri, 3 Nov 2023 22:19:17 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1861848) for causing Linux asan J1 exceptions CLOSED TREE Backed out changeset 69a9a6852a6b (bug 1861848) Backed out changeset 1496b731cc40 (bug 1861848) --- dom/base/CCGCScheduler.cpp | 8 ++------ dom/ipc/tests/browser_gc_schedule.js | 22 +++++----------------- xpcom/threads/IdlePeriodState.cpp | 24 +++++++++++------------- xpcom/threads/IdlePeriodState.h | 5 +++++ xpcom/threads/moz.build | 2 +- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/dom/base/CCGCScheduler.cpp b/dom/base/CCGCScheduler.cpp index e12fc2a7120d..0f703cfef15b 100644 --- a/dom/base/CCGCScheduler.cpp +++ b/dom/base/CCGCScheduler.cpp @@ -8,7 +8,6 @@ #include "mozilla/StaticPrefs_javascript.h" #include "mozilla/CycleCollectedJSRuntime.h" #include "mozilla/ProfilerMarkers.h" -#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/PerfStats.h" #include "nsRefreshDriver.h" @@ -467,17 +466,14 @@ RefPtr CCGCScheduler::MayGCNow( case JS::GCReason::USER_INACTIVE: case JS::GCReason::FULL_GC_TIMER: case JS::GCReason::CC_FINISHED: { - if (dom::ContentChild::GetSingleton() && - dom::ContentChild::GetSingleton()->GetProcessPriority() < - hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND) { + if (XRE_IsContentProcess()) { IdleSchedulerChild* child = IdleSchedulerChild::GetMainThreadIdleScheduler(); if (child) { return child->MayGCNow(); } } - // Foreground content processes and the parent process don't ask - // IdleSchedulerParent whether GC can be run. + // The parent process doesn't ask IdleSchedulerParent if it can GC. break; } default: diff --git a/dom/ipc/tests/browser_gc_schedule.js b/dom/ipc/tests/browser_gc_schedule.js index c5648d6c1125..53f8a70ab28a 100644 --- a/dom/ipc/tests/browser_gc_schedule.js +++ b/dom/ipc/tests/browser_gc_schedule.js @@ -119,8 +119,7 @@ function checkAllCompleted(events, expectTabsCompleted) { } } -async function setupTabsAndOneForForeground(num_tabs) { - ++num_tabs; +async function setupTabs(num_tabs) { var pids = []; const parent_pid = getProcessID(); @@ -152,12 +151,6 @@ async function setupTabsAndOneForForeground(num_tabs) { pids.push(tab_pid); } - // Since calling openNewForegroundTab several times in a row doesn't update - // process priorities correctly, we need to explicitly switch tabs. - for (let tab of tabs) { - await BrowserTestUtils.switchTab(gBrowser, tab); - } - return tabs; } @@ -179,11 +172,6 @@ function startNextCollection( SpecialPowers.Cu.getJSTestingFunctions().finishgc(); }); - if (tab.selected) { - // One isn't expected to use the return value with foreground tab! - return {}; - } - var waitBegin = SpecialPowers.spawn(browser, [], waitForGCBegin); var waitEnd = SpecialPowers.spawn(browser, [], waitForGCEnd); waits.push({ promise: waitBegin, tab: tab_num, state: "begin" }); @@ -201,7 +189,7 @@ add_task(async function gcOneAtATime() { }); const num_tabs = 12; - var tabs = await setupTabsAndOneForForeground(num_tabs); + var tabs = await setupTabs(num_tabs); info("Tabs ready, Asking for GCs"); var waits = []; @@ -232,7 +220,7 @@ add_task(async function gcAbort() { }); const num_tabs = 2; - var tabs = await setupTabsAndOneForForeground(num_tabs); + var tabs = await setupTabs(num_tabs); info("Tabs ready, Asking for GCs"); var waits = []; @@ -275,7 +263,7 @@ add_task(async function gcJSInitiatedDuring() { }); const num_tabs = 3; - var tabs = await setupTabsAndOneForForeground(num_tabs); + var tabs = await setupTabs(num_tabs); info("Tabs ready, Asking for GCs"); var waits = []; @@ -332,7 +320,7 @@ add_task(async function gcJSInitiatedBefore() { }); const num_tabs = 8; - var tabs = await setupTabsAndOneForForeground(num_tabs); + var tabs = await setupTabs(num_tabs); info("Tabs ready"); var waits = []; diff --git a/xpcom/threads/IdlePeriodState.cpp b/xpcom/threads/IdlePeriodState.cpp index ff1a9f4096c3..ca7f15321f6b 100644 --- a/xpcom/threads/IdlePeriodState.cpp +++ b/xpcom/threads/IdlePeriodState.cpp @@ -8,9 +8,9 @@ #include "mozilla/IdlePeriodState.h" #include "mozilla/StaticPrefs_idle_period.h" #include "mozilla/ipc/IdleSchedulerChild.h" -#include "mozilla/dom/ContentChild.h" #include "nsIIdlePeriod.h" #include "nsThreadManager.h" +#include "nsThreadUtils.h" #include "nsXPCOM.h" #include "nsXULAppAPI.h" @@ -150,9 +150,6 @@ TimeStamp IdlePeriodState::GetIdleToken(TimeStamp aLocalIdlePeriodHint, "Why are we touching idle state off the main thread?"); if (!ShouldGetIdleToken()) { - // If the process was in background, it may have an idle token, but it can - // be cleared now. - ClearIdleToken(); return aLocalIdlePeriodHint; } @@ -173,12 +170,15 @@ void IdlePeriodState::RequestIdleToken(TimeStamp aLocalIdlePeriodHint) { "Why are we touching idle state off the main thread?"); MOZ_ASSERT(!mActive); - if (!mIdleScheduler && ShouldGetIdleToken()) { - // For now cross-process idle scheduler is supported only on the main - // threads of the child processes. - mIdleScheduler = ipc::IdleSchedulerChild::GetMainThreadIdleScheduler(); - if (mIdleScheduler) { - mIdleScheduler->Init(this); + if (!mIdleSchedulerInitialized) { + mIdleSchedulerInitialized = true; + if (ShouldGetIdleToken()) { + // For now cross-process idle scheduler is supported only on the main + // threads of the child processes. + mIdleScheduler = ipc::IdleSchedulerChild::GetMainThreadIdleScheduler(); + if (mIdleScheduler) { + mIdleScheduler->Init(this); + } } } @@ -250,8 +250,6 @@ void IdlePeriodState::ClearIdleToken() { bool IdlePeriodState::ShouldGetIdleToken() { return StaticPrefs::idle_period_cross_process_scheduling() && - dom::ContentChild::GetSingleton() && - dom::ContentChild::GetSingleton()->GetProcessPriority() < - hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND; + XRE_IsContentProcess(); } } // namespace mozilla diff --git a/xpcom/threads/IdlePeriodState.h b/xpcom/threads/IdlePeriodState.h index 94d66156774c..d50fce64be74 100644 --- a/xpcom/threads/IdlePeriodState.h +++ b/xpcom/threads/IdlePeriodState.h @@ -186,6 +186,11 @@ class IdlePeriodState { // not holding any locks, but may do the latter while holding locks. TimeStamp mCachedIdleDeadline; + // mIdleSchedulerInitialized is true if our mIdleScheduler has been + // initialized. It may be null even after initialiazation, in various + // situations. + bool mIdleSchedulerInitialized = false; + // mActive is true when the PrioritizedEventQueue or TaskController we are // associated with is running tasks. bool mActive = true; diff --git a/xpcom/threads/moz.build b/xpcom/threads/moz.build index 06d10ad33112..741d037c235b 100644 --- a/xpcom/threads/moz.build +++ b/xpcom/threads/moz.build @@ -82,7 +82,6 @@ EXPORTS.mozilla += [ ] SOURCES += [ - "IdlePeriodState.cpp", "IdleTaskRunner.cpp", "ThreadDelay.cpp", ] @@ -93,6 +92,7 @@ UNIFIED_SOURCES += [ "CPUUsageWatcher.cpp", "DelayedRunnable.cpp", "EventQueue.cpp", + "IdlePeriodState.cpp", "InputTaskManager.cpp", "LazyIdleThread.cpp", "MainThreadIdlePeriod.cpp",