Bug 667183 - Create a static nsGlobalWindow::Init method to do one-shot initializations currently in nsGlobalWindow ctor. r=jst
☠☠ backed out by 902d3de6f41d ☠ ☠
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 31 Aug 2011 01:36:07 +0200
changeset 77554 0432fe833c934a82ac6bead26c81f11d750e8699
parent 77553 b844a60d123f73d0ebbe520d26c4a8c0bb986a71
child 77555 902d3de6f41dfb75d8896ef3e9c86b46ba9ea771
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs667183
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 667183 - Create a static nsGlobalWindow::Init method to do one-shot initializations currently in nsGlobalWindow ctor. r=jst
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
layout/build/nsLayoutStatics.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -925,68 +925,68 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalW
       // if this fails to open, Dump() knows to just go to stdout
       // on null.
       gDumpFile = fopen(fname, "wb+");
     } else {
       gDumpFile = stdout;
     }
   }
 
-  if (!gEntropyCollector) {
-    CallGetService(NS_ENTROPYCOLLECTOR_CONTRACTID, &gEntropyCollector);
-  }
-
   mSerial = ++gSerialCounter;
 
 #ifdef DEBUG
   if (!PR_GetEnv("MOZ_QUIET")) {
     printf("++DOMWINDOW == %d (%p) [serial = %d] [outer = %p]\n", gRefCnt,
            static_cast<void*>(static_cast<nsIScriptGlobalObject*>(this)),
            gSerialCounter, static_cast<void*>(aOuterWindow));
   }
 #endif
 
 #ifdef PR_LOGGING
-  if (!gDOMLeakPRLog)
-    gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
-
   if (gDOMLeakPRLog)
     PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
            ("DOMWINDOW %p created outer=%p", this, aOuterWindow));
 #endif
 
-  // TODO: could be moved to a ::Init() method, see bug 667183.
-  if (!sWindowsById) {
-    sWindowsById = new WindowByIdTable();
-    if (!sWindowsById->Init()) {
-      delete sWindowsById;
-      sWindowsById = nsnull;
-      NS_ERROR("sWindowsById initialization failed!");
-    }
-  }
-
-  if (sWindowsById) {
-    NS_ASSERTION(!sWindowsById->Get(mWindowID),
-                 "This window shouldn't be in the hash table yet!");
-    sWindowsById->Put(mWindowID, this);
-  }
+  NS_ASSERTION(sWindowsById, "Windows hash table must be created!");
+  NS_ASSERTION(!sWindowsById->Get(mWindowID),
+               "This window shouldn't be in the hash table yet!");
+  sWindowsById->Put(mWindowID, this);
+}
+
+/* static */
+void
+nsGlobalWindow::Init()
+{
+  CallGetService(NS_ENTROPYCOLLECTOR_CONTRACTID, &gEntropyCollector);
+  NS_ASSERTION(gEntropyCollector,
+               "gEntropyCollector should have been initialized!");
+
+#ifdef PR_LOGGING
+  gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
+  NS_ASSERTION(gDOMLeakPRLog, "gDOMLeakPRLog should have been initialized!");
+#endif
+
+  sWindowsById = new WindowByIdTable();
+  // There are two reasons to have Init() failing: if we were not able to
+  // alloc the memory or if the size we want to init is too high. None of them
+  // should happen.
+  NS_ASSERTION(sWindowsById->Init(), "Init() should not fail!");
 }
 
 nsGlobalWindow::~nsGlobalWindow()
 {
   // We have to check if sWindowsById isn't null because ::Shutdown might have
   // been called.
   if (sWindowsById) {
     NS_ASSERTION(sWindowsById->Get(mWindowID),
                  "This window should be in the hash table");
     sWindowsById->Remove(mWindowID);
   }
-  if (!--gRefCnt) {
-    NS_IF_RELEASE(gEntropyCollector);
-  }
+
 #ifdef DEBUG
   if (!PR_GetEnv("MOZ_QUIET")) {
     nsCAutoString url;
     if (mLastOpenedURI) {
       mLastOpenedURI->GetSpec(url);
     }
 
     printf("--DOMWINDOW == %d (%p) [serial = %d] [outer = %p] [url = %s]\n",
@@ -1057,16 +1057,18 @@ nsGlobalWindow::ShutDown()
 {
   NS_IF_RELEASE(sGlobalStorageList);
 
   if (gDumpFile && gDumpFile != stdout) {
     fclose(gDumpFile);
   }
   gDumpFile = nsnull;
 
+  NS_IF_RELEASE(gEntropyCollector);
+
   delete sWindowsById;
   sWindowsById = nsnull;
 }
 
 // static
 void
 nsGlobalWindow::CleanupCachedXBLHandlers(nsGlobalWindow* aWindow)
 {
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -481,16 +481,17 @@ public:
   PRBool IsChromeWindow() const
   {
     return mIsChrome;
   }
 
   nsresult Observe(nsISupports* aSubject, const char* aTopic,
                    const PRUnichar* aData);
 
+  static void Init();
   static void ShutDown();
   static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow);
   static PRBool IsCallerChrome();
   static void CloseBlockScriptTerminationFunc(nsISupports *aRef);
 
   static void RunPendingTimeoutsRecursive(nsGlobalWindow *aTopWindow,
                                           nsGlobalWindow *aWindow);
 
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -154,16 +154,18 @@ nsLayoutStatics::Initialize()
 
   nsJSRuntime::Startup();
   rv = nsRegion::InitStatic();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsRegion");
     return rv;
   }
 
+  nsGlobalWindow::Init();
+
   rv = nsContentUtils::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsContentUtils");
     return rv;
   }
 
   rv = nsAttrValue::Init();
   if (NS_FAILED(rv)) {