Bug 1237201 part 7 - Handle Vector OOM in nsPerformanceStats, telemetry. r=Yoric

This commit is contained in:
Jan de Mooij 2016-01-14 15:19:37 +01:00
parent dabcd72958
commit 366cd49655
5 changed files with 41 additions and 14 deletions

View File

@ -221,8 +221,10 @@ AutoStopwatch::AutoStopwatch(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IM
}
for (auto group = groups->begin(); group < groups->end(); group++) {
auto acquired = acquireGroup(*group);
if (acquired)
groups_.append(acquired);
if (acquired) {
if (!groups_.append(acquired))
MOZ_CRASH();
}
}
if (groups_.length() == 0) {
// We are not in charge of monitoring anything.

View File

@ -164,7 +164,9 @@ nsPerformanceObservationTarget::SetTarget(nsPerformanceGroupDetails* details) {
NS_IMETHODIMP
nsPerformanceObservationTarget::AddJankObserver(nsIPerformanceObserver* observer) {
mObservers.append(observer);
if (!mObservers.append(observer)) {
MOZ_CRASH();
}
return NS_OK;
};
@ -188,7 +190,9 @@ void
nsPerformanceObservationTarget::NotifyJankObservers(nsIPerformanceGroupDetails* source, nsIPerformanceAlert* gravity) {
// Copy the vector to make sure that it won't change under our feet.
mozilla::Vector<nsCOMPtr<nsIPerformanceObserver>> observers;
observers.appendAll(mObservers);
if (!observers.appendAll(mObservers)) {
MOZ_CRASH();
}
// Now actually notify.
for (auto iter = observers.begin(), end = observers.end(); iter < end; ++iter) {
@ -733,7 +737,9 @@ nsPerformanceStatsService::Dispose()
// not modify the hashtable while iterating it.
GroupVector groups;
for (auto iter = mGroups.Iter(); !iter.Done(); iter.Next()) {
groups.append(iter.Get()->GetKey());
if (!groups.append(iter.Get()->GetKey())) {
MOZ_CRASH();
}
}
for (auto iter = groups.begin(), end = groups.end(); iter < end; ++iter) {
RefPtr<nsPerformanceGroup> group = *iter;
@ -1007,7 +1013,10 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx, JSGroupVector& ou
}
// All compartments belong to the top group.
out.append(mTopGroup);
if (!out.append(mTopGroup)) {
JS_ReportOutOfMemory(cx);
return false;
}
nsAutoString name;
CompartmentName(cx, global, name);
@ -1032,7 +1041,10 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx, JSGroupVector& ou
nsPerformanceGroup::GroupScope::ADDON)
);
}
out.append(entry->GetGroup());
if (!out.append(entry->GetGroup())) {
JS_ReportOutOfMemory(cx);
return false;
}
}
// Find out if the compartment is executed by a window. If so, its
@ -1054,7 +1066,10 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx, JSGroupVector& ou
nsPerformanceGroup::GroupScope::WINDOW)
);
}
out.append(entry->GetGroup());
if (!out.append(entry->GetGroup())) {
JS_ReportOutOfMemory(cx);
return false;
}
}
// All compartments have their own group.
@ -1063,7 +1078,10 @@ nsPerformanceStatsService::GetPerformanceGroups(JSContext* cx, JSGroupVector& ou
name, addonId, windowId,
mProcessId, isSystem,
nsPerformanceGroup::GroupScope::COMPARTMENT);
out.append(group);
if (!out.append(group)) {
JS_ReportOutOfMemory(cx);
return false;
}
return true;
}
@ -1190,8 +1208,9 @@ nsPerformanceStatsService::CommitGroup(uint64_t iteration,
if (totalTimeDelta >= mJankAlertThreshold) {
if (!group->HasPendingAlert()) {
group->SetHasPendingAlert(true);
mPendingAlerts.append(group);
if (mPendingAlerts.append(group)) {
group->SetHasPendingAlert(true);
}
return;
}
}

View File

@ -16,6 +16,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/Likely.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/unused.h"
#include "base/histogram.h"
#include "base/pickle.h"
@ -3669,7 +3670,8 @@ TelemetryImpl::RecordThreadHangStats(Telemetry::ThreadHangStats& aStats)
MutexAutoLock autoLock(sTelemetry->mThreadHangStatsMutex);
sTelemetry->mThreadHangStats.append(Move(aStats));
// Ignore OOM.
mozilla::Unused << sTelemetry->mThreadHangStats.append(Move(aStats));
}
NS_IMPL_ISUPPORTS(TelemetryImpl, nsITelemetry, nsIMemoryReporter)

View File

@ -187,7 +187,9 @@ public:
void Add(PRIntervalTime aTime, HangMonitor::HangAnnotationsPtr aAnnotations) {
TimeHistogram::Add(aTime);
if (aAnnotations) {
mAnnotations.append(Move(aAnnotations));
if (!mAnnotations.append(Move(aAnnotations))) {
MOZ_CRASH();
}
}
}
};

View File

@ -437,7 +437,9 @@ BackgroundHangThread::ReportHang(PRIntervalTime aHangTime)
}
// Add new histogram
newHistogram.Add(aHangTime, Move(mAnnotations));
mStats.mHangs.append(Move(newHistogram));
if (!mStats.mHangs.append(Move(newHistogram))) {
MOZ_CRASH();
}
return mStats.mHangs.back();
}