Bug 1521191, part 1 - Add method to disable dump statistics. r=froydnj
☠☠ backed out by 044a86a4032c ☠ ☠
authorAndrew McCreight <continuation@gmail.com>
Thu, 24 Jan 2019 21:30:44 +0000
changeset 455492 d6ce4b187195a3e5a763c810578e928b628847aa
parent 455491 b2261781d719058d48913a1330071a3fcfb75976
child 455493 38d3da4804d7a15fe363ab159045ab361b21beee
push id35439
push useraciure@mozilla.com
push dateSat, 26 Jan 2019 09:35:29 +0000
treeherdermozilla-central@edfd8a13603c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1521191
milestone66.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 1521191, part 1 - Add method to disable dump statistics. r=froydnj In order to test the test harness's handling of a process failing to produce a leak log, add a special function that disables the bloat log output. Differential Revision: https://phabricator.services.mozilla.com/D17534
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
xpcom/base/nsTraceRefcnt.cpp
xpcom/base/nsTraceRefcnt.h
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -324,16 +324,22 @@ interface nsIXPCComponents_Utils : nsISu
     void unlinkGhostWindows();
 
     /*
      * In an NS_FREE_PERMANENT_DATA build, intentionally leak a C++ object. This
      * is needed to test leak checking.
      */
     void intentionallyLeak();
 
+    /*
+     * In a debug build, make XPCOM not print out a bloat log in this process.
+     * This is needed to test leak checking.
+     */
+    void disableDumpStatistics();
+
     [implicit_jscontext]
     jsval getJSTestingFunctions();
 
     /*
      * To be called from JS only.
      *
      * Call 'function', using the provided stack as the async stack responsible
      * for the call, and propagate its return value or the exception it throws.
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -41,16 +41,17 @@
 #include "nsPIDOMWindow.h"
 #include "nsGlobalWindow.h"
 #include "nsScriptError.h"
 #include "GeckoProfiler.h"
 #include "mozilla/EditorSpellCheck.h"
 #include "nsCommandLine.h"
 #include "nsCommandParams.h"
 #include "nsPersistentProperties.h"
+#include "nsTraceRefcnt.h"
 #include "nsIDocumentEncoder.h"
 
 using namespace mozilla;
 using namespace JS;
 using namespace js;
 using namespace xpc;
 using mozilla::dom::Exception;
 
@@ -1753,16 +1754,26 @@ nsXPCComponents_Utils::IntentionallyLeak
   Unused << new IntentionallyLeakedObject();
   return NS_OK;
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }
 
 NS_IMETHODIMP
+nsXPCComponents_Utils::DisableDumpStatistics() {
+#ifdef DEBUG
+  nsTraceRefcnt::DisableDumpStatistics();
+  return NS_OK;
+#else
+  return NS_ERROR_NOT_IMPLEMENTED;
+#endif
+}
+
+NS_IMETHODIMP
 nsXPCComponents_Utils::GetJSTestingFunctions(JSContext* cx,
                                              MutableHandleValue retval) {
   JSObject* obj = js::GetTestingFunctions(cx);
   if (!obj) {
     return NS_ERROR_XPC_JAVASCRIPT_ERROR;
   }
   retval.setObject(*obj);
   return NS_OK;
--- a/xpcom/base/nsTraceRefcnt.cpp
+++ b/xpcom/base/nsTraceRefcnt.cpp
@@ -112,16 +112,17 @@ static bool gLogLeaksOnly;
 // if gActivityTLS == BAD_TLS_INDEX, then we're
 // unitialized... otherwise this points to a NSPR TLS thread index
 // indicating whether addref activity is legal. If the PTR_TO_INT32 is 0 then
 // activity is ok, otherwise not!
 static unsigned gActivityTLS = BAD_TLS_INDEX;
 
 static bool gInitialized;
 static nsrefcnt gInitCount;
+static bool gDisableDumpStatistics = false;
 
 static FILE* gBloatLog = nullptr;
 static FILE* gRefcntsLog = nullptr;
 static FILE* gAllocLog = nullptr;
 static FILE* gCOMPtrLog = nullptr;
 
 static void WalkTheStackSavingLocations(std::vector<void*>& aLocations);
 
@@ -394,16 +395,20 @@ nsresult nsTraceRefcnt::DumpStatistics()
 
   AutoTraceLogLock lock;
 
   MOZ_ASSERT(!gDumpedStatistics,
              "Calling DumpStatistics more than once may result in "
              "bogus positive or negative leaks being reported");
   gDumpedStatistics = true;
 
+  if (gDisableDumpStatistics) {
+    return NS_OK;
+  }
+
   // Don't try to log while we hold the lock, we'd deadlock.
   AutoRestore<LoggingType> saveLogging(gLogging);
   gLogging = NoLogging;
 
   BloatEntry total("TOTAL", 0);
   for (auto iter = gBloatView->Iter(); !iter.Done(); iter.Next()) {
     BloatEntry* entry = iter.Data();
     if (nsCRT::strcmp(entry->GetClassName(), "TOTAL") != 0) {
@@ -1158,8 +1163,10 @@ void nsTraceRefcnt::Shutdown() {
 
 void nsTraceRefcnt::SetActivityIsLegal(bool aLegal) {
   if (gActivityTLS == BAD_TLS_INDEX) {
     PR_NewThreadPrivateIndex(&gActivityTLS, nullptr);
   }
 
   PR_SetThreadPrivate(gActivityTLS, reinterpret_cast<void*>(!aLegal));
 }
+
+void nsTraceRefcnt::DisableDumpStatistics() { gDisableDumpStatistics = true; }
--- a/xpcom/base/nsTraceRefcnt.h
+++ b/xpcom/base/nsTraceRefcnt.h
@@ -20,11 +20,17 @@ class nsTraceRefcnt {
   static void WalkTheStack(FILE* aStream);
 
   /**
    * Tell nsTraceRefcnt whether refcounting, allocation, and destruction
    * activity is legal.  This is used to trigger assertions for any such
    * activity that occurs because of static constructors or destructors.
    */
   static void SetActivityIsLegal(bool aLegal);
+
+  /**
+   * Disable bloat log output at shutdown. This is used to test that the
+   * test harness handles a missing log properly.
+   */
+  static void DisableDumpStatistics();
 };
 
 #endif  // nsTraceRefcnt_h