зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1181445 (part 3) - Use nsTHashTable::Iterator in nsObserverService. r=froydnj.
--HG-- extra : rebase_source : 1bbbc86315455a5af29d34c80feac2f206d7d9f2
This commit is contained in:
Родитель
e4c39dc6c4
Коммит
8626fc2a98
|
@ -41,53 +41,34 @@ GetObserverServiceLog()
|
|||
}
|
||||
#define LOG(x) MOZ_LOG(GetObserverServiceLog(), mozilla::LogLevel::Debug, x)
|
||||
|
||||
namespace mozilla {
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize)
|
||||
{
|
||||
struct SuspectObserver
|
||||
{
|
||||
SuspectObserver(const char* aTopic, size_t aReferentCount)
|
||||
: topic(aTopic)
|
||||
, referentCount(aReferentCount)
|
||||
{
|
||||
}
|
||||
const char* topic;
|
||||
size_t referentCount;
|
||||
: mTopic(aTopic)
|
||||
, mReferentCount(aReferentCount)
|
||||
{}
|
||||
const char* mTopic;
|
||||
size_t mReferentCount;
|
||||
};
|
||||
|
||||
struct ObserverServiceReferentCount
|
||||
{
|
||||
ObserverServiceReferentCount()
|
||||
: numStrong(0)
|
||||
, numWeakAlive(0)
|
||||
, numWeakDead(0)
|
||||
{
|
||||
}
|
||||
size_t numStrong;
|
||||
size_t numWeakAlive;
|
||||
size_t numWeakDead;
|
||||
nsTArray<SuspectObserver> suspectObservers;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
PLDHashOperator
|
||||
nsObserverService::CountReferents(nsObserverList* aObserverList,
|
||||
void* aClosure)
|
||||
{
|
||||
if (!aObserverList) {
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
ObserverServiceReferentCount* referentCount =
|
||||
static_cast<ObserverServiceReferentCount*>(aClosure);
|
||||
|
||||
size_t numStrong = 0;
|
||||
size_t numWeakAlive = 0;
|
||||
size_t numWeakDead = 0;
|
||||
nsTArray<SuspectObserver> suspectObservers;
|
||||
|
||||
nsTArray<ObserverRef>& observers = aObserverList->mObservers;
|
||||
for (auto iter = mObserverTopicTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsObserverList* observerList = iter.Get();
|
||||
if (!observerList) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsTArray<ObserverRef>& observers = observerList->mObservers;
|
||||
for (uint32_t i = 0; i < observers.Length(); i++) {
|
||||
if (observers[i].isWeakRef) {
|
||||
nsCOMPtr<nsIObserver> observerRef(
|
||||
|
@ -102,38 +83,24 @@ nsObserverService::CountReferents(nsObserverList* aObserverList,
|
|||
}
|
||||
}
|
||||
|
||||
referentCount->numStrong += numStrong;
|
||||
referentCount->numWeakAlive += numWeakAlive;
|
||||
referentCount->numWeakDead += numWeakDead;
|
||||
|
||||
// Keep track of topics that have a suspiciously large number
|
||||
// of referents (symptom of leaks).
|
||||
size_t total = numStrong + numWeakAlive + numWeakDead;
|
||||
if (total > kSuspectReferentCount) {
|
||||
SuspectObserver suspect(aObserverList->GetKey(), total);
|
||||
referentCount->suspectObservers.AppendElement(suspect);
|
||||
SuspectObserver suspect(observerList->GetKey(), total);
|
||||
suspectObservers.AppendElement(suspect);
|
||||
}
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize)
|
||||
{
|
||||
ObserverServiceReferentCount referentCount;
|
||||
mObserverTopicTable.EnumerateEntries(CountReferents, &referentCount);
|
||||
|
||||
// These aren't privacy-sensitive and so don't need anonymizing.
|
||||
nsresult rv;
|
||||
for (uint32_t i = 0; i < referentCount.suspectObservers.Length(); i++) {
|
||||
SuspectObserver& suspect = referentCount.suspectObservers[i];
|
||||
nsPrintfCString suspectPath("observer-service-suspect/"
|
||||
"referent(topic=%s)",
|
||||
suspect.topic);
|
||||
for (uint32_t i = 0; i < suspectObservers.Length(); i++) {
|
||||
SuspectObserver& suspect = suspectObservers[i];
|
||||
nsPrintfCString suspectPath("observer-service-suspect/referent(topic=%s)",
|
||||
suspect.mTopic);
|
||||
rv = aHandleReport->Callback(
|
||||
/* process */ EmptyCString(),
|
||||
suspectPath, KIND_OTHER, UNITS_COUNT, suspect.referentCount,
|
||||
suspectPath, KIND_OTHER, UNITS_COUNT, suspect.mReferentCount,
|
||||
NS_LITERAL_CSTRING("A topic with a suspiciously large number of "
|
||||
"referents. This may be symptomatic of a leak "
|
||||
"if the number of referents is high with "
|
||||
|
@ -148,7 +115,7 @@ nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|||
rv = aHandleReport->Callback(
|
||||
/* process */ EmptyCString(),
|
||||
NS_LITERAL_CSTRING("observer-service/referent/strong"),
|
||||
KIND_OTHER, UNITS_COUNT, referentCount.numStrong,
|
||||
KIND_OTHER, UNITS_COUNT, numStrong,
|
||||
NS_LITERAL_CSTRING("The number of strong references held by the "
|
||||
"observer service."),
|
||||
aData);
|
||||
|
@ -160,7 +127,7 @@ nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|||
rv = aHandleReport->Callback(
|
||||
/* process */ EmptyCString(),
|
||||
NS_LITERAL_CSTRING("observer-service/referent/weak/alive"),
|
||||
KIND_OTHER, UNITS_COUNT, referentCount.numWeakAlive,
|
||||
KIND_OTHER, UNITS_COUNT, numWeakAlive,
|
||||
NS_LITERAL_CSTRING("The number of weak references held by the "
|
||||
"observer service that are still alive."),
|
||||
aData);
|
||||
|
@ -172,7 +139,7 @@ nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|||
rv = aHandleReport->Callback(
|
||||
/* process */ EmptyCString(),
|
||||
NS_LITERAL_CSTRING("observer-service/referent/weak/dead"),
|
||||
KIND_OTHER, UNITS_COUNT, referentCount.numWeakDead,
|
||||
KIND_OTHER, UNITS_COUNT, numWeakDead,
|
||||
NS_LITERAL_CSTRING("The number of weak references held by the "
|
||||
"observer service that are dead."),
|
||||
aData);
|
||||
|
@ -350,19 +317,6 @@ NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports* aSubject,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
static PLDHashOperator
|
||||
AppendStrongObservers(nsObserverList* aObserverList, void* aClosure)
|
||||
{
|
||||
nsCOMArray<nsIObserver>* array = static_cast<nsCOMArray<nsIObserver>*>(aClosure);
|
||||
|
||||
if (aObserverList) {
|
||||
aObserverList->AppendStrongObservers(*array);
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsObserverService::UnmarkGrayStrongObservers()
|
||||
{
|
||||
|
@ -370,7 +324,12 @@ nsObserverService::UnmarkGrayStrongObservers()
|
|||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
nsCOMArray<nsIObserver> strongObservers;
|
||||
mObserverTopicTable.EnumerateEntries(AppendStrongObservers, &strongObservers);
|
||||
for (auto iter = mObserverTopicTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsObserverList* aObserverList = iter.Get();
|
||||
if (aObserverList) {
|
||||
aObserverList->AppendStrongObservers(strongObservers);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < strongObservers.Length(); ++i) {
|
||||
xpc_TryUnmarkWrappedGrayObject(strongObservers[i]);
|
||||
|
|
|
@ -46,8 +46,6 @@ private:
|
|||
void RegisterReporter();
|
||||
|
||||
static const size_t kSuspectReferentCount = 100;
|
||||
static PLDHashOperator CountReferents(nsObserverList* aObserverList,
|
||||
void* aClosure);
|
||||
bool mShuttingDown;
|
||||
nsTHashtable<nsObserverList> mObserverTopicTable;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче