Bug 1122322 (follow-up) - Fix busted paths in worker memory reporter. r=bent, a=sledru
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1607,16 +1607,24 @@ public:
aWorkerPrivate->OfflineStatusChangeEventInternal(aCx, mIsOffline);
return true;
}
private:
bool mIsOffline;
};
+#ifdef DEBUG
+static bool
+StartsWithExplicit(nsACString& s)
+{
+ return StringBeginsWith(s, NS_LITERAL_CSTRING("explicit/"));
+}
+#endif
+
class WorkerJSRuntimeStats : public JS::RuntimeStats
{
const nsACString& mRtPath;
public:
explicit WorkerJSRuntimeStats(const nsACString& aRtPath)
: JS::RuntimeStats(JsWorkerMallocSizeOf), mRtPath(aRtPath)
{ }
@@ -1639,16 +1647,19 @@ public:
{
MOZ_ASSERT(!aZoneStats->extra);
// ReportJSRuntimeExplicitTreeStats expects that
// aZoneStats->extra is a xpc::ZoneStatsExtras pointer.
xpc::ZoneStatsExtras* extras = new xpc::ZoneStatsExtras;
extras->pathPrefix = mRtPath;
extras->pathPrefix += nsPrintfCString("zone(0x%p)/", (void *)aZone);
+
+ MOZ_ASSERT(StartsWithExplicit(extras->pathPrefix));
+
aZoneStats->extra = extras;
}
virtual void
initExtraCompartmentStats(JSCompartment* aCompartment,
JS::CompartmentStats* aCompartmentStats)
MOZ_OVERRIDE
{
@@ -1665,16 +1676,19 @@ public:
(void *)js::GetCompartmentZone(aCompartment));
extras->jsPathPrefix += js::IsAtomsCompartment(aCompartment)
? NS_LITERAL_CSTRING("compartment(web-worker-atoms)/")
: NS_LITERAL_CSTRING("compartment(web-worker)/");
// This should never be used when reporting with workers (hence the "?!").
extras->domPathPrefix.AssignLiteral("explicit/workers/?!/");
+ MOZ_ASSERT(StartsWithExplicit(extras->jsPathPrefix));
+ MOZ_ASSERT(StartsWithExplicit(extras->domPathPrefix));
+
extras->location = nullptr;
aCompartmentStats->extra = extras;
}
};
class MessagePortRunnable MOZ_FINAL : public WorkerRunnable
{
@@ -1900,25 +1914,24 @@ public:
NS_IMETHOD
CollectReports(nsIMemoryReporterCallback* aCallback,
nsISupports* aClosure, bool aAnonymize)
{
AssertIsOnMainThread();
// Assumes that WorkerJSRuntimeStats will hold a reference to |path|, and
- // not a copy, as TryToMapAddon() may later modify if.
+ // not a copy, as TryToMapAddon() may later modify it.
nsCString path;
WorkerJSRuntimeStats rtStats(path);
{
MutexAutoLock lock(mMutex);
- if (!mWorkerPrivate ||
- !mWorkerPrivate->BlockAndCollectRuntimeStats(&rtStats, aAnonymize)) {
+ if (!mWorkerPrivate) {
// Returning NS_OK here will effectively report 0 memory.
return NS_OK;
}
path.AppendLiteral("explicit/workers/workers(");
if (aAnonymize && !mWorkerPrivate->Domain().IsEmpty()) {
path.AppendLiteral("<anonymized-domain>)/worker(<anonymized-url>");
} else {
@@ -1932,16 +1945,21 @@ public:
path.AppendLiteral(")/worker(");
NS_ConvertUTF16toUTF8 escapedURL(mWorkerPrivate->ScriptURL());
escapedURL.ReplaceChar('/', '\\');
path.Append(escapedURL);
}
path.AppendPrintf(", 0x%p)/", static_cast<void*>(mWorkerPrivate));
TryToMapAddon(path);
+
+ if (!mWorkerPrivate->BlockAndCollectRuntimeStats(&rtStats, aAnonymize)) {
+ // Returning NS_OK here will effectively report 0 memory.
+ return NS_OK;
+ }
}
return xpc::ReportJSRuntimeExplicitTreeStats(rtStats, path,
aCallback, aClosure,
aAnonymize);
}
private:
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2661,18 +2661,17 @@ class OrphanReporter : public JS::Object
private:
nsTHashtable <nsISupportsHashKey> mAlreadyMeasuredOrphanTrees;
};
#ifdef DEBUG
static bool
StartsWithExplicit(nsACString& s)
{
- const char* e = "explicit/";
- return Substring(s, 0, strlen(e)).Equals(e);
+ return StringBeginsWith(s, NS_LITERAL_CSTRING("explicit/"));
}
#endif
class XPCJSRuntimeStats : public JS::RuntimeStats
{
WindowPaths *mWindowPaths;
WindowPaths *mTopWindowPaths;
bool mGetLocations;