Bug 1641211: Clear crashed processes from the e10s preallocator. r=jesup

Differential Revision: https://phabricator.services.mozilla.com/D80292
This commit is contained in:
Kris Maglione 2020-06-22 10:24:48 +00:00
Родитель 54e4e1bf4b
Коммит 99694471ec
3 изменённых файлов: 18 добавлений и 27 удалений

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

@ -164,6 +164,7 @@
#include "nsDirectoryServiceDefs.h"
#include "nsDocShell.h"
#include "nsEmbedCID.h"
#include "nsFocusManager.h"
#include "nsFrameLoader.h"
#include "nsFrameMessageManager.h"
#include "nsHashPropertyBag.h"
@ -922,6 +923,8 @@ already_AddRefed<ContentParent> ContentParent::GetUsedBrowserProcess(
!aRemoteType.EqualsLiteral(EXTENSION_REMOTE_TYPE) && // Bug 1638119
(p = PreallocatedProcessManager::Take(aRemoteType)) &&
!p->mShutdownPending) {
MOZ_DIAGNOSTIC_ASSERT(!p->IsDead());
// p may be a preallocated process, or (if not PREALLOC_REMOTE_TYPE)
// a perviously-used process that's being recycled. Currently this is
// only done for short-duration web (DEFAULT_REMOTE_TYPE) processes
@ -1635,6 +1638,9 @@ void ContentParent::ShutDownMessageManager() {
void ContentParent::AddToPool(nsTArray<ContentParent*>& aPool) {
MOZ_DIAGNOSTIC_ASSERT(!mIsInPool);
MOZ_DIAGNOSTIC_ASSERT(!IsDead());
MOZ_DIAGNOSTIC_ASSERT(!mShutdownPending);
MOZ_DIAGNOSTIC_ASSERT(!mCalledKillHard);
aPool.AppendElement(this);
mIsInPool = true;
}
@ -1708,6 +1714,8 @@ void ContentParent::MarkAsDead() {
RemoveFromList();
}
PreallocatedProcessManager::Erase(this);
#ifdef MOZ_WIDGET_ANDROID
if (mLifecycleState == LifecycleState::ALIVE) {
nsCOMPtr<nsIEventTarget> launcherThread(GetIPCLauncher());
@ -1939,7 +1947,6 @@ bool ContentParent::TryToRecycle() {
(unsigned int)ChildID(), (TimeStamp::Now() - mActivateTS).ToSeconds()));
if (mShutdownPending || mCalledKillHard || !IsAlive() ||
!mRemoteType.EqualsLiteral(DEFAULT_REMOTE_TYPE) ||
(TimeStamp::Now() - mActivateTS).ToSeconds() > kMaxLifeSpan) {
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("TryToRecycle did not take ownership of %p", this));

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

@ -62,8 +62,6 @@ class PreallocatedProcessManagerImpl final : public nsIObserver {
void Disable();
void CloseProcesses();
void ObserveProcessShutdown(nsISupports* aSubject);
bool IsEmpty() const {
return mPreallocatedProcesses.empty() && !mLaunchInProgress;
}
@ -85,7 +83,6 @@ uint32_t PreallocatedProcessManagerImpl::sNumBlockers = 0;
bool PreallocatedProcessManagerImpl::sShutdown = false;
const char* const PreallocatedProcessManagerImpl::kObserverTopics[] = {
"ipc:content-shutdown",
"memory-pressure",
"profile-change-teardown",
NS_XPCOM_SHUTDOWN_OBSERVER_ID,
@ -140,9 +137,7 @@ NS_IMETHODIMP
PreallocatedProcessManagerImpl::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData) {
if (!strcmp("ipc:content-shutdown", aTopic)) {
ObserveProcessShutdown(aSubject);
} else if (!strcmp("nsPref:changed", aTopic)) {
if (!strcmp("nsPref:changed", aTopic)) {
// The only other observer we registered was for our prefs.
RereadPrefs();
} else if (!strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID, aTopic) ||
@ -202,7 +197,7 @@ already_AddRefed<ContentParent> PreallocatedProcessManagerImpl::Take(
if (process) {
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("Reuse " DEFAULT_REMOTE_TYPE " process %p",
mPreallocatedE10SProcess.get()));
process.get()));
}
}
if (!process && !mPreallocatedProcesses.empty()) {
@ -245,6 +240,13 @@ bool PreallocatedProcessManagerImpl::Provide(ContentParent* aParent) {
void PreallocatedProcessManagerImpl::Erase(ContentParent* aParent) {
// Ensure this ContentParent isn't cached
for (auto it = mPreallocatedProcesses.begin();
it != mPreallocatedProcesses.end(); it++) {
if (*it == aParent) {
mPreallocatedProcesses.erase(it);
break;
}
}
if (mPreallocatedE10SProcess == aParent) {
mPreallocatedE10SProcess = nullptr;
}
@ -387,25 +389,6 @@ void PreallocatedProcessManagerImpl::CloseProcesses() {
}
}
void PreallocatedProcessManagerImpl::ObserveProcessShutdown(
nsISupports* aSubject) {
nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(aSubject);
NS_ENSURE_TRUE_VOID(props);
uint64_t childID = CONTENT_PROCESS_ID_UNKNOWN;
props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"), &childID);
NS_ENSURE_TRUE_VOID(childID != CONTENT_PROCESS_ID_UNKNOWN);
for (auto it = mPreallocatedProcesses.begin();
it != mPreallocatedProcesses.end(); it++) {
if (childID == (*it)->ChildID()) {
mPreallocatedProcesses.erase(it);
break;
}
}
// The ContentParent is responsible for removing itself as a blocker
}
inline PreallocatedProcessManagerImpl*
PreallocatedProcessManager::GetPPMImpl() {
if (PreallocatedProcessManagerImpl::sShutdown) {

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

@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "mozilla/AlreadyAddRefed.h"
#include "nsStringFwd.h"
namespace mozilla {
namespace dom {