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
|
|
|
|
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"
|
2015-08-04 00:34:47 +03:00
|
|
|
#include "mozilla/SharedThreadPool.h"
|
2009-05-18 22:15:05 +04:00
|
|
|
#include "mozilla/XPCOM.h"
|
2009-08-29 03:16:19 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2009-05-18 22:15:05 +04:00
|
|
|
|
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"
|
2016-11-02 23:57:17 +03:00
|
|
|
#include "mozilla/dom/VideoDecoderManagerChild.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-03-03 04:24:36 +03:00
|
|
|
#include "nsObserverList.h"
|
2001-10-23 02:01:27 +04:00
|
|
|
#include "nsObserverService.h"
|
1999-05-19 01:43:13 +04:00
|
|
|
#include "nsProperties.h"
|
2000-01-05 12:29:25 +03:00
|
|
|
#include "nsPersistentProperties.h"
|
1999-12-04 23:31:38 +03:00
|
|
|
#include "nsScriptableInputStream.h"
|
2003-03-14 00:23:18 +03:00
|
|
|
#include "nsBinaryStream.h"
|
2004-03-02 04:11:06 +03:00
|
|
|
#include "nsStorageStream.h"
|
2005-07-19 03:39:56 +04:00
|
|
|
#include "nsPipe.h"
|
2011-06-08 22:08:31 +04:00
|
|
|
#include "nsScriptableBase64Encoder.h"
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2000-06-03 13:46:12 +04:00
|
|
|
#include "nsMemoryImpl.h"
|
2003-07-08 02:11:36 +04:00
|
|
|
#include "nsDebugImpl.h"
|
2014-02-27 01:36:36 +04:00
|
|
|
#include "nsTraceRefcnt.h"
|
2000-07-22 09:48:04 +04:00
|
|
|
#include "nsErrorService.h"
|
2001-12-07 22:54:16 +03:00
|
|
|
|
2002-10-07 23:03:41 +04:00
|
|
|
#include "nsArray.h"
|
2005-10-04 21:19:14 +04:00
|
|
|
#include "nsINIParserImpl.h"
|
1999-08-04 11:08:58 +04:00
|
|
|
#include "nsSupportsPrimitives.h"
|
2000-04-18 06:34:54 +04:00
|
|
|
#include "nsConsoleService.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
|
|
|
|
1999-10-05 04:07:39 +04:00
|
|
|
#include "xptinfo.h"
|
2000-02-15 09:45:30 +03:00
|
|
|
#include "nsIInterfaceInfoManager.h"
|
2005-11-08 21:17:49 +03:00
|
|
|
#include "xptiprivate.h"
|
2013-03-09 06:54:10 +04:00
|
|
|
#include "mozilla/XPTInterfaceInfoManager.h"
|
1999-05-28 05:14:59 +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"
|
2001-01-23 00:52:01 +03:00
|
|
|
#include "nsProcess.h"
|
2004-01-23 13:23:12 +03:00
|
|
|
#include "nsEnvironment.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"
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_UNIX)
|
2002-06-10 22:50:11 +04:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2002-06-10 23:47:22 +04:00
|
|
|
#endif
|
2000-01-25 00:28:28 +03:00
|
|
|
#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
|
|
|
|
2006-01-02 05:30:32 +03:00
|
|
|
#include "nsStringStream.h"
|
2014-08-13 22:45:37 +04:00
|
|
|
extern nsresult nsStringInputStreamConstructor(nsISupports*, REFNSIID, void**);
|
2006-01-02 05:30:32 +03: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
|
|
|
|
2004-11-25 02:21:14 +03:00
|
|
|
#include "nsHashPropertyBag.h"
|
|
|
|
|
2006-07-21 20:28:51 +04:00
|
|
|
#include "nsUnicharInputStream.h"
|
2001-11-01 02:35:07 +03:00
|
|
|
#include "nsVariant.h"
|
|
|
|
|
2005-11-22 00:01:45 +03:00
|
|
|
#include "nsUUIDGenerator.h"
|
|
|
|
|
2009-05-07 23:21:54 +04:00
|
|
|
#include "nsIOUtil.h"
|
|
|
|
|
2003-03-15 04:04:32 +03:00
|
|
|
#include "SpecialSystemDirectory.h"
|
2002-09-27 17:07:01 +04:00
|
|
|
|
2008-10-09 07:51:54 +04:00
|
|
|
#if defined(XP_WIN)
|
2005-05-17 01:23:09 +04:00
|
|
|
#include "nsWindowsRegKey.h"
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 16:57:34 +04:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2006-02-19 00:09:59 +03:00
|
|
|
#include "nsMacUtilsImpl.h"
|
2006-02-17 19:19:53 +03:00
|
|
|
#endif
|
|
|
|
|
2006-07-06 10:32:03 +04:00
|
|
|
#include "nsSystemInfo.h"
|
2008-03-06 04:28:25 +03:00
|
|
|
#include "nsMemoryReporterManager.h"
|
2012-10-30 04:41:14 +04:00
|
|
|
#include "nsMemoryInfoDumper.h"
|
2013-07-26 19:37:02 +04:00
|
|
|
#include "nsSecurityConsoleMessage.h"
|
2012-10-25 19:36:24 +04:00
|
|
|
#include "nsMessageLoop.h"
|
2006-07-06 10:32:03 +04:00
|
|
|
|
2014-03-20 06:52:11 +04:00
|
|
|
#include "nsStatusReporterManager.h"
|
|
|
|
|
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"
|
2011-10-12 21:52:26 +04:00
|
|
|
#include "mozilla/HangMonitor.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
|
|
|
|
2010-06-12 00:13:26 +04:00
|
|
|
#include "nsChromeRegistry.h"
|
|
|
|
#include "nsChromeProtocolHandler.h"
|
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"
|
2013-12-05 07:32:50 +04:00
|
|
|
#include "mozilla/SystemMemoryReporter.h"
|
2014-09-19 22:17:17 +04:00
|
|
|
#include "mozilla/UniquePtr.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"
|
2014-04-22 16:44:04 +04:00
|
|
|
#if defined(MOZ_VPX) && !defined(MOZ_VPX_NO_MEM_REPORTING)
|
2015-01-29 06:01:46 +03:00
|
|
|
#if defined(HAVE_STDINT_H)
|
|
|
|
// mozilla-config.h defines HAVE_STDINT_H, and then it's defined *again* in
|
|
|
|
// vpx_config.h (which we include via vpx_mem.h, below). This redefinition
|
|
|
|
// triggers a build warning on MSVC, so we have to #undef it first.
|
|
|
|
#undef HAVE_STDINT_H
|
|
|
|
#endif
|
2014-02-26 01:35:13 +04:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
#endif
|
2014-02-25 20:04:50 +04:00
|
|
|
|
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"
|
|
|
|
|
2016-04-05 17:09:12 +03:00
|
|
|
#if EXPOSE_INTL_API
|
|
|
|
#include "unicode/putil.h"
|
|
|
|
#endif
|
|
|
|
|
2013-03-09 06:54:10 +04:00
|
|
|
using namespace mozilla;
|
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
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static AtExitManager* sExitManager;
|
|
|
|
static MessageLoop* sMessageLoop;
|
|
|
|
static bool sCommandLineWasInitialized;
|
2009-08-28 23:46:21 +04:00
|
|
|
static BrowserProcessSubThread* sIOThread;
|
2014-01-14 20:33:31 +04:00
|
|
|
static 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
|
|
|
|
|
2003-09-08 04:31:50 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess)
|
2001-01-23 00:52:01 +03:00
|
|
|
|
2016-05-03 23:25:41 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsID)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsString)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCString)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRBool)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint8)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint16)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint32)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint64)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRTime)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsChar)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt16)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloat)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDouble)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointer)
|
1999-08-04 11:08:58 +04:00
|
|
|
|
2005-03-02 19:37:53 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init)
|
2016-07-20 23:16:40 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimer)
|
2003-03-14 00:23:18 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryOutputStream)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryInputStream)
|
2004-03-02 04:11:06 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageStream)
|
2005-07-23 18:05:25 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVersionComparatorImpl)
|
2011-06-08 22:08:31 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableBase64Encoder)
|
2002-01-28 02:56:02 +03:00
|
|
|
|
2015-10-09 20:24:23 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariantCC)
|
2001-11-01 02:35:07 +03:00
|
|
|
|
2014-09-08 20:41:32 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHashPropertyBagCC)
|
2004-11-25 02:21:14 +03:00
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
NS_GENERIC_AGGREGATED_CONSTRUCTOR(nsProperties)
|
2005-09-28 17:13:27 +04:00
|
|
|
|
2006-05-15 02:41:47 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUUIDGenerator, Init)
|
2005-11-22 00:01:45 +03:00
|
|
|
|
2010-04-27 16:57:34 +04:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2006-02-19 00:09:59 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacUtilsImpl)
|
2006-02-17 19:19:53 +03:00
|
|
|
#endif
|
|
|
|
|
2006-07-06 10:32:03 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemInfo, Init)
|
|
|
|
|
2009-10-03 11:21:34 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMemoryReporterManager, Init)
|
2008-03-06 04:28:25 +03:00
|
|
|
|
2012-10-30 04:41:14 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMemoryInfoDumper)
|
|
|
|
|
2014-03-20 06:52:11 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStatusReporterManager, Init)
|
|
|
|
|
2009-05-07 23:21:54 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIOUtil)
|
|
|
|
|
2013-07-26 19:37:02 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityConsoleMessage)
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static nsresult
|
2014-08-13 22:45:37 +04:00
|
|
|
nsThreadManagerGetSingleton(nsISupports* aOuter,
|
2006-05-10 21:30:15 +04:00
|
|
|
const nsIID& aIID,
|
2014-08-13 22:45:37 +04:00
|
|
|
void** aInstancePtr)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsThreadPool)
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static nsresult
|
2014-08-13 22:45:37 +04:00
|
|
|
nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* aOuter,
|
2002-01-28 02:56:02 +03:00
|
|
|
const nsIID& aIID,
|
2014-08-13 22:45:37 +04:00
|
|
|
void** aInstancePtr)
|
2001-11-27 01:31:39 +03:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_ASSERTION(aInstancePtr, "null outptr");
|
|
|
|
if (NS_WARN_IF(aOuter)) {
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
2002-01-28 02:56:02 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager> iim(XPTInterfaceInfoManager::GetSingleton());
|
|
|
|
if (!iim) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-11-27 01:31:39 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
return iim->QueryInterface(aIID, aInstancePtr);
|
2001-11-27 01:31:39 +03:00
|
|
|
}
|
|
|
|
|
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(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kINIParserFactoryCID, NS_INIPARSERFACTORY_CID);
|
2001-03-12 23:43:02 +03:00
|
|
|
|
2010-06-12 00:13:26 +04:00
|
|
|
NS_DEFINE_NAMED_CID(NS_CHROMEREGISTRY_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_CHROMEPROTOCOLHANDLER_CID);
|
|
|
|
|
2013-07-26 19:37:02 +04:00
|
|
|
NS_DEFINE_NAMED_CID(NS_SECURITY_CONSOLE_MESSAGE_CID);
|
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsChromeRegistry,
|
|
|
|
nsChromeRegistry::GetSingleton)
|
2010-06-12 00:13:26 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChromeProtocolHandler)
|
|
|
|
|
2001-03-12 23:43:02 +03:00
|
|
|
#define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
|
2002-07-02 03:36:03 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static already_AddRefed<nsIFactory>
|
2014-08-13 22:45:37 +04:00
|
|
|
CreateINIParserFactory(const mozilla::Module& aModule,
|
|
|
|
const mozilla::Module::CIDEntry& aEntry)
|
2010-06-10 22:11:11 +04:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
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
|
|
|
#define COMPONENT(NAME, Ctor) static NS_DEFINE_CID(kNS_##NAME##_CID, NS_##NAME##_CID);
|
2016-08-23 08:57:36 +03:00
|
|
|
#define COMPONENT_M(NAME, Ctor, Selector) static NS_DEFINE_CID(kNS_##NAME##_CID, NS_##NAME##_CID);
|
2010-06-10 22:11:11 +04:00
|
|
|
#include "XPCOMModule.inc"
|
|
|
|
#undef COMPONENT
|
2016-08-23 08:57:36 +03:00
|
|
|
#undef COMPONENT_M
|
2006-07-06 10:32:03 +04:00
|
|
|
|
2013-10-11 00:41:00 +04:00
|
|
|
#define COMPONENT(NAME, Ctor) { &kNS_##NAME##_CID, false, nullptr, Ctor },
|
2016-08-23 08:57:36 +03:00
|
|
|
#define COMPONENT_M(NAME, Ctor, Selector) { &kNS_##NAME##_CID, false, nullptr, Ctor, Selector },
|
2010-06-10 22:11:11 +04:00
|
|
|
const mozilla::Module::CIDEntry kXPCOMCIDEntries[] = {
|
2016-08-23 08:57:36 +03:00
|
|
|
{ &kComponentManagerCID, true, nullptr, nsComponentManagerImpl::Create, Module::ALLOW_IN_GPU_PROCESS },
|
2014-08-13 22:45:37 +04:00
|
|
|
{ &kINIParserFactoryCID, false, CreateINIParserFactory },
|
2010-06-10 22:11:11 +04:00
|
|
|
#include "XPCOMModule.inc"
|
2014-08-13 22:45:37 +04:00
|
|
|
{ &kNS_CHROMEREGISTRY_CID, false, nullptr, nsChromeRegistryConstructor },
|
|
|
|
{ &kNS_CHROMEPROTOCOLHANDLER_CID, false, nullptr, nsChromeProtocolHandlerConstructor },
|
|
|
|
{ &kNS_SECURITY_CONSOLE_MESSAGE_CID, false, nullptr, nsSecurityConsoleMessageConstructor },
|
|
|
|
{ nullptr }
|
2001-03-12 23:43:02 +03:00
|
|
|
};
|
2010-06-10 22:11:11 +04:00
|
|
|
#undef COMPONENT
|
2016-08-23 08:57:36 +03:00
|
|
|
#undef COMPONENT_M
|
2001-03-12 23:43:02 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
#define COMPONENT(NAME, Ctor) { NS_##NAME##_CONTRACTID, &kNS_##NAME##_CID },
|
2016-08-23 08:57:36 +03:00
|
|
|
#define COMPONENT_M(NAME, Ctor, Selector) { NS_##NAME##_CONTRACTID, &kNS_##NAME##_CID, Selector },
|
2010-06-10 22:11:11 +04:00
|
|
|
const mozilla::Module::ContractIDEntry kXPCOMContracts[] = {
|
|
|
|
#include "XPCOMModule.inc"
|
2014-08-13 22:45:37 +04:00
|
|
|
{ NS_CHROMEREGISTRY_CONTRACTID, &kNS_CHROMEREGISTRY_CID },
|
|
|
|
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "chrome", &kNS_CHROMEPROTOCOLHANDLER_CID },
|
|
|
|
{ NS_INIPARSERFACTORY_CONTRACTID, &kINIParserFactoryCID },
|
|
|
|
{ NS_SECURITY_CONSOLE_MESSAGE_CONTRACTID, &kNS_SECURITY_CONSOLE_MESSAGE_CID },
|
|
|
|
{ nullptr }
|
2010-06-10 22:11:11 +04:00
|
|
|
};
|
2001-03-12 23:43:02 +03:00
|
|
|
#undef COMPONENT
|
2016-08-23 08:57:36 +03:00
|
|
|
#undef COMPONENT_M
|
2001-03-12 23:43:02 +03:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
const mozilla::Module kXPCOMModule = {
|
2016-08-23 08:57:36 +03:00
|
|
|
mozilla::Module::kVersion, kXPCOMCIDEntries, kXPCOMContracts,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
Module::ALLOW_IN_GPU_PROCESS
|
2014-08-13 22:45:37 +04:00
|
|
|
};
|
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)
|
2003-07-08 02:11:36 +04:00
|
|
|
{
|
2015-05-07 08:28:37 +03:00
|
|
|
return nsDebugImpl::Create(nullptr, NS_GET_IID(nsIDebug2), (void**)aResult);
|
2003-07-08 02:11:36 +04:00
|
|
|
}
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_InitXPCOM(nsIServiceManager** aResult,
|
|
|
|
nsIFile* aBinDirectory)
|
2000-08-17 02:40:27 +04:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
return NS_InitXPCOM2(aResult, aBinDirectory, nullptr);
|
2000-08-17 02:40:27 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ICUReporter final
|
2014-08-13 22:45:37 +04:00
|
|
|
: public nsIMemoryReporter
|
|
|
|
, public CountingAllocatorBase<ICUReporter>
|
2013-07-20 07:14:34 +04:00
|
|
|
{
|
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
|
2014-08-13 22:45:37 +04:00
|
|
|
{
|
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
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
/* static */ template<> Atomic<size_t>
|
|
|
|
CountingAllocatorBase<ICUReporter>::sAmount(0);
|
2013-07-20 07:14:34 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class OggReporter final
|
2014-08-13 22:45:37 +04:00
|
|
|
: public nsIMemoryReporter
|
|
|
|
, public 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
|
2014-08-13 22:45:37 +04:00
|
|
|
{
|
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
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
/* static */ template<> Atomic<size_t>
|
|
|
|
CountingAllocatorBase<OggReporter>::sAmount(0);
|
2014-02-25 20:04:50 +04:00
|
|
|
|
2014-02-26 01:35:13 +04:00
|
|
|
#ifdef MOZ_VPX
|
2015-03-21 19:28:04 +03:00
|
|
|
class VPXReporter final
|
2014-08-13 22:45:37 +04:00
|
|
|
: public nsIMemoryReporter
|
|
|
|
, public CountingAllocatorBase<VPXReporter>
|
2014-02-26 01:35:13 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2014-02-26 01:35:13 +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
|
2014-08-13 22:45:37 +04:00
|
|
|
{
|
2016-08-24 08:23:45 +03:00
|
|
|
MOZ_COLLECT_REPORT(
|
2014-08-13 22:45:37 +04:00
|
|
|
"explicit/media/libvpx", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
|
|
|
|
"Memory allocated through libvpx for WebM media files.");
|
2016-08-24 08:23:45 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2014-08-13 22:45:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~VPXReporter() {}
|
2014-02-26 01:35:13 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(VPXReporter, nsIMemoryReporter)
|
2014-02-26 01:35:13 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
/* static */ template<> Atomic<size_t>
|
|
|
|
CountingAllocatorBase<VPXReporter>::sAmount(0);
|
2014-02-26 01:35:13 +04:00
|
|
|
#endif /* MOZ_VPX */
|
|
|
|
|
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)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_InitXPCOM2(nsIServiceManager** aResult,
|
|
|
|
nsIFile* aBinDirectory,
|
|
|
|
nsIDirectoryServiceProvider* aAppFileLocationProvider)
|
1999-05-19 01:43:13 +04:00
|
|
|
{
|
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();
|
|
|
|
|
2015-10-19 22:22:11 +03:00
|
|
|
mozilla::LogModule::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-08-13 22:45:37 +04:00
|
|
|
// Initialize the available memory tracker before other threads have had a
|
|
|
|
// chance to start up, because the initialization is not thread-safe.
|
|
|
|
mozilla::AvailableMemoryTracker::Init();
|
2012-04-09 21:53:08 +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)) {
|
2014-09-19 22:17:17 +04:00
|
|
|
UniquePtr<BrowserProcessSubThread> ioThread = 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;
|
|
|
|
}
|
1999-10-30 05:52:55 +04:00
|
|
|
|
2017-02-02 01:08:46 +03:00
|
|
|
// Init the SystemGroup for dispatching main thread runnables.
|
|
|
|
SystemGroup::InitStatic();
|
|
|
|
|
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-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_UNIX)
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StartupNativeCharsetUtils();
|
2002-06-10 23:44:07 +04:00
|
|
|
#endif
|
2010-08-11 02:08:06 +04:00
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_StartupLocalFile();
|
2000-12-09 07:11:05 +03: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) {
|
|
|
|
nsDirectoryService::gService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR,
|
|
|
|
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,
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
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
|
|
|
#if defined(MOZ_VPX) && !defined(MOZ_VPX_NO_MEM_REPORTING)
|
|
|
|
// And for VPX.
|
|
|
|
vpx_mem_set_functions(VPXReporter::CountingMalloc,
|
|
|
|
VPXReporter::CountingCalloc,
|
|
|
|
VPXReporter::CountingRealloc,
|
|
|
|
VPXReporter::CountingFree,
|
|
|
|
memcpy,
|
|
|
|
memset,
|
|
|
|
memmove);
|
|
|
|
#endif
|
2013-04-23 00:49:52 +04:00
|
|
|
|
2016-04-05 17:09:12 +03:00
|
|
|
#if EXPOSE_INTL_API && defined(MOZ_ICU_DATA_ARCHIVE)
|
|
|
|
nsCOMPtr<nsIFile> greDir;
|
|
|
|
nsDirectoryService::gService->Get(NS_GRE_DIR,
|
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(greDir));
|
|
|
|
MOZ_ASSERT(greDir);
|
|
|
|
nsAutoCString nativeGREPath;
|
|
|
|
greDir->GetNativePath(nativeGREPath);
|
|
|
|
u_setDataDirectory(nativeGREPath.get());
|
|
|
|
#endif
|
|
|
|
|
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) {
|
|
|
|
NS_RUNTIMEABORT(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The iimanager constructor searches and registers XPT files.
|
|
|
|
// (We trigger the singleton's lazy construction here to make that happen.)
|
|
|
|
(void)XPTInterfaceInfoManager::GetSingleton();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2015-08-04 00:34:47 +03:00
|
|
|
// Init SharedThreadPool (which needs the service manager).
|
|
|
|
SharedThreadPool::InitStatics();
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Force layout to spin up so that nsContentUtils is available for cx stack
|
2017-01-26 23:43:38 +03:00
|
|
|
// munging. Note that layout registers a number of static atoms, and also
|
|
|
|
// seals the static atom table, so NS_RegisterStaticAtom may not be called
|
|
|
|
// beyond this point.
|
2014-08-13 22:45:37 +04:00
|
|
|
nsCOMPtr<nsISupports> componentLoader =
|
|
|
|
do_GetService("@mozilla.org/moz/jsloader;1");
|
|
|
|
|
2017-05-10 05:52:17 +03:00
|
|
|
mozilla::ScriptPreloader::GetSingleton();
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::scache::StartupCache::GetSingleton();
|
|
|
|
mozilla::AvailableMemoryTracker::Activate();
|
|
|
|
|
|
|
|
// 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
|
|
|
// We only want the SystemMemoryReporter running in one process, because it
|
|
|
|
// profiles the entire system. The main process is the obvious place for
|
|
|
|
// it.
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2014-08-13 22:45:37 +04:00
|
|
|
mozilla::SystemMemoryReporter::Init();
|
|
|
|
}
|
2013-12-05 07:32:50 +04:00
|
|
|
|
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());
|
2014-02-26 01:35:13 +04:00
|
|
|
#ifdef MOZ_VPX
|
2014-08-13 22:45:37 +04:00
|
|
|
RegisterStrongMemoryReporter(new VPXReporter());
|
2014-02-26 01:35:13 +04:00
|
|
|
#endif
|
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::HangMonitor::Startup();
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
mozilla::LogModule::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;
|
|
|
|
}
|
|
|
|
|
2017-02-02 01:08:46 +03:00
|
|
|
// Init the SystemGroup for dispatching main thread runnables.
|
|
|
|
SystemGroup::InitStatic();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-07 11:13:33 +03:00
|
|
|
SharedThreadPool::InitStatics();
|
2016-10-31 08:35:56 +03:00
|
|
|
mozilla::Telemetry::Init();
|
2016-10-24 11:07:54 +03:00
|
|
|
mozilla::HangMonitor::Startup();
|
|
|
|
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)
|
2009-06-16 23:36:44 +04:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-06-16 23:36:44 +04:00
|
|
|
nsresult
|
2014-08-13 22:45:37 +04:00
|
|
|
ShutdownXPCOM(nsIServiceManager* aServMgr)
|
1999-07-28 11:57:39 +04:00
|
|
|
{
|
2014-08-13 22:45:37 +04:00
|
|
|
// Make sure the hang monitor is enabled for shutdown.
|
|
|
|
HangMonitor::NotifyActivity();
|
|
|
|
|
|
|
|
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;
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> moduleLoaders;
|
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);
|
|
|
|
}
|
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();
|
2016-11-02 23:57:17 +03:00
|
|
|
mozilla::dom::VideoDecoderManagerChild::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-18 14:01:06 +03:00
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
HangMonitor::NotifyActivity();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// We save the "xpcom-shutdown-loaders" observers to notify after
|
|
|
|
// the observerservice is gone.
|
|
|
|
if (observerService) {
|
2016-01-15 21:12:07 +03:00
|
|
|
mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownLoaders);
|
2014-08-13 22:45:37 +04:00
|
|
|
observerService->EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
|
|
|
|
getter_AddRefs(moduleLoaders));
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (moduleLoaders) {
|
|
|
|
bool more;
|
|
|
|
nsCOMPtr<nsISupports> el;
|
|
|
|
while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) {
|
|
|
|
moduleLoaders->GetNext(getter_AddRefs(el));
|
|
|
|
|
|
|
|
// Don't worry about weak-reference observers here: there is
|
|
|
|
// no reason for weak-ref observers to register for
|
|
|
|
// xpcom-shutdown-loaders
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
|
|
|
|
if (obs) {
|
|
|
|
obs->Observe(nullptr, NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, nullptr);
|
|
|
|
}
|
2005-11-30 21:51:27 +03:00
|
|
|
}
|
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
moduleLoaders = nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-06-22 06:40:21 +03:00
|
|
|
profiler_add_marker("Shutdown xpcom");
|
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 nsLocalFile string conversion
|
|
|
|
NS_ShutdownLocalFile();
|
2002-06-10 23:44:07 +04:00
|
|
|
#ifdef XP_UNIX
|
2014-08-13 22:45:37 +04:00
|
|
|
NS_ShutdownNativeCharsetUtils();
|
2002-06-10 23:44:07 +04:00
|
|
|
#endif
|
2000-12-09 07:11:05 +03: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
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// In optimized builds we don't do shutdown collections by default, so
|
|
|
|
// uncollected (garbage) objects may keep the nsXPConnect singleton alive,
|
2016-09-14 16:48:17 +03:00
|
|
|
// and its XPCJSContext along with it. However, we still destroy various
|
2014-08-13 22:45:37 +04:00
|
|
|
// bits of state in JS_ShutDown(), so we need to make sure the profiler
|
|
|
|
// can't access them when it shuts down. This call nulls out the
|
2016-09-14 16:48:17 +03:00
|
|
|
// JS pseudo-stack's internal reference to the main thread JSContext,
|
|
|
|
// duplicating the call in XPCJSContext::~XPCJSContext() in case that
|
2014-08-13 22:45:37 +04:00
|
|
|
// never fired.
|
2017-03-09 09:06:35 +03:00
|
|
|
profiler_clear_js_context();
|
2014-02-20 17:43:55 +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
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
// Release our own singletons
|
|
|
|
// Do this _after_ shutting down the component manager, because the
|
|
|
|
// JS component loader will use XPConnect to call nsIModule::canUnload,
|
|
|
|
// and that will spin up the InterfaceInfoManager again -- bad mojo
|
|
|
|
XPTInterfaceInfoManager::FreeInterfaceInfoManager();
|
1999-10-05 04:07:39 +04: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();
|
|
|
|
|
2016-05-26 04:45:17 +03:00
|
|
|
NS_ShutdownAtomTable();
|
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
|
|
|
|
2014-08-13 22:45:37 +04:00
|
|
|
HangMonitor::Shutdown();
|
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
|