2014-05-05 21:30:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-10-08 01:50:20 +04:00
|
|
|
|
2014-02-27 01:36:36 +04:00
|
|
|
#include "nsTraceRefcnt.h"
|
2013-09-12 21:18:36 +04:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2014-08-01 20:27:35 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2010-02-04 01:17:09 +03:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2001-08-14 08:18:27 +04:00
|
|
|
#include "nscore.h"
|
1998-09-12 23:25:06 +04:00
|
|
|
#include "nsISupports.h"
|
2009-04-03 20:43:08 +04:00
|
|
|
#include "nsTArray.h"
|
2014-08-01 20:27:35 +04:00
|
|
|
#include "nsTHashtable.h"
|
2010-08-06 02:11:23 +04:00
|
|
|
#include "prenv.h"
|
1999-10-05 03:36:18 +04:00
|
|
|
#include "plstr.h"
|
2007-06-07 02:05:25 +04:00
|
|
|
#include "prlink.h"
|
1999-10-14 08:37:13 +04:00
|
|
|
#include "nsCRT.h"
|
2000-02-24 08:40:40 +03:00
|
|
|
#include <math.h>
|
2014-08-01 20:27:35 +04:00
|
|
|
#include "nsHashKeys.h"
|
2011-12-03 04:26:04 +04:00
|
|
|
#include "nsStackWalkPrivate.h"
|
2007-08-11 01:28:22 +04:00
|
|
|
#include "nsStackWalk.h"
|
2013-09-19 22:27:35 +04:00
|
|
|
#include "nsString.h"
|
2014-07-04 14:34:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2014-08-01 20:27:35 +04:00
|
|
|
#include "CodeAddressService.h"
|
1998-09-12 23:25:06 +04:00
|
|
|
|
2009-11-10 22:16:12 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#define getpid _getpid
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
#include "mozilla/BlockingResourceBase.h"
|
2013-11-05 16:45:20 +04:00
|
|
|
#include "mozilla/PoisonIOInterposer.h"
|
2010-02-04 01:17:09 +03:00
|
|
|
|
2010-11-05 20:26:51 +03:00
|
|
|
#ifdef HAVE_DLOPEN
|
1999-10-09 00:29:47 +04:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2000-02-24 08:40:40 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
void
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_MeanAndStdDev(double aNumberOfValues,
|
|
|
|
double aSumOfValues, double aSumOfSquaredValues,
|
|
|
|
double* aMeanResult, double* aStdDevResult)
|
2000-02-24 08:40:40 +03:00
|
|
|
{
|
|
|
|
double mean = 0.0, var = 0.0, stdDev = 0.0;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aNumberOfValues > 0.0 && aSumOfValues >= 0) {
|
|
|
|
mean = aSumOfValues / aNumberOfValues;
|
|
|
|
double temp =
|
|
|
|
(aNumberOfValues * aSumOfSquaredValues) - (aSumOfValues * aSumOfValues);
|
|
|
|
if (temp < 0.0 || aNumberOfValues <= 1) {
|
2000-02-24 08:40:40 +03:00
|
|
|
var = 0.0;
|
2014-05-13 21:41:38 +04:00
|
|
|
} else {
|
|
|
|
var = temp / (aNumberOfValues * (aNumberOfValues - 1));
|
|
|
|
}
|
2000-02-24 08:40:40 +03:00
|
|
|
// for some reason, Windows says sqrt(0.0) is "-1.#J" (?!) so do this:
|
|
|
|
stdDev = var != 0.0 ? sqrt(var) : 0.0;
|
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
*aMeanResult = mean;
|
|
|
|
*aStdDevResult = stdDev;
|
2000-02-24 08:40:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
#define NS_IMPL_REFCNT_LOGGING
|
|
|
|
|
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
1999-11-19 08:08:58 +03:00
|
|
|
#include "plhash.h"
|
2000-06-15 06:23:55 +04:00
|
|
|
#include "prmem.h"
|
1999-10-09 00:29:47 +04:00
|
|
|
|
1998-09-19 10:56:22 +04:00
|
|
|
#include "prlock.h"
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
// TraceRefcnt has to use bare PRLock instead of mozilla::Mutex
|
|
|
|
// because TraceRefcnt can be used very early in startup.
|
1998-09-19 10:56:22 +04:00
|
|
|
static PRLock* gTraceLock;
|
|
|
|
|
|
|
|
#define LOCK_TRACELOG() PR_Lock(gTraceLock)
|
|
|
|
#define UNLOCK_TRACELOG() PR_Unlock(gTraceLock)
|
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
static PLHashTable* gBloatView;
|
|
|
|
static PLHashTable* gTypesToLog;
|
1999-11-11 06:23:24 +03:00
|
|
|
static PLHashTable* gObjectsToLog;
|
|
|
|
static PLHashTable* gSerialNumbers;
|
2013-01-04 01:53:51 +04:00
|
|
|
static intptr_t gNextSerialNumber;
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gLogging;
|
|
|
|
static bool gLogLeaksOnly;
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
#define BAD_TLS_INDEX ((unsigned)-1)
|
2006-02-10 18:00:36 +03:00
|
|
|
|
|
|
|
// 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!
|
2012-08-22 19:56:38 +04:00
|
|
|
static unsigned gActivityTLS = BAD_TLS_INDEX;
|
2006-02-10 18:00:36 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gInitialized;
|
2006-02-10 18:00:36 +03:00
|
|
|
static nsrefcnt gInitCount;
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static FILE* gBloatLog = nullptr;
|
|
|
|
static FILE* gRefcntsLog = nullptr;
|
|
|
|
static FILE* gAllocLog = nullptr;
|
|
|
|
static FILE* gCOMPtrLog = nullptr;
|
1999-10-21 07:44:37 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
struct serialNumberRecord
|
|
|
|
{
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialNumber;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t refCount;
|
|
|
|
int32_t COMPtrCount;
|
2000-06-15 06:23:55 +04:00
|
|
|
};
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
struct nsTraceRefcntStats
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mAddRefs;
|
|
|
|
uint64_t mReleases;
|
|
|
|
uint64_t mCreates;
|
|
|
|
uint64_t mDestroys;
|
2003-08-05 09:29:10 +04:00
|
|
|
double mRefsOutstandingTotal;
|
|
|
|
double mRefsOutstandingSquared;
|
|
|
|
double mObjsOutstandingTotal;
|
|
|
|
double mObjsOutstandingSquared;
|
|
|
|
};
|
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
static const char kStaticCtorDtorWarning[] =
|
|
|
|
"XPCOM objects created/destroyed from static ctor/dtor";
|
|
|
|
|
|
|
|
static void
|
|
|
|
AssertActivityIsLegal()
|
|
|
|
{
|
2015-02-20 20:38:47 +03:00
|
|
|
if (gActivityTLS == BAD_TLS_INDEX || PR_GetThreadPrivate(gActivityTLS)) {
|
2010-08-06 02:11:23 +04:00
|
|
|
if (PR_GetEnv("MOZ_FATAL_STATIC_XPCOM_CTORS_DTORS")) {
|
|
|
|
NS_RUNTIMEABORT(kStaticCtorDtorWarning);
|
|
|
|
} else {
|
|
|
|
NS_WARNING(kStaticCtorDtorWarning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# define ASSERT_ACTIVITY_IS_LEGAL \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
AssertActivityIsLegal(); \
|
|
|
|
PR_END_MACRO
|
|
|
|
#else
|
|
|
|
# define ASSERT_ACTIVITY_IS_LEGAL PR_BEGIN_MACRO PR_END_MACRO
|
|
|
|
#endif // DEBUG
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2003-03-25 17:53:01 +03:00
|
|
|
// These functions are copied from nsprpub/lib/ds/plhash.c, with changes
|
|
|
|
// to the functions not called Default* to free the serialNumberRecord or
|
|
|
|
// the BloatEntry.
|
2000-06-15 06:23:55 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static void*
|
|
|
|
DefaultAllocTable(void* aPool, size_t aSize)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return PR_MALLOC(aSize);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2014-05-13 21:41:38 +04:00
|
|
|
DefaultFreeTable(void* aPool, void* aItem)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
PR_Free(aItem);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static PLHashEntry*
|
|
|
|
DefaultAllocEntry(void* aPool, const void* aKey)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-05-05 21:30:39 +04:00
|
|
|
return PR_NEW(PLHashEntry);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2014-05-13 21:41:38 +04:00
|
|
|
SerialNumberFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aFlag == HT_FREE_ENTRY) {
|
|
|
|
PR_Free(reinterpret_cast<serialNumberRecord*>(aHashEntry->value));
|
|
|
|
PR_Free(aHashEntry);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2014-05-13 21:41:38 +04:00
|
|
|
TypesToLogFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
|
2003-03-25 17:53:01 +03:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aFlag == HT_FREE_ENTRY) {
|
|
|
|
free(const_cast<char*>(reinterpret_cast<const char*>(aHashEntry->key)));
|
|
|
|
PR_Free(aHashEntry);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-03-25 17:53:01 +03:00
|
|
|
}
|
|
|
|
|
2003-04-04 19:10:37 +04:00
|
|
|
static const PLHashAllocOps serialNumberHashAllocOps = {
|
2014-05-05 21:30:39 +04:00
|
|
|
DefaultAllocTable, DefaultFreeTable,
|
|
|
|
DefaultAllocEntry, SerialNumberFreeEntry
|
2003-03-25 17:53:01 +03:00
|
|
|
};
|
|
|
|
|
2003-04-04 19:10:37 +04:00
|
|
|
static const PLHashAllocOps typesToLogHashAllocOps = {
|
2014-05-05 21:30:39 +04:00
|
|
|
DefaultAllocTable, DefaultFreeTable,
|
|
|
|
DefaultAllocEntry, TypesToLogFreeEntry
|
2000-06-15 06:23:55 +04:00
|
|
|
};
|
|
|
|
|
2000-02-05 05:07:45 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-08 21:25:20 +04:00
|
|
|
#ifdef MOZ_STACKWALKING
|
2014-08-01 20:27:35 +04:00
|
|
|
|
|
|
|
class CodeAddressServiceStringTable MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
2014-08-06 17:31:21 +04:00
|
|
|
CodeAddressServiceStringTable() : mSet(32) {}
|
2014-08-01 20:27:35 +04:00
|
|
|
|
|
|
|
const char* Intern(const char* aString)
|
|
|
|
{
|
|
|
|
nsCharPtrHashKey* e = mSet.PutEntry(aString);
|
|
|
|
return e->GetKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return mSet.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef nsTHashtable<nsCharPtrHashKey> StringSet;
|
|
|
|
StringSet mSet;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CodeAddressServiceStringAlloc MOZ_FINAL
|
|
|
|
{
|
|
|
|
static char* copy(const char* aStr) { return strdup(aStr); }
|
2014-08-10 20:27:23 +04:00
|
|
|
static void free(char* aPtr) { ::free(aPtr); }
|
2014-08-01 20:27:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// WalkTheStack does not hold any locks needed by NS_DescribeCodeAddress, so
|
|
|
|
// this class does not need to do anything.
|
|
|
|
struct CodeAddressServiceLock MOZ_FINAL
|
|
|
|
{
|
|
|
|
static void Unlock() {}
|
|
|
|
static void Lock() {}
|
|
|
|
static bool IsLocked() { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef mozilla::CodeAddressService<CodeAddressServiceStringTable,
|
|
|
|
CodeAddressServiceStringAlloc,
|
|
|
|
CodeAddressServiceLock> WalkTheStackCodeAddressService;
|
|
|
|
|
|
|
|
mozilla::StaticAutoPtr<WalkTheStackCodeAddressService> gCodeAddressService;
|
|
|
|
|
2014-09-08 21:25:20 +04:00
|
|
|
#endif // MOZ_STACKWALKING
|
2014-08-01 20:27:35 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
class BloatEntry
|
|
|
|
{
|
1999-10-08 01:50:20 +04:00
|
|
|
public:
|
2014-05-13 21:41:38 +04:00
|
|
|
BloatEntry(const char* aClassName, uint32_t aClassSize)
|
|
|
|
: mClassSize(aClassSize)
|
|
|
|
{
|
|
|
|
mClassName = PL_strdup(aClassName);
|
1999-10-12 04:29:54 +04:00
|
|
|
Clear(&mNewStats);
|
|
|
|
Clear(&mAllStats);
|
2000-02-22 16:25:20 +03:00
|
|
|
mTotalLeaked = 0;
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
~BloatEntry()
|
|
|
|
{
|
2000-12-02 19:10:50 +03:00
|
|
|
PL_strfree(mClassName);
|
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
uint32_t GetClassSize()
|
|
|
|
{
|
|
|
|
return (uint32_t)mClassSize;
|
|
|
|
}
|
|
|
|
const char* GetClassName()
|
|
|
|
{
|
|
|
|
return mClassName;
|
|
|
|
}
|
1999-12-10 07:27:52 +03:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static void Clear(nsTraceRefcntStats* aStats)
|
|
|
|
{
|
|
|
|
aStats->mAddRefs = 0;
|
|
|
|
aStats->mReleases = 0;
|
|
|
|
aStats->mCreates = 0;
|
|
|
|
aStats->mDestroys = 0;
|
|
|
|
aStats->mRefsOutstandingTotal = 0;
|
|
|
|
aStats->mRefsOutstandingSquared = 0;
|
|
|
|
aStats->mObjsOutstandingTotal = 0;
|
|
|
|
aStats->mObjsOutstandingSquared = 0;
|
1999-10-12 04:29:54 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void Accumulate()
|
|
|
|
{
|
2014-05-05 21:30:39 +04:00
|
|
|
mAllStats.mAddRefs += mNewStats.mAddRefs;
|
|
|
|
mAllStats.mReleases += mNewStats.mReleases;
|
|
|
|
mAllStats.mCreates += mNewStats.mCreates;
|
|
|
|
mAllStats.mDestroys += mNewStats.mDestroys;
|
|
|
|
mAllStats.mRefsOutstandingTotal += mNewStats.mRefsOutstandingTotal;
|
|
|
|
mAllStats.mRefsOutstandingSquared += mNewStats.mRefsOutstandingSquared;
|
|
|
|
mAllStats.mObjsOutstandingTotal += mNewStats.mObjsOutstandingTotal;
|
|
|
|
mAllStats.mObjsOutstandingSquared += mNewStats.mObjsOutstandingSquared;
|
|
|
|
Clear(&mNewStats);
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void AddRef(nsrefcnt aRefcnt)
|
|
|
|
{
|
1999-10-12 04:29:54 +04:00
|
|
|
mNewStats.mAddRefs++;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aRefcnt == 1) {
|
1999-10-12 04:29:54 +04:00
|
|
|
Ctor();
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
|
|
|
AccountRefs();
|
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void Release(nsrefcnt aRefcnt)
|
|
|
|
{
|
1999-10-12 04:29:54 +04:00
|
|
|
mNewStats.mReleases++;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aRefcnt == 0) {
|
1999-10-12 04:29:54 +04:00
|
|
|
Dtor();
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
|
|
|
AccountRefs();
|
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void Ctor()
|
|
|
|
{
|
1999-10-12 04:29:54 +04:00
|
|
|
mNewStats.mCreates++;
|
|
|
|
AccountObjs();
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void Dtor()
|
|
|
|
{
|
1999-10-12 04:29:54 +04:00
|
|
|
mNewStats.mDestroys++;
|
|
|
|
AccountObjs();
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void AccountRefs()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t cnt = (mNewStats.mAddRefs - mNewStats.mReleases);
|
1999-10-12 04:29:54 +04:00
|
|
|
mNewStats.mRefsOutstandingTotal += cnt;
|
2000-02-05 05:07:45 +03:00
|
|
|
mNewStats.mRefsOutstandingSquared += cnt * cnt;
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void AccountObjs()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t cnt = (mNewStats.mCreates - mNewStats.mDestroys);
|
1999-10-12 04:29:54 +04:00
|
|
|
mNewStats.mObjsOutstandingTotal += cnt;
|
2000-02-05 05:07:45 +03:00
|
|
|
mNewStats.mObjsOutstandingSquared += cnt * cnt;
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static int DumpEntry(PLHashEntry* aHashEntry, int aIndex, void* aArg)
|
|
|
|
{
|
|
|
|
BloatEntry* entry = (BloatEntry*)aHashEntry->value;
|
1999-10-09 00:29:47 +04:00
|
|
|
if (entry) {
|
1999-10-12 04:29:54 +04:00
|
|
|
entry->Accumulate();
|
2014-05-13 21:41:38 +04:00
|
|
|
static_cast<nsTArray<BloatEntry*>*>(aArg)->AppendElement(entry);
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
1999-10-12 04:29:54 +04:00
|
|
|
return HT_ENUMERATE_NEXT;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static int TotalEntries(PLHashEntry* aHashEntry, int aIndex, void* aArg)
|
|
|
|
{
|
|
|
|
BloatEntry* entry = (BloatEntry*)aHashEntry->value;
|
1999-10-28 12:35:53 +04:00
|
|
|
if (entry && nsCRT::strcmp(entry->mClassName, "TOTAL") != 0) {
|
2014-05-13 21:41:38 +04:00
|
|
|
entry->Total((BloatEntry*)aArg);
|
1999-10-16 05:57:18 +04:00
|
|
|
}
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void Total(BloatEntry* aTotal)
|
|
|
|
{
|
|
|
|
aTotal->mAllStats.mAddRefs += mNewStats.mAddRefs + mAllStats.mAddRefs;
|
|
|
|
aTotal->mAllStats.mReleases += mNewStats.mReleases + mAllStats.mReleases;
|
|
|
|
aTotal->mAllStats.mCreates += mNewStats.mCreates + mAllStats.mCreates;
|
|
|
|
aTotal->mAllStats.mDestroys += mNewStats.mDestroys + mAllStats.mDestroys;
|
|
|
|
aTotal->mAllStats.mRefsOutstandingTotal +=
|
|
|
|
mNewStats.mRefsOutstandingTotal + mAllStats.mRefsOutstandingTotal;
|
|
|
|
aTotal->mAllStats.mRefsOutstandingSquared +=
|
|
|
|
mNewStats.mRefsOutstandingSquared + mAllStats.mRefsOutstandingSquared;
|
|
|
|
aTotal->mAllStats.mObjsOutstandingTotal +=
|
|
|
|
mNewStats.mObjsOutstandingTotal + mAllStats.mObjsOutstandingTotal;
|
|
|
|
aTotal->mAllStats.mObjsOutstandingSquared +=
|
|
|
|
mNewStats.mObjsOutstandingSquared + mAllStats.mObjsOutstandingSquared;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t count = (mNewStats.mCreates + mAllStats.mCreates);
|
2014-05-13 21:41:38 +04:00
|
|
|
aTotal->mClassSize += mClassSize * count; // adjust for average in DumpTotal
|
|
|
|
aTotal->mTotalLeaked += (uint64_t)(mClassSize *
|
|
|
|
((mNewStats.mCreates + mAllStats.mCreates)
|
|
|
|
- (mNewStats.mDestroys + mAllStats.mDestroys)));
|
1999-10-16 05:57:18 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void DumpTotal(FILE* aOut)
|
|
|
|
{
|
2000-01-27 08:14:51 +03:00
|
|
|
mClassSize /= mAllStats.mCreates;
|
2014-05-13 21:41:38 +04:00
|
|
|
Dump(-1, aOut, nsTraceRefcnt::ALL_STATS);
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static bool HaveLeaks(nsTraceRefcntStats* aStats)
|
|
|
|
{
|
|
|
|
return ((aStats->mAddRefs != aStats->mReleases) ||
|
|
|
|
(aStats->mCreates != aStats->mDestroys));
|
1999-10-12 04:29:54 +04:00
|
|
|
}
|
|
|
|
|
2014-08-25 23:17:15 +04:00
|
|
|
bool PrintDumpHeader(FILE* aOut, const char* aMsg,
|
|
|
|
nsTraceRefcnt::StatisticsType aType)
|
2014-05-13 21:41:38 +04:00
|
|
|
{
|
|
|
|
fprintf(aOut, "\n== BloatView: %s, %s process %d\n", aMsg,
|
2009-11-10 22:16:12 +03:00
|
|
|
XRE_ChildProcessTypeToString(XRE_GetProcessType()), getpid());
|
2008-08-04 01:39:04 +04:00
|
|
|
nsTraceRefcntStats& stats =
|
2014-05-13 21:41:38 +04:00
|
|
|
(aType == nsTraceRefcnt::NEW_STATS) ? mNewStats : mAllStats;
|
|
|
|
if (gLogLeaksOnly && !HaveLeaks(&stats)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2008-08-04 01:39:04 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf(aOut,
|
2014-05-05 21:30:39 +04:00
|
|
|
"\n" \
|
|
|
|
" |<----------------Class--------------->|<-----Bytes------>|<----------------Objects---------------->|<--------------References-------------->|\n" \
|
|
|
|
" Per-Inst Leaked Total Rem Mean StdDev Total Rem Mean StdDev\n");
|
2008-08-04 01:39:04 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
this->DumpTotal(aOut);
|
2008-08-04 01:39:04 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void Dump(int aIndex, FILE* aOut, nsTraceRefcnt::StatisticsType aType)
|
|
|
|
{
|
2014-08-25 23:17:15 +04:00
|
|
|
nsTraceRefcntStats* stats =
|
|
|
|
(aType == nsTraceRefcnt::NEW_STATS) ? &mNewStats : &mAllStats;
|
1999-10-23 07:16:19 +04:00
|
|
|
if (gLogLeaksOnly && !HaveLeaks(stats)) {
|
2008-08-04 01:39:04 +04:00
|
|
|
return;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
1999-12-10 07:27:52 +03:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
double meanRefs;
|
|
|
|
double stddevRefs;
|
2008-08-04 01:39:04 +04:00
|
|
|
NS_MeanAndStdDev(stats->mAddRefs + stats->mReleases,
|
|
|
|
stats->mRefsOutstandingTotal,
|
2000-02-05 05:07:45 +03:00
|
|
|
stats->mRefsOutstandingSquared,
|
|
|
|
&meanRefs, &stddevRefs);
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
double meanObjs;
|
|
|
|
double stddevObjs;
|
2000-02-05 05:07:45 +03:00
|
|
|
NS_MeanAndStdDev(stats->mCreates + stats->mDestroys,
|
2008-08-04 01:39:04 +04:00
|
|
|
stats->mObjsOutstandingTotal,
|
2000-02-05 05:07:45 +03:00
|
|
|
stats->mObjsOutstandingSquared,
|
|
|
|
&meanObjs, &stddevObjs);
|
1999-10-12 04:29:54 +04:00
|
|
|
|
|
|
|
if ((stats->mAddRefs - stats->mReleases) != 0 ||
|
|
|
|
stats->mAddRefs != 0 ||
|
|
|
|
meanRefs != 0 ||
|
|
|
|
stddevRefs != 0 ||
|
|
|
|
(stats->mCreates - stats->mDestroys) != 0 ||
|
|
|
|
stats->mCreates != 0 ||
|
|
|
|
meanObjs != 0 ||
|
|
|
|
stddevObjs != 0) {
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf(aOut, "%4d %-40.40s %8d %8" PRIu64 " %8" PRIu64 " %8" PRIu64 " (%8.2f +/- %8.2f) %8" PRIu64 " %8" PRIu64 " (%8.2f +/- %8.2f)\n",
|
|
|
|
aIndex + 1, mClassName,
|
2012-08-22 19:56:38 +04:00
|
|
|
(int32_t)mClassSize,
|
2000-02-22 16:25:20 +03:00
|
|
|
(nsCRT::strcmp(mClassName, "TOTAL"))
|
2014-05-13 21:41:38 +04:00
|
|
|
? (uint64_t)((stats->mCreates - stats->mDestroys) * mClassSize)
|
|
|
|
: mTotalLeaked,
|
1999-10-23 07:16:19 +04:00
|
|
|
stats->mCreates,
|
|
|
|
(stats->mCreates - stats->mDestroys),
|
|
|
|
meanObjs,
|
2008-08-04 01:39:04 +04:00
|
|
|
stddevObjs,
|
1999-10-23 07:16:19 +04:00
|
|
|
stats->mAddRefs,
|
|
|
|
(stats->mAddRefs - stats->mReleases),
|
|
|
|
meanRefs,
|
|
|
|
stddevRefs);
|
1999-10-12 04:29:54 +04:00
|
|
|
}
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
1999-10-08 01:50:20 +04:00
|
|
|
protected:
|
2000-12-02 19:10:50 +03:00
|
|
|
char* mClassName;
|
1999-10-29 22:48:37 +04:00
|
|
|
double mClassSize; // this is stored as a double because of the way we compute the avg class size for total bloat
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mTotalLeaked; // used only for TOTAL entry
|
1999-10-12 04:29:54 +04:00
|
|
|
nsTraceRefcntStats mNewStats;
|
|
|
|
nsTraceRefcntStats mAllStats;
|
1999-10-08 01:50:20 +04:00
|
|
|
};
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2014-05-13 21:41:38 +04:00
|
|
|
BloatViewFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
|
2003-03-25 17:53:01 +03:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aFlag == HT_FREE_ENTRY) {
|
|
|
|
BloatEntry* entry = reinterpret_cast<BloatEntry*>(aHashEntry->value);
|
2014-05-05 21:30:39 +04:00
|
|
|
delete entry;
|
2014-05-13 21:41:38 +04:00
|
|
|
PR_Free(aHashEntry);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-03-25 17:53:01 +03:00
|
|
|
}
|
|
|
|
|
2003-04-04 19:10:37 +04:00
|
|
|
const static PLHashAllocOps bloatViewHashAllocOps = {
|
2014-05-05 21:30:39 +04:00
|
|
|
DefaultAllocTable, DefaultFreeTable,
|
|
|
|
DefaultAllocEntry, BloatViewFreeEntry
|
2003-03-25 17:53:01 +03:00
|
|
|
};
|
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
static void
|
|
|
|
RecreateBloatView()
|
|
|
|
{
|
2008-08-04 01:39:04 +04:00
|
|
|
gBloatView = PL_NewHashTable(256,
|
1999-10-09 00:29:47 +04:00
|
|
|
PL_HashString,
|
|
|
|
PL_CompareStrings,
|
|
|
|
PL_CompareValues,
|
2013-10-11 00:41:00 +04:00
|
|
|
&bloatViewHashAllocOps, nullptr);
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static BloatEntry*
|
2012-08-22 19:56:38 +04:00
|
|
|
GetBloatEntry(const char* aTypeName, uint32_t aInstanceSize)
|
1999-10-09 00:29:47 +04:00
|
|
|
{
|
|
|
|
if (!gBloatView) {
|
|
|
|
RecreateBloatView();
|
|
|
|
}
|
2013-10-11 00:41:00 +04:00
|
|
|
BloatEntry* entry = nullptr;
|
1999-10-09 00:29:47 +04:00
|
|
|
if (gBloatView) {
|
|
|
|
entry = (BloatEntry*)PL_HashTableLookup(gBloatView, aTypeName);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!entry && aInstanceSize > 0) {
|
2000-06-02 19:50:36 +04:00
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
entry = new BloatEntry(aTypeName, aInstanceSize);
|
|
|
|
PLHashEntry* e = PL_HashTableAdd(gBloatView, aTypeName, entry);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!e) {
|
1999-10-09 00:29:47 +04:00
|
|
|
delete entry;
|
2013-10-11 00:41:00 +04:00
|
|
|
entry = nullptr;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
2000-06-02 19:50:36 +04:00
|
|
|
} else {
|
2008-08-04 01:39:04 +04:00
|
|
|
NS_ASSERTION(aInstanceSize == 0 ||
|
|
|
|
entry->GetClassSize() == aInstanceSize,
|
2000-06-02 19:50:36 +04:00
|
|
|
"bad size recorded");
|
1999-12-10 07:27:52 +03:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
1999-10-12 04:29:54 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static int
|
|
|
|
DumpSerialNumbers(PLHashEntry* aHashEntry, int aIndex, void* aClosure)
|
1999-11-11 06:23:24 +03:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
serialNumberRecord* record =
|
|
|
|
reinterpret_cast<serialNumberRecord*>(aHashEntry->value);
|
2014-02-25 08:01:54 +04:00
|
|
|
#ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf((FILE*)aClosure, "%" PRIdPTR
|
2014-05-05 21:30:39 +04:00
|
|
|
" @%p (%d references; %d from COMPtrs)\n",
|
|
|
|
record->serialNumber,
|
|
|
|
NS_INT32_TO_PTR(aHashEntry->key),
|
|
|
|
record->refCount,
|
|
|
|
record->COMPtrCount);
|
2014-02-25 08:01:54 +04:00
|
|
|
#else
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf((FILE*)aClosure, "%" PRIdPTR
|
2014-05-05 21:30:39 +04:00
|
|
|
" @%p (%d references)\n",
|
|
|
|
record->serialNumber,
|
|
|
|
NS_INT32_TO_PTR(aHashEntry->key),
|
|
|
|
record->refCount);
|
2014-02-25 08:01:54 +04:00
|
|
|
#endif
|
1999-11-11 06:23:24 +03:00
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-25 23:17:15 +04:00
|
|
|
template<>
|
2014-05-13 21:41:38 +04:00
|
|
|
class nsDefaultComparator<BloatEntry*, BloatEntry*>
|
|
|
|
{
|
2014-05-05 21:30:39 +04:00
|
|
|
public:
|
2014-05-13 21:41:38 +04:00
|
|
|
bool Equals(BloatEntry* const& aEntry1, BloatEntry* const& aEntry2) const
|
|
|
|
{
|
|
|
|
return PL_strcmp(aEntry1->GetClassName(), aEntry2->GetClassName()) == 0;
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
bool LessThan(BloatEntry* const& aEntry1, BloatEntry* const& aEntry2) const
|
|
|
|
{
|
|
|
|
return PL_strcmp(aEntry1->GetClassName(), aEntry2->GetClassName()) < 0;
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2009-04-03 20:43:08 +04:00
|
|
|
};
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
#endif /* NS_IMPL_REFCNT_LOGGING */
|
1999-10-12 04:29:54 +04:00
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
nsresult
|
2014-05-13 21:41:38 +04:00
|
|
|
nsTraceRefcnt::DumpStatistics(StatisticsType aType, FILE* aOut)
|
1999-10-08 01:50:20 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gBloatLog || !gBloatView) {
|
1999-10-23 07:16:19 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!aOut) {
|
|
|
|
aOut = gBloatLog;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOCK_TRACELOG();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasLogging = gLogging;
|
2011-10-17 18:59:28 +04:00
|
|
|
gLogging = false; // turn off logging for this method
|
2008-08-04 01:39:04 +04:00
|
|
|
|
|
|
|
BloatEntry total("TOTAL", 0);
|
|
|
|
PL_HashTableEnumerateEntries(gBloatView, BloatEntry::TotalEntries, &total);
|
1999-10-12 13:30:12 +04:00
|
|
|
const char* msg;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aType == NEW_STATS) {
|
|
|
|
if (gLogLeaksOnly) {
|
1999-10-23 07:16:19 +04:00
|
|
|
msg = "NEW (incremental) LEAK STATISTICS";
|
2014-05-13 21:41:38 +04:00
|
|
|
} else {
|
1999-10-23 07:16:19 +04:00
|
|
|
msg = "NEW (incremental) LEAK AND BLOAT STATISTICS";
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (gLogLeaksOnly) {
|
1999-10-23 07:16:19 +04:00
|
|
|
msg = "ALL (cumulative) LEAK STATISTICS";
|
2014-05-13 21:41:38 +04:00
|
|
|
} else {
|
1999-10-23 07:16:19 +04:00
|
|
|
msg = "ALL (cumulative) LEAK AND BLOAT STATISTICS";
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
1999-10-12 13:30:12 +04:00
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
const bool leaked = total.PrintDumpHeader(aOut, msg, aType);
|
2000-04-18 10:00:24 +04:00
|
|
|
|
2009-04-03 20:43:08 +04:00
|
|
|
nsTArray<BloatEntry*> entries;
|
2008-08-04 01:39:04 +04:00
|
|
|
PL_HashTableEnumerateEntries(gBloatView, BloatEntry::DumpEntry, &entries);
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t count = entries.Length();
|
2000-04-18 10:00:24 +04:00
|
|
|
|
2008-08-04 01:39:04 +04:00
|
|
|
if (!gLogLeaksOnly || leaked) {
|
2000-04-18 10:00:24 +04:00
|
|
|
// Sort the entries alphabetically by classname.
|
2009-04-03 20:43:08 +04:00
|
|
|
entries.Sort();
|
2000-04-18 10:00:24 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2009-04-03 20:43:08 +04:00
|
|
|
BloatEntry* entry = entries[i];
|
2014-05-13 21:41:38 +04:00
|
|
|
entry->Dump(i, aOut, aType);
|
2000-04-18 10:00:24 +04:00
|
|
|
}
|
2008-08-04 01:39:04 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf(aOut, "\n");
|
2000-04-18 10:00:24 +04:00
|
|
|
}
|
1999-10-12 04:29:54 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf(aOut, "nsTraceRefcnt::DumpStatistics: %d entries\n", count);
|
2008-08-04 01:39:04 +04:00
|
|
|
|
1999-11-11 06:23:24 +03:00
|
|
|
if (gSerialNumbers) {
|
2014-05-13 21:41:38 +04:00
|
|
|
fprintf(aOut, "\nSerial Numbers of Leaked Objects:\n");
|
|
|
|
PL_HashTableEnumerateEntries(gSerialNumbers, DumpSerialNumbers, aOut);
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
|
|
|
|
1999-10-12 13:30:12 +04:00
|
|
|
gLogging = wasLogging;
|
1999-10-09 00:29:47 +04:00
|
|
|
UNLOCK_TRACELOG();
|
1999-10-09 02:04:04 +04:00
|
|
|
#endif
|
2008-08-04 01:39:04 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
void
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::ResetStatistics()
|
1999-10-09 00:29:47 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
1999-10-09 00:29:47 +04:00
|
|
|
LOCK_TRACELOG();
|
|
|
|
if (gBloatView) {
|
|
|
|
PL_HashTableDestroy(gBloatView);
|
2012-07-30 18:20:58 +04:00
|
|
|
gBloatView = nullptr;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
UNLOCK_TRACELOG();
|
1999-10-09 02:04:04 +04:00
|
|
|
#endif
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2014-05-13 21:41:38 +04:00
|
|
|
static bool
|
|
|
|
LogThisType(const char* aTypeName)
|
1999-10-09 00:29:47 +04:00
|
|
|
{
|
|
|
|
void* he = PL_HashTableLookup(gTypesToLog, aTypeName);
|
2014-05-13 21:41:38 +04:00
|
|
|
return he != nullptr;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
1999-10-08 01:50:20 +04:00
|
|
|
|
2015-02-20 20:38:47 +03:00
|
|
|
static PLHashNumber
|
|
|
|
HashNumber(const void* aKey)
|
|
|
|
{
|
|
|
|
return PLHashNumber(NS_PTR_TO_INT32(aKey));
|
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static intptr_t
|
|
|
|
GetSerialNumber(void* aPtr, bool aCreate)
|
1999-11-11 06:23:24 +03:00
|
|
|
{
|
2014-08-25 23:17:15 +04:00
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers,
|
2015-02-20 20:38:47 +03:00
|
|
|
HashNumber(aPtr),
|
2014-08-25 23:17:15 +04:00
|
|
|
aPtr);
|
1999-11-11 06:23:24 +03:00
|
|
|
if (hep && *hep) {
|
2013-01-04 01:53:51 +04:00
|
|
|
return reinterpret_cast<serialNumberRecord*>((*hep)->value)->serialNumber;
|
2014-05-13 21:41:38 +04:00
|
|
|
} else if (aCreate) {
|
|
|
|
serialNumberRecord* record = PR_NEW(serialNumberRecord);
|
2000-06-15 06:23:55 +04:00
|
|
|
record->serialNumber = ++gNextSerialNumber;
|
|
|
|
record->refCount = 0;
|
|
|
|
record->COMPtrCount = 0;
|
2015-02-20 20:38:47 +03:00
|
|
|
PL_HashTableRawAdd(gSerialNumbers, hep, HashNumber(aPtr),
|
2014-08-25 23:17:15 +04:00
|
|
|
aPtr, reinterpret_cast<void*>(record));
|
1999-11-11 06:23:24 +03:00
|
|
|
return gNextSerialNumber;
|
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
return 0;
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static int32_t*
|
|
|
|
GetRefCount(void* aPtr)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-08-25 23:17:15 +04:00
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers,
|
2015-02-20 20:38:47 +03:00
|
|
|
HashNumber(aPtr),
|
2014-08-25 23:17:15 +04:00
|
|
|
aPtr);
|
2000-06-15 06:23:55 +04:00
|
|
|
if (hep && *hep) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return &((reinterpret_cast<serialNumberRecord*>((*hep)->value))->refCount);
|
2000-06-15 06:23:55 +04:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 08:01:54 +04:00
|
|
|
#if defined(NS_IMPL_REFCNT_LOGGING) && defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
|
2014-05-13 21:41:38 +04:00
|
|
|
static int32_t*
|
|
|
|
GetCOMPtrCount(void* aPtr)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-08-25 23:17:15 +04:00
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers,
|
2015-02-20 20:38:47 +03:00
|
|
|
HashNumber(aPtr),
|
2014-08-25 23:17:15 +04:00
|
|
|
aPtr);
|
2000-06-15 06:23:55 +04:00
|
|
|
if (hep && *hep) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return &((reinterpret_cast<serialNumberRecord*>((*hep)->value))->COMPtrCount);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
return nullptr;
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
2012-09-07 23:32:33 +04:00
|
|
|
#endif
|
2000-06-15 06:23:55 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static void
|
|
|
|
RecycleSerialNumberPtr(void* aPtr)
|
1999-11-11 06:23:24 +03:00
|
|
|
{
|
|
|
|
PL_HashTableRemove(gSerialNumbers, aPtr);
|
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static bool
|
|
|
|
LogThisObj(intptr_t aSerialNumber)
|
1999-11-11 06:23:24 +03:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return (bool)PL_HashTableLookup(gObjectsToLog, (const void*)aSerialNumber);
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:19:50 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#define FOPEN_NO_INHERIT "N"
|
|
|
|
#else
|
|
|
|
#define FOPEN_NO_INHERIT
|
|
|
|
#endif
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static bool
|
|
|
|
InitLog(const char* aEnvVar, const char* aMsg, FILE** aResult)
|
1998-09-12 23:25:06 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
const char* value = getenv(aEnvVar);
|
1999-10-23 07:16:19 +04:00
|
|
|
if (value) {
|
|
|
|
if (nsCRT::strcmp(value, "1") == 0) {
|
2014-05-13 21:41:38 +04:00
|
|
|
*aResult = stdout;
|
2008-08-04 01:39:04 +04:00
|
|
|
fprintf(stdout, "### %s defined -- logging %s to stdout\n",
|
2014-05-13 21:41:38 +04:00
|
|
|
aEnvVar, aMsg);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2014-05-13 21:41:38 +04:00
|
|
|
} else if (nsCRT::strcmp(value, "2") == 0) {
|
|
|
|
*aResult = stderr;
|
2008-08-04 01:39:04 +04:00
|
|
|
fprintf(stdout, "### %s defined -- logging %s to stderr\n",
|
2014-05-13 21:41:38 +04:00
|
|
|
aEnvVar, aMsg);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2014-05-13 21:41:38 +04:00
|
|
|
} else {
|
|
|
|
FILE* stream;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString fname(value);
|
2009-11-10 22:16:12 +03:00
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
2014-05-05 21:30:39 +04:00
|
|
|
bool hasLogExtension =
|
|
|
|
fname.RFind(".log", true, -1, 4) == kNotFound ? false : true;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (hasLogExtension) {
|
2009-11-10 22:16:12 +03:00
|
|
|
fname.Cut(fname.Length() - 4, 4);
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2014-05-22 07:48:51 +04:00
|
|
|
fname.Append('_');
|
2009-11-10 22:16:12 +03:00
|
|
|
fname.Append((char*)XRE_ChildProcessTypeToString(XRE_GetProcessType()));
|
|
|
|
fname.AppendLiteral("_pid");
|
2012-08-22 19:56:38 +04:00
|
|
|
fname.AppendInt((uint32_t)getpid());
|
2014-05-13 21:41:38 +04:00
|
|
|
if (hasLogExtension) {
|
2009-11-10 22:16:12 +03:00
|
|
|
fname.AppendLiteral(".log");
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2009-11-10 22:16:12 +03:00
|
|
|
}
|
2010-01-27 19:19:50 +03:00
|
|
|
stream = ::fopen(fname.get(), "w" FOPEN_NO_INHERIT);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (stream) {
|
2012-07-03 17:15:34 +04:00
|
|
|
MozillaRegisterDebugFD(fileno(stream));
|
2014-05-13 21:41:38 +04:00
|
|
|
*aResult = stream;
|
2008-08-04 01:39:04 +04:00
|
|
|
fprintf(stdout, "### %s defined -- logging %s to %s\n",
|
2014-05-13 21:41:38 +04:00
|
|
|
aEnvVar, aMsg, fname.get());
|
|
|
|
} else {
|
2008-08-04 01:39:04 +04:00
|
|
|
fprintf(stdout, "### %s defined -- unable to log %s to %s\n",
|
2014-05-13 21:41:38 +04:00
|
|
|
aEnvVar, aMsg, fname.get());
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
2013-10-11 00:41:00 +04:00
|
|
|
return stream != nullptr;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
1999-10-23 07:16:19 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1999-10-23 07:16:19 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
1999-11-11 06:23:24 +03:00
|
|
|
|
2014-07-07 18:10:00 +04:00
|
|
|
static void
|
|
|
|
maybeUnregisterAndCloseFile(FILE*& aFile)
|
|
|
|
{
|
|
|
|
if (!aFile) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MozillaUnRegisterDebugFILE(aFile);
|
|
|
|
fclose(aFile);
|
|
|
|
aFile = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
static void
|
|
|
|
InitTraceLog()
|
1999-10-23 07:16:19 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
if (gInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
gInitialized = true;
|
1999-10-23 07:16:19 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
bool defined = InitLog("XPCOM_MEM_BLOAT_LOG", "bloat/leaks", &gBloatLog);
|
|
|
|
if (!defined) {
|
1999-10-23 07:16:19 +04:00
|
|
|
gLogLeaksOnly = InitLog("XPCOM_MEM_LEAK_LOG", "leaks", &gBloatLog);
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
1999-10-23 07:16:19 +04:00
|
|
|
if (defined || gLogLeaksOnly) {
|
|
|
|
RecreateBloatView();
|
2002-01-24 12:20:51 +03:00
|
|
|
if (!gBloatView) {
|
|
|
|
NS_WARNING("out of memory");
|
2014-07-07 18:10:00 +04:00
|
|
|
maybeUnregisterAndCloseFile(gBloatLog);
|
2011-10-17 18:59:28 +04:00
|
|
|
gLogLeaksOnly = false;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
1999-10-23 07:16:19 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
InitLog("XPCOM_MEM_REFCNT_LOG", "refcounts", &gRefcntsLog);
|
1999-10-23 07:16:19 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
InitLog("XPCOM_MEM_ALLOC_LOG", "new/delete", &gAllocLog);
|
1999-10-23 07:16:19 +04:00
|
|
|
|
|
|
|
const char* classes = getenv("XPCOM_MEM_LOG_CLASSES");
|
2000-06-15 06:23:55 +04:00
|
|
|
|
2014-02-25 08:01:54 +04:00
|
|
|
#ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
|
2000-06-15 06:23:55 +04:00
|
|
|
if (classes) {
|
2014-05-13 21:41:38 +04:00
|
|
|
InitLog("XPCOM_MEM_COMPTR_LOG", "nsCOMPtr", &gCOMPtrLog);
|
2000-06-15 06:23:55 +04:00
|
|
|
} else {
|
|
|
|
if (getenv("XPCOM_MEM_COMPTR_LOG")) {
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "### XPCOM_MEM_COMPTR_LOG defined -- but XPCOM_MEM_LOG_CLASSES is not defined\n");
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
}
|
2014-02-25 08:01:54 +04:00
|
|
|
#else
|
|
|
|
const char* comptr_log = getenv("XPCOM_MEM_COMPTR_LOG");
|
|
|
|
if (comptr_log) {
|
|
|
|
fprintf(stdout, "### XPCOM_MEM_COMPTR_LOG defined -- but it will not work without dynamic_cast\n");
|
|
|
|
}
|
|
|
|
#endif
|
2000-06-15 06:23:55 +04:00
|
|
|
|
1999-10-23 07:16:19 +04:00
|
|
|
if (classes) {
|
2000-02-24 09:02:38 +03:00
|
|
|
// if XPCOM_MEM_LOG_CLASSES was set to some value, the value is interpreted
|
1999-10-23 07:16:19 +04:00
|
|
|
// as a list of class names to track
|
|
|
|
gTypesToLog = PL_NewHashTable(256,
|
|
|
|
PL_HashString,
|
|
|
|
PL_CompareStrings,
|
|
|
|
PL_CompareValues,
|
2013-10-11 00:41:00 +04:00
|
|
|
&typesToLogHashAllocOps, nullptr);
|
2002-01-24 12:20:51 +03:00
|
|
|
if (!gTypesToLog) {
|
|
|
|
NS_WARNING("out of memory");
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "### XPCOM_MEM_LOG_CLASSES defined -- unable to log specific classes\n");
|
2014-05-13 21:41:38 +04:00
|
|
|
} else {
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "### XPCOM_MEM_LOG_CLASSES defined -- only logging these classes: ");
|
1999-10-23 07:16:19 +04:00
|
|
|
const char* cp = classes;
|
|
|
|
for (;;) {
|
2014-05-13 21:41:38 +04:00
|
|
|
char* cm = (char*)strchr(cp, ',');
|
1999-10-23 07:16:19 +04:00
|
|
|
if (cm) {
|
|
|
|
*cm = '\0';
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
2013-08-22 14:31:48 +04:00
|
|
|
PL_HashTableAdd(gTypesToLog, strdup(cp), (void*)1);
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "%s ", cp);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!cm) {
|
|
|
|
break;
|
|
|
|
}
|
1999-10-23 07:16:19 +04:00
|
|
|
*cm = ',';
|
|
|
|
cp = cm + 1;
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "\n");
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
1999-11-11 06:23:24 +03:00
|
|
|
|
|
|
|
gSerialNumbers = PL_NewHashTable(256,
|
|
|
|
HashNumber,
|
|
|
|
PL_CompareValues,
|
|
|
|
PL_CompareValues,
|
2013-10-11 00:41:00 +04:00
|
|
|
&serialNumberHashAllocOps, nullptr);
|
1999-11-19 06:50:28 +03:00
|
|
|
|
|
|
|
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* objects = getenv("XPCOM_MEM_LOG_OBJECTS");
|
|
|
|
if (objects) {
|
|
|
|
gObjectsToLog = PL_NewHashTable(256,
|
|
|
|
HashNumber,
|
|
|
|
PL_CompareValues,
|
|
|
|
PL_CompareValues,
|
2013-10-11 00:41:00 +04:00
|
|
|
nullptr, nullptr);
|
1999-11-11 06:23:24 +03:00
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
if (!gObjectsToLog) {
|
|
|
|
NS_WARNING("out of memory");
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "### XPCOM_MEM_LOG_OBJECTS defined -- unable to log specific objects\n");
|
2014-05-13 21:41:38 +04:00
|
|
|
} else if (!(gRefcntsLog || gAllocLog || gCOMPtrLog)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "### XPCOM_MEM_LOG_OBJECTS defined -- but none of XPCOM_MEM_(REFCNT|ALLOC|COMPTR)_LOG is defined\n");
|
2014-05-13 21:41:38 +04:00
|
|
|
} else {
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "### XPCOM_MEM_LOG_OBJECTS defined -- only logging these objects: ");
|
1999-11-11 06:23:24 +03:00
|
|
|
const char* cp = objects;
|
|
|
|
for (;;) {
|
2014-05-13 21:41:38 +04:00
|
|
|
char* cm = (char*)strchr(cp, ',');
|
1999-11-11 06:23:24 +03:00
|
|
|
if (cm) {
|
|
|
|
*cm = '\0';
|
|
|
|
}
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t top = 0;
|
|
|
|
intptr_t bottom = 0;
|
1999-11-11 06:23:24 +03:00
|
|
|
while (*cp) {
|
2000-06-15 06:23:55 +04:00
|
|
|
if (*cp == '-') {
|
|
|
|
bottom = top;
|
|
|
|
top = 0;
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
top *= 10;
|
|
|
|
top += *cp - '0';
|
1999-11-11 06:23:24 +03:00
|
|
|
++cp;
|
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
if (!bottom) {
|
|
|
|
bottom = top;
|
|
|
|
}
|
2013-01-04 01:53:51 +04:00
|
|
|
for (intptr_t serialno = bottom; serialno <= top; serialno++) {
|
2000-06-15 06:23:55 +04:00
|
|
|
PL_HashTableAdd(gObjectsToLog, (const void*)serialno, (void*)1);
|
2013-09-12 21:18:36 +04:00
|
|
|
fprintf(stdout, "%" PRIdPTR " ", serialno);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!cm) {
|
|
|
|
break;
|
|
|
|
}
|
1999-11-11 06:23:24 +03:00
|
|
|
*cm = ',';
|
|
|
|
cp = cm + 1;
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "\n");
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
1999-10-23 07:16:19 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
1999-11-19 06:50:28 +03:00
|
|
|
|
2014-10-22 06:13:05 +04:00
|
|
|
if (gBloatLog || gRefcntsLog || gAllocLog || gCOMPtrLog) {
|
2011-10-17 18:59:28 +04:00
|
|
|
gLogging = true;
|
1999-10-23 07:16:19 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
1999-10-23 07:16:19 +04:00
|
|
|
gTraceLock = PR_NewLock();
|
1998-09-12 23:25:06 +04:00
|
|
|
}
|
1999-11-19 06:50:28 +03:00
|
|
|
|
1999-10-09 02:04:04 +04:00
|
|
|
#endif
|
1998-09-12 23:25:06 +04:00
|
|
|
|
2007-08-11 01:28:22 +04:00
|
|
|
extern "C" {
|
1999-06-21 06:29:17 +04:00
|
|
|
|
2014-09-08 21:25:20 +04:00
|
|
|
#ifdef MOZ_STACKWALKING
|
2014-05-13 21:41:38 +04:00
|
|
|
static void
|
2014-09-11 08:47:01 +04:00
|
|
|
PrintStackFrame(uint32_t aFrameNumber, void* aPC, void* aSP, void* aClosure)
|
1999-06-16 06:05:32 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
FILE* stream = (FILE*)aClosure;
|
2007-08-11 01:29:37 +04:00
|
|
|
nsCodeAddressDetails details;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
NS_DescribeCodeAddress(aPC, &details);
|
2014-09-02 09:56:05 +04:00
|
|
|
NS_FormatCodeAddressDetails(buf, sizeof(buf), aFrameNumber, aPC, &details);
|
|
|
|
fprintf(stream, "%s\n", buf);
|
|
|
|
fflush(stream);
|
2000-06-27 02:23:47 +04:00
|
|
|
}
|
2014-08-01 20:27:35 +04:00
|
|
|
|
|
|
|
static void
|
2014-09-11 08:47:01 +04:00
|
|
|
PrintStackFrameCached(uint32_t aFrameNumber, void* aPC, void* aSP,
|
|
|
|
void* aClosure)
|
2014-08-01 20:27:35 +04:00
|
|
|
{
|
2014-09-02 07:03:06 +04:00
|
|
|
auto stream = static_cast<FILE*>(aClosure);
|
|
|
|
static const size_t buflen = 1024;
|
|
|
|
char buf[buflen];
|
2014-09-11 08:47:01 +04:00
|
|
|
gCodeAddressService->GetLocation(aFrameNumber, aPC, buf, buflen);
|
2014-09-02 07:03:06 +04:00
|
|
|
fprintf(stream, " %s\n", buf);
|
2014-09-02 09:56:05 +04:00
|
|
|
fflush(stream);
|
2014-08-01 20:27:35 +04:00
|
|
|
}
|
2013-12-19 00:03:11 +04:00
|
|
|
#endif
|
2000-06-27 02:23:47 +04:00
|
|
|
|
2007-08-11 01:28:22 +04:00
|
|
|
}
|
1999-10-21 07:44:37 +04:00
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
void
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::WalkTheStack(FILE* aStream)
|
1999-10-21 07:44:37 +04:00
|
|
|
{
|
2014-09-08 21:25:20 +04:00
|
|
|
#ifdef MOZ_STACKWALKING
|
2012-12-21 09:31:57 +04:00
|
|
|
NS_StackWalk(PrintStackFrame, /* skipFrames */ 2, /* maxFrames */ 0, aStream,
|
|
|
|
0, nullptr);
|
2013-12-19 00:03:11 +04:00
|
|
|
#endif
|
1998-09-12 23:25:06 +04:00
|
|
|
}
|
1999-06-15 07:25:27 +04:00
|
|
|
|
2014-08-01 20:27:35 +04:00
|
|
|
void
|
|
|
|
nsTraceRefcnt::WalkTheStackCached(FILE* aStream)
|
|
|
|
{
|
2014-09-08 21:25:20 +04:00
|
|
|
#ifdef MOZ_STACKWALKING
|
2014-08-01 20:27:35 +04:00
|
|
|
if (!gCodeAddressService) {
|
|
|
|
gCodeAddressService = new WalkTheStackCodeAddressService();
|
|
|
|
}
|
2014-08-25 23:17:15 +04:00
|
|
|
NS_StackWalk(PrintStackFrameCached, /* skipFrames */ 2, /* maxFrames */ 0,
|
2014-09-02 07:03:06 +04:00
|
|
|
aStream, 0, nullptr);
|
2014-08-01 20:27:35 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-02-11 10:16:11 +03:00
|
|
|
// This thing is exported by libstdc++
|
1999-10-09 00:29:47 +04:00
|
|
|
// Yes, this is a gcc only hack
|
|
|
|
#if defined(MOZ_DEMANGLE_SYMBOLS)
|
2004-02-11 10:16:11 +03:00
|
|
|
#include <cxxabi.h>
|
1999-10-09 00:29:47 +04:00
|
|
|
#include <stdlib.h> // for free()
|
|
|
|
#endif // MOZ_DEMANGLE_SYMBOLS
|
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
void
|
2014-05-13 21:41:38 +04:00
|
|
|
nsTraceRefcnt::DemangleSymbol(const char* aSymbol,
|
|
|
|
char* aBuffer,
|
1999-10-09 00:29:47 +04:00
|
|
|
int aBufLen)
|
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_ASSERTION(aSymbol, "null symbol");
|
|
|
|
NS_ASSERTION(aBuffer, "null buffer");
|
|
|
|
NS_ASSERTION(aBufLen >= 32 , "pulled 32 out of you know where");
|
1999-10-09 00:29:47 +04:00
|
|
|
|
|
|
|
aBuffer[0] = '\0';
|
|
|
|
|
|
|
|
#if defined(MOZ_DEMANGLE_SYMBOLS)
|
2014-05-05 21:30:39 +04:00
|
|
|
/* See demangle.h in the gcc source for the voodoo */
|
2014-05-13 21:41:38 +04:00
|
|
|
char* demangled = abi::__cxa_demangle(aSymbol, 0, 0, 0);
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
if (demangled) {
|
|
|
|
strncpy(aBuffer, demangled, aBufLen);
|
1999-10-09 00:29:47 +04:00
|
|
|
free(demangled);
|
|
|
|
}
|
|
|
|
#endif // MOZ_DEMANGLE_SYMBOLS
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
|
|
|
NS_LogInit()
|
2000-12-23 19:43:32 +03:00
|
|
|
{
|
2014-07-04 14:34:15 +04:00
|
|
|
NS_SetMainThread();
|
|
|
|
|
2011-12-03 04:26:04 +04:00
|
|
|
// FIXME: This is called multiple times, we should probably not allow that.
|
2014-09-08 21:25:20 +04:00
|
|
|
#ifdef MOZ_STACKWALKING
|
2011-12-03 04:26:04 +04:00
|
|
|
StackWalkInitCriticalAddress();
|
2013-12-19 00:03:11 +04:00
|
|
|
#endif
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2014-05-13 21:41:38 +04:00
|
|
|
if (++gInitCount) {
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::SetActivityIsLegal(true);
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2006-02-10 18:00:36 +03:00
|
|
|
#endif
|
2003-08-05 09:29:10 +04:00
|
|
|
}
|
2000-12-23 19:43:32 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
|
|
|
NS_LogTerm()
|
2010-02-04 01:17:09 +03:00
|
|
|
{
|
|
|
|
mozilla::LogTerm();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
void
|
|
|
|
LogTerm()
|
2003-08-05 09:29:10 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_ASSERTION(gInitCount > 0,
|
|
|
|
"NS_LogTerm without matching NS_LogInit");
|
|
|
|
|
|
|
|
if (--gInitCount == 0) {
|
2010-02-04 01:17:09 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* FIXME bug 491977: This is only going to operate on the
|
|
|
|
* BlockingResourceBase which is compiled into
|
|
|
|
* libxul/libxpcom_core.so. Anyone using external linkage will
|
|
|
|
* have their own copy of BlockingResourceBase statics which will
|
|
|
|
* not be freed by this method.
|
|
|
|
*
|
|
|
|
* It sounds like what we really want is to be able to register a
|
|
|
|
* callback function to call at XPCOM shutdown. Note that with
|
|
|
|
* this solution, however, we need to guarantee that
|
|
|
|
* BlockingResourceBase::Shutdown() runs after all other shutdown
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
BlockingResourceBase::Shutdown();
|
|
|
|
#endif
|
2014-05-05 21:30:39 +04:00
|
|
|
|
2006-02-10 19:19:13 +03:00
|
|
|
if (gInitialized) {
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::DumpStatistics();
|
|
|
|
nsTraceRefcnt::ResetStatistics();
|
2006-02-10 19:19:13 +03:00
|
|
|
}
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::Shutdown();
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::SetActivityIsLegal(false);
|
2006-02-10 18:00:36 +03:00
|
|
|
gActivityTLS = BAD_TLS_INDEX;
|
|
|
|
#endif
|
|
|
|
}
|
2000-12-23 19:43:32 +03:00
|
|
|
}
|
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
|
|
|
NS_LogAddRef(void* aPtr, nsrefcnt aRefcnt,
|
2014-08-25 23:17:15 +04:00
|
|
|
const char* aClass, uint32_t aClassSize)
|
1998-09-12 23:25:06 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2000-12-23 19:43:32 +03:00
|
|
|
ASSERT_ACTIVITY_IS_LEGAL;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gInitialized) {
|
1999-10-16 05:57:18 +04:00
|
|
|
InitTraceLog();
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
if (gLogging) {
|
|
|
|
LOCK_TRACELOG();
|
2000-04-13 07:51:43 +04:00
|
|
|
|
1999-10-23 07:16:19 +04:00
|
|
|
if (gBloatLog) {
|
2014-08-25 23:17:15 +04:00
|
|
|
BloatEntry* entry = GetBloatEntry(aClass, aClassSize);
|
1999-10-09 00:29:47 +04:00
|
|
|
if (entry) {
|
2003-08-05 09:29:10 +04:00
|
|
|
entry->AddRef(aRefcnt);
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 13:42:18 +04:00
|
|
|
// Here's the case where MOZ_COUNT_CTOR was not used,
|
1999-10-16 05:57:18 +04:00
|
|
|
// yet we still want to see creation information:
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2014-08-25 23:17:15 +04:00
|
|
|
bool loggingThisType = (!gTypesToLog || LogThisType(aClass));
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialno = 0;
|
1999-11-11 06:23:24 +03:00
|
|
|
if (gSerialNumbers && loggingThisType) {
|
2003-08-05 09:29:10 +04:00
|
|
|
serialno = GetSerialNumber(aPtr, aRefcnt == 1);
|
2008-06-03 05:28:59 +04:00
|
|
|
NS_ASSERTION(serialno != 0,
|
|
|
|
"Serial number requested for unrecognized pointer! "
|
|
|
|
"Are you memmoving a refcounted object?");
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* count = GetRefCount(aPtr);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (count) {
|
2000-06-15 06:23:55 +04:00
|
|
|
(*count)++;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
|
2003-08-05 09:29:10 +04:00
|
|
|
if (aRefcnt == 1 && gAllocLog && loggingThisType && loggingThisObject) {
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gAllocLog, "\n<%s> %p %" PRIdPTR " Create\n", aClass, aPtr, serialno);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gAllocLog);
|
1999-10-16 05:57:18 +04:00
|
|
|
}
|
|
|
|
|
1999-11-11 06:23:24 +03:00
|
|
|
if (gRefcntsLog && loggingThisType && loggingThisObject) {
|
2014-05-21 05:03:27 +04:00
|
|
|
// Can't use PR_LOG(), b/c it truncates the line
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gRefcntsLog, "\n<%s> %p %" PRIuPTR " AddRef %" PRIuPTR "\n",
|
|
|
|
aClass, aPtr, serialno, aRefcnt);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gRefcntsLog);
|
2014-05-21 05:03:27 +04:00
|
|
|
fflush(gRefcntsLog);
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
UNLOCK_TRACELOG();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
2014-08-25 23:17:15 +04:00
|
|
|
NS_LogRelease(void* aPtr, nsrefcnt aRefcnt, const char* aClass)
|
1999-10-09 00:29:47 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2000-12-23 19:43:32 +03:00
|
|
|
ASSERT_ACTIVITY_IS_LEGAL;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gInitialized) {
|
1999-10-16 05:57:18 +04:00
|
|
|
InitTraceLog();
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
if (gLogging) {
|
|
|
|
LOCK_TRACELOG();
|
|
|
|
|
1999-10-23 07:16:19 +04:00
|
|
|
if (gBloatLog) {
|
2014-08-25 23:17:15 +04:00
|
|
|
BloatEntry* entry = GetBloatEntry(aClass, 0);
|
1999-10-09 00:29:47 +04:00
|
|
|
if (entry) {
|
2003-08-05 09:29:10 +04:00
|
|
|
entry->Release(aRefcnt);
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-16 05:57:18 +04:00
|
|
|
|
2014-08-25 23:17:15 +04:00
|
|
|
bool loggingThisType = (!gTypesToLog || LogThisType(aClass));
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialno = 0;
|
1999-11-11 06:23:24 +03:00
|
|
|
if (gSerialNumbers && loggingThisType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
serialno = GetSerialNumber(aPtr, false);
|
2008-06-03 05:28:59 +04:00
|
|
|
NS_ASSERTION(serialno != 0,
|
|
|
|
"Serial number requested for unrecognized pointer! "
|
|
|
|
"Are you memmoving a refcounted object?");
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* count = GetRefCount(aPtr);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (count) {
|
2000-06-15 06:23:55 +04:00
|
|
|
(*count)--;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
|
1999-11-11 06:23:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
|
1999-11-11 06:23:24 +03:00
|
|
|
if (gRefcntsLog && loggingThisType && loggingThisObject) {
|
2014-05-21 05:03:27 +04:00
|
|
|
// Can't use PR_LOG(), b/c it truncates the line
|
|
|
|
fprintf(gRefcntsLog,
|
2015-02-20 20:38:46 +03:00
|
|
|
"\n<%s> %p %" PRIuPTR " Release %" PRIuPTR "\n",
|
|
|
|
aClass, aPtr, serialno, aRefcnt);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gRefcntsLog);
|
2014-05-21 05:03:27 +04:00
|
|
|
fflush(gRefcntsLog);
|
1999-10-09 00:29:47 +04:00
|
|
|
}
|
|
|
|
|
2010-07-05 13:42:18 +04:00
|
|
|
// Here's the case where MOZ_COUNT_DTOR was not used,
|
1999-10-16 05:57:18 +04:00
|
|
|
// yet we still want to see deletion information:
|
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
if (aRefcnt == 0 && gAllocLog && loggingThisType && loggingThisObject) {
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gAllocLog, "\n<%s> %p %" PRIdPTR " Destroy\n", aClass, aPtr, serialno);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gAllocLog);
|
1999-10-16 05:57:18 +04:00
|
|
|
}
|
1999-11-11 06:23:24 +03:00
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
if (aRefcnt == 0 && gSerialNumbers && loggingThisType) {
|
1999-11-11 06:23:24 +03:00
|
|
|
RecycleSerialNumberPtr(aPtr);
|
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
|
|
|
UNLOCK_TRACELOG();
|
1998-09-12 23:25:06 +04:00
|
|
|
}
|
1999-10-16 05:57:18 +04:00
|
|
|
#endif
|
1998-09-12 23:25:06 +04:00
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_LogCtor(void* aPtr, const char* aType, uint32_t aInstanceSize)
|
1999-06-15 07:25:27 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2000-12-23 19:43:32 +03:00
|
|
|
ASSERT_ACTIVITY_IS_LEGAL;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gInitialized) {
|
1999-10-16 05:57:18 +04:00
|
|
|
InitTraceLog();
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
1999-10-16 05:57:18 +04:00
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
if (gLogging) {
|
|
|
|
LOCK_TRACELOG();
|
|
|
|
|
1999-10-23 07:16:19 +04:00
|
|
|
if (gBloatLog) {
|
1999-10-21 07:44:37 +04:00
|
|
|
BloatEntry* entry = GetBloatEntry(aType, aInstanceSize);
|
1999-10-09 00:29:47 +04:00
|
|
|
if (entry) {
|
|
|
|
entry->Ctor();
|
|
|
|
}
|
1999-10-08 01:50:20 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisType = (!gTypesToLog || LogThisType(aType));
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialno = 0;
|
2000-04-22 04:40:13 +04:00
|
|
|
if (gSerialNumbers && loggingThisType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
serialno = GetSerialNumber(aPtr, true);
|
2000-04-22 04:40:13 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
|
2000-04-22 04:40:13 +04:00
|
|
|
if (gAllocLog && loggingThisType && loggingThisObject) {
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gAllocLog, "\n<%s> %p %" PRIdPTR " Ctor (%d)\n",
|
|
|
|
aType, aPtr, serialno, aInstanceSize);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gAllocLog);
|
1999-10-16 05:57:18 +04:00
|
|
|
}
|
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
UNLOCK_TRACELOG();
|
1999-06-15 07:25:27 +04:00
|
|
|
}
|
1999-10-08 01:50:20 +04:00
|
|
|
#endif
|
1999-06-15 07:25:27 +04:00
|
|
|
}
|
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_LogDtor(void* aPtr, const char* aType, uint32_t aInstanceSize)
|
1999-06-15 07:25:27 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2000-12-23 19:43:32 +03:00
|
|
|
ASSERT_ACTIVITY_IS_LEGAL;
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gInitialized) {
|
1999-10-16 05:57:18 +04:00
|
|
|
InitTraceLog();
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
1999-10-16 05:57:18 +04:00
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
if (gLogging) {
|
|
|
|
LOCK_TRACELOG();
|
1999-10-05 03:36:18 +04:00
|
|
|
|
1999-10-23 07:16:19 +04:00
|
|
|
if (gBloatLog) {
|
1999-10-21 07:44:37 +04:00
|
|
|
BloatEntry* entry = GetBloatEntry(aType, aInstanceSize);
|
1999-10-09 00:29:47 +04:00
|
|
|
if (entry) {
|
|
|
|
entry->Dtor();
|
1999-10-05 03:36:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisType = (!gTypesToLog || LogThisType(aType));
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialno = 0;
|
2000-04-22 04:40:13 +04:00
|
|
|
if (gSerialNumbers && loggingThisType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
serialno = GetSerialNumber(aPtr, false);
|
2000-04-22 04:40:13 +04:00
|
|
|
RecycleSerialNumberPtr(aPtr);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
|
2000-04-22 04:40:13 +04:00
|
|
|
|
1999-10-16 05:57:18 +04:00
|
|
|
// (If we're on a losing architecture, don't do this because we'll be
|
|
|
|
// using LogDeleteXPCOM instead to get file and line numbers.)
|
2000-04-22 04:40:13 +04:00
|
|
|
if (gAllocLog && loggingThisType && loggingThisObject) {
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gAllocLog, "\n<%s> %p %" PRIdPTR " Dtor (%d)\n",
|
|
|
|
aType, aPtr, serialno, aInstanceSize);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gAllocLog);
|
1999-10-16 05:57:18 +04:00
|
|
|
}
|
|
|
|
|
1999-10-09 00:29:47 +04:00
|
|
|
UNLOCK_TRACELOG();
|
1999-10-05 03:36:18 +04:00
|
|
|
}
|
1999-10-09 00:29:47 +04:00
|
|
|
#endif
|
1999-10-05 03:36:18 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
|
|
|
NS_LogCOMPtrAddRef(void* aCOMPtr, nsISupports* aObject)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-02-25 08:01:54 +04:00
|
|
|
#if defined(NS_IMPL_REFCNT_LOGGING) && defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
|
2000-12-23 19:43:32 +03:00
|
|
|
// Get the most-derived object.
|
2014-05-13 21:41:38 +04:00
|
|
|
void* object = dynamic_cast<void*>(aObject);
|
2000-12-23 19:43:32 +03:00
|
|
|
|
2000-06-15 06:23:55 +04:00
|
|
|
// This is a very indirect way of finding out what the class is
|
|
|
|
// of the object being logged. If we're logging a specific type,
|
2008-08-04 01:39:04 +04:00
|
|
|
// then
|
2000-06-15 06:23:55 +04:00
|
|
|
if (!gTypesToLog || !gSerialNumbers) {
|
2006-02-10 18:00:36 +03:00
|
|
|
return;
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialno = GetSerialNumber(object, false);
|
2000-06-15 06:23:55 +04:00
|
|
|
if (serialno == 0) {
|
2006-02-10 18:00:36 +03:00
|
|
|
return;
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gInitialized) {
|
2000-06-15 06:23:55 +04:00
|
|
|
InitTraceLog();
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
if (gLogging) {
|
|
|
|
LOCK_TRACELOG();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* count = GetCOMPtrCount(object);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (count) {
|
2000-06-15 06:23:55 +04:00
|
|
|
(*count)++;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
|
2000-06-15 06:23:55 +04:00
|
|
|
|
|
|
|
if (gCOMPtrLog && loggingThisObject) {
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gCOMPtrLog, "\n<?> %p %" PRIdPTR " nsCOMPtrAddRef %d %p\n",
|
|
|
|
object, serialno, count ? (*count) : -1, aCOMPtr);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gCOMPtrLog);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
UNLOCK_TRACELOG();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
EXPORT_XPCOM_API(void)
|
|
|
|
NS_LogCOMPtrRelease(void* aCOMPtr, nsISupports* aObject)
|
2000-06-15 06:23:55 +04:00
|
|
|
{
|
2014-02-25 08:01:54 +04:00
|
|
|
#if defined(NS_IMPL_REFCNT_LOGGING) && defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
|
2000-12-23 19:43:32 +03:00
|
|
|
// Get the most-derived object.
|
2014-05-13 21:41:38 +04:00
|
|
|
void* object = dynamic_cast<void*>(aObject);
|
2000-12-23 19:43:32 +03:00
|
|
|
|
2000-06-15 06:23:55 +04:00
|
|
|
// This is a very indirect way of finding out what the class is
|
|
|
|
// of the object being logged. If we're logging a specific type,
|
2008-08-04 01:39:04 +04:00
|
|
|
// then
|
2000-06-15 06:23:55 +04:00
|
|
|
if (!gTypesToLog || !gSerialNumbers) {
|
2006-02-10 18:00:36 +03:00
|
|
|
return;
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
2013-01-04 01:53:51 +04:00
|
|
|
intptr_t serialno = GetSerialNumber(object, false);
|
2000-06-15 06:23:55 +04:00
|
|
|
if (serialno == 0) {
|
2006-02-10 18:00:36 +03:00
|
|
|
return;
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
if (!gInitialized) {
|
2000-06-15 06:23:55 +04:00
|
|
|
InitTraceLog();
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
if (gLogging) {
|
|
|
|
LOCK_TRACELOG();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* count = GetCOMPtrCount(object);
|
2014-05-13 21:41:38 +04:00
|
|
|
if (count) {
|
2000-06-15 06:23:55 +04:00
|
|
|
(*count)--;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2000-06-15 06:23:55 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
|
2000-06-15 06:23:55 +04:00
|
|
|
|
|
|
|
if (gCOMPtrLog && loggingThisObject) {
|
2015-02-20 20:38:46 +03:00
|
|
|
fprintf(gCOMPtrLog, "\n<?> %p %" PRIdPTR " nsCOMPtrRelease %d %p\n",
|
|
|
|
object, serialno, count ? (*count) : -1, aCOMPtr);
|
2014-08-01 20:27:35 +04:00
|
|
|
nsTraceRefcnt::WalkTheStackCached(gCOMPtrLog);
|
2000-06-15 06:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
UNLOCK_TRACELOG();
|
|
|
|
}
|
2003-08-05 09:29:10 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
void
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::Shutdown()
|
2003-08-05 09:29:10 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2014-09-08 21:25:20 +04:00
|
|
|
#ifdef MOZ_STACKWALKING
|
2014-08-01 20:27:35 +04:00
|
|
|
gCodeAddressService = nullptr;
|
|
|
|
#endif
|
2003-08-05 09:29:10 +04:00
|
|
|
if (gBloatView) {
|
|
|
|
PL_HashTableDestroy(gBloatView);
|
2012-07-30 18:20:58 +04:00
|
|
|
gBloatView = nullptr;
|
2003-08-05 09:29:10 +04:00
|
|
|
}
|
|
|
|
if (gTypesToLog) {
|
|
|
|
PL_HashTableDestroy(gTypesToLog);
|
2012-07-30 18:20:58 +04:00
|
|
|
gTypesToLog = nullptr;
|
2003-08-05 09:29:10 +04:00
|
|
|
}
|
|
|
|
if (gObjectsToLog) {
|
|
|
|
PL_HashTableDestroy(gObjectsToLog);
|
2012-07-30 18:20:58 +04:00
|
|
|
gObjectsToLog = nullptr;
|
2003-08-05 09:29:10 +04:00
|
|
|
}
|
|
|
|
if (gSerialNumbers) {
|
|
|
|
PL_HashTableDestroy(gSerialNumbers);
|
2012-07-30 18:20:58 +04:00
|
|
|
gSerialNumbers = nullptr;
|
2003-08-05 09:29:10 +04:00
|
|
|
}
|
2012-07-03 17:15:34 +04:00
|
|
|
maybeUnregisterAndCloseFile(gBloatLog);
|
|
|
|
maybeUnregisterAndCloseFile(gRefcntsLog);
|
|
|
|
maybeUnregisterAndCloseFile(gAllocLog);
|
|
|
|
maybeUnregisterAndCloseFile(gCOMPtrLog);
|
2003-08-05 09:29:10 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
void
|
2014-02-27 01:36:36 +04:00
|
|
|
nsTraceRefcnt::SetActivityIsLegal(bool aLegal)
|
2003-08-05 09:29:10 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
#ifdef NS_IMPL_REFCNT_LOGGING
|
2014-05-13 21:41:38 +04:00
|
|
|
if (gActivityTLS == BAD_TLS_INDEX) {
|
2012-07-30 18:20:58 +04:00
|
|
|
PR_NewThreadPrivateIndex(&gActivityTLS, nullptr);
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2006-02-10 18:00:36 +03:00
|
|
|
|
2015-02-20 20:38:47 +03:00
|
|
|
PR_SetThreadPrivate(gActivityTLS, reinterpret_cast<void*>(!aLegal));
|
2003-08-05 09:29:10 +04:00
|
|
|
#endif
|
|
|
|
}
|