mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 749010 (part 2) - Move code around to merge two anonymous namespaces; no functional changes. r=bent.
This commit is contained in:
parent
d572db8f5f
commit
125cde6303
@ -74,6 +74,8 @@ USING_WORKERS_NAMESPACE
|
||||
using namespace mozilla::dom::workers::events;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(JsWorkerMallocSizeOf, "js-worker")
|
||||
|
||||
namespace {
|
||||
|
||||
const char gErrorChars[] = "error";
|
||||
@ -123,171 +125,6 @@ SwapToISupportsArray(SmartPtr<T>& aSrc,
|
||||
dest->swap(rawSupports);
|
||||
}
|
||||
|
||||
} /* anonymous namespace */
|
||||
|
||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(JsWorkerMallocSizeOf, "js-worker")
|
||||
|
||||
struct WorkerJSRuntimeStats : public JS::RuntimeStats
|
||||
{
|
||||
WorkerJSRuntimeStats(nsACString &aRtPath)
|
||||
: JS::RuntimeStats(JsWorkerMallocSizeOf), mRtPath(aRtPath) { }
|
||||
|
||||
~WorkerJSRuntimeStats() {
|
||||
for (size_t i = 0; i != compartmentStatsVector.length(); i++) {
|
||||
free(compartmentStatsVector[i].extra1);
|
||||
// no need to free |extra2|, because it's a static string
|
||||
}
|
||||
}
|
||||
|
||||
virtual void initExtraCompartmentStats(JSCompartment *c,
|
||||
JS::CompartmentStats *cstats) MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(!cstats->extra1);
|
||||
MOZ_ASSERT(!cstats->extra2);
|
||||
|
||||
// ReportJSRuntimeExplicitTreeStats expects that cstats->{extra1,extra2}
|
||||
// are char pointers.
|
||||
|
||||
// This is the |cJSPathPrefix|. Each worker has exactly two compartments:
|
||||
// one for atoms, and one for everything else.
|
||||
nsCString cJSPathPrefix(mRtPath);
|
||||
cJSPathPrefix += js::IsAtomsCompartment(c)
|
||||
? NS_LITERAL_CSTRING("compartment(web-worker-atoms)/")
|
||||
: NS_LITERAL_CSTRING("compartment(web-worker)/");
|
||||
cstats->extra1 = strdup(cJSPathPrefix.get());
|
||||
|
||||
// This is the |cDOMPathPrefix|, which should never be used when reporting
|
||||
// with workers (hence the "?!").
|
||||
cstats->extra2 = (void *)"explicit/workers/?!/";
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString mRtPath;
|
||||
};
|
||||
|
||||
BEGIN_WORKERS_NAMESPACE
|
||||
|
||||
class WorkerMemoryReporter MOZ_FINAL : public nsIMemoryMultiReporter
|
||||
{
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsCString mAddressString;
|
||||
nsCString mRtPath;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
WorkerMemoryReporter(WorkerPrivate* aWorkerPrivate)
|
||||
: mWorkerPrivate(aWorkerPrivate)
|
||||
{
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
nsCString escapedDomain(aWorkerPrivate->Domain());
|
||||
escapedDomain.ReplaceChar('/', '\\');
|
||||
|
||||
NS_ConvertUTF16toUTF8 escapedURL(aWorkerPrivate->ScriptURL());
|
||||
escapedURL.ReplaceChar('/', '\\');
|
||||
|
||||
{
|
||||
// 64bit address plus '0x' plus null terminator.
|
||||
char address[21];
|
||||
uint32_t addressSize =
|
||||
JS_snprintf(address, sizeof(address), "%p", aWorkerPrivate);
|
||||
if (addressSize != uint32_t(-1)) {
|
||||
mAddressString.Assign(address, addressSize);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("JS_snprintf failed!");
|
||||
mAddressString.AssignLiteral("<unknown address>");
|
||||
}
|
||||
}
|
||||
|
||||
mRtPath = NS_LITERAL_CSTRING("explicit/workers/workers(") +
|
||||
escapedDomain + NS_LITERAL_CSTRING(")/worker(") +
|
||||
escapedURL + NS_LITERAL_CSTRING(", ") + mAddressString +
|
||||
NS_LITERAL_CSTRING(")/");
|
||||
}
|
||||
|
||||
nsresult
|
||||
CollectForRuntime(bool aIsQuick, void* aData)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (!mWorkerPrivate) {
|
||||
#ifdef DEBUG
|
||||
nsCAutoString message("Unable to report memory for ");
|
||||
if (mWorkerPrivate->IsChromeWorker()) {
|
||||
message.AppendLiteral("Chrome");
|
||||
}
|
||||
message += NS_LITERAL_CSTRING("Worker (") + mAddressString +
|
||||
NS_LITERAL_CSTRING(")! It is either using ctypes or is in "
|
||||
"the process of being destroyed");
|
||||
NS_WARNING(message.get());
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mWorkerPrivate->BlockAndCollectRuntimeStats(aIsQuick, aData)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetName(nsACString &aName)
|
||||
{
|
||||
aName.AssignLiteral("workers");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
CollectReports(nsIMemoryMultiReporterCallback* aCallback,
|
||||
nsISupports* aClosure)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
WorkerJSRuntimeStats rtStats(mRtPath);
|
||||
nsresult rv = CollectForRuntime(/* isQuick = */false, &rtStats);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Always report, even if we're disabled, so that we at least get an entry
|
||||
// in about::memory.
|
||||
return xpc::ReportJSRuntimeExplicitTreeStats(rtStats, mRtPath,
|
||||
aCallback, aClosure);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
GetExplicitNonHeap(PRInt64 *aAmount)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
return CollectForRuntime(/* isQuick = */true, aAmount);
|
||||
}
|
||||
|
||||
void Disable()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
// Setting mWorkerPrivate to nsnull is safe only because we've locked the
|
||||
// worker's mutex on the worker's thread, in the caller. So we check that.
|
||||
//
|
||||
// Also, we may have already disabled the reporter (and thus set
|
||||
// mWorkerPrivate to nsnull) due to the use of CTypes (see
|
||||
// ChromeWorkerScope.cpp). That's why the NULL check is necessary.
|
||||
if (mWorkerPrivate) {
|
||||
mWorkerPrivate->mMutex.AssertCurrentThreadOwns();
|
||||
}
|
||||
#endif
|
||||
mWorkerPrivate = nsnull;
|
||||
}
|
||||
};
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(WorkerMemoryReporter, nsIMemoryMultiReporter)
|
||||
|
||||
namespace {
|
||||
|
||||
struct WorkerStructuredCloneCallbacks
|
||||
{
|
||||
static JSObject*
|
||||
@ -1629,6 +1466,165 @@ public:
|
||||
|
||||
} /* anonymous namespace */
|
||||
|
||||
struct WorkerJSRuntimeStats : public JS::RuntimeStats
|
||||
{
|
||||
WorkerJSRuntimeStats(nsACString &aRtPath)
|
||||
: JS::RuntimeStats(JsWorkerMallocSizeOf), mRtPath(aRtPath) { }
|
||||
|
||||
~WorkerJSRuntimeStats() {
|
||||
for (size_t i = 0; i != compartmentStatsVector.length(); i++) {
|
||||
free(compartmentStatsVector[i].extra1);
|
||||
// no need to free |extra2|, because it's a static string
|
||||
}
|
||||
}
|
||||
|
||||
virtual void initExtraCompartmentStats(JSCompartment *c,
|
||||
JS::CompartmentStats *cstats) MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(!cstats->extra1);
|
||||
MOZ_ASSERT(!cstats->extra2);
|
||||
|
||||
// ReportJSRuntimeExplicitTreeStats expects that cstats->{extra1,extra2}
|
||||
// are char pointers.
|
||||
|
||||
// This is the |cJSPathPrefix|. Each worker has exactly two compartments:
|
||||
// one for atoms, and one for everything else.
|
||||
nsCString cJSPathPrefix(mRtPath);
|
||||
cJSPathPrefix += js::IsAtomsCompartment(c)
|
||||
? NS_LITERAL_CSTRING("compartment(web-worker-atoms)/")
|
||||
: NS_LITERAL_CSTRING("compartment(web-worker)/");
|
||||
cstats->extra1 = strdup(cJSPathPrefix.get());
|
||||
|
||||
// This is the |cDOMPathPrefix|, which should never be used when reporting
|
||||
// with workers (hence the "?!").
|
||||
cstats->extra2 = (void *)"explicit/workers/?!/";
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString mRtPath;
|
||||
};
|
||||
|
||||
BEGIN_WORKERS_NAMESPACE
|
||||
|
||||
class WorkerMemoryReporter MOZ_FINAL : public nsIMemoryMultiReporter
|
||||
{
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsCString mAddressString;
|
||||
nsCString mRtPath;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
WorkerMemoryReporter(WorkerPrivate* aWorkerPrivate)
|
||||
: mWorkerPrivate(aWorkerPrivate)
|
||||
{
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
nsCString escapedDomain(aWorkerPrivate->Domain());
|
||||
escapedDomain.ReplaceChar('/', '\\');
|
||||
|
||||
NS_ConvertUTF16toUTF8 escapedURL(aWorkerPrivate->ScriptURL());
|
||||
escapedURL.ReplaceChar('/', '\\');
|
||||
|
||||
{
|
||||
// 64bit address plus '0x' plus null terminator.
|
||||
char address[21];
|
||||
uint32_t addressSize =
|
||||
JS_snprintf(address, sizeof(address), "%p", aWorkerPrivate);
|
||||
if (addressSize != uint32_t(-1)) {
|
||||
mAddressString.Assign(address, addressSize);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("JS_snprintf failed!");
|
||||
mAddressString.AssignLiteral("<unknown address>");
|
||||
}
|
||||
}
|
||||
|
||||
mRtPath = NS_LITERAL_CSTRING("explicit/workers/workers(") +
|
||||
escapedDomain + NS_LITERAL_CSTRING(")/worker(") +
|
||||
escapedURL + NS_LITERAL_CSTRING(", ") + mAddressString +
|
||||
NS_LITERAL_CSTRING(")/");
|
||||
}
|
||||
|
||||
nsresult
|
||||
CollectForRuntime(bool aIsQuick, void* aData)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (!mWorkerPrivate) {
|
||||
#ifdef DEBUG
|
||||
nsCAutoString message("Unable to report memory for ");
|
||||
if (mWorkerPrivate->IsChromeWorker()) {
|
||||
message.AppendLiteral("Chrome");
|
||||
}
|
||||
message += NS_LITERAL_CSTRING("Worker (") + mAddressString +
|
||||
NS_LITERAL_CSTRING(")! It is either using ctypes or is in "
|
||||
"the process of being destroyed");
|
||||
NS_WARNING(message.get());
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mWorkerPrivate->BlockAndCollectRuntimeStats(aIsQuick, aData)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetName(nsACString &aName)
|
||||
{
|
||||
aName.AssignLiteral("workers");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
CollectReports(nsIMemoryMultiReporterCallback* aCallback,
|
||||
nsISupports* aClosure)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
WorkerJSRuntimeStats rtStats(mRtPath);
|
||||
nsresult rv = CollectForRuntime(/* isQuick = */false, &rtStats);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Always report, even if we're disabled, so that we at least get an entry
|
||||
// in about::memory.
|
||||
return xpc::ReportJSRuntimeExplicitTreeStats(rtStats, mRtPath,
|
||||
aCallback, aClosure);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
GetExplicitNonHeap(PRInt64 *aAmount)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
return CollectForRuntime(/* isQuick = */true, aAmount);
|
||||
}
|
||||
|
||||
void Disable()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
// Setting mWorkerPrivate to nsnull is safe only because we've locked the
|
||||
// worker's mutex on the worker's thread, in the caller. So we check that.
|
||||
//
|
||||
// Also, we may have already disabled the reporter (and thus set
|
||||
// mWorkerPrivate to nsnull) due to the use of CTypes (see
|
||||
// ChromeWorkerScope.cpp). That's why the NULL check is necessary.
|
||||
if (mWorkerPrivate) {
|
||||
mWorkerPrivate->mMutex.AssertCurrentThreadOwns();
|
||||
}
|
||||
#endif
|
||||
mWorkerPrivate = nsnull;
|
||||
}
|
||||
};
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(WorkerMemoryReporter, nsIMemoryMultiReporter)
|
||||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
mozilla::dom::workers::AssertIsOnMainThread()
|
||||
|
Loading…
x
Reference in New Issue
Block a user