root-compmgr
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 95 b35cbfa6ad4f8bac97b5a0ae2a3bfc18ed88de35
permissions -rw-r--r--
State as of now

* * *

diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -255,7 +255,7 @@ nsXPTIInterfaceInfoManagerGetSingleton(n
     NS_ASSERTION(aInstancePtr, "null outptr");
     NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
 
-    nsCOMPtr<nsIInterfaceInfoManager> iim
+    nsIInterfaceInfoManager* iim
         (xptiInterfaceInfoManager::GetInterfaceInfoManagerNoAddRef());
     if (!iim)
         return NS_ERROR_FAILURE;
@@ -289,10 +289,10 @@ static PRBool CheckUpdateFile()
 static PRBool CheckUpdateFile()
 {
     nsresult rv;
-    nsCOMPtr<nsIFile> file;
+    nsIFile* file = nsnull;
     rv = nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, 
                                            NS_GET_IID(nsIFile), 
-                                           getter_AddRefs(file));
+                                           (void**)&file);
 
     if (NS_FAILED(rv)) {
         NS_WARNING("Getting NS_XPCOM_CURRENT_PROCESS_DIR failed");
@@ -306,10 +306,10 @@ static PRBool CheckUpdateFile()
     if (!exists)
         return PR_FALSE;
 
-    nsCOMPtr<nsIFile> compregFile;
+    nsIFile* compregFile = nsnull;
     rv = nsDirectoryService::gService->Get(NS_XPCOM_COMPONENT_REGISTRY_FILE,
                                            NS_GET_IID(nsIFile),
-                                           getter_AddRefs(compregFile));
+                                           (void**)&compregFile);
 
     
     if (NS_FAILED(rv)) {
@@ -328,7 +328,7 @@ static PRBool CheckUpdateFile()
 }
 
 
-nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
+nsComponentManagerImpl::Root* nsComponentManagerImpl::gComponentManager = NULL;
 PRBool gXPCOMShuttingDown = PR_FALSE;
 
 // For each class that wishes to support nsIClassInfo, add a line like this
@@ -528,7 +528,7 @@ NS_InitXPCOM3(nsIServiceManager* *result
     if (NS_FAILED(rv))
         return rv;
 
-    nsCOMPtr<nsIFile> xpcomLib;
+    nsIFile* xpcomLib = nsnull;
             
     PRBool value;
     if (binDirectory)
@@ -537,13 +537,13 @@ NS_InitXPCOM3(nsIServiceManager* *result
 
         if (NS_SUCCEEDED(rv) && value) {
             nsDirectoryService::gService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory);
-            binDirectory->Clone(getter_AddRefs(xpcomLib));
+            binDirectory->Clone(&xpcomLib);
         }
     }
     else {
         nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, 
                                           NS_GET_IID(nsIFile), 
-                                          getter_AddRefs(xpcomLib));
+                                          (void**)&xpcomLib);
     }
 
     if (xpcomLib) {
@@ -562,7 +562,6 @@ NS_InitXPCOM3(nsIServiceManager* *result
     nsComponentManagerImpl *compMgr = new nsComponentManagerImpl();
     if (compMgr == NULL)
         return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(compMgr);
     
     rv = compMgr->Init(staticComponents, componentCount);
     if (NS_FAILED(rv))
@@ -571,17 +570,20 @@ NS_InitXPCOM3(nsIServiceManager* *result
         return rv;
     }
 
-    nsComponentManagerImpl::gComponentManager = compMgr;
+    nsComponentManagerImpl::gComponentManager =
+        new nsComponentManagerImpl::Root(compMgr);
+    if (!nsComponentManagerImpl::gComponentManager)
+        return NS_ERROR_OUT_OF_MEMORY;
 
     if (result) {
         nsIServiceManager *serviceManager =
             static_cast<nsIServiceManager*>(compMgr);
 
-        NS_ADDREF(*result = serviceManager);
+        *result = serviceManager;
     }
 
-    nsCOMPtr<nsIMemory> memory;
-    NS_GetMemoryManager(getter_AddRefs(memory));
+    nsIMemory* memory = nsnull;
+    NS_GetMemoryManager(&memory);
     rv = compMgr->RegisterService(kMemoryCID, memory);
     if (NS_FAILED(rv)) return rv;
 
@@ -598,8 +600,8 @@ NS_InitXPCOM3(nsIServiceManager* *result
 
     // Category Manager
     {
-      nsCOMPtr<nsIFactory> categoryManagerFactory;
-      if ( NS_FAILED(rv = NS_CategoryManagerGetFactory(getter_AddRefs(categoryManagerFactory))) )
+      nsIFactory* categoryManagerFactory = nsnull;
+      if ( NS_FAILED(rv = NS_CategoryManagerGetFactory(&categoryManagerFactory)) )
         return rv;
 
       NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
@@ -612,13 +614,13 @@ NS_InitXPCOM3(nsIServiceManager* *result
       if ( NS_FAILED(rv) ) return rv;
     }
 
-    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(
+    nsIComponentRegistrar* registrar = do_QueryInterface(
         static_cast<nsIComponentManager*>(compMgr), &rv);
     if (registrar) {
         for (int i = 0; i < components_length; i++)
             RegisterGenericFactory(registrar, &components[i]);
 
-        nsCOMPtr<nsIFactory> iniParserFactory(new nsINIParserFactory());
+        nsIFactory* iniParserFactory(new nsINIParserFactory());
         if (iniParserFactory)
             registrar->RegisterFactory(kINIParserFactoryCID, 
                                        "nsINIParserFactory",
@@ -636,12 +638,14 @@ NS_InitXPCOM3(nsIServiceManager* *result
     nsIInterfaceInfoManager* iim =
         xptiInterfaceInfoManager::GetInterfaceInfoManagerNoAddRef();
 
-    if (CheckUpdateFile() || NS_FAILED(
-        nsComponentManagerImpl::gComponentManager->ReadPersistentRegistry())) {
+    if (CheckUpdateFile() ||
+        NS_FAILED(nsComponentManagerImpl::gComponentManager->instance->
+                  ReadPersistentRegistry())) {
         // If the component registry is out of date, malformed, or incomplete,
         // autoregister the default component directories.
         (void) iim->AutoRegisterInterfaces();
-        nsComponentManagerImpl::gComponentManager->AutoRegister(nsnull);
+        nsComponentManagerImpl::gComponentManager->instance->
+            AutoRegister(nsnull);
     }
 
     // After autoreg, but before we actually instantiate any components,
@@ -688,24 +692,24 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
     NS_ENSURE_STATE(NS_IsMainThread());
 
     nsresult rv;
-    nsCOMPtr<nsISimpleEnumerator> moduleLoaders;
+    nsISimpleEnumerator* moduleLoaders = nsnull;
 
     // 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();
+        nsIThread* thread = do_GetCurrentThread();
         NS_ENSURE_STATE(thread);
 
-        nsRefPtr<nsObserverService> observerService;
+        nsObserverService* observerService = nsnull;
         CallGetService("@mozilla.org/observer-service;1",
-                       (nsObserverService**) getter_AddRefs(observerService));
+                       (nsObserverService**) &observerService);
 
         if (observerService)
         {
-            nsCOMPtr<nsIServiceManager> mgr;
-            rv = NS_GetServiceManager(getter_AddRefs(mgr));
+            nsIServiceManager* mgr = nsnull;
+            rv = NS_GetServiceManager(&mgr);
             if (NS_SUCCEEDED(rv))
             {
                 (void) observerService->
@@ -741,7 +745,7 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
         if (observerService) {
             observerService->
                 EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
-                                   getter_AddRefs(moduleLoaders));
+                                   &moduleLoaders);
 
             observerService->Shutdown();
         }
@@ -761,7 +765,7 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
 
     // Shutdown global servicemanager
     if (nsComponentManagerImpl::gComponentManager) {
-        nsComponentManagerImpl::gComponentManager->FreeServices();
+        nsComponentManagerImpl::gComponentManager->instance->FreeServices();
     }
 
     nsProxyObjectManager::Shutdown();
@@ -771,16 +775,16 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
 
     if (moduleLoaders) {
         PRBool more;
-        nsCOMPtr<nsISupports> el;
+        nsISupports* el = nsnull;
         while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) &&
                more) {
-            moduleLoaders->GetNext(getter_AddRefs(el));
+            moduleLoaders->GetNext(&el);
 
             // Don't worry about weak-reference observers here: there is
             // no reason for weak-ref observers to register for
             // xpcom-shutdown-loaders
 
-            nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
+            nsIObserver* obs(do_QueryInterface(el));
             if (obs)
                 (void) obs->Observe(nsnull,
                                     NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
@@ -799,7 +803,7 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
     // 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();
+        rv = nsComponentManagerImpl::gComponentManager->instance->Shutdown();
         NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
     } else
         NS_WARNING("Component Manager was never created ...");
@@ -812,6 +816,7 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
 
     // Finally, release the component manager last because it unloads the
     // libraries:
+    delete nsComponentManagerImpl::gComponentManager;
     nsComponentManagerImpl::gComponentManager = nsnull;
 
 #ifdef DEBUG
diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -170,7 +170,8 @@ nsGetServiceFromCategory::get(const nsII
     nsXPIDLCString value;
     nsICategoryManager* catman = nsnull;
     void *result = NULL;
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     if (!compMgr) {
         rv = NS_ERROR_NOT_INITIALIZED;
         goto error;
@@ -964,13 +965,6 @@ nsComponentManagerImpl::ReadPersistentRe
             continue;
         }
 
-        void *mem;
-        PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
-        if (!mem) {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-            goto out;
-        }
-
         nsFactoryEntry *entry =
             new nsFactoryEntry(aClass, loadertype, values[4]);
 
@@ -1213,7 +1207,7 @@ AutoRegEntryWriter(nsIHashable *aKey, PR
     nsILocalFile* lf(do_QueryInterface(aKey));
 
     nsCAutoString location;
-    nsComponentManagerImpl::gComponentManager->
+    nsComponentManagerImpl::gComponentManager->instance->
         RegistryLocationForFile(lf, location);
 
     PR_fprintf(fd, "%s,%lld\n", location.get(), (PRInt64) aTimestamp);
@@ -1920,10 +1914,6 @@ nsComponentManagerImpl::RegisterService(
     nsFactoryEntry *entry = GetFactoryEntry(aClass);
 
     if (!entry) {
-        void *mem;
-        PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
-        if (!mem)
-            return NS_ERROR_OUT_OF_MEMORY;
         entry = new nsFactoryEntry(aClass, (nsIFactory*) nsnull);
 
         nsFactoryTableEntry* factoryTableEntry =
@@ -1981,10 +1971,6 @@ nsComponentManagerImpl::RegisterService(
     nsFactoryEntry *entry = GetFactoryEntry(aContractID, contractIDLen);
 
     if (!entry) {
-        void *mem;
-        PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
-        if (!mem)
-            return NS_ERROR_OUT_OF_MEMORY;
         entry = new nsFactoryEntry(kEmptyCID, (nsIFactory*) nsnull);
 
         nsContractIDTableEntry* contractIDTableEntry =
@@ -2433,11 +2419,6 @@ nsComponentManagerImpl::RegisterFactory(
         return NS_ERROR_FACTORY_EXISTS;
     }
 
-    void *mem;
-    PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
-    if (!mem)
-        return NS_ERROR_OUT_OF_MEMORY;
-
     entry = new nsFactoryEntry(aClass, aFactory, entry);
 
     factoryTableEntry->mFactoryEntry = entry;
@@ -2591,13 +2572,6 @@ nsComponentManagerImpl::RegisterComponen
         entry->ReInit(typeIndex, aRegistryName);
     }
     else {
-
-        // Arena allocate the nsFactoryEntry
-        void *mem;
-        PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
-        if (!mem)
-            return NS_ERROR_OUT_OF_MEMORY;
-
         mRegistryDirty = PR_TRUE;
         entry = new nsFactoryEntry(aClass,
                                    typeIndex,
@@ -3193,7 +3167,7 @@ RegisterStaticModule(const char *key, ns
                      nsTArray<DeferredModule, GCAllocator> &deferred)
 {
     nsresult rv = module->
-        RegisterSelf(nsComponentManagerImpl::gComponentManager,
+        RegisterSelf(nsComponentManagerImpl::gComponentManager->instance,
                      nsnull, key, staticComponentType);
 
     if (NS_ERROR_FACTORY_REGISTER_AGAIN == rv) {
@@ -3492,9 +3466,10 @@ nsFactoryEntry::nsFactoryEntry(const nsC
     mLoaderType(aLoaderType),
     mLocationKey(
       ArenaStrdup(aLocationKey,
-                  &nsComponentManagerImpl::gComponentManager->mArena)),
+                  &nsComponentManagerImpl::gComponentManager->instance->mArena)),
     mParent(aParent)
 {
+    ASSERT_GCObject(this);
 }
 
 void
@@ -3506,7 +3481,7 @@ nsFactoryEntry::ReInit(LoaderType  aLoad
     if (!mLocationKey || strcmp(mLocationKey, aLocationKey)) {
         mLocationKey =
             ArenaStrdup(aLocationKey,
-                        &nsComponentManagerImpl::gComponentManager->mArena);
+                        &nsComponentManagerImpl::gComponentManager->instance->mArena);
     }
 }
 
@@ -3522,20 +3497,20 @@ nsFactoryEntry::GetFactory(nsIFactory **
         nsIModule* module = nsnull;
 
         if (mLoaderType == NS_LOADER_TYPE_STATIC) {
-            rv = nsComponentManagerImpl::gComponentManager->
+            rv = nsComponentManagerImpl::gComponentManager->instance->
                 mStaticModuleLoader.
                 GetModuleFor(mLocationKey,
                              &module);
         }
         else {
             nsILocalFile* moduleFile = nsnull;
-            rv = nsComponentManagerImpl::gComponentManager->
+            rv = nsComponentManagerImpl::gComponentManager->instance->
                 FileForRegistryLocation(nsDependentCString(mLocationKey),
                                         &moduleFile);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsIModuleLoader* loader =
-                nsComponentManagerImpl::gComponentManager->
+                nsComponentManagerImpl::gComponentManager->instance->
                     LoaderForType(mLoaderType);
             if (!loader)
                 return NS_ERROR_FAILURE;
@@ -3553,7 +3528,7 @@ nsFactoryEntry::GetFactory(nsIFactory **
         }
 
         rv = module->
-            GetClassObject(nsComponentManagerImpl::gComponentManager,
+            GetClassObject(nsComponentManagerImpl::gComponentManager->instance,
                            mCid,
                            NS_GET_IID(nsIFactory),
                            getter_AddRefs(mFactory));
@@ -3572,11 +3547,7 @@ nsFactoryEntry::GetFactory(nsIFactory **
 
 nsFactoryEntry::~nsFactoryEntry()
 {
-    // nsFactoryEntry is arena-allocated. So we don't delete it;
-    // call the destructor by hand.
-
-    if (mParent)
-        mParent->~nsFactoryEntry();
+    NS_NOTREACHED("Not finalized!");
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -3586,37 +3557,24 @@ NS_COM nsresult
 NS_COM nsresult
 NS_GetComponentManager(nsIComponentManager* *result)
 {
-    if (nsComponentManagerImpl::gComponentManager == nsnull)
-    {
-        // XPCOM needs initialization.
-        nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
-        if (NS_FAILED(rv))
-            return rv;
+    if (!nsComponentManagerImpl::gComponentManager) {
+        NS_ERROR("XPCOM was not initialized.");
+        return NS_ERROR_NOT_INITIALIZED;
     }
 
-    *result = static_cast<nsIComponentManager*>
-                         (nsComponentManagerImpl::gComponentManager);
-    NS_IF_ADDREF(*result);
+    *result = nsComponentManagerImpl::gComponentManager->instance;
     return NS_OK;
 }
 
 NS_COM nsresult
 NS_GetServiceManager(nsIServiceManager* *result)
 {
-    nsresult rv = NS_OK;
-
-    if (nsComponentManagerImpl::gComponentManager == nsnull)
-    {
-        // XPCOM needs initialization.
-        rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
+    if (!nsComponentManagerImpl::gComponentManager) {
+        NS_ERROR("XPCOM was not initalized.");
+        return NS_ERROR_NOT_INITIALIZED;
     }
 
-    if (NS_FAILED(rv))
-        return rv;
-
-    *result = static_cast<nsIServiceManager*>
-                         (nsComponentManagerImpl::gComponentManager);
-    NS_IF_ADDREF(*result);
+    *result = nsComponentManagerImpl::gComponentManager->instance;
     return NS_OK;
 }
 
@@ -3624,19 +3582,10 @@ NS_COM nsresult
 NS_COM nsresult
 NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
 {
-    nsresult rv = NS_OK;
-
-    if (nsComponentManagerImpl::gComponentManager == nsnull)
-    {
-        // XPCOM needs initialization.
-        rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
+    if (!nsComponentManagerImpl::gComponentManager) {
+        NS_ERROR("XPCOM was not initalized.");
+        return NS_ERROR_NOT_INITIALIZED;
     }
-
-    if (NS_FAILED(rv))
-        return rv;
-
-    *result = static_cast<nsIComponentRegistrar*>
-                         (nsComponentManagerImpl::gComponentManager);
-    NS_IF_ADDREF(*result);
+    *result = nsComponentManagerImpl::gComponentManager->instance;
     return NS_OK;
 }
diff --git a/xpcom/components/nsComponentManager.h b/xpcom/components/nsComponentManager.h
--- a/xpcom/components/nsComponentManager.h
+++ b/xpcom/components/nsComponentManager.h
@@ -168,7 +168,19 @@ public:
     // nsComponentManagerImpl methods:
     nsComponentManagerImpl();
 
-    static nsComponentManagerImpl* gComponentManager;
+    class Root : public MMgc::GCRoot
+    {
+    public:
+        Root(nsComponentManagerImpl *compMgr)
+            : MMgc::GCRoot(NS_GetGC())
+            , instance(compMgr)
+        {
+        }
+
+        nsComponentManagerImpl* instance;
+    };
+
+    static Root *gComponentManager;
     nsresult Init(nsStaticModuleInfo const *aStaticModules,
                   PRUint32 aStaticModuleCount);
     // NOTE: XPCOM initialization must call either ReadPersistentRegistry or
diff --git a/xpcom/components/nsNativeComponentLoader.cpp b/xpcom/components/nsNativeComponentLoader.cpp
--- a/xpcom/components/nsNativeComponentLoader.cpp
+++ b/xpcom/components/nsNativeComponentLoader.cpp
@@ -117,7 +117,7 @@ nsNativeModuleLoader::LoadModule(nsILoca
         LowerCaseEqualsLiteral(MOZ_DLL_SUFFIX))
         return NS_ERROR_INVALID_ARG;
 
-    nsCOMPtr<nsIHashable> hashedFile(do_QueryInterface(aFile));
+    nsIHashable* hashedFile(do_QueryInterface(aFile));
     if (!hashedFile) {
         NS_ERROR("nsIFile is not nsIHashable");
         return NS_NOINTERFACE;
@@ -183,7 +183,7 @@ nsNativeModuleLoader::LoadModule(nsILoca
 
     if (proc) {
         nsIModule* module;
-        rv = proc(nsComponentManagerImpl::gComponentManager,
+        rv = proc(nsComponentManagerImpl::gComponentManager->instance,
                   aFile,
                   &module);
         if (NS_SUCCEEDED(rv)) {
diff --git a/xpcom/components/nsServiceManagerObsolete.cpp b/xpcom/components/nsServiceManagerObsolete.cpp
--- a/xpcom/components/nsServiceManagerObsolete.cpp
+++ b/xpcom/components/nsServiceManagerObsolete.cpp
@@ -55,7 +55,7 @@ nsServiceManager::GetGlobalServiceManage
         
     // this method does not addref for historical reasons.
     // we return the nsIServiceManagerObsolete interface via a cast.
-    *result =  (nsIServiceManager*) static_cast<nsIServiceManagerObsolete*>(nsComponentManagerImpl::gComponentManager);
+    *result =  (nsIServiceManager*) static_cast<nsIServiceManagerObsolete*>(nsComponentManagerImpl::gComponentManager->instance);
     return NS_OK;
 }
 
@@ -76,7 +76,7 @@ nsServiceManager::GetService(const nsCID
     if (nsComponentManagerImpl::gComponentManager == nsnull)
         return NS_ERROR_UNEXPECTED;
     
-    return nsComponentManagerImpl::gComponentManager->GetService(aClass, aIID, (void**)result);
+    return nsComponentManagerImpl::gComponentManager->instance->GetService(aClass, aIID, (void**)result);
 }
 
 nsresult
@@ -97,7 +97,7 @@ nsServiceManager::RegisterService(const 
     if (nsComponentManagerImpl::gComponentManager == nsnull)
         return NS_ERROR_UNEXPECTED;
     
-    return nsComponentManagerImpl::gComponentManager->RegisterService(aClass, aService);
+    return nsComponentManagerImpl::gComponentManager->instance->RegisterService(aClass, aService);
 }
 
 nsresult
@@ -108,7 +108,7 @@ nsServiceManager::UnregisterService(cons
     if (nsComponentManagerImpl::gComponentManager == nsnull)
         return NS_ERROR_UNEXPECTED;
     
-    return nsComponentManagerImpl::gComponentManager->UnregisterService(aClass);
+    return nsComponentManagerImpl::gComponentManager->instance->UnregisterService(aClass);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -124,7 +124,7 @@ nsServiceManager::GetService(const char*
     if (nsComponentManagerImpl::gComponentManager == nsnull)
         return NS_ERROR_UNEXPECTED;
 
-    return nsComponentManagerImpl::gComponentManager->GetServiceByContractID(aContractID, aIID, (void**)result);
+    return nsComponentManagerImpl::gComponentManager->instance->GetServiceByContractID(aContractID, aIID, (void**)result);
 }
 
 nsresult
@@ -145,7 +145,7 @@ nsServiceManager::RegisterService(const 
     if (nsComponentManagerImpl::gComponentManager == nsnull)
         return NS_ERROR_UNEXPECTED;
     
-    return nsComponentManagerImpl::gComponentManager->RegisterService(aContractID, aService);
+    return nsComponentManagerImpl::gComponentManager->instance->RegisterService(aContractID, aService);
 }
 
 nsresult
@@ -162,6 +162,6 @@ nsServiceManager::UnregisterService(cons
     if (nsComponentManagerImpl::gComponentManager == nsnull)
         return NS_ERROR_UNEXPECTED;
 
-    return nsComponentManagerImpl::gComponentManager->UnregisterService(aContractID);
+    return nsComponentManagerImpl::gComponentManager->instance->UnregisterService(aContractID);
 }
 
diff --git a/xpcom/components/nsStaticComponentLoader.cpp b/xpcom/components/nsStaticComponentLoader.cpp
--- a/xpcom/components/nsStaticComponentLoader.cpp
+++ b/xpcom/components/nsStaticComponentLoader.cpp
@@ -137,8 +137,8 @@ nsStaticModuleLoader::EnumerateModules(S
         if (!c->module) {
             nsIModule* module;
             nsresult rv = c->info.
-                getModule(nsComponentManagerImpl::gComponentManager, nsnull,
-                          &module);
+                getModule(nsComponentManagerImpl::gComponentManager->instance,
+                          nsnull, &module);
             WB(NS_GetGC(), mInfoHash.entryStore, &c->module, module);
             
             LOG(("nSCL: EnumerateModules(): %lx\n", rv));
@@ -165,8 +165,8 @@ nsStaticModuleLoader::GetModuleFor(const
     if (!info->module) {
         nsIModule* module;
         rv = info->info.
-            getModule(nsComponentManagerImpl::gComponentManager, nsnull,
-                      &module);
+            getModule(nsComponentManagerImpl::gComponentManager->instance,
+                      nsnull, &module);
  
         WB(NS_GetGC(), mInfoHash.entryStore, &info->module, module);
 
diff --git a/xpcom/glue/nsComponentManagerUtils.cpp b/xpcom/glue/nsComponentManagerUtils.cpp
--- a/xpcom/glue/nsComponentManagerUtils.cpp
+++ b/xpcom/glue/nsComponentManagerUtils.cpp
@@ -53,8 +53,8 @@ nsresult
 nsresult
 CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
 {
-    nsCOMPtr<nsIServiceManager> servMgr;
-    nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
+    nsIServiceManager* servMgr = nsnull;
+    nsresult status = NS_GetServiceManager(&servMgr);
     if (servMgr)
         status = servMgr->GetService(aCID, aIID, aResult);
     return status;
@@ -63,8 +63,8 @@ nsresult
 nsresult
 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
 {
-    nsCOMPtr<nsIServiceManager> servMgr;
-    nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
+    nsIServiceManager* servMgr = nsnull;
+    nsresult status = NS_GetServiceManager(&servMgr);
     if (servMgr)
         status = servMgr->GetServiceByContractID(aContractID, aIID, aResult);
     return status;
@@ -77,7 +77,8 @@ nsresult
 nsresult
 CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
 {
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
 
     return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult);
@@ -86,7 +87,8 @@ nsresult
 nsresult
 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
 {
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
 
     return compMgr->
@@ -102,8 +104,8 @@ CallCreateInstance(const nsCID &aCID, ns
 CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
                    const nsIID &aIID, void **aResult)
 {
-    nsCOMPtr<nsIComponentManager> compMgr;
-    nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
+    nsIComponentManager* compMgr = nsnull;
+    nsresult status = NS_GetComponentManager(&compMgr);
     if (compMgr)
         status = compMgr->CreateInstance(aCID, aDelegate, aIID, aResult);
     return status;
@@ -113,8 +115,8 @@ CallCreateInstance(const char *aContract
 CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
                    const nsIID &aIID, void **aResult)
 {
-    nsCOMPtr<nsIComponentManager> compMgr;
-    nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
+    nsIComponentManager* compMgr = nsnull;
+    nsresult status = NS_GetComponentManager(&compMgr);
     if (compMgr)
         status = compMgr->CreateInstanceByContractID(aContractID, aDelegate,
                                                      aIID, aResult);
@@ -124,8 +126,8 @@ nsresult
 nsresult
 CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
 {
-    nsCOMPtr<nsIComponentManager> compMgr;
-    nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
+    nsIComponentManager* compMgr = nsnull;
+    nsresult status = NS_GetComponentManager(&compMgr);
     if (compMgr)
         status = compMgr->GetClassObject(aCID, aIID, aResult);
     return status;
@@ -134,8 +136,8 @@ nsresult
 nsresult
 CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
 {
-    nsCOMPtr<nsIComponentManager> compMgr;
-    nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
+    nsIComponentManager* compMgr = nsnull;
+    nsresult status = NS_GetComponentManager(&compMgr);
     if (compMgr)
         status = compMgr->GetClassObjectByContractID(aContractID, aIID,
                                                      aResult);
@@ -150,7 +152,8 @@ CallCreateInstance(const nsCID &aCID, ns
 CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
                    const nsIID &aIID, void **aResult)
 {
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
 
     return compMgr->
@@ -161,7 +164,8 @@ CallCreateInstance(const char *aContract
 CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
                    const nsIID &aIID, void **aResult)
 {
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
 
     return compMgr->
@@ -173,7 +177,8 @@ nsresult
 nsresult
 CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
 {
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
 
     return compMgr->
@@ -183,7 +188,8 @@ nsresult
 nsresult
 CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
 {
-    nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
+    nsComponentManagerImpl *compMgr =
+        nsComponentManagerImpl::gComponentManager->instance;
     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
 
     return compMgr->