Backed out changesets 9beb53e53951, 4420bb4e5e7c, de1da65301a8, and cd9c2aaf1343 (bug 970307) for causing frequent B2G debug mochitest-11 crashes.

This commit is contained in:
Ryan VanderMeulen 2014-11-24 17:18:27 -05:00
parent 5168639c83
commit fb8d05cd59
28 changed files with 30 additions and 554 deletions

View File

@ -103,12 +103,6 @@ this.DOMApplicationRegistry = {
this.cpmm.addMessageListener(aMsgName, this);
}).bind(this));
this.resetList();
Services.obs.addObserver(this, "xpcom-shutdown", false);
},
resetList: function() {
this.cpmm.sendAsyncMessage("Webapps:RegisterForMessages", {
messages: APPS_IPC_MSG_NAMES
});
@ -116,7 +110,6 @@ this.DOMApplicationRegistry = {
// We need to prime the cache with the list of apps.
let list = this.cpmm.sendSyncMessage("Webapps:GetList", { })[0];
this.webapps = list.webapps;
// We need a fast mapping from localId -> app, so we add an index.
// We also add the manifest to the app object.
this.localIdIndex = { };
@ -125,6 +118,8 @@ this.DOMApplicationRegistry = {
this.localIdIndex[app.localId] = app;
app.manifest = list.manifests[id];
}
Services.obs.addObserver(this, "xpcom-shutdown", false);
},
observe: function(aSubject, aTopic, aData) {

View File

@ -19,7 +19,6 @@
#include "nsServiceManagerUtils.h"
#include "nsXPCOMCIDInternal.h"
#include "ProfilerHelpers.h"
#include "nsThread.h"
namespace mozilla {
namespace dom {
@ -173,10 +172,6 @@ private:
~TransactionQueue()
{ }
#ifdef MOZ_NUWA_PROCESS
nsThread* mThread;
#endif
NS_DECL_NSIRUNNABLE
};
@ -796,9 +791,6 @@ TransactionQueue::TransactionQueue(TransactionThreadPool* aThreadPool,
mObjectStoreNames(aObjectStoreNames),
mMode(aMode),
mShouldFinish(false)
#ifdef MOZ_NUWA_PROCESS
, mThread(nullptr)
#endif
{
MOZ_ASSERT(aThreadPool);
aThreadPool->AssertIsOnOwningThread();
@ -824,12 +816,6 @@ TransactionThreadPool::TransactionQueue::Dispatch(nsIRunnable* aRunnable)
mQueue.AppendElement(aRunnable);
#ifdef MOZ_NUWA_PROCESS
if (mThread) {
mThread->SetWorking();
}
#endif
mMonitor.Notify();
}
@ -863,12 +849,6 @@ TransactionThreadPool::TransactionQueue::Run()
nsAutoTArray<nsCOMPtr<nsIRunnable>, 10> queue;
nsRefPtr<FinishCallback> finishCallback;
bool shouldFinish = false;
#ifdef MOZ_NUWA_PROCESS
mThread = static_cast<nsThread*>(NS_GetCurrentThread());
// Set ourself as working thread. We can reset later if we found
// our queue is empty.
mThread->SetWorking();
#endif
do {
NS_ASSERTION(queue.IsEmpty(), "Should have cleared this!");
@ -876,9 +856,6 @@ TransactionThreadPool::TransactionQueue::Run()
{
MonitorAutoLock lock(mMonitor);
while (!mShouldFinish && mQueue.IsEmpty()) {
#ifdef MOZ_NUWA_PROCESS
mThread->SetIdle();
#endif
if (NS_FAILED(mMonitor.Wait())) {
NS_ERROR("Failed to wait!");
}
@ -911,10 +888,6 @@ TransactionThreadPool::TransactionQueue::Run()
}
} while (!shouldFinish);
#ifdef MOZ_NUWA_PROCESS
mThread = nullptr;
#endif
#ifdef DEBUG
if (kDEBUGThreadSleepMS) {
MOZ_ALWAYS_TRUE(

View File

@ -507,12 +507,6 @@ NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback)
ContentChild* ContentChild::sSingleton;
static void
PostForkPreload()
{
TabChild::PostForkPreload();
}
// Performs initialization that is not fork-safe, i.e. that must be done after
// forking from the Nuwa process.
static void
@ -523,7 +517,6 @@ InitOnContentProcessCreated()
if (IsNuwaProcess()) {
return;
}
PostForkPreload();
#endif
// This will register cross-process observer.
@ -1245,6 +1238,7 @@ ContentChild::RecvPBrowserConstructor(PBrowserChild* aActor,
{
// This runs after AllocPBrowserChild() returns and the IPC machinery for this
// PBrowserChild has been set up.
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
nsITabChild* tc =
@ -1992,11 +1986,8 @@ bool
ContentChild::RecvFlushMemory(const nsString& reason)
{
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess() || ManagedPBrowserChild().Length() == 0) {
if (IsNuwaProcess()) {
// Don't flush memory in the nuwa process: the GC thread could be frozen.
// If there's no PBrowser child, don't flush memory, either. GC writes
// to copy-on-write pages and makes preallocated process take more memory
// before it actually becomes an app.
return true;
}
#endif
@ -2084,28 +2075,12 @@ ContentChild::RecvAppInfo(const nsCString& version, const nsCString& buildID,
// BrowserElementChild.js.
if ((mIsForApp || mIsForBrowser)
#ifdef MOZ_NUWA_PROCESS
&& IsNuwaProcess()
&& !IsNuwaProcess()
#endif
) {
PreloadSlowThings();
#ifndef MOZ_NUWA_PROCESS
PostForkPreload();
#endif
}
#ifdef MOZ_NUWA_PROCESS
// Some modules are initialized in preloading. We need to wait until the
// tasks they dispatched to chrome process are done.
if (IsNuwaProcess()) {
SendNuwaWaitForFreeze();
}
#endif
return true;
}
bool
ContentChild::RecvNuwaFreeze()
{
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess()) {
ContentChild::GetSingleton()->RecvGarbageCollect();
@ -2113,6 +2088,7 @@ ContentChild::RecvNuwaFreeze()
FROM_HERE, NewRunnableFunction(OnFinishNuwaPreparation));
}
#endif
return true;
}
@ -2367,36 +2343,6 @@ RunNuwaFork()
DoNuwaFork();
}
}
class NuwaForkCaller: public nsRunnable
{
public:
NS_IMETHODIMP
Run() {
// We want to ensure that the PBackground actor gets cloned in the Nuwa
// process before we freeze. Also, we have to do this to avoid deadlock.
// Protocols that are "opened" (e.g. PBackground, PCompositor) block the
// main thread to wait for the IPC thread during the open operation.
// NuwaSpawnWait() blocks the IPC thread to wait for the main thread when
// the Nuwa process is forked. Unless we ensure that the two cannot happen
// at the same time then we risk deadlock. Spinning the event loop here
// guarantees the ordering is safe for PBackground.
if (!BackgroundChild::GetForCurrentThread()) {
// Dispatch ourself again.
NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL);
} else {
MessageLoop* ioloop = XRE_GetIOMessageLoop();
ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork));
}
return NS_OK;
}
private:
virtual
~NuwaForkCaller()
{
}
};
#endif
bool
@ -2408,9 +2354,22 @@ ContentChild::RecvNuwaFork()
}
sNuwaForking = true;
nsRefPtr<NuwaForkCaller> runnable = new NuwaForkCaller();
NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL);
// We want to ensure that the PBackground actor gets cloned in the Nuwa
// process before we freeze. Also, we have to do this to avoid deadlock.
// Protocols that are "opened" (e.g. PBackground, PCompositor) block the
// main thread to wait for the IPC thread during the open operation.
// NuwaSpawnWait() blocks the IPC thread to wait for the main thread when
// the Nuwa process is forked. Unless we ensure that the two cannot happen
// at the same time then we risk deadlock. Spinning the event loop here
// guarantees the ordering is safe for PBackground.
while (!BackgroundChild::GetForCurrentThread()) {
if (NS_WARN_IF(!NS_ProcessNextEvent())) {
return false;
}
}
MessageLoop* ioloop = XRE_GetIOMessageLoop();
ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork));
return true;
#else
return false; // Makes the underlying IPC channel abort.

View File

@ -350,8 +350,6 @@ public:
virtual bool RecvNotifyPhoneStateChange(const nsString& state) MOZ_OVERRIDE;
virtual bool RecvNuwaFreeze() MOZ_OVERRIDE;
void AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS);
void RemoveIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS);
virtual bool RecvNotifyIdleObserver(const uint64_t& aObserver,

View File

@ -122,7 +122,6 @@
#include "nsServiceManagerUtils.h"
#include "nsStyleSheetService.h"
#include "nsThreadUtils.h"
#include "nsThreadManager.h"
#include "nsToolkitCompsCID.h"
#include "nsWidgetsCID.h"
#include "PreallocatedProcessManager.h"
@ -1371,28 +1370,6 @@ StaticAutoPtr<LinkedList<SystemMessageHandledListener> >
NS_IMPL_ISUPPORTS(SystemMessageHandledListener,
nsITimerCallback)
#ifdef MOZ_NUWA_PROCESS
class NuwaFreezeListener : public nsThreadManager::AllThreadsWereIdleListener
{
public:
NuwaFreezeListener(ContentParent* parent)
: mParent(parent)
{
}
void OnAllThreadsWereIdle()
{
unused << mParent->SendNuwaFreeze();
nsThreadManager::get()->RemoveAllThreadsWereIdleListener(this);
}
private:
nsRefPtr<ContentParent> mParent;
virtual ~NuwaFreezeListener()
{
}
};
#endif // MOZ_NUWA_PROCESS
} // anonymous namespace
void
@ -2080,8 +2057,6 @@ ContentParent::ContentParent(ContentParent* aTemplate,
priority = PROCESS_PRIORITY_FOREGROUND;
}
mSendPermissionUpdates = aTemplate->mSendPermissionUpdates;
InitInternal(priority,
false, /* Setup Off-main thread compositing */
false /* Send registered chrome */);
@ -2239,7 +2214,7 @@ ContentParent::IsForApp()
#ifdef MOZ_NUWA_PROCESS
bool
ContentParent::IsNuwaProcess() const
ContentParent::IsNuwaProcess()
{
return mIsNuwaProcess;
}
@ -2588,19 +2563,6 @@ ContentParent::RecvNuwaReady()
#endif
}
bool
ContentParent::RecvNuwaWaitForFreeze()
{
#ifdef MOZ_NUWA_PROCESS
nsRefPtr<NuwaFreezeListener> listener = new NuwaFreezeListener(this);
nsThreadManager::get()->AddAllThreadsWereIdleListener(listener);
return true;
#else // MOZ_NUWA_PROCESS
NS_ERROR("ContentParent::RecvNuwaWaitForFreeze() not implemented!");
return false;
#endif // MOZ_NUWA_PROCESS
}
bool
ContentParent::RecvAddNewProcess(const uint32_t& aPid,
const InfallibleTArray<ProtocolFdMapping>& aFds)

View File

@ -206,7 +206,7 @@ public:
return mIsForBrowser;
}
#ifdef MOZ_NUWA_PROCESS
bool IsNuwaProcess() const;
bool IsNuwaProcess();
#endif
GeckoChildProcessHost* Process() {
@ -220,11 +220,7 @@ public:
}
bool NeedsPermissionsUpdate() const {
#ifdef MOZ_NUWA_PROCESS
return !IsNuwaProcess() && mSendPermissionUpdates;
#else
return mSendPermissionUpdates;
#endif
}
bool NeedsDataStoreInfos() const {
@ -683,8 +679,6 @@ private:
virtual bool RecvNuwaReady() MOZ_OVERRIDE;
virtual bool RecvNuwaWaitForFreeze() MOZ_OVERRIDE;
virtual bool RecvAddNewProcess(const uint32_t& aPid,
const InfallibleTArray<ProtocolFdMapping>& aFds) MOZ_OVERRIDE;

View File

@ -518,7 +518,6 @@ child:
intr GetProfile()
returns (nsCString aProfile);
NuwaFreeze();
parent:
/**
* Tell the parent process a new accessible document has been created.
@ -729,9 +728,6 @@ parent:
async SystemMessageHandled();
NuwaReady();
// Sent when nuwa finished its initialization process and is waiting for
// parent's signal to make it freeze.
NuwaWaitForFreeze();
sync AddNewProcess(uint32_t pid, ProtocolFdMapping[] aFds);

View File

@ -833,21 +833,6 @@ TabChild::PreloadSlowThings()
ClearOnShutdown(&sPreallocatedTab);
}
/*static*/ void
TabChild::PostForkPreload()
{
// Preallocated Tab can be null if we are forked directly from b2g. In such
// case we don't need to preload anything, just return.
if (!sPreallocatedTab) {
return;
}
// Rebuild connections to parent.
sPreallocatedTab->RecvLoadRemoteScript(
NS_LITERAL_STRING("chrome://global/content/post-fork-preload.js"),
true);
}
/*static*/ already_AddRefed<TabChild>
TabChild::Create(nsIContentChild* aManager,
const TabId& aTabId,

View File

@ -268,7 +268,6 @@ public:
* on the critical path.
*/
static void PreloadSlowThings();
static void PostForkPreload();
/** Return a TabChild with the given attributes. */
static already_AddRefed<TabChild>

View File

@ -9,4 +9,3 @@ toolkit.jar:
content/global/BrowserElementChildPreload.js (../browser-element/BrowserElementChildPreload.js)
* content/global/BrowserElementPanning.js (../browser-element/BrowserElementPanning.js)
content/global/preload.js (preload.js)
content/global/post-fork-preload.js (post-fork-preload.js)

View File

@ -1,20 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// Preload some things, in an attempt to make app startup faster.
//
// This script is run when the preallocated process starts. It is injected as
// a frame script.
// If Nuwa process is enabled, this script will run in preallocated process
// forked by Nuwa.
(function (global) {
"use strict";
Components.utils.import("resource://gre/modules/AppsServiceChild.jsm");
Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
getService(Ci["nsIProtocolProxyService"]);
DOMApplicationRegistry.resetList();
})(this);

View File

@ -6,7 +6,6 @@
//
// This script is run when the preallocated process starts. It is injected as
// a frame script.
// If nuwa is enabled, this script will run in Nuwa process before frozen.
const BrowserElementIsPreloaded = true;
@ -54,6 +53,7 @@ const BrowserElementIsPreloaded = true;
Cc["@mozilla.org/network/idn-service;1"].getService(Ci["nsIIDNService"]);
Cc["@mozilla.org/network/io-service;1"].getService(Ci["nsIIOService2"]);
Cc["@mozilla.org/network/mime-hdrparam;1"].getService(Ci["nsIMIMEHeaderParam"]);
Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(Ci["nsIProtocolProxyService"]);
Cc["@mozilla.org/network/socket-transport-service;1"].getService(Ci["nsISocketTransportService"]);
Cc["@mozilla.org/network/stream-transport-service;1"].getService(Ci["nsIStreamTransportService"]);
Cc["@mozilla.org/network/url-parser;1?auth=maybe"].getService(Ci["nsIURLParser"]);

View File

@ -76,7 +76,7 @@ function runTest()
let timeout = setTimeout(function() {
ok(false, "Nuwa process is not launched");
testEnd();
}, 240000);
}, 60000);
function testEnd() {
cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);

View File

@ -77,7 +77,7 @@ function runTest()
let timeout = setTimeout(function() {
ok(false, "Nuwa process is not launched");
testEnd();
}, 240000);
}, 90000);
function testEnd() {
cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);

View File

@ -65,9 +65,6 @@ public:
NS_IMETHOD Run()
{
MOZ_ASSERT(!NS_IsMainThread());
#ifdef MOZ_NUWA_PROCESS
NS_SetIgnoreStatusOfCurrentThread();
#endif
nsAutoString event;
gWpaSupplicant->WaitForEvent(event, mInterface);
if (!event.IsEmpty()) {

View File

@ -65,7 +65,6 @@
#include "nsPrintfCString.h"
#include "nsProxyRelease.h"
#include "nsSandboxFlags.h"
#include "nsThread.h"
#include "xpcpublic.h"
#ifdef ANDROID
@ -4167,17 +4166,6 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
{
MutexAutoLock lock(mMutex);
#ifdef MOZ_NUWA_PROCESS
{
nsThread *thr = static_cast<nsThread*>(NS_GetCurrentThread());
ReentrantMonitorAutoEnter mon(thr->ThreadStatusMonitor());
if (mControlQueue.IsEmpty() &&
!(normalRunnablesPending = NS_HasPendingEvents(mThread))) {
thr->SetIdle();
}
}
#endif // MOZ_NUWA_PROCESS
while (mControlQueue.IsEmpty() &&
!(normalRunnablesPending = NS_HasPendingEvents(mThread))) {
WaitForWorkerEvents();

View File

@ -701,7 +701,6 @@ nsSocketTransportService::Run()
"NuwaMarkCurrentThread is undefined!");
NuwaMarkCurrentThread(nullptr, nullptr);
}
NS_SetIgnoreStatusOfCurrentThread();
#endif
SOCKET_LOG(("STS thread init\n"));

View File

@ -805,7 +805,7 @@ class B2GOptions(MochitestOptions):
defaults["testPath"] = ""
defaults["extensionsToExclude"] = ["specialpowers"]
# See dependencies of bug 1038943.
defaults["defaultLeakThreshold"] = 5308
defaults["defaultLeakThreshold"] = 5180
self.set_defaults(**defaults)
def verifyRemoteOptions(self, options):

View File

@ -127,8 +127,6 @@ public:
}
#endif
NS_SetIgnoreStatusOfCurrentThread();
int lowMemFd = open("/sys/kernel/mm/lowmemkiller/notify_trigger_active",
O_RDONLY | O_CLOEXEC);
NS_ENSURE_STATE(lowMemFd != -1);

View File

@ -375,11 +375,3 @@ nsAutoLowPriorityIO::~nsAutoLowPriorityIO()
#endif
}
#ifdef MOZ_NUWA_PROCESS
#ifdef MOZILLA_INTERNAL_API
void
NS_SetIgnoreStatusOfCurrentThread() {
nsThreadManager::get()->SetIgnoreThreadStatus();
}
#endif // MOZILLA_INTERNAL_API
#endif // MOZ_NUWA_PROCESS

View File

@ -565,19 +565,4 @@ private:
void
NS_SetMainThread();
/**
* Helpers for thread to report their status when compiled with Nuwa.
*/
#ifdef MOZILLA_INTERNAL_API
#ifdef MOZ_NUWA_PROCESS
extern void
NS_SetIgnoreStatusOfCurrentThread();
#else // MOZ_NUWA_PROCESS
inline void
NS_SetIgnoreStatusOfCurrentThread()
{
}
#endif // MOZ_NUWA_PROCESS
#endif // MOZILLA_INTERNAL_API
#endif // nsThreadUtils_h__

View File

@ -207,7 +207,6 @@ TimerThread::Run()
}
#endif
NS_SetIgnoreStatusOfCurrentThread();
MonitorAutoLock lock(mMonitor);
// We need to know how many microseconds give a positive PRIntervalTime. This

View File

@ -13,6 +13,7 @@
#undef LOG
#endif
#include "mozilla/ReentrantMonitor.h"
#include "nsMemoryPressure.h"
#include "nsThreadManager.h"
#include "nsIClassInfoImpl.h"
@ -328,10 +329,6 @@ nsThread::ThreadFunc(void* aArg)
// Inform the ThreadManager
nsThreadManager::get()->RegisterCurrentThread(self);
#ifdef MOZ_NUWA_PROCESS
self->mThreadStatusInfo =
static_cast<void*>(nsThreadManager::get()->GetCurrentThreadStatusInfo());
#endif
mozilla::IOInterposer::RegisterCurrentThread();
@ -437,10 +434,6 @@ nsThread::nsThread(MainThreadFlag aMainThread, uint32_t aStackSize)
, mShutdownRequired(false)
, mEventsAreDoomed(false)
, mIsMainThread(aMainThread)
#ifdef MOZ_NUWA_PROCESS
, mThreadStatusMonitor("nsThread.mThreadStatusLock")
, mThreadStatusInfo(nullptr)
#endif
{
}
@ -488,11 +481,6 @@ nsThread::InitCurrentThread()
SetupCurrentThreadForChaosMode();
nsThreadManager::get()->RegisterCurrentThread(this);
#ifdef MOZ_NUWA_PROCESS
mThreadStatusInfo =
static_cast<void*>(nsThreadManager::get()->GetCurrentThreadStatusInfo());
#endif
return NS_OK;
}
@ -508,15 +496,7 @@ nsThread::PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget)
NS_WARNING("An event was posted to a thread that will never run it (rejected)");
return NS_ERROR_UNEXPECTED;
}
#ifdef MOZ_NUWA_PROCESS
{
ReentrantMonitorAutoEnter mon(mThreadStatusMonitor);
SetWorking();
#endif // MOZ_NUWA_PROCESS
queue->PutEvent(aEvent);
#ifdef MOZ_NUWA_PROCESS
}
#endif // MOZ_NUWA_PROCESS
queue->PutEvent(aEvent);
// Make sure to grab the observer before dropping the lock, otherwise the
// event that we just placed into the queue could run and eventually delete
@ -857,15 +837,6 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
--mRunningEvent;
#ifdef MOZ_NUWA_PROCESS
{
ReentrantMonitorAutoEnter mon(mThreadStatusMonitor);
if ((!mEvents->GetEvent(false, nullptr)) && (mRunningEvent == 0)) {
SetIdle();
}
}
#endif // MOZ_NUWA_PROCESS
NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent,
(this, mRunningEvent, *aResult));
@ -1075,22 +1046,6 @@ nsThread::SetMainThreadObserver(nsIThreadObserver* aObserver)
return NS_OK;
}
#ifdef MOZ_NUWA_PROCESS
void
nsThread::SetWorking()
{
nsThreadManager::get()->SetThreadIsWorking(
static_cast<nsThreadManager::ThreadStatusInfo*>(mThreadStatusInfo), true);
}
void
nsThread::SetIdle()
{
nsThreadManager::get()->SetThreadIsWorking(
static_cast<nsThreadManager::ThreadStatusInfo*>(mThreadStatusInfo), false);
}
#endif
//-----------------------------------------------------------------------------
NS_IMETHODIMP

View File

@ -16,7 +16,6 @@
#include "nsTObserverArray.h"
#include "mozilla/Attributes.h"
#include "nsAutoPtr.h"
#include "mozilla/ReentrantMonitor.h"
// A native thread
class nsThread
@ -66,14 +65,6 @@ public:
static nsresult
SetMainThreadObserver(nsIThreadObserver* aObserver);
#ifdef MOZ_NUWA_PROCESS
void SetWorking();
void SetIdle();
mozilla::ReentrantMonitor& ThreadStatusMonitor() {
return mThreadStatusMonitor;
}
#endif
protected:
static nsIThreadObserver* sMainThreadObserver;
@ -191,12 +182,6 @@ protected:
// Set to true when events posted to this thread will never run.
bool mEventsAreDoomed;
MainThreadFlag mIsMainThread;
#ifdef MOZ_NUWA_PROCESS
mozilla::ReentrantMonitor mThreadStatusMonitor;
// The actual type is defined in nsThreadManager.h which is not exposed to
// file out of thread module.
void* mThreadStatusInfo;
#endif
};
//-----------------------------------------------------------------------------

View File

@ -11,7 +11,6 @@
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "mozilla/ThreadLocal.h"
#include "mozilla/ReentrantMonitor.h"
#ifdef MOZ_CANARY
#include <fcntl.h>
#include <unistd.h>
@ -48,54 +47,6 @@ NS_SetMainThread()
typedef nsTArray<nsRefPtr<nsThread>> nsThreadArray;
#ifdef MOZ_NUWA_PROCESS
class NotifyAllThreadsWereIdle: public nsRunnable
{
public:
NotifyAllThreadsWereIdle(
nsTArray<nsRefPtr<nsThreadManager::AllThreadsWereIdleListener>>* aListeners)
: mListeners(aListeners)
{
}
virtual NS_IMETHODIMP
Run() {
// Copy listener array, which may be modified during call back.
nsTArray<nsRefPtr<nsThreadManager::AllThreadsWereIdleListener>> arr(*mListeners);
for (size_t i = 0; i < arr.Length(); i++) {
arr[i]->OnAllThreadsWereIdle();
}
return NS_OK;
}
private:
// Raw pointer, since it's pointing to a member of thread manager.
nsTArray<nsRefPtr<nsThreadManager::AllThreadsWereIdleListener>>* mListeners;
};
struct nsThreadManager::ThreadStatusInfo {
Atomic<bool> mWorking;
Atomic<bool> mWillBeWorking;
bool mIgnored;
nsThreadManager *mMgr;
ThreadStatusInfo(nsThreadManager *aManager)
: mWorking(false)
, mWillBeWorking(false)
, mIgnored(false)
, mMgr(aManager)
{
ReentrantMonitorAutoEnter mon(*(mMgr->mMonitor));
mMgr->mThreadStatusInfos.AppendElement(this);
}
~ThreadStatusInfo()
{
ReentrantMonitorAutoEnter mon(*(mMgr->mMonitor));
mMgr->mThreadStatusInfos.RemoveElement(this);
}
};
#endif // MOZ_NUWA_PROCESS
//-----------------------------------------------------------------------------
static void
@ -104,14 +55,6 @@ ReleaseObject(void* aData)
static_cast<nsISupports*>(aData)->Release();
}
#ifdef MOZ_NUWA_PROCESS
static void
DeleteThreadStatusInfo(void* aData)
{
delete static_cast<nsThreadManager::ThreadStatusInfo*>(aData);
}
#endif
static PLDHashOperator
AppendAndRemoveThread(PRThread* aKey, nsRefPtr<nsThread>& aThread, void* aArg)
{
@ -153,17 +96,7 @@ nsThreadManager::Init()
return NS_ERROR_FAILURE;
}
#ifdef MOZ_NUWA_PROCESS
if (PR_NewThreadPrivateIndex(&mThreadStatusInfoIndex,
DeleteThreadStatusInfo) == PR_FAILURE) {
return NS_ERROR_FAILURE;
}
#endif // MOZ_NUWA_PROCESS
mLock = new Mutex("nsThreadManager.mLock");
#ifdef MOZ_NUWA_PROCESS
mMonitor = MakeUnique<ReentrantMonitor>("nsThreadManager.mMonitor");
#endif // MOZ_NUWA_PROCESS
#ifdef MOZ_CANARY
const int flags = O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK;
@ -261,9 +194,6 @@ nsThreadManager::Shutdown()
// Remove the TLS entry for the main thread.
PR_SetThreadPrivate(mCurThreadIndex, nullptr);
#ifdef MOZ_NUWA_PROCESS
PR_SetThreadPrivate(mThreadStatusInfoIndex, nullptr);
#endif
}
void
@ -296,9 +226,6 @@ nsThreadManager::UnregisterCurrentThread(nsThread* aThread)
PR_SetThreadPrivate(mCurThreadIndex, nullptr);
// Ref-count balanced via ReleaseObject
#ifdef MOZ_NUWA_PROCESS
PR_SetThreadPrivate(mThreadStatusInfoIndex, nullptr);
#endif
}
nsThread*
@ -323,21 +250,6 @@ nsThreadManager::GetCurrentThread()
return thread.get(); // reference held in TLS
}
#ifdef MOZ_NUWA_PROCESS
nsThreadManager::ThreadStatusInfo*
nsThreadManager::GetCurrentThreadStatusInfo()
{
void* data = PR_GetThreadPrivate(mThreadStatusInfoIndex);
if (!data) {
ThreadStatusInfo *thrInfo = new ThreadStatusInfo(this);
PR_SetThreadPrivate(mThreadStatusInfoIndex, thrInfo);
data = thrInfo;
}
return static_cast<ThreadStatusInfo*>(data);
}
#endif
NS_IMETHODIMP
nsThreadManager::NewThread(uint32_t aCreationFlags,
uint32_t aStackSize,
@ -430,127 +342,3 @@ nsThreadManager::GetHighestNumberOfThreads()
MutexAutoLock lock(*mLock);
return mHighestNumberOfThreads;
}
#ifdef MOZ_NUWA_PROCESS
void
nsThreadManager::SetIgnoreThreadStatus()
{
GetCurrentThreadStatusInfo()->mIgnored = true;
}
void
nsThreadManager::SetThreadIdle()
{
SetThreadIsWorking(GetCurrentThreadStatusInfo(), false);
}
void
nsThreadManager::SetThreadWorking()
{
SetThreadIsWorking(GetCurrentThreadStatusInfo(), true);
}
void
nsThreadManager::SetThreadIsWorking(ThreadStatusInfo* aInfo, bool aIsWorking)
{
aInfo->mWillBeWorking = aIsWorking;
if (mThreadsIdledListeners.Length() > 0) {
// A race condition occurs since we don't want threads to try to enter the
// monitor (nsThreadManager::mMonitor) when no one cares about their status.
// And thus the race can happen when we put the first listener into
// |mThreadsIdledListeners|:
//
// (1) Thread A wants to dispatch a task to Thread B.
// (2) Thread A checks |mThreadsIdledListeners|, and nothing is in the
// list. So Thread A decides not to enter |mMonitor| when updating B's
// status.
// (3) Thread A is suspended just before it changed status of B.
// (4) A listener is added to |mThreadsIdledListeners|
// (5) Now is Thread C's turn to run. Thread C finds there's something in
// |mThreadsIdledListeners|, so it enters |mMonitor| and check all
// thread info structs in |mThreadStatusInfos| while A is in the middle
// of changing B's status.
//
// Then C may find Thread B is an idle thread (which is not correct, because
// A attempted to change B's status prior to C starting to walk throught
// |mThreadStatusInfo|), but the fact that thread A is working (thread A
// hasn't finished dispatching a task to thread B) can prevent thread C from
// firing a bogus notification.
//
// If the state transition that happens outside the monitor is in the other
// direction, the race condition could be:
//
// (1) Thread D has just finished its jobs and wants to set its status to idle.
// (2) Thread D checks |mThreadsIdledListeners|, and nothing is in the list.
// So Thread D decides not to enter |mMonitor|.
// (3) Thread D is is suspended before it updates its own status.
// (4) A listener is put into |mThreadsIdledListeners|.
// (5) Thread C wants to changes status of itself. It checks
// |mThreadsIdledListeners| and finds something inside the list. Thread C
// then enters |mMonitor|, updates its status and checks thread info in
// |mThreadStatusInfos| while D is changing status of itself out of monitor.
//
// Thread C will find that thread D is working (D actually wants to change its
// status to idle before C starting to check), then C returns without firing
// any notification. Finding that thread D is working can make our checking
// mechanism miss a chance to fire a notification: because thread D thought
// there's nothing in |mThreadsIdledListeners| and thus won't check the
// |mThreadStatusInfos| after changing the status of itself.
//
// |mWillBeWorking| can be used to address this problem. We require each
// thread to put the value that is going to be set to |mWorking| to
// |mWillBeWorking| before the thread decide whether it should enter
// |mMonitor| to change status or not. Thus C finds that D is working while
// D's |mWillBeWorking| is false, and C realizes that D is just updating and
// can treat D as an idle thread.
//
// It doesn't matter whether D will check thread status after changing its
// own status or not. If D checks, which means D will enter the monitor
// before updating status, thus D must be blocked until C has finished
// dispatching the notification task to main thread, and D will find that main
// thread is working and will not fire an additional event. On the other hand,
// if D doesn't check |mThreadStatusInfos|, it's still ok, because C has
// treated D as an idle thread already.
bool hasWorkingThread = false;
ReentrantMonitorAutoEnter mon(*mMonitor);
// Get data structure of thread info.
aInfo->mWorking = aIsWorking;
for (size_t i = 0; i < mThreadStatusInfos.Length(); i++) {
ThreadStatusInfo *info = mThreadStatusInfos[i];
if (!info->mIgnored) {
if (info->mWorking) {
if (info->mWillBeWorking) {
hasWorkingThread = true;
break;
}
}
}
}
if (!hasWorkingThread) {
nsRefPtr<NotifyAllThreadsWereIdle> runnable =
new NotifyAllThreadsWereIdle(&mThreadsIdledListeners);
NS_DispatchToMainThread(runnable);
}
} else {
// Update thread info without holding any lock.
aInfo->mWorking = aIsWorking;
}
}
void
nsThreadManager::AddAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener)
{
MOZ_ASSERT(GetCurrentThreadStatusInfo()->mWorking);
mThreadsIdledListeners.AppendElement(listener);
}
void
nsThreadManager::RemoveAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener)
{
mThreadsIdledListeners.RemoveElement(listener);
}
#endif // MOZ_NUWA_PROCESS

View File

@ -14,26 +14,9 @@
class nsIRunnable;
namespace mozilla {
class ReentrantMonitor;
}
class nsThreadManager : public nsIThreadManager
{
public:
#ifdef MOZ_NUWA_PROCESS
struct ThreadStatusInfo;
class AllThreadsWereIdleListener {
public:
NS_INLINE_DECL_REFCOUNTING(AllThreadsWereIdleListener);
virtual void OnAllThreadsWereIdle() = 0;
protected:
virtual ~AllThreadsWereIdleListener()
{
}
};
#endif // MOZ_NUWA_PROCESS
NS_DECL_ISUPPORTS
NS_DECL_NSITHREADMANAGER
@ -71,17 +54,6 @@ public:
{
}
#ifdef MOZ_NUWA_PROCESS
void SetIgnoreThreadStatus();
void SetThreadIdle();
void SetThreadWorking();
void SetThreadIsWorking(ThreadStatusInfo* aInfo, bool aIsWorking);
void AddAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener);
void RemoveAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener);
ThreadStatusInfo* GetCurrentThreadStatusInfo();
#endif // MOZ_NUWA_PROCESS
private:
nsThreadManager()
: mCurThreadIndex(0)
@ -90,9 +62,6 @@ private:
, mInitialized(false)
, mCurrentNumberOfThreads(1)
, mHighestNumberOfThreads(1)
#ifdef MOZ_NUWA_PROCESS
, mMonitor(nullptr)
#endif
{
}
@ -109,13 +78,6 @@ private:
uint32_t mCurrentNumberOfThreads;
// The highest number of threads encountered so far during the session
uint32_t mHighestNumberOfThreads;
#ifdef MOZ_NUWA_PROCESS
unsigned mThreadStatusInfoIndex;
nsTArray<nsRefPtr<AllThreadsWereIdleListener>> mThreadsIdledListeners;
nsTArray<ThreadStatusInfo*> mThreadStatusInfos;
mozilla::UniquePtr<mozilla::ReentrantMonitor> mMonitor;
#endif // MOZ_NUWA_PROCESS
};
#define NS_THREADMANAGER_CID \

View File

@ -150,6 +150,7 @@ NS_IMETHODIMP
nsThreadPool::Run()
{
LOG(("THRD-P(%p) enter\n", this));
mThreadNaming.SetThreadPoolName(mName);
nsCOMPtr<nsIThread> current;
@ -207,9 +208,6 @@ nsThreadPool::Run()
} else {
PRIntervalTime delta = timeout - (now - idleSince);
LOG(("THRD-P(%p) waiting [%d]\n", this, delta));
#ifdef MOZ_NUWA_PROCESS
nsThreadManager::get()->SetThreadIdle();
#endif // MOZ_NUWA_PROCESS
mon.Wait(delta);
}
} else if (wasIdle) {
@ -219,9 +217,6 @@ nsThreadPool::Run()
}
if (event) {
LOG(("THRD-P(%p) running [%p]\n", this, event.get()));
#ifdef MOZ_NUWA_PROCESS
nsThreadManager::get()->SetThreadWorking();
#endif // MOZ_NUWA_PROCESS
event->Run();
}
} while (!exitThread);

View File

@ -559,13 +559,6 @@ nsTimerImpl::Fire()
return;
}
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess() && IsNuwaReady()) {
// A timer event fired after Nuwa frozen can freeze main thread.
return;
}
#endif
PROFILER_LABEL("Timer", "Fire",
js::ProfileEntry::Category::OTHER);