2015-04-09 20:25:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2018-12-19 07:28:14 +03:00
|
|
|
#include "XPCOMModule.h"
|
|
|
|
|
2009-10-22 03:01:16 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2013-07-20 07:14:34 +04:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-05-07 22:48:59 +04:00
|
|
|
#include "mozilla/Poison.h"
|
2018-11-14 21:07:28 +03:00
|
|
|
#include "mozilla/RemoteDecoderManagerChild.h"
|
2015-08-04 00:34:47 +03:00
|
|
|
#include "mozilla/SharedThreadPool.h"
|
2009-05-18 22:15:05 +04:00
|
|
|
#include "mozilla/XPCOM.h"
|
2019-02-09 02:09:20 +03:00
|
|
|
#include "mozJSComponentLoader.h"
|
2009-08-29 03:16:19 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2009-05-18 22:15:05 +04:00
|
|
|
|
2018-02-13 13:55:16 +03:00
|
|
|
#ifndef ANDROID
|
|
|
|
# include "nsTerminator.h"
|
|
|
|
#endif
|
|
|
|
|
2001-12-07 22:54:16 +03:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
2009-05-18 22:15:05 +04:00
|
|
|
|
2014-04-16 04:48:02 +04:00
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
2016-03-22 21:08:38 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2014-05-07 13:06:19 +04:00
|
|
|
|
|
|
|
#include "prlink.h"
|
2014-04-16 04:48:02 +04:00
|
|
|
|
2013-04-30 21:41:22 +04:00
|
|
|
#include "nsCycleCollector.h"
|
2001-10-23 02:01:27 +04:00
|
|
|
#include "nsObserverService.h"
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2003-07-08 02:11:36 +04:00
|
|
|
#include "nsDebugImpl.h"
|
2018-12-19 07:28:14 +03:00
|
|
|
#include "nsSystemInfo.h"
|
2001-12-07 22:54:16 +03:00
|
|
|
|
2005-10-04 21:19:14 +04:00
|
|
|
#include "nsINIParserImpl.h"
|
1999-05-19 01:43:13 +04:00
|
|
|
|
|
|
|
#include "nsComponentManager.h"
|
2002-09-24 01:46:25 +04:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
1999-05-19 01:43:13 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadManager.h"
|
|
|
|
#include "nsThreadPool.h"
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2001-12-16 09:13:17 +03:00
|
|
|
#include "nsTimerImpl.h"
|
|
|
|
#include "TimerThread.h"
|
|
|
|
|
1999-10-02 03:30:06 +04:00
|
|
|
#include "nsThread.h"
|
2005-07-23 18:05:25 +04:00
|
|
|
#include "nsVersionComparatorImpl.h"
|
1999-10-02 03:30:06 +04:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsLocalFile.h"
|
|
|
|
#include "nsDirectoryService.h"
|
2000-08-12 00:31:57 +04:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2002-07-18 09:09:10 +04:00
|
|
|
#include "nsCategoryManager.h"
|
2000-02-06 05:02:24 +03:00
|
|
|
#include "nsICategoryManager.h"
|
2002-02-16 04:19:24 +03:00
|
|
|
#include "nsMultiplexInputStream.h"
|
1999-10-26 02:48:44 +04:00
|
|
|
|
2001-10-21 03:19:07 +04:00
|
|
|
#include "nsAtomTable.h"
|
2014-02-27 01:36:35 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2000-03-31 13:50:00 +04:00
|
|
|
|
2006-07-06 10:32:03 +04:00
|
|
|
#include "nsSystemInfo.h"
|
2008-03-06 04:28:25 +03:00
|
|
|
#include "nsMemoryReporterManager.h"
|
2012-10-25 19:36:24 +04:00
|
|
|
#include "nsMessageLoop.h"
|
2017-11-11 02:03:23 +03:00
|
|
|
#include "nss.h"
|
bug 1485087 - remove the option to use the TLS session cache from nsITLSServerSocket r=jryans,mayhemer
As initially implemented, nsITLSServerSocket by default enabled the use of the
TLS session cache provided by NSS. However, no consumers of nsITLSServerSocket
actually used it. Because it was an option, though, PSM had to jump through some
hoops to a) make it work in the first place and b) not have NSS panic on
shutdown. Furthermore, it meant increased memory usage for every user of Firefox
(and again, nothing actually used the feature, so this was for naught).
In bug 1479918, we discovered that if PSM shut down before Necko, NSS could
attempt to acquire a lock on the session cache that had been deleted, causing a
shutdown hang. We probably should make it less easy to make this mistake in NSS,
but in the meantime bug 1479918 needs uplifting and this workaround is the
safest, most straight-forward way to achieve this.
Differential Revision: https://phabricator.services.mozilla.com/D3919
--HG--
extra : moz-landing-system : lando
2018-08-24 19:00:34 +03:00
|
|
|
#include "ssl.h"
|
2006-07-06 10:32:03 +04:00
|
|
|
|
2004-06-15 20:38:43 +04:00
|
|
|
#include <locale.h>
|
2010-04-02 22:38:25 +04:00
|
|
|
#include "mozilla/Services.h"
|
2010-08-11 02:08:06 +04:00
|
|
|
#include "mozilla/Omnijar.h"
|
Bug 1359653: Part 5 - Pre-load scripts needed during startup in a background thread. r=shu,erahm
One of the things that I've noticed in profiling startup overhead is that,
even with the startup cache, we spend about 130ms just loading and decoding
scripts from the startup cache on my machine.
I think we should be able to do better than that by doing some of that work in
the background for scripts that we know we'll need during startup. With this
change, we seem to consistently save about 3-5% on non-e10s startup overhead
on talos. But there's a lot of room for tuning, and I think we get some
considerable improvement with a few ongoing tweeks.
Some notes about the approach:
- Setting up the off-thread compile is fairly expensive, since we need to
create a global object, and a lot of its built-in prototype objects for each
compile. So in order for there to be a performance improvement for OMT
compiles, the script has to be pretty large. Right now, the tipping point
seems to be about 20K.
There's currently no easy way to improve the per-compile setup overhead, but
we should be able to combine the off-thread compiles for multiple smaller
scripts into a single operation without any additional per-script overhead.
- The time we spend setting up scripts for OMT compile is almost entirely
CPU-bound. That means that we have a chunk of about 20-50ms where we can
safely schedule thread-safe IO work during early startup, so if we schedule
some of our current synchronous IO operations on background threads during the
script cache setup, we basically get them for free, and can probably increase
the number of scripts we compile in the background.
- I went with an uncompressed mmap of the raw XDR data for a storage format.
That currently occupies about 5MB of disk space. Gzipped, it's ~1.2MB, so
compressing it might save some startup disk IO, but keeping it uncompressed
simplifies a lot of the OMT and even main thread decoding process, but, more
importantly:
- We currently don't use the startup cache in content processes, for a variety
of reasons. However, with this approach, I think we can safely store the
cached script data from a content process before we load any untrusted code
into it, and then share mmapped startup cache data between all content
processes. That should speed up content process startup *a lot*, and very
likely save memory, too. And:
- If we're especially concerned about saving per-process memory, and we keep
the cache data mapped for the lifetime of the JS runtime, I think that with
some effort we can probably share the static string data from scripts between
content processes, without any copying. Right now, it looks like for the main
process, there's about 1.5MB of string-ish data in the XDR dumps. It's
probably less for content processes, but if we could save .5MB per process
this way, it might make it easier to increase the number of content processes
we allow.
MozReview-Commit-ID: CVJahyNktKB
--HG--
extra : source : 1c7df945505930d2d86a076ee20807104324c8cc
extra : histedit_source : 75e193839edf727874f01b2a9f6852f6c1f087fb%2C3ce966d7dcf2bd0454a7d673d0467097456bd782
2017-05-06 22:24:22 +03:00
|
|
|
#include "mozilla/ScriptPreloader.h"
|
2017-02-02 01:08:46 +03:00
|
|
|
#include "mozilla/SystemGroup.h"
|
2012-01-11 00:29:58 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-11-22 23:17:29 +04:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2004-06-15 20:38:43 +04:00
|
|
|
|
2014-03-15 02:27:21 +04:00
|
|
|
#include "mozilla/PoisonIOInterposer.h"
|
2013-11-05 16:45:20 +04:00
|
|
|
#include "mozilla/LateWriteChecks.h"
|
2010-06-12 00:13:26 +04:00
|
|
|
|
2010-08-12 23:37:44 +04:00
|
|
|
#include "mozilla/scache/StartupCache.h"
|
|
|
|
|
2009-07-30 01:11:42 +04:00
|
|
|
#include "base/at_exit.h"
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
#include "mozilla/ipc/BrowserProcessSubThread.h"
|
2011-12-15 23:48:38 +04:00
|
|
|
#include "mozilla/AvailableMemoryTracker.h"
|
2012-01-27 00:54:03 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2014-08-25 23:34:00 +04:00
|
|
|
#include "mozilla/CountingAllocatorBase.h"
|
2014-09-19 22:17:17 +04:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2019-09-10 01:39:46 +03:00
|
|
|
#include "mozilla/ServoStyleConsts.h"
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
|
|
|
|
2014-02-25 20:04:50 +04:00
|
|
|
#include "ogg/ogg.h"
|
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-10-06 12:37:45 +04:00
|
|
|
|
2013-07-20 07:14:34 +04:00
|
|
|
#include "jsapi.h"
|
2015-10-31 02:14:32 +03:00
|
|
|
#include "js/Initialization.h"
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
2009-07-30 01:11:42 +04:00
|
|
|
using base::AtExitManager;
|
2009-08-28 23:46:21 +04:00
|
|
|
using mozilla::ipc::BrowserProcessSubThread;
|
2009-07-30 01:11:42 +04:00
|
|
|
|
2018-04-27 10:48:39 +03:00
|
|
|
// From toolkit/library/rust/lib.rs
|
|
|
|
extern "C" void GkRust_Init();
|
|
|
|
extern "C" void GkRust_Shutdown();
|
|
|
|
|
2009-07-30 01:11:42 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
static AtExitManager* sExitManager;
|
|
|
|
static MessageLoop* sMessageLoop;
|
|
|
|
static bool sCommandLineWasInitialized;
|
2009-08-28 23:46:21 +04:00
|
|
|
static BrowserProcessSubThread* sIOThread;
|
2019-11-20 22:58:05 +03:00
|
|
|
static mozilla::BackgroundHangMonitor* sMainHangMonitor;
|
2009-07-30 01:11:42 +04:00
|
|
|
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// Registry Factory creation function defined in nsRegistry.cpp
|
|
|
|
// We hook into this function locally to create and register the registry
|
|
|
|
// Since noone outside xpcom needs to know about this and nsRegistry.cpp
|
|
|
|
// does not have a local include file, we are putting this definition
|
|
|
|
// here rather than in nsIRegistry.h
|
2003-01-29 01:17:58 +03:00
|
|
|
extern nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
|
2014-08-13 22:45:37 +04:00
|
|
|
extern nsresult NS_CategoryManagerGetFactory(nsIFactory**);
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2010-10-16 23:58:20 +04:00
|
|
|
#ifdef XP_WIN
|
2012-09-25 04:50:30 +04:00
|
|
|
extern nsresult CreateAnonTempFileRemover();
|
2010-10-16 23:58:20 +04:00
|
|
|
#endif
|
|
|
|
|
2018-12-19 07:28:14 +03:00
|
|
|
nsresult nsThreadManagerGetSingleton(nsISupports* aOuter, const nsIID& aIID,
|
|
|
|
void** aInstancePtr) {
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_ASSERTION(aInstancePtr, "null outptr");
|
|
|
|
if (NS_WARN_IF(aOuter)) {
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2016-06-10 09:04:49 +03:00
|
|
|
return nsThreadManager::get().QueryInterface(aIID, aInstancePtr);
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2018-12-19 07:28:14 +03:00
|
|
|
nsresult nsLocalFileConstructor(nsISupports* aOuter, const nsIID& aIID,
|
|
|
|
void** aInstancePtr) {
|
|
|
|
return nsLocalFile::nsLocalFileConstructor(aOuter, aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
2013-10-11 00:41:00 +04:00
|
|
|
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool gXPCOMShuttingDown = false;
|
2013-07-08 00:23:43 +04:00
|
|
|
bool gXPCOMThreadsShutDown = false;
|
2014-10-10 23:06:57 +04:00
|
|
|
char16_t* gGREBinPath = nullptr;
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static NS_DEFINE_CID(kINIParserFactoryCID, NS_INIPARSERFACTORY_CID);
|
2001-03-12 23:43:02 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static already_AddRefed<nsIFactory> CreateINIParserFactory(
|
2014-08-13 22:45:37 +04:00
|
|
|
const mozilla::Module& aModule, const mozilla::Module::CIDEntry& aEntry) {
|
|
|
|
nsCOMPtr<nsIFactory> f = new nsINIParserFactory();
|
|
|
|
return f.forget();
|
2010-06-10 22:11:11 +04:00
|
|
|
}
|
2005-11-22 00:01:45 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
const mozilla::Module::CIDEntry kXPCOMCIDEntries[] = {
|
2014-08-13 22:45:37 +04:00
|
|
|
{&kINIParserFactoryCID, false, CreateINIParserFactory}, {nullptr}};
|
2001-03-12 23:43:02 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
const mozilla::Module::ContractIDEntry kXPCOMContracts[] = {
|
2014-08-13 22:45:37 +04:00
|
|
|
{NS_INIPARSERFACTORY_CONTRACTID, &kINIParserFactoryCID}, {nullptr}};
|
2001-03-12 23:43:02 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
const mozilla::Module kXPCOMModule = {
|
|
|
|
mozilla::Module::kVersion,
|
2016-08-23 08:57:36 +03:00
|
|
|
kXPCOMCIDEntries,
|
|
|
|
kXPCOMContracts,
|
|
|
|
nullptr,
|
2019-01-18 12:12:56 +03:00
|
|
|
nullptr,
|
2016-08-23 08:57:36 +03:00
|
|
|
nullptr,
|
2018-11-30 13:46:48 +03:00
|
|
|
nullptr,
|
2019-11-20 22:58:05 +03:00
|
|
|
mozilla::Module::ALLOW_IN_GPU_RDD_VR_AND_SOCKET_PROCESS};
|
2000-08-17 02:40:27 +04:00
|
|
|
|
2003-07-08 02:11:36 +04:00
|
|
|
// gDebug will be freed during shutdown.
|
2015-05-07 08:28:37 +03:00
|
|
|
static nsIDebug2* gDebug = nullptr;
|
2005-11-08 21:17:49 +03:00
|
|
|
|
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2015-05-07 08:28:37 +03:00
|
|
|
NS_GetDebug(nsIDebug2** aResult) {
|
|
|
|
return nsDebugImpl::Create(nullptr, NS_GET_IID(nsIDebug2), (void**)aResult);
|
2003-07-08 02:11:36 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
class ICUReporter final : public nsIMemoryReporter,
|
2019-11-20 22:58:05 +03:00
|
|
|
public mozilla::CountingAllocatorBase<ICUReporter> {
|
2013-08-23 09:24:16 +04:00
|
|
|
public:
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-12-08 10:09:10 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
static void* Alloc(const void*, size_t aSize) {
|
|
|
|
return CountingMalloc(aSize);
|
|
|
|
}
|
2013-08-23 09:24:16 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
static void* Realloc(const void*, void* aPtr, size_t aSize) {
|
|
|
|
return CountingRealloc(aPtr, aSize);
|
|
|
|
}
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
static void Free(const void*, void* aPtr) { return CountingFree(aPtr); }
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2013-08-23 09:24:16 +04:00
|
|
|
private:
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD
|
2014-08-13 22:45:37 +04:00
|
|
|
CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aAnonymize) override {
|
2016-08-24 08:23:45 +03:00
|
|
|
MOZ_COLLECT_REPORT(
|
2014-08-13 22:45:37 +04:00
|
|
|
"explicit/icu", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
|
|
|
|
"Memory used by ICU, a Unicode and globalization support library.");
|
2016-08-24 08:23:45 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~ICUReporter() {}
|
2013-08-23 09:24:16 +04:00
|
|
|
};
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(ICUReporter, nsIMemoryReporter)
|
2013-12-08 10:09:10 +04:00
|
|
|
|
2018-07-31 22:22:54 +03:00
|
|
|
/* static */ template <>
|
2019-11-20 22:58:05 +03:00
|
|
|
mozilla::CountingAllocatorBase<ICUReporter>::AmountType
|
|
|
|
mozilla::CountingAllocatorBase<ICUReporter>::sAmount(0);
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
class OggReporter final : public nsIMemoryReporter,
|
2019-11-20 22:58:05 +03:00
|
|
|
public mozilla::CountingAllocatorBase<OggReporter> {
|
2014-02-25 20:04:50 +04:00
|
|
|
public:
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2014-02-25 20:04:50 +04:00
|
|
|
|
|
|
|
private:
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD
|
2014-08-13 22:45:37 +04:00
|
|
|
CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aAnonymize) override {
|
2016-08-24 08:23:45 +03:00
|
|
|
MOZ_COLLECT_REPORT(
|
2014-08-13 22:45:37 +04:00
|
|
|
"explicit/media/libogg", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
|
2016-08-24 08:23:45 +03:00
|
|
|
"Memory allocated through libogg for Ogg, Theora, and related media "
|
|
|
|
"files.");
|
|
|
|
|
|
|
|
return NS_OK;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~OggReporter() {}
|
2014-02-25 20:04:50 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(OggReporter, nsIMemoryReporter)
|
2014-02-25 20:04:50 +04:00
|
|
|
|
2018-07-31 22:22:54 +03:00
|
|
|
/* static */ template <>
|
2019-11-20 22:58:05 +03:00
|
|
|
mozilla::CountingAllocatorBase<OggReporter>::AmountType
|
|
|
|
mozilla::CountingAllocatorBase<OggReporter>::sAmount(0);
|
2014-02-25 20:04:50 +04:00
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
static bool sInitializedJS = false;
|
|
|
|
|
2014-09-29 22:51:04 +04:00
|
|
|
// Note that on OSX, aBinDirectory will point to .app/Contents/Resources/browser
|
2005-11-08 21:17:49 +03:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2019-03-15 09:38:09 +03:00
|
|
|
NS_InitXPCOM(nsIServiceManager** aResult, nsIFile* aBinDirectory,
|
2019-11-22 15:40:17 +03:00
|
|
|
nsIDirectoryServiceProvider* aAppFileLocationProvider,
|
|
|
|
bool aInitJSContext) {
|
2014-11-27 00:19:57 +03:00
|
|
|
static bool sInitialized = false;
|
|
|
|
if (sInitialized) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sInitialized = true;
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
mozPoisonValueInit();
|
2013-05-07 22:48:59 +04:00
|
|
|
|
2015-06-10 03:44:46 +03:00
|
|
|
NS_LogInit();
|
|
|
|
|
2016-05-26 04:45:17 +03:00
|
|
|
NS_InitAtomTable();
|
|
|
|
|
2018-04-03 18:32:00 +03:00
|
|
|
// We don't have the arguments by hand here. If logging has already been
|
|
|
|
// initialized by a previous call to LogModule::Init with the arguments
|
|
|
|
// passed, passing (0, nullptr) is alright here.
|
|
|
|
mozilla::LogModule::Init(0, nullptr);
|
2015-10-19 22:22:11 +03:00
|
|
|
|
2018-04-27 10:48:39 +03:00
|
|
|
GkRust_Init();
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// We are not shutting down
|
|
|
|
gXPCOMShuttingDown = false;
|
2002-06-11 23:26:04 +04:00
|
|
|
|
2014-04-26 18:56:54 +04:00
|
|
|
#ifdef XP_UNIX
|
2014-08-13 22:45:37 +04:00
|
|
|
// Discover the current value of the umask, and save it where
|
|
|
|
// nsSystemInfo::Init can retrieve it when necessary. There is no way
|
|
|
|
// to read the umask without changing it, and the setting is process-
|
|
|
|
// global, so this must be done while we are still single-threaded; the
|
|
|
|
// nsSystemInfo object is typically created much later, when some piece
|
|
|
|
// of chrome JS wants it. The system call is specified as unable to fail.
|
|
|
|
nsSystemInfo::gUserUmask = ::umask(0777);
|
|
|
|
::umask(nsSystemInfo::gUserUmask);
|
2014-04-26 18:56:54 +04:00
|
|
|
#endif
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Set up chromium libs
|
|
|
|
NS_ASSERTION(!sExitManager && !sMessageLoop, "Bad logic!");
|
2009-07-30 01:11:42 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (!AtExitManager::AlreadyRegistered()) {
|
|
|
|
sExitManager = new AtExitManager();
|
|
|
|
}
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2015-12-27 03:34:11 +03:00
|
|
|
MessageLoop* messageLoop = MessageLoop::current();
|
|
|
|
if (!messageLoop) {
|
2016-03-28 20:28:14 +03:00
|
|
|
sMessageLoop = new MessageLoopForUI(MessageLoop::TYPE_MOZILLA_PARENT);
|
2014-08-13 22:45:37 +04:00
|
|
|
sMessageLoop->set_thread_name("Gecko");
|
2017-03-29 18:56:14 +03:00
|
|
|
// Set experimental values for main thread hangs:
|
|
|
|
// 128ms for transient hangs and 8192ms for permanent hangs
|
|
|
|
sMessageLoop->set_hang_timeouts(128, 8192);
|
2015-12-27 03:34:11 +03:00
|
|
|
} else if (messageLoop->type() == MessageLoop::TYPE_MOZILLA_CHILD) {
|
|
|
|
messageLoop->set_thread_name("Gecko_Child");
|
2017-03-29 18:56:14 +03:00
|
|
|
messageLoop->set_hang_timeouts(128, 8192);
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess() &&
|
2014-08-13 22:45:37 +04:00
|
|
|
!BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)) {
|
2019-11-20 22:58:05 +03:00
|
|
|
mozilla::UniquePtr<BrowserProcessSubThread> ioThread =
|
|
|
|
mozilla::MakeUnique<BrowserProcessSubThread>(
|
|
|
|
BrowserProcessSubThread::IO);
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
base::Thread::Options options;
|
|
|
|
options.message_loop_type = MessageLoop::TYPE_IO;
|
|
|
|
if (NS_WARN_IF(!ioThread->StartWithOptions(options))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-08-28 23:46:21 +04:00
|
|
|
}
|
2009-07-30 01:11:42 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
sIOThread = ioThread.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Establish the main thread here.
|
2016-06-10 09:04:49 +03:00
|
|
|
rv = nsThreadManager::get().Init();
|
2014-08-13 22:45:37 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2019-11-09 00:07:29 +03:00
|
|
|
AUTO_PROFILER_INIT2;
|
1999-10-30 05:52:55 +04:00
|
|
|
|
2019-11-20 22:58:05 +03:00
|
|
|
// Init the mozilla::SystemGroup for dispatching main thread runnables.
|
|
|
|
mozilla::SystemGroup::InitStatic();
|
2017-02-02 01:08:46 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Set up the timer globals/timer thread
|
|
|
|
rv = nsTimerImpl::Startup();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2004-05-11 13:38:50 +04:00
|
|
|
|
2011-05-01 22:59:24 +04:00
|
|
|
#ifndef ANDROID
|
2014-08-13 22:45:37 +04:00
|
|
|
// If the locale hasn't already been setup by our embedder,
|
|
|
|
// get us out of the "C" locale and into the system
|
|
|
|
if (strcmp(setlocale(LC_ALL, nullptr), "C") == 0) {
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
}
|
2005-01-31 00:33:47 +03:00
|
|
|
#endif
|
2004-06-15 20:38:43 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
nsDirectoryService::RealInit();
|
2002-01-28 02:56:02 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
bool value;
|
2011-07-21 11:57:07 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aBinDirectory) {
|
|
|
|
rv = aBinDirectory->IsDirectory(&value);
|
2002-09-27 17:07:01 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && value) {
|
2019-09-04 15:04:52 +03:00
|
|
|
nsDirectoryService::gService->SetCurrentProcessDirectory(aBinDirectory);
|
2006-05-01 07:47:02 +04:00
|
|
|
}
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2011-07-21 11:57:07 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (aAppFileLocationProvider) {
|
|
|
|
rv = nsDirectoryService::gService->RegisterProvider(
|
|
|
|
aAppFileLocationProvider);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2006-05-01 07:47:02 +04:00
|
|
|
}
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2002-01-28 02:56:02 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
nsCOMPtr<nsIFile> xpcomLib;
|
2014-10-10 23:06:57 +04:00
|
|
|
nsDirectoryService::gService->Get(NS_GRE_BIN_DIR, NS_GET_IID(nsIFile),
|
2014-08-13 22:45:37 +04:00
|
|
|
getter_AddRefs(xpcomLib));
|
|
|
|
MOZ_ASSERT(xpcomLib);
|
2011-07-21 11:57:07 +04:00
|
|
|
|
2014-10-10 23:06:57 +04:00
|
|
|
// set gGREBinPath
|
2014-08-13 22:45:37 +04:00
|
|
|
nsAutoString path;
|
|
|
|
xpcomLib->GetPath(path);
|
2014-10-10 23:06:57 +04:00
|
|
|
gGREBinPath = ToNewUnicode(path);
|
2014-09-29 22:51:04 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
xpcomLib->AppendNative(nsDependentCString(XPCOM_DLL));
|
|
|
|
nsDirectoryService::gService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
|
2010-08-11 02:08:06 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if (!mozilla::Omnijar::IsInitialized()) {
|
|
|
|
mozilla::Omnijar::Init();
|
|
|
|
}
|
2010-08-11 02:08:06 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
if ((sCommandLineWasInitialized = !CommandLine::IsInitialized())) {
|
2009-09-04 11:23:06 +04:00
|
|
|
#ifdef OS_WIN
|
2014-08-13 22:45:37 +04:00
|
|
|
CommandLine::Init(0, nullptr);
|
2009-09-04 11:23:06 +04:00
|
|
|
#else
|
2014-08-13 22:45:37 +04:00
|
|
|
nsCOMPtr<nsIFile> binaryFile;
|
|
|
|
nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(binaryFile));
|
|
|
|
if (NS_WARN_IF(!binaryFile)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-09-04 11:23:06 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
rv = binaryFile->AppendNative(NS_LITERAL_CSTRING("nonexistent-executable"));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2013-03-26 01:26:00 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
nsCString binaryPath;
|
|
|
|
rv = binaryFile->GetNativePath(binaryPath);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-02-25 20:04:50 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
static char const* const argv = {strdup(binaryPath.get())};
|
|
|
|
CommandLine::Init(1, &argv);
|
2014-02-26 01:35:13 +04:00
|
|
|
#endif
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2014-02-26 01:35:13 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_ASSERTION(nsComponentManagerImpl::gComponentManager == nullptr,
|
|
|
|
"CompMgr not null at init");
|
2014-04-08 18:36:30 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Create the Component/Service Manager
|
|
|
|
nsComponentManagerImpl::gComponentManager = new nsComponentManagerImpl();
|
|
|
|
NS_ADDREF(nsComponentManagerImpl::gComponentManager);
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Global cycle collector initialization.
|
|
|
|
if (!nsCycleCollector_init()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2002-01-28 02:56:02 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// And start it up for this thread too.
|
|
|
|
nsCycleCollector_startup();
|
2000-06-03 13:46:12 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Register ICU memory functions. This really shouldn't be necessary: the
|
|
|
|
// JS engine should do this on its own inside JS_Init, and memory-reporting
|
|
|
|
// code should call a JSAPI function to observe ICU memory usage. But we
|
|
|
|
// can't define the alloc/free functions in the JS engine, because it can't
|
|
|
|
// depend on the XPCOM-based memory reporting goop. So for now, we have
|
|
|
|
// this oddness.
|
|
|
|
mozilla::SetICUMemoryFunctions();
|
2005-12-13 20:55:43 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Do the same for libogg.
|
|
|
|
ogg_set_mem_functions(
|
|
|
|
OggReporter::CountingMalloc, OggReporter::CountingCalloc,
|
|
|
|
OggReporter::CountingRealloc, OggReporter::CountingFree);
|
2005-06-07 23:35:20 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Initialize the JS engine.
|
2016-04-08 02:08:49 +03:00
|
|
|
const char* jsInitFailureReason = JS_InitWithFailureDiagnostic();
|
|
|
|
if (jsInitFailureReason) {
|
2019-02-03 11:09:37 +03:00
|
|
|
MOZ_CRASH_UNSAFE(jsInitFailureReason);
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
2016-08-23 08:57:36 +03:00
|
|
|
sInitializedJS = true;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
rv = nsComponentManagerImpl::gComponentManager->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(nsComponentManagerImpl::gComponentManager);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult) {
|
|
|
|
NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
// After autoreg, but before we actually instantiate any components,
|
|
|
|
// add any services listed in the "xpcom-directory-providers" category
|
|
|
|
// to the directory service.
|
|
|
|
nsDirectoryService::gService->RegisterCategoryProviders();
|
|
|
|
|
2019-11-20 22:58:05 +03:00
|
|
|
// Init mozilla::SharedThreadPool (which needs the service manager).
|
|
|
|
mozilla::SharedThreadPool::InitStatics();
|
2015-08-04 00:34:47 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::scache::StartupCache::GetSingleton();
|
2018-07-04 22:06:07 +03:00
|
|
|
mozilla::AvailableMemoryTracker::Init();
|
2014-08-13 22:45:37 +04:00
|
|
|
|
|
|
|
// Notify observers of xpcom autoregistration start
|
|
|
|
NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_CATEGORY, nullptr,
|
|
|
|
NS_XPCOM_STARTUP_OBSERVER_ID);
|
2010-10-16 23:58:20 +04:00
|
|
|
#ifdef XP_WIN
|
2014-08-13 22:45:37 +04:00
|
|
|
CreateAnonTempFileRemover();
|
2010-10-16 23:58:20 +04:00
|
|
|
#endif
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// The memory reporter manager is up and running -- register our reporters.
|
|
|
|
RegisterStrongMemoryReporter(new ICUReporter());
|
|
|
|
RegisterStrongMemoryReporter(new OggReporter());
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::Telemetry::Init();
|
2012-01-11 00:29:58 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::BackgroundHangMonitor::Startup();
|
2012-08-31 23:20:20 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
const MessageLoop* const loop = MessageLoop::current();
|
|
|
|
sMainHangMonitor = new mozilla::BackgroundHangMonitor(
|
|
|
|
loop->thread_name().c_str(), loop->transient_hang_timeout(),
|
|
|
|
loop->permanent_hang_timeout());
|
2014-01-14 20:33:31 +04:00
|
|
|
|
2019-11-22 15:40:17 +03:00
|
|
|
if (aInitJSContext) {
|
|
|
|
xpc::InitializeJSContext();
|
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
return NS_OK;
|
1999-05-19 01:43:13 +04:00
|
|
|
}
|
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
NS_InitMinimalXPCOM() {
|
|
|
|
mozPoisonValueInit();
|
|
|
|
NS_SetMainThread();
|
|
|
|
mozilla::TimeStamp::Startup();
|
|
|
|
NS_LogInit();
|
|
|
|
NS_InitAtomTable();
|
2018-04-03 18:32:00 +03:00
|
|
|
|
|
|
|
// We don't have the arguments by hand here. If logging has already been
|
|
|
|
// initialized by a previous call to LogModule::Init with the arguments
|
|
|
|
// passed, passing (0, nullptr) is alright here.
|
|
|
|
mozilla::LogModule::Init(0, nullptr);
|
2016-08-23 08:57:36 +03:00
|
|
|
|
2018-05-04 08:31:32 +03:00
|
|
|
GkRust_Init();
|
|
|
|
|
2016-06-10 09:04:49 +03:00
|
|
|
nsresult rv = nsThreadManager::get().Init();
|
2016-08-23 08:57:36 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-11-20 22:58:05 +03:00
|
|
|
// Init the mozilla::SystemGroup for dispatching main thread runnables.
|
|
|
|
mozilla::SystemGroup::InitStatic();
|
2017-02-02 01:08:46 +03:00
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
// Set up the timer globals/timer thread.
|
|
|
|
rv = nsTimerImpl::Startup();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
// Create the Component/Service Manager
|
|
|
|
nsComponentManagerImpl::gComponentManager = new nsComponentManagerImpl();
|
|
|
|
NS_ADDREF(nsComponentManagerImpl::gComponentManager);
|
|
|
|
|
|
|
|
rv = nsComponentManagerImpl::gComponentManager->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(nsComponentManagerImpl::gComponentManager);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
// Global cycle collector initialization.
|
|
|
|
if (!nsCycleCollector_init()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2019-11-20 22:58:05 +03:00
|
|
|
mozilla::SharedThreadPool::InitStatics();
|
2016-10-31 08:35:56 +03:00
|
|
|
mozilla::Telemetry::Init();
|
2016-10-24 11:07:54 +03:00
|
|
|
mozilla::BackgroundHangMonitor::Startup();
|
2016-09-21 12:24:43 +03:00
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-08-13 02:09:25 +04:00
|
|
|
|
1999-07-31 04:07:31 +04:00
|
|
|
//
|
|
|
|
// NS_ShutdownXPCOM()
|
|
|
|
//
|
|
|
|
// The shutdown sequence for xpcom would be
|
|
|
|
//
|
2005-11-30 21:51:27 +03:00
|
|
|
// - Notify "xpcom-shutdown" for modules to release primary (root) references
|
2006-03-03 16:48:25 +03:00
|
|
|
// - Shutdown XPCOM timers
|
2005-11-30 21:51:27 +03:00
|
|
|
// - Notify "xpcom-shutdown-threads" for thread joins
|
2006-01-17 18:41:40 +03:00
|
|
|
// - Shutdown the event queues
|
1999-07-31 04:07:31 +04:00
|
|
|
// - Release the Global Service Manager
|
|
|
|
// - Release all service instances held by the global service manager
|
|
|
|
// - Release the Global Service Manager itself
|
|
|
|
// - Release the Component Manager
|
|
|
|
// - Release all factories cached by the Component Manager
|
2005-11-30 21:51:27 +03:00
|
|
|
// - Notify module loaders to shut down
|
1999-07-31 04:07:31 +04:00
|
|
|
// - Unload Libraries
|
2000-09-14 03:57:52 +04:00
|
|
|
// - Release Contractid Cache held by Component Manager
|
1999-07-31 04:07:31 +04:00
|
|
|
// - Release dll abstraction held by Component Manager
|
|
|
|
// - Release the Registry held by Component Manager
|
|
|
|
// - Finally, release the component manager itself
|
|
|
|
//
|
2005-11-08 21:17:49 +03:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_ShutdownXPCOM(nsIServiceManager* aServMgr) {
|
|
|
|
return mozilla::ShutdownXPCOM(aServMgr);
|
2009-06-16 23:36:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-02-11 10:35:32 +04:00
|
|
|
void SetICUMemoryFunctions() {
|
2014-08-13 22:45:37 +04:00
|
|
|
static bool sICUReporterInitialized = false;
|
|
|
|
if (!sICUReporterInitialized) {
|
|
|
|
if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc,
|
|
|
|
ICUReporter::Free)) {
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("JS_SetICUMemoryFunctions failed.");
|
2014-02-11 10:35:32 +04:00
|
|
|
}
|
2014-08-13 22:45:37 +04:00
|
|
|
sICUReporterInitialized = true;
|
|
|
|
}
|
2014-02-11 10:35:32 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) {
|
|
|
|
// Make sure the hang monitor is enabled for shutdown.
|
2018-04-30 04:21:20 +03:00
|
|
|
BackgroundHangMonitor().NotifyActivity();
|
2014-08-13 22:45:37 +04:00
|
|
|
|
|
|
|
if (!NS_IsMainThread()) {
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("Shutdown on wrong thread");
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
2011-10-12 21:52:26 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Notify observers of xpcom shutting down
|
|
|
|
{
|
|
|
|
// Block it so that the COMPtr will get deleted before we hit
|
|
|
|
// servicemanager shutdown
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!thread)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-11-20 01:27:37 +04:00
|
|
|
}
|
2005-11-30 21:51:27 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsObserverService> observerService;
|
2014-08-13 22:45:37 +04:00
|
|
|
CallGetService("@mozilla.org/observer-service;1",
|
2014-08-25 23:17:15 +04:00
|
|
|
(nsObserverService**)getter_AddRefs(observerService));
|
2014-08-13 22:45:37 +04:00
|
|
|
|
|
|
|
if (observerService) {
|
2016-01-15 21:12:07 +03:00
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::WillShutdown);
|
2014-08-13 22:45:37 +04:00
|
|
|
observerService->NotifyObservers(
|
|
|
|
nullptr, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID, nullptr);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIServiceManager> mgr;
|
|
|
|
rv = NS_GetServiceManager(getter_AddRefs(mgr));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2016-01-15 21:12:07 +03:00
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::Shutdown);
|
2014-08-13 22:45:37 +04:00
|
|
|
observerService->NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
|
|
|
|
nullptr);
|
|
|
|
}
|
2018-02-13 13:55:16 +03:00
|
|
|
|
|
|
|
#ifndef ANDROID
|
|
|
|
mozilla::XPCOMShutdownNotified();
|
|
|
|
#endif
|
2005-11-23 23:21:46 +03:00
|
|
|
}
|
2005-11-30 21:51:27 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// This must happen after the shutdown of media and widgets, which
|
|
|
|
// are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification.
|
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
gfxPlatform::ShutdownLayersIPC();
|
2018-11-14 21:07:28 +03:00
|
|
|
mozilla::RemoteDecoderManagerChild::Shutdown();
|
2012-01-27 00:54:03 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::scache::StartupCache::DeleteSingleton();
|
|
|
|
if (observerService) {
|
2016-01-15 21:12:07 +03:00
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownThreads);
|
2014-08-13 22:45:37 +04:00
|
|
|
observerService->NotifyObservers(
|
|
|
|
nullptr, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID, nullptr);
|
2016-01-18 14:01:06 +03:00
|
|
|
}
|
2000-01-11 00:26:56 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
gXPCOMThreadsShutDown = true;
|
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
|
|
|
|
// Shutdown the timer thread and all timers that might still be alive before
|
|
|
|
// shutting down the component manager
|
|
|
|
nsTimerImpl::Shutdown();
|
1999-12-08 05:03:25 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
|
|
|
|
// Shutdown all remaining threads. This method does not return until
|
|
|
|
// all threads created using the thread manager (with the exception of
|
|
|
|
// the main thread) have exited.
|
2016-06-10 09:04:49 +03:00
|
|
|
nsThreadManager::get().Shutdown();
|
2014-08-13 22:45:37 +04:00
|
|
|
|
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
|
2018-04-30 04:21:20 +03:00
|
|
|
BackgroundHangMonitor().NotifyActivity();
|
2014-08-13 22:45:37 +04:00
|
|
|
|
|
|
|
// Late-write checks needs to find the profile directory, so it has to
|
|
|
|
// be initialized before mozilla::services::Shutdown or (because of
|
|
|
|
// xpcshell tests replacing the service) modules being unloaded.
|
|
|
|
mozilla::InitLateWriteChecks();
|
|
|
|
|
|
|
|
if (observerService) {
|
2019-02-06 04:27:24 +03:00
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownLoaders);
|
2014-08-13 22:45:37 +04:00
|
|
|
observerService->Shutdown();
|
2005-12-13 20:55:43 +03:00
|
|
|
}
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Free ClearOnShutdown()'ed smart pointers. This needs to happen *after*
|
|
|
|
// we've finished notifying observers of XPCOM shutdown, because shutdown
|
|
|
|
// observers themselves might call ClearOnShutdown().
|
2016-01-15 21:12:07 +03:00
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownFinal);
|
2005-12-13 20:55:43 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// XPCOM is officially in shutdown mode NOW
|
|
|
|
// Set this only after the observers have been notified as this
|
|
|
|
// will cause servicemanager to become inaccessible.
|
|
|
|
mozilla::services::Shutdown();
|
|
|
|
|
|
|
|
// We may have AddRef'd for the caller of NS_InitXPCOM, so release it
|
|
|
|
// here again:
|
|
|
|
NS_IF_RELEASE(aServMgr);
|
|
|
|
|
|
|
|
// Shutdown global servicemanager
|
|
|
|
if (nsComponentManagerImpl::gComponentManager) {
|
|
|
|
nsComponentManagerImpl::gComponentManager->FreeServices();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release the directory service
|
2016-07-21 19:54:16 +03:00
|
|
|
nsDirectoryService::gService = nullptr;
|
2014-08-13 22:45:37 +04:00
|
|
|
|
2015-04-01 08:29:55 +03:00
|
|
|
free(gGREBinPath);
|
2014-10-10 23:06:57 +04:00
|
|
|
gGREBinPath = nullptr;
|
2014-08-13 22:45:37 +04:00
|
|
|
|
2019-02-09 02:09:20 +03:00
|
|
|
// FIXME: This can cause harmless writes from sqlite committing
|
|
|
|
// log files. We have to ignore them before we can move
|
|
|
|
// the mozilla::PoisonWrite call before this point. See bug
|
|
|
|
// 834945 for the details.
|
|
|
|
mozJSComponentLoader::Unload();
|
2014-08-13 22:45:37 +04:00
|
|
|
|
2018-02-09 00:43:23 +03:00
|
|
|
// Clear the profiler's JS context before cycle collection. The profiler will
|
|
|
|
// notify the JS engine that it can let go of any data it's holding on to for
|
|
|
|
// profiling purposes.
|
|
|
|
PROFILER_CLEAR_JS_CONTEXT();
|
|
|
|
|
2016-09-08 23:04:30 +03:00
|
|
|
bool shutdownCollect;
|
|
|
|
#ifdef NS_FREE_PERMANENT_DATA
|
|
|
|
shutdownCollect = true;
|
|
|
|
#else
|
|
|
|
shutdownCollect = !!PR_GetEnv("MOZ_CC_RUN_DURING_SHUTDOWN");
|
|
|
|
#endif
|
|
|
|
nsCycleCollector_shutdown(shutdownCollect);
|
2013-06-25 19:42:39 +04:00
|
|
|
|
2019-02-27 15:57:11 +03:00
|
|
|
// There can be code trying to refer to global objects during the final cc
|
|
|
|
// shutdown. This is the phase for such global objects to correctly release.
|
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownPostLastCycleCollection);
|
|
|
|
|
2019-01-18 18:40:15 +03:00
|
|
|
PROFILER_ADD_MARKER("Shutdown xpcom", OTHER);
|
2014-08-13 22:45:37 +04:00
|
|
|
// If we are doing any shutdown checks, poison writes.
|
|
|
|
if (gShutdownChecks != SCM_NOTHING) {
|
2013-11-05 16:45:20 +04:00
|
|
|
#ifdef XP_MACOSX
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::OnlyReportDirtyWrites();
|
2013-11-05 16:45:20 +04:00
|
|
|
#endif /* XP_MACOSX */
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::BeginLateWriteChecks();
|
|
|
|
}
|
2013-03-07 01:04:58 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Shutdown xpcom. This will release all loaders and cause others holding
|
|
|
|
// a refcount to the component manager to release it.
|
|
|
|
if (nsComponentManagerImpl::gComponentManager) {
|
|
|
|
rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Component Manager was never created ...");
|
|
|
|
}
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2016-08-23 08:57:36 +03:00
|
|
|
if (sInitializedJS) {
|
|
|
|
// Shut down the JS engine.
|
|
|
|
JS_ShutDown();
|
|
|
|
sInitializedJS = false;
|
|
|
|
}
|
1999-10-08 01:50:20 +04:00
|
|
|
|
2017-11-11 02:03:23 +03:00
|
|
|
// After all threads have been joined and the component manager has been shut
|
|
|
|
// down, any remaining objects that could be holding NSS resources (should)
|
|
|
|
// have been released, so we can safely shut down NSS.
|
|
|
|
if (NSS_IsInitialized()) {
|
bug 1485087 - remove the option to use the TLS session cache from nsITLSServerSocket r=jryans,mayhemer
As initially implemented, nsITLSServerSocket by default enabled the use of the
TLS session cache provided by NSS. However, no consumers of nsITLSServerSocket
actually used it. Because it was an option, though, PSM had to jump through some
hoops to a) make it work in the first place and b) not have NSS panic on
shutdown. Furthermore, it meant increased memory usage for every user of Firefox
(and again, nothing actually used the feature, so this was for naught).
In bug 1479918, we discovered that if PSM shut down before Necko, NSS could
attempt to acquire a lock on the session cache that had been deleted, causing a
shutdown hang. We probably should make it less easy to make this mistake in NSS,
but in the meantime bug 1479918 needs uplifting and this workaround is the
safest, most straight-forward way to achieve this.
Differential Revision: https://phabricator.services.mozilla.com/D3919
--HG--
extra : moz-landing-system : lando
2018-08-24 19:00:34 +03:00
|
|
|
SSL_ClearSessionCache();
|
2017-11-11 02:03:23 +03:00
|
|
|
if (NSS_Shutdown() != SECSuccess) {
|
2018-02-09 23:11:15 +03:00
|
|
|
// If you're seeing this crash and/or warning, some NSS resources are
|
2019-01-29 03:06:57 +03:00
|
|
|
// still in use (see bugs 1417680 and 1230312). Set the environment
|
|
|
|
// variable 'MOZ_IGNORE_NSS_SHUTDOWN_LEAKS' to some value to ignore this.
|
2019-11-14 17:51:53 +03:00
|
|
|
// Also, if leak checking is enabled, report this as a fake leak instead
|
|
|
|
// of crashing.
|
2018-02-09 23:11:15 +03:00
|
|
|
#if defined(DEBUG) && !defined(ANDROID)
|
2019-11-14 17:51:53 +03:00
|
|
|
if (!getenv("MOZ_IGNORE_NSS_SHUTDOWN_LEAKS") &&
|
|
|
|
!getenv("XPCOM_MEM_BLOAT_LOG")) {
|
2019-01-29 03:06:57 +03:00
|
|
|
MOZ_CRASH("NSS_Shutdown failed");
|
|
|
|
} else {
|
2019-11-14 17:51:53 +03:00
|
|
|
# ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
// Create a fake leak.
|
|
|
|
NS_LogCtor((void*)0x100, "NSSShutdownFailed", 100);
|
|
|
|
# endif // NS_BUILD_REFCNT_LOGGING
|
2019-01-29 03:06:57 +03:00
|
|
|
NS_WARNING("NSS_Shutdown failed");
|
|
|
|
}
|
2018-02-09 23:11:15 +03:00
|
|
|
#else
|
|
|
|
NS_WARNING("NSS_Shutdown failed");
|
2019-11-14 17:51:53 +03:00
|
|
|
#endif // defined(DEBUG) && !defined(ANDROID)
|
2017-11-11 02:03:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Finally, release the component manager last because it unloads the
|
|
|
|
// libraries:
|
|
|
|
if (nsComponentManagerImpl::gComponentManager) {
|
|
|
|
nsrefcnt cnt;
|
|
|
|
NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
|
|
|
|
NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
|
|
|
|
}
|
|
|
|
nsComponentManagerImpl::gComponentManager = nullptr;
|
|
|
|
nsCategoryManager::Destroy();
|
2003-08-01 18:40:33 +04:00
|
|
|
|
2017-02-02 01:08:46 +03:00
|
|
|
// Shut down SystemGroup for main thread dispatching.
|
|
|
|
SystemGroup::Shutdown();
|
|
|
|
|
2018-04-27 10:48:39 +03:00
|
|
|
GkRust_Shutdown();
|
|
|
|
|
2019-09-10 01:39:46 +03:00
|
|
|
#ifdef NS_FREE_PERMANENT_DATA
|
|
|
|
// By the time we're shutting down, there may still be async parse tasks going
|
|
|
|
// on in the Servo thread-pool. This is fairly uncommon, though not
|
|
|
|
// impossible. CSS parsing heavily uses the atom table, so obviously it's not
|
|
|
|
// fine to get rid of it.
|
|
|
|
//
|
|
|
|
// In leak-checking / ASAN / etc. builds, shut down the servo thread-pool,
|
|
|
|
// which will wait for all the work to be done. For other builds, we don't
|
|
|
|
// really want to wait on shutdown for possibly slow tasks. So just leak the
|
|
|
|
// atom table in those.
|
|
|
|
Servo_ShutdownThreadPool();
|
2016-05-26 04:45:17 +03:00
|
|
|
NS_ShutdownAtomTable();
|
2019-09-10 01:39:46 +03:00
|
|
|
#endif
|
2014-08-08 18:04:45 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_IF_RELEASE(gDebug);
|
2014-08-08 18:04:45 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
delete sIOThread;
|
|
|
|
sIOThread = nullptr;
|
|
|
|
|
|
|
|
delete sMessageLoop;
|
|
|
|
sMessageLoop = nullptr;
|
|
|
|
|
|
|
|
if (sCommandLineWasInitialized) {
|
|
|
|
CommandLine::Terminate();
|
|
|
|
sCommandLineWasInitialized = false;
|
|
|
|
}
|
2014-08-08 18:04:45 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
delete sExitManager;
|
|
|
|
sExitManager = nullptr;
|
2009-07-30 01:11:42 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
Omnijar::CleanUp();
|
2011-10-12 21:52:26 +04:00
|
|
|
|
Bug 1382440 - Watch CPU usage in BHR r=froydnj
We would like to be able to see if a given hang in BHR occurred
under high CPU load, as this is an indication that the hang is
of less use to us, since it's likely that the external CPU use
is more responsible for it.
The way this works is fairly simple. We get the system CPU usage
on a scale from 0 to 1, and we get the current process's CPU
usage, also on a scale from 0 to 1, and we subtract the latter
from the former. We then compare this value to a threshold, which
is 1 - (1 / p), where p is the number of (virtual) cores on the
machine. This threshold might need to be tuned, so that we
require an entire physical core in order to not annotate the hang,
but for now it seemed the most reasonable line in the sand.
I should note that this considers CPU usage in child or parent
processes as external. While we are responsible for that CPU usage,
it still indicates that the stack we receive from BHR is of little
value to us, since the source of the actual hang is external to
that stack.
MozReview-Commit-ID: JkG53zq1MdY
--HG--
extra : rebase_source : 16553a9b5eac0a73cd1619c6ee01fa177ca60e58
2017-07-24 23:46:09 +03:00
|
|
|
BackgroundHangMonitor::Shutdown();
|
2014-01-14 20:33:31 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
delete sMainHangMonitor;
|
|
|
|
sMainHangMonitor = nullptr;
|
2014-08-08 18:04:45 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_LogTerm();
|
2010-03-04 22:50:28 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
return NS_OK;
|
1999-07-28 11:57:39 +04:00
|
|
|
}
|
2009-06-16 23:36:44 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|