Skip to content

Commit

Permalink
Issue #2654 - Remove pre-allocated process manager.
Browse files Browse the repository at this point in the history
Resolves #2654
  • Loading branch information
wolfbeast committed Nov 19, 2024
1 parent dcba66d commit 945e5b8
Show file tree
Hide file tree
Showing 22 changed files with 16 additions and 879 deletions.
2 changes: 0 additions & 2 deletions dom/browser-element/mochitest/priority/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ support-files =

[test_Simple.html]
[test_HighPriority.html]
[test_Preallocated.html]
disabled = bug 968604, bug 987164
[test_WebGLContextLost.html]
disabled = bug 865844
71 changes: 0 additions & 71 deletions dom/browser-element/mochitest/priority/test_Preallocated.html

This file was deleted.

64 changes: 0 additions & 64 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ ContentChild::Init(MessageLoop* aIOLoop,
#endif

SendGetProcessAttributes(&mID, &mIsForBrowser);
InitProcessAttributes();

#ifdef NS_PRINTING
// Force the creation of the nsPrintingProxy so that it's IPC counterpart,
Expand All @@ -570,12 +569,6 @@ ContentChild::Init(MessageLoop* aIOLoop,
return true;
}

void
ContentChild::InitProcessAttributes()
{
SetProcessName(NS_LITERAL_STRING("Web Content"), true);
}

void
ContentChild::SetProcessName(const nsAString& aName, bool aDontOverride)
{
Expand Down Expand Up @@ -1248,15 +1241,6 @@ ContentChild::RecvBidiKeyboardNotify(const bool& aIsLangRTL,
return true;
}

static CancelableRunnable* sFirstIdleTask;

static void FirstIdle(void)
{
MOZ_ASSERT(sFirstIdleTask);
sFirstIdleTask = nullptr;
ContentChild::GetSingleton()->SendFirstIdle();
}

mozilla::jsipc::PJavaScriptChild *
ContentChild::AllocPJavaScriptChild()
{
Expand Down Expand Up @@ -1325,22 +1309,6 @@ ContentChild::RecvPBrowserConstructor(PBrowserChild* aActor,
os->NotifyObservers(tc, "tab-child-created", nullptr);
}

static bool hasRunOnce = false;
if (!hasRunOnce) {
hasRunOnce = true;

MOZ_ASSERT(!sFirstIdleTask);
RefPtr<CancelableRunnable> firstIdleTask = NewCancelableRunnableFunction(FirstIdle);
sFirstIdleTask = firstIdleTask;
MessageLoop::current()->PostIdleTask(firstIdleTask.forget());

// Redo InitProcessAttributes() when the app or browser is really
// launching so the attributes will be correct.
mID = aCpID;
mIsForBrowser = aIsForBrowser;
InitProcessAttributes();
}

return true;
}

Expand Down Expand Up @@ -1789,9 +1757,6 @@ ContentChild::ActorDestroy(ActorDestroyReason why)
// keep persistent state.
ProcessChild::QuickExit();
#else
if (sFirstIdleTask) {
sFirstIdleTask->Cancel();
}

nsHostObjectProtocolHandler::RemoveDataEntries();

Expand Down Expand Up @@ -2085,16 +2050,6 @@ ContentChild::RecvCycleCollect()
return true;
}

static void
PreloadSlowThings()
{
// This fetches and creates all the built-in stylesheets.
nsLayoutStylesheetCache::Get()->UserContentSheet();

TabChild::PreloadSlowThings();

}

bool
ContentChild::RecvAppInfo(const nsCString& version, const nsCString& buildID,
const nsCString& name, const nsCString& UAName,
Expand All @@ -2110,25 +2065,6 @@ ContentChild::RecvAppInfo(const nsCString& version, const nsCString& buildID,
return true;
}

bool
ContentChild::RecvAppInit()
{
if (!Preferences::GetBool("dom.ipc.processPrelaunch.enabled", false)) {
return true;
}

// If we're part of the mozbrowser machinery, go ahead and start
// preloading things. We can only do this for mozbrowser because
// PreloadSlowThings() may set the docshell of the first TabChild
// inactive, and we can only safely restore it to active from
// BrowserElementChild.js.
if (mIsForBrowser) {
PreloadSlowThings();
}

return true;
}

bool
ContentChild::RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig)
{
Expand Down
4 changes: 0 additions & 4 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ class ContentChild final : public PContentChild
base::ProcessId aParentPid,
IPC::Channel* aChannel);

void InitProcessAttributes();

void InitXPCOM();

void InitGraphicsDeviceData();
Expand Down Expand Up @@ -380,8 +378,6 @@ class ContentChild final : public PContentChild
const nsCString& name, const nsCString& UAName,
const nsCString& ID, const nsCString& vendor) override;

virtual bool RecvAppInit() override;

virtual bool
RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig) override;

Expand Down
91 changes: 7 additions & 84 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
#include "nsThreadUtils.h"
#include "nsToolkitCompsCID.h"
#include "nsWidgetsCID.h"
#include "PreallocatedProcessManager.h"
#include "ProcessPriorityManager.h"
#include "SandboxHal.h"
#include "ScreenManagerParent.h"
Expand Down Expand Up @@ -490,25 +489,6 @@ static const char* sObserverTopics[] = {
"cacheservice:empty-cache",
};

// PreallocateAppProcess is called by the PreallocatedProcessManager.
// ContentParent then takes this process back within
// GetNewOrPreallocatedAppProcess.
/*static*/ already_AddRefed<ContentParent>
ContentParent::PreallocateAppProcess()
{
RefPtr<ContentParent> process =
new ContentParent(/* aOpener = */ nullptr,
/* isForBrowserElement = */ false,
/* isForPreallocated = */ true);

if (!process->LaunchSubprocess(PROCESS_PRIORITY_PREALLOC)) {
return nullptr;
}

process->Init();
return process.forget();
}

/*static*/ void
ContentParent::StartUp()
{
Expand All @@ -530,9 +510,6 @@ ContentParent::StartUp()

BackgroundChild::Startup();

// Try to preallocate a process that we can transform into an app later.
PreallocatedProcessManager::AllocateAfterDelay();

sDisableUnsafeCPOWWarnings = PR_GetEnv("DISABLE_UNSAFE_CPOW_WARNINGS");
}

Expand Down Expand Up @@ -637,23 +614,14 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
} while (currIdx != startIdx);
}

// Try to take and transform the preallocated process into browser.
RefPtr<ContentParent> p = PreallocatedProcessManager::Take();
if (p) {
p->TransformPreallocatedIntoBrowser(aOpener);
} else {
// Failed in using the preallocated process: fork from the chrome process.
p = new ContentParent(aOpener,
aForBrowserElement,
/* isForPreallocated = */ false);

if (!p->LaunchSubprocess(aPriority)) {
return nullptr;
}
RefPtr<ContentParent> p = new ContentParent(aOpener, aForBrowserElement);

p->Init();
if (!p->LaunchSubprocess(aPriority)) {
return nullptr;
}

p->Init();

p->mLargeAllocationProcess = aLargeAllocationProcess;

p->ForwardKnownInfo();
Expand Down Expand Up @@ -711,12 +679,6 @@ ContentParent::SendAsyncUpdate(nsIWidget* aWidget)
ContentParent::SendAsyncUpdate(nsIWidget* aWidget) {}
#endif

bool
ContentParent::PreallocatedProcessReady()
{
return true;
}

bool
ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
const hal::ProcessPriority& aPriority,
Expand Down Expand Up @@ -1132,15 +1094,6 @@ ContentParent::SetPriorityAndCheckIsAlive(ProcessPriority aPriority)
return true;
}

void
ContentParent::TransformPreallocatedIntoBrowser(ContentParent* aOpener)
{
// Reset mIsForBrowser and mOSPrivileges for browser.
mMetamorphosed = true;
mOpener = aOpener;
mIsForBrowser = true;
}

void
ContentParent::ShutDownProcess(ShutDownMethod aMethod)
{
Expand Down Expand Up @@ -1691,20 +1644,14 @@ ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PR
}

ContentParent::ContentParent(ContentParent* aOpener,
bool aIsForBrowser,
bool aIsForPreallocated)
bool aIsForBrowser)
: nsIContentParent()
, mOpener(aOpener)
, mIsForBrowser(aIsForBrowser)
, mIsPreallocated(aIsForPreallocated)
, mLargeAllocationProcess(false)
{
InitializeMembers(); // Perform common initialization.

// No more than one of aIsForBrowser, aIsForPreallocated should be
// true.
MOZ_ASSERT(aIsForBrowser + aIsForPreallocated <= 1);

mMetamorphosed = true;

// Insert ourselves into the global linked list of ContentParent objects.
Expand Down Expand Up @@ -1814,11 +1761,6 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
}
}

if (gAppData) {
// Sending all information to content process.
Unused << SendAppInit();
}

nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
if (sheetService) {
// This looks like a lot of work, but in a normal browser session we just
Expand Down Expand Up @@ -2118,17 +2060,6 @@ ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
return true;
}

bool
ContentParent::RecvFirstIdle()
{
// When the ContentChild goes idle, it sends us a FirstIdle message
// which we use as a good time to prelaunch another process. If we
// prelaunch any sooner than this, then we'll be competing with the
// child process and slowing it down.
PreallocatedProcessManager::AllocateAfterDelay();
return true;
}

bool
ContentParent::RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel,
const bool& aHidden)
Expand Down Expand Up @@ -2513,19 +2444,11 @@ ContentParent::KillHard(const char* aReason)
otherProcessHandle, /*force=*/true));
}

bool
ContentParent::IsPreallocated() const
{
return mIsPreallocated;
}

void
ContentParent::FriendlyName(nsAString& aName, bool aAnonymize)
{
aName.Truncate();
if (IsPreallocated()) {
aName.AssignLiteral("(Preallocated)");
} else if (mIsForBrowser) {
if (mIsForBrowser) {
aName.AssignLiteral("Browser");
} else if (aAnonymize) {
aName.AssignLiteral("<anonymized-name>");
Expand Down
Loading

0 comments on commit 945e5b8

Please sign in to comment.