Backed out 5 changesets (bug 1497707) for android mass failures. CLOSED TREE

Backed out changeset bb1b80139e37 (bug 1497707)
Backed out changeset 11c813f192e2 (bug 1497707)
Backed out changeset 32595f9e73d3 (bug 1497707)
Backed out changeset f37f2d39ec9c (bug 1497707)
Backed out changeset 80bf9ddf5bed (bug 1497707)

--HG--
extra : rebase_source : 598b7732d9b994dfeb63c417841a4b9516ecdf19
This commit is contained in:
Dorel Luca 2018-10-18 00:35:39 +03:00
parent 337c32ba46
commit 88bfc3786c
17 changed files with 211 additions and 88 deletions

View File

@ -157,6 +157,7 @@ add_task(async function() {
let startupRecorder = Cc["@mozilla.org/test/startuprecorder;1"].getService().wrappedJSObject;
await startupRecorder.done;
let loader = Cc["@mozilla.org/moz/jsloader;1"].getService(Ci.xpcIJSModuleLoader);
let componentStacks = new Map();
let data = Cu.cloneInto(startupRecorder.data.code, {});
// Keep only the file name for components, as the path is an absolute file
@ -165,14 +166,14 @@ add_task(async function() {
data[phase].components =
data[phase].components.map(uri => {
let fileName = uri.replace(/.*\//, "");
componentStacks.set(fileName, Cu.getComponentLoadStack(uri));
componentStacks.set(fileName, loader.getComponentLoadStack(uri));
return fileName;
}).filter(c => c != "startupRecorder.js");
}
function printStack(scriptType, name) {
if (scriptType == "modules")
info(Cu.getModuleImportStack(name));
info(loader.getModuleImportStack(name));
else if (scriptType == "components")
info(componentStacks.get(name));
}

View File

@ -110,16 +110,17 @@ add_task(async function() {
Cm.QueryInterface(Ci.nsIServiceManager);
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
let collectStacks = AppConstants.NIGHTLY_BUILD || AppConstants.DEBUG;
let loader = Cc["@mozilla.org/moz/jsloader;1"].getService(Ci.xpcIJSModuleLoader);
let components = {};
for (let component of Cu.loadedComponents()) {
for (let component of loader.loadedComponents()) {
/* Keep only the file name for components, as the path is an absolute file
URL rather than a resource:// URL like for modules. */
components[component.replace(/.*\//, "")] =
collectStacks ? Cu.getComponentLoadStack(component) : "";
collectStacks ? loader.getComponentLoadStack(component) : "";
}
let modules = {};
for (let module of Cu.loadedModules()) {
modules[module] = collectStacks ? Cu.getModuleImportStack(module) : "";
for (let module of loader.loadedModules()) {
modules[module] = collectStacks ? loader.getModuleImportStack(module) : "";
}
let services = {};
for (let contractID of Object.keys(Cc)) {

View File

@ -43,6 +43,7 @@ let afterPaintListener = () => {
*/
function startupRecorder() {
this.wrappedJSObject = this;
this.loader = Cc["@mozilla.org/moz/jsloader;1"].getService(Ci.xpcIJSModuleLoader);
this.data = {
images: {
"image-drawing": new Set(),
@ -63,8 +64,8 @@ startupRecorder.prototype = {
return;
this.data.code[name] = {
components: Cu.loadedComponents(),
modules: Cu.loadedModules(),
components: this.loader.loadedComponents(),
modules: this.loader.loadedModules(),
services: Object.keys(Cc).filter(c => {
try {
return Cm.isServiceInstantiatedByContractID(c, Ci.nsISupports);

View File

@ -10,6 +10,7 @@ XPIDL_SOURCES += [
'nsIXPCScriptable.idl',
'xpccomponents.idl',
'xpcIJSGetFactory.idl',
'xpcIJSModuleLoader.idl',
'xpcIJSWeakReference.idl',
'xpcjsid.idl',
]

View File

@ -0,0 +1,24 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsISupports.idl"
[scriptable, builtinclass, uuid(4f94b21f-2920-4bd9-8251-5fb60fb054b2)]
interface xpcIJSModuleLoader : nsISupports
{
// These functions are for startup testing purposes. They are not expected
// to be used for production code.
void loadedModules([optional] out unsigned long length,
[retval, array, size_is(length)] out string aModules);
void loadedComponents([optional] out unsigned long length,
[retval, array, size_is(length)] out string aComponents);
// These 2 functions will only return useful values if the
// "browser.startup.record" preference was true at the time the JS file
// was loaded.
ACString getModuleImportStack(in AUTF8String aLocation);
ACString getComponentLoadStack(in AUTF8String aLocation);
};

View File

@ -738,20 +738,6 @@ interface nsIXPCComponents_Utils : nsISupports
/* Create a persistent property object. */
nsIPersistentProperties createPersistentProperties();
// These functions are for startup testing purposes. They are not expected
// to be used for production code.
void loadedModules([optional] out unsigned long length,
[retval, array, size_is(length)] out string aModules);
void loadedComponents([optional] out unsigned long length,
[retval, array, size_is(length)] out string aComponents);
// These 2 functions will only return useful values if the
// "browser.startup.record" preference was true at the time the JS file
// was loaded.
ACString getModuleImportStack(in AUTF8String aLocation);
ACString getComponentLoadStack(in AUTF8String aLocation);
};
/**

View File

@ -315,6 +315,8 @@ mozJSComponentLoader*
mozJSComponentLoader::sSelf;
NS_IMPL_ISUPPORTS(mozJSComponentLoader,
mozilla::ModuleLoader,
xpcIJSModuleLoader,
nsIObserver)
nsresult
@ -1062,9 +1064,8 @@ mozJSComponentLoader::IsModuleLoaded(const nsACString& aLocation,
return NS_OK;
}
void
mozJSComponentLoader::LoadedModules(uint32_t* length,
char*** aModules)
NS_IMETHODIMP mozJSComponentLoader::LoadedModules(uint32_t* length,
char*** aModules)
{
char** modules = new char*[mImports.Count()];
*length = mImports.Count();
@ -1074,11 +1075,12 @@ mozJSComponentLoader::LoadedModules(uint32_t* length,
*modules = NS_xstrdup(iter.Data()->location);
modules++;
}
return NS_OK;
}
void
mozJSComponentLoader::LoadedComponents(uint32_t* length,
char*** aComponents)
NS_IMETHODIMP mozJSComponentLoader::LoadedComponents(uint32_t* length,
char*** aComponents)
{
char** comp = new char*[mModules.Count()];
*length = mModules.Count();
@ -1088,9 +1090,11 @@ mozJSComponentLoader::LoadedComponents(uint32_t* length,
*comp = NS_xstrdup(iter.Data()->location);
comp++;
}
return NS_OK;
}
nsresult
NS_IMETHODIMP
mozJSComponentLoader::GetModuleImportStack(const nsACString& aLocation,
nsACString& retval)
{
@ -1114,7 +1118,7 @@ mozJSComponentLoader::GetModuleImportStack(const nsACString& aLocation,
#endif
}
nsresult
NS_IMETHODIMP
mozJSComponentLoader::GetComponentLoadStack(const nsACString& aLocation,
nsACString& retval)
{

View File

@ -8,13 +8,13 @@
#define mozJSComponentLoader_h
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/FileLocation.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Module.h"
#include "mozilla/ModuleLoader.h"
#include "nsAutoPtr.h"
#include "nsISupports.h"
#include "nsIObserver.h"
#include "nsIURI.h"
#include "xpcIJSModuleLoader.h"
#include "nsClassHashtable.h"
#include "nsDataHashtable.h"
#include "jsapi.h"
@ -41,20 +41,19 @@ namespace mozilla {
#define STARTUP_RECORDER_ENABLED
#endif
class mozJSComponentLoader final : public nsIObserver
class mozJSComponentLoader final : public mozilla::ModuleLoader,
public xpcIJSModuleLoader,
public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_XPCIJSMODULELOADER
NS_DECL_NSIOBSERVER
mozJSComponentLoader();
void LoadedModules(uint32_t* aLength, char*** aModules);
void LoadedComponents(uint32_t* aLength, char*** aComponents);
nsresult GetModuleImportStack(const nsACString& aLocation, nsACString& aRetval);
nsresult GetComponentLoadStack(const nsACString& aLocation, nsACString& aRetval);
const mozilla::Module* LoadModule(mozilla::FileLocation& aFile);
// ModuleLoader
const mozilla::Module* LoadModule(mozilla::FileLocation& aFile) override;
void FindTargetObject(JSContext* aCx,
JS::MutableHandleObject aTargetObject);

View File

@ -3270,36 +3270,6 @@ nsXPCComponents_Utils::CreatePersistentProperties(nsIPersistentProperties** aPer
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::LoadedModules(uint32_t* aLength,
char*** aModules)
{
mozJSComponentLoader::Get()->LoadedModules(aLength, aModules);
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::LoadedComponents(uint32_t* aLength,
char*** aComponents)
{
mozJSComponentLoader::Get()->LoadedComponents(aLength, aComponents);
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetModuleImportStack(const nsACString& aLocation,
nsACString& aRetval)
{
return mozJSComponentLoader::Get()->GetModuleImportStack(aLocation, aRetval);
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetComponentLoadStack(const nsACString& aLocation,
nsACString& aRetval)
{
return mozJSComponentLoader::Get()->GetComponentLoadStack(aLocation, aRetval);
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

View File

@ -39,5 +39,8 @@ NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID);
{ MOZJSCOMPONENTLOADER_CONTRACTID, &kMOZJSCOMPONENTLOADER_CID }, \
{ MOZJSSUBSCRIPTLOADER_CONTRACTID, &kMOZ_JSSUBSCRIPTLOADER_CID },
#define XPCONNECT_CATEGORIES \
{ "module-loader", "js", MOZJSCOMPONENTLOADER_CONTRACTID },
nsresult xpcModuleCtor();
void xpcModuleDtor();

View File

@ -668,6 +668,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
};
static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
XPCONNECT_CATEGORIES
{ "content-policy", NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID, NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID },
{ "content-policy", NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID, NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID },
{ "content-policy", "CSPService", CSPSERVICE_CONTRACTID },

View File

@ -156,7 +156,7 @@ class TestPACMan : public ::testing::Test {
nsresult rv = nsComponentManagerImpl::gComponentManager->UnregisterFactory(kNS_TESTDHCPCLIENTSERVICE_CID, factoryEntry->mFactory);
ASSERT_EQ(NS_OK, rv);
}
nsComponentManagerImpl::gComponentManager->RegisterModule(&kSysDHCPClientModule);
nsComponentManagerImpl::gComponentManager->RegisterModule(&kSysDHCPClientModule, nullptr);
mPACMan = new nsPACMan(nullptr);
mPACMan->SetWPADOverDHCPEnabled(true);

View File

@ -47,8 +47,9 @@ add_task(async function test_loaded_scripts() {
"No extra APIs should be loaded at startup for a simple extension");
let loadedModules = Cu.loadedModules()
.filter(url => url.startsWith("resource://gre/modules/Extension"));
const loader = Cc["@mozilla.org/moz/jsloader;1"].getService(Ci.xpcIJSModuleLoader);
let loadedModules = loader.loadedModules()
.filter(url => url.startsWith("resource://gre/modules/Extension"));
deepEqual(loadedModules.sort(), STARTUP_MODULES.sort(),
"No extra extension modules should be loaded at startup for a simple extension");

View File

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_ModuleLoader_h
#define mozilla_ModuleLoader_h
#include "nsISupports.h"
#include "mozilla/Module.h"
#include "mozilla/FileLocation.h"
#define MOZILLA_MODULELOADER_PSEUDO_IID \
{ 0xD951A8CE, 0x6E9F, 0x464F, \
{ 0x8A, 0xC8, 0x14, 0x61, 0xC0, 0xD3, 0x63, 0xC8 } }
namespace mozilla {
/**
* Module loaders are responsible for loading a component file. The static
* component loader is special and does not use this abstract interface.
*
* @note Implementations of this interface should be threadsafe,
* methods may be called from any thread.
*/
class ModuleLoader : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_MODULELOADER_PSEUDO_IID)
/**
* Return the module for a specified file. The caller should cache
* the module: the implementer should not expect for the same file
* to be loaded multiple times. The Module object should either be
* statically or permanently allocated; it will not be freed.
*/
virtual const Module* LoadModule(mozilla::FileLocation& aFile) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(ModuleLoader, MOZILLA_MODULELOADER_PSEUDO_IID)
} // namespace mozilla
#endif // mozilla_ModuleLoader_h

View File

@ -26,6 +26,7 @@ EXPORTS += [
EXPORTS.mozilla += [
'GenericFactory.h',
'Module.h',
'ModuleLoader.h',
'ModuleUtils.h',
]
@ -46,7 +47,6 @@ LOCAL_INCLUDES += [
'../build',
'../ds',
'/chrome',
'/js/xpconnect/loader',
'/modules/libjar',
]

View File

@ -38,7 +38,6 @@
#include "ManifestParser.h"
#include "nsNetUtil.h"
#include "mozilla/Services.h"
#include "mozJSComponentLoader.h"
#include "mozilla/GenericFactory.h"
#include "nsSupportsPrimitives.h"
@ -71,8 +70,25 @@ static LazyLogModule nsComponentManagerLog("nsComponentManager");
#define SHOW_CI_ON_EXISTING_SERVICE
#endif
// Bloated registry buffer size to improve startup performance -- needs to
// be big enough to fit the entire file into memory or it'll thrash.
// 512K is big enough to allow for some future growth in the registry.
#define BIG_REGISTRY_BUFLEN (512*1024)
// Common Key Names
const char xpcomComponentsKeyName[] = "software/mozilla/XPCOM/components";
const char xpcomKeyName[] = "software/mozilla/XPCOM";
// Common Value Names
const char fileSizeValueName[] = "FileSize";
const char lastModValueName[] = "LastModTimeStamp";
const char nativeComponentType[] = "application/x-mozilla-native";
const char staticComponentType[] = "application/x-mozilla-static";
NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
#define UID_STRING_LENGTH 39
nsresult
nsGetServiceFromCategory::operator()(const nsIID& aIID,
void** aInstancePtr) const
@ -341,17 +357,17 @@ nsComponentManagerImpl::Init()
nsCategoryManager::GetSingleton()->SuppressNotifications(true);
RegisterModule(&kXPCOMModule);
RegisterModule(&kXPCOMModule, nullptr);
for (auto module : AllStaticModules()) {
if (module) { // On local Windows builds, the list may contain null
// pointers from padding.
RegisterModule(module);
RegisterModule(module, nullptr);
}
}
for (uint32_t i = 0; i < sExtraStaticModules->Length(); ++i) {
RegisterModule((*sExtraStaticModules)[i]);
RegisterModule((*sExtraStaticModules)[i], nullptr);
}
bool loadChromeManifests = (XRE_GetProcessType() != GeckoProcessType_GPU);
@ -505,7 +521,8 @@ AsLiteralCString(const char* aStr)
}
void
nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule)
nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule,
FileLocation* aFile)
{
mLock.AssertNotCurrentThreadOwns();
@ -520,8 +537,19 @@ nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule)
// category manager.
MutexLock lock(mLock);
KnownModule* m = new KnownModule(aModule);
mKnownStaticModules.AppendElement(m);
KnownModule* m;
if (aFile) {
nsCString uri;
aFile->GetURIString(uri);
NS_ASSERTION(!mKnownModules.Get(uri),
"Must not register a binary module twice.");
m = new KnownModule(aModule, *aFile);
mKnownModules.Put(uri, m);
} else {
m = new KnownModule(aModule);
mKnownStaticModules.AppendElement(m);
}
if (aModule->mCIDs) {
const mozilla::Module::CIDEntry* entry;
@ -774,6 +802,19 @@ nsComponentManagerImpl::RereadChromeManifests(bool aChromeOnly)
}
}
bool
nsComponentManagerImpl::KnownModule::EnsureLoader()
{
if (!mLoader) {
nsCString extension;
mFile.GetURIString(extension);
CutExtension(extension);
mLoader =
nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
}
return !!mLoader;
}
bool
nsComponentManagerImpl::KnownModule::Load()
{
@ -781,15 +822,11 @@ nsComponentManagerImpl::KnownModule::Load()
return false;
}
if (!mModule) {
nsCString extension;
mFile.GetURIString(extension);
CutExtension(extension);
if (!extension.Equals("js")) {
if (!EnsureLoader()) {
return false;
}
RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::GetOrCreate();
mModule = loader->LoadModule(mFile);
mModule = mLoader->LoadModule(mFile);
if (!mModule) {
mFailed = true;
@ -836,6 +873,7 @@ nsresult nsComponentManagerImpl::Shutdown(void)
// Release all cached factories
mContractIDs.Clear();
mFactories.Clear(); // XXX release the objects, don't just clear
mLoaderMap.Clear();
mKnownModules.Clear();
mKnownStaticModules.Clear();
@ -1512,6 +1550,23 @@ nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
return NS_OK;
}
already_AddRefed<mozilla::ModuleLoader>
nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
{
nsCOMPtr<mozilla::ModuleLoader> loader = mLoaderMap.Get(aExt);
if (!loader) {
loader = do_GetServiceFromCategory(NS_LITERAL_CSTRING("module-loader"),
aExt);
if (!loader) {
return nullptr;
}
mLoaderMap.Put(aExt, loader);
}
return loader.forget();
}
NS_IMETHODIMP
nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
const char* aName,
@ -1720,6 +1775,8 @@ nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
{
size_t n = aMallocSizeOf(this);
n += mLoaderMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mFactories.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mFactories.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
@ -1746,6 +1803,7 @@ nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
// - mLoaderMap's keys and values
// - mMon
// - sModuleLocations' entries
// - mKnownStaticModules' entries?
@ -1890,7 +1948,8 @@ XRE_AddStaticComponent(const mozilla::Module* aComponent)
if (nsComponentManagerImpl::gComponentManager &&
nsComponentManagerImpl::NORMAL ==
nsComponentManagerImpl::gComponentManager->mStatus) {
nsComponentManagerImpl::gComponentManager->RegisterModule(aComponent);
nsComponentManagerImpl::gComponentManager->RegisterModule(aComponent,
nullptr);
}
return NS_OK;

View File

@ -19,6 +19,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Module.h"
#include "mozilla/ModuleLoader.h"
#include "mozilla/Mutex.h"
#include "nsXULAppAPI.h"
#include "nsIFactory.h"
@ -39,6 +40,7 @@
#include "mozilla/Attributes.h"
struct nsFactoryEntry;
class nsIServiceManager;
struct PRThread;
#define NS_COMPONENTMANAGER_CID \
@ -49,6 +51,17 @@ struct PRThread;
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
}
/* keys for registry use */
extern const char xpcomKeyName[];
extern const char xpcomComponentsKeyName[];
extern const char lastModValueName[];
extern const char fileSizeValueName[];
extern const char nativeComponentType[];
extern const char staticComponentType[];
#ifdef DEBUG
#define XPCOM_CHECK_PENDING_CIDS
#endif
////////////////////////////////////////////////////////////////////////////////
extern const mozilla::Module kXPCOMModule;
@ -141,6 +154,9 @@ public:
nsresult FreeServices();
already_AddRefed<mozilla::ModuleLoader> LoaderForExtension(const nsACString& aExt);
nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader> mLoaderMap;
already_AddRefed<nsIFactory> FindFactory(const nsCID& aClass);
already_AddRefed<nsIFactory> FindFactory(const char* aContractID,
uint32_t aContractIDLen);
@ -182,6 +198,14 @@ public:
/**
* Static or binary module.
*/
KnownModule(const mozilla::Module* aModule, mozilla::FileLocation& aFile)
: mModule(aModule)
, mFile(aFile)
, mLoaded(false)
, mFailed(false)
{
}
explicit KnownModule(const mozilla::Module* aModule)
: mModule(aModule)
, mLoaded(false)
@ -192,6 +216,7 @@ public:
explicit KnownModule(mozilla::FileLocation& aFile)
: mModule(nullptr)
, mFile(aFile)
, mLoader(nullptr)
, mLoaded(false)
, mFailed(false)
{
@ -204,6 +229,7 @@ public:
}
}
bool EnsureLoader();
bool Load();
const mozilla::Module* Module() const { return mModule; }
@ -217,6 +243,7 @@ public:
private:
const mozilla::Module* mModule;
mozilla::FileLocation mFile;
nsCOMPtr<mozilla::ModuleLoader> mLoader;
bool mLoaded;
bool mFailed;
};
@ -228,7 +255,8 @@ public:
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownModules;
// Mutex not held
void RegisterModule(const mozilla::Module* aModule);
void RegisterModule(const mozilla::Module* aModule,
mozilla::FileLocation* aFile);
// Mutex held