Bug 435122 - "Use TraceMalloc to get stack traces of potential deadlocks". r=bsmedberg+dbaron.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 26 Jun 2008 10:12:42 -0700
changeset 15553 dfb267af6f44d1d8b684a7a6e8958bf86289d674
parent 15552 8a770f50ccd3c41ff6cb2892011edb95ec2921dc
child 15554 939c783149f367ad5c5ffc3d7e7000ec0ece5773
push id310
push userbturner@mozilla.com
push dateThu, 26 Jun 2008 17:12:58 +0000
treeherdermozilla-central@dfb267af6f44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs435122
milestone1.9.1a1pre
Bug 435122 - "Use TraceMalloc to get stack traces of potential deadlocks". r=bsmedberg+dbaron.
browser/app/Makefile.in
layout/build/Makefile.in
toolkit/library/Makefile.in
toolkit/library/libxul-config.mk
toolkit/toolkit-tiers.mk
tools/trace-malloc/Makefile.in
tools/trace-malloc/lib/Makefile.in
xpcom/build.mk
xpcom/build/Makefile.in
xpcom/glue/Makefile.in
xpcom/glue/nsAutoLock.cpp
xulrunner/app/Makefile.in
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -155,26 +155,17 @@ NSDISTMODE = copy
 include $(topsrcdir)/config/config.mk
 
 ifdef _MSC_VER
 # Always enter a Windows program through wmain, whether or not we're
 # a console application.
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
 endif
 
-ifndef BUILD_STATIC_LIBS
-
-ifdef NS_TRACE_MALLOC
-# when libxul is enabled, trace-malloc is part of it
-ifndef MOZ_ENABLE_LIBXUL
-EXTRA_DSO_LIBS += tracemalloc
-endif
-endif
-
-else
+ifdef BUILD_STATIC_LIBS
 include $(topsrcdir)/config/static-config.mk
 
 EXTRA_DEPS	+= \
 	$(STATIC_EXTRA_DEPS) \
 	$(NULL)
 DEFINES		+= $(STATIC_DEFINES)
 CPPSRCS		+= $(STATIC_CPPSRCS)
 EXTRA_DSO_LIBS	+= $(STATIC_EXTRA_DSO_LIBS)
--- a/layout/build/Makefile.in
+++ b/layout/build/Makefile.in
@@ -211,20 +211,16 @@ endif
 EXTRA_DSO_LDOPTS = \
 		$(LIBS_DIR) \
 		$(EXTRA_DSO_LIBS) \
 		$(MOZ_UNICHARUTIL_LIBS) \
 		$(MOZ_COMPONENT_LIBS) \
 		$(MOZ_JS_LIBS) \
 		$(NULL)
 
-ifdef NS_TRACE_MALLOC
-EXTRA_DSO_LIBS	+= tracemalloc
-endif
-
 ifdef MOZ_ENABLE_GTK2
 EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) \
 		    -lXrender \
 		    $(NULL)
 endif
 
 ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 EXTRA_DSO_LDOPTS += \
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -163,23 +163,16 @@ REQUIRES += \
 CPPSRCS += \
 	$(RDF_UTIL_SRC_LCPPSRCS) \
 	$(NULL)
 
 GARBAGE += \
 	$(RDF_UTIL_SRC_LCPPSRCS) \
 	$(NULL)
 endif
-else
-ifdef NS_TRACE_MALLOC
-# In libxul builds, tracemalloc is part of libxul instead.
-ifndef MOZ_ENABLE_LIBXUL
-EXTRA_DSO_LIBS += tracemalloc
-endif
-endif
 endif
 
 ifneq (,$(filter OS2 WINCE WINNT,$(OS_ARCH)))
 SDK_LIBRARY = $(IMPORT_LIBRARY)
 else
 SDK_LIBRARY = $(SHARED_LIBRARY)
 endif
 
--- a/toolkit/library/libxul-config.mk
+++ b/toolkit/library/libxul-config.mk
@@ -342,12 +342,8 @@ endif
 
 ifneq (,$(filter layout-debug,$(MOZ_EXTENSIONS)))
 COMPONENT_LIBS += gkdebug
 endif
 
 ifdef GC_LEAK_DETECTOR
 EXTRA_DSO_LIBS += boehm
 endif
-
-ifdef NS_TRACE_MALLOC
-STATIC_LIBS += tracemalloc
-endif
--- a/toolkit/toolkit-tiers.mk
+++ b/toolkit/toolkit-tiers.mk
@@ -73,20 +73,16 @@ endif
 ifndef MOZ_NATIVE_LCMS
 tier_external_dirs	+= modules/lcms
 endif
 
 #
 # tier "gecko" - core components
 #
 
-ifdef NS_TRACE_MALLOC
-tier_gecko_dirs += tools/trace-malloc/lib
-endif
-
 tier_gecko_dirs += \
 		js/src/xpconnect \
 		intl/chardet \
 		$(NULL)
 
 ifdef MOZ_ENABLE_GTK2
 tier_gecko_dirs     += widget/src/gtkxtbin
 endif
--- a/tools/trace-malloc/Makefile.in
+++ b/tools/trace-malloc/Makefile.in
@@ -79,18 +79,16 @@ LOCAL_INCLUDES	+= -I$(topsrcdir)/config/
 endif
 
 include $(topsrcdir)/config/config.mk
 
 ifdef MOZ_ENABLE_LIBXUL
 ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 EXTRA_DSO_LIBS	= xul
 endif
-else
-EXTRA_DSO_LIBS	= tracemalloc
 endif
 
 LIBS		+= \
 		$(LIBS_DIR) \
 		tmreader.$(OBJ_SUFFIX) \
 		adreader.$(OBJ_SUFFIX) \
 		$(EXTRA_DSO_LIBS) \
 		$(XPCOM_GLUE_LDOPTS) \
--- a/tools/trace-malloc/lib/Makefile.in
+++ b/tools/trace-malloc/lib/Makefile.in
@@ -41,16 +41,19 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= tracemalloc
 LIBRARY_NAME	= tracemalloc
 EXPORT_LIBRARY	= 1
 DEFFILE		= $(win_srcdir)/tm.def
+
+FORCE_STATIC_LIB = 1
+
 LIBXUL_LIBRARY	= 1
 
 REQUIRES	= xpcom
 
 CSRCS		= \
 		nsTraceMalloc.c \
 		$(NULL)
 
--- a/xpcom/build.mk
+++ b/xpcom/build.mk
@@ -32,9 +32,13 @@
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 TIERS += xpcom
 
-tier_xpcom_dirs = xpcom
+ifdef NS_TRACE_MALLOC
+tier_xpcom_dirs = tools/trace-malloc/lib
+endif
+
+tier_xpcom_dirs += xpcom
--- a/xpcom/build/Makefile.in
+++ b/xpcom/build/Makefile.in
@@ -73,16 +73,20 @@ MOZILLA_INTERNAL_API = 1
 REQUIRES	= string \
 		  $(NULL)
 
 # pull in MoreFiles for MacOSX
 ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 REQUIRES += macmorefiles
 endif
 
+ifdef NS_TRACE_MALLOC
+REQUIRES += tracemalloc
+endif
+
 CSRCS		= \
 		$(XPCOM_GLUE_SRC_LCSRCS) \
 		$(NULL)
 
 CPPSRCS		= \
 		$(XPCOM_GLUE_SRC_LCPPSRCS) \
 		$(XPCOM_GLUENS_SRC_LCPPSRCS) \
 		nsXPComInit.cpp \
@@ -114,16 +118,22 @@ SHARED_LIBRARY_LIBS = \
 		../base/$(LIB_PREFIX)xpcombase_s.$(LIB_SUFFIX) \
 		../reflect/xptcall/src/$(LIB_PREFIX)xptcall.$(LIB_SUFFIX) \
 		../reflect/xptcall/src/$(LIB_PREFIX)xptcmd.$(LIB_SUFFIX) \
 		../reflect/xptinfo/src/$(LIB_PREFIX)xptinfo.$(LIB_SUFFIX) \
 		$(DIST)/lib/$(LIB_PREFIX)xpt.$(LIB_SUFFIX) \
 		../string/src/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
 		$(NULL)
 
+ifdef NS_TRACE_MALLOC
+SHARED_LIBRARY_LIBS += \
+		$(DEPTH)/tools/trace-malloc/lib/$(LIB_PREFIX)tracemalloc.$(LIB_SUFFIX) \
+		$(NULL)
+endif
+
 LOCAL_INCLUDES	= \
 		-I$(srcdir) \
 		-I.. \
 		-I$(srcdir)/../glue \
 		-I$(srcdir)/../base \
 		-I$(srcdir)/../ds \
 		-I$(srcdir)/../io \
 		-I$(srcdir)/../components \
--- a/xpcom/glue/Makefile.in
+++ b/xpcom/glue/Makefile.in
@@ -50,16 +50,20 @@ DIRS            = standalone
 MODULE		= xpcom
 LIBRARY_NAME	= xpcomglue_s
 DIST_INSTALL	= 1
 
 REQUIRES = \
 		string \
 		$(NULL)
 
+ifdef NS_TRACE_MALLOC
+REQUIRES += tracemalloc
+endif
+
 LOCAL_INCLUDES	= \
 		-I$(srcdir)/../build \
 		$(NULL)
 
 CSRCS		= \
 		$(XPCOM_GLUE_SRC_LCSRCS) \
 		$(NULL)  
 
--- a/xpcom/glue/nsAutoLock.cpp
+++ b/xpcom/glue/nsAutoLock.cpp
@@ -41,31 +41,31 @@
 
 #include "plhash.h"
 #include "prprf.h"
 #include "prlock.h"
 #include "prthread.h"
 #include "nsDebug.h"
 #include "nsVoidArray.h"
 
-#ifdef NS_TRACE_MALLOC_XXX
+#ifdef NS_TRACE_MALLOC
 # include <stdio.h>
 # include "nsTraceMalloc.h"
 #endif
 
 static PRUintn      LockStackTPI = (PRUintn)-1;
 static PLHashTable* OrderTable = 0;
 static PRLock*      OrderTableLock = 0;
 
 static const char* const LockTypeNames[] = {"Lock", "Monitor", "CMonitor"};
 
 struct nsNamedVector : public nsVoidArray {
     const char* mName;
 
-#ifdef NS_TRACE_MALLOC_XXX
+#ifdef NS_TRACE_MALLOC
     // Callsites for the inner locks/monitors stored in our base nsVoidArray.
     // This array parallels our base nsVoidArray.
     nsVoidArray mInnerSites;
 #endif
 
     nsNamedVector(const char* name = 0, PRUint32 initialSize = 0)
         : nsVoidArray(initialSize),
           mName(name)
@@ -252,17 +252,17 @@ static PRBool WellOrdered(const void* ad
                         break;
                     }
                 }
 
                 if (rv) {
                     // Assert (addr1 < addr2) into the order table.
                     // XXX fix plvector/nsVector to use const void*
                     vec1->AppendElement((void*) addr2);
-#ifdef NS_TRACE_MALLOC_XXX
+#ifdef NS_TRACE_MALLOC
                     vec1->mInnerSites.AppendElement((void*) callsite2);
 #endif
                 }
             }
         }
     }
 
     PR_Unlock(OrderTableLock);
@@ -280,18 +280,18 @@ nsAutoLockBase::nsAutoLockBase(void* add
         if (stackTop->mAddr == addr) {
             // Ignore reentry: it's legal for monitors, and NSPR will assert
             // if you reenter a PRLock.
         } else if (!addr) {
             // Ignore null addresses: the caller promises not to use the
             // lock at all, and NSPR will assert if you enter it.
         } else {
             const void* node =
-#ifdef NS_TRACE_MALLOC_XXX
-                NS_GetStackTrace(1)
+#ifdef NS_TRACE_MALLOC
+                (const void*)NS_TraceMallocGetStackTrace();
 #else
                 nsnull
 #endif
                 ;
             nsNamedVector* vec1;
             nsNamedVector* vec2;
             PRUint32 i2;
 
@@ -300,22 +300,24 @@ nsAutoLockBase::nsAutoLockBase(void* add
                 PR_snprintf(buf, sizeof buf,
                             "Potential deadlock between %s%s@%p and %s%s@%p",
                             vec1->mName ? vec1->mName : "",
                             LockTypeNames[stackTop->mType],
                             stackTop->mAddr,
                             vec2->mName ? vec2->mName : "",
                             LockTypeNames[type],
                             addr);
-#ifdef NS_TRACE_MALLOC_XXX
+#ifdef NS_TRACE_MALLOC
                 fprintf(stderr, "\n*** %s\n\nCurrent stack:\n", buf);
-                NS_DumpStackTrace(node, stderr);
+                NS_TraceMallocPrintStackTrace(stderr,
+                                              NS_TraceMallocGetStackTrace());
 
                 fputs("\nPrevious stack:\n", stderr);
-                NS_DumpStackTrace(vec2->mInnerSites.ElementAt(i2), stderr);
+                NS_TraceMallocPrintStackTrace(stderr,
+                    (nsTMStackTraceIDStruct *)vec2->mInnerSites.ElementAt(i2));
                 putc('\n', stderr);
 #endif
                 NS_ERROR(buf);
             }
         }
     }
 
     mAddr = addr;
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -143,20 +143,16 @@ NSDISTMODE = copy
 include $(topsrcdir)/config/config.mk
 
 ifdef _MSC_VER
 # Always enter a Windows program through wmain, whether or not we're
 # a console application.
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
 endif
 
-ifdef NS_TRACE_MALLOC
-EXTRA_DSO_LIBS += tracemalloc
-endif
-
 ifeq ($(OS_ARCH),WINNT)
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 version winspool)
 RCINCLUDE = splash.rc
 ifndef GNU_CC
 RCFLAGS += -DMOZ_XULRUNNER -I$(srcdir)
 else
 RCFLAGS += -DMOZ_XULRUNNER --include-dir $(srcdir)
 endif