Bug 546477 - add explicit/js/stack memory reporter. r=luke.

This commit is contained in:
Nicholas Nethercote 2011-06-02 19:40:57 -07:00
parent f4a9b1d48b
commit 5270309d78
3 changed files with 32 additions and 7 deletions

View File

@ -156,9 +156,7 @@ StackSegment::computeNextFrame(StackFrame *fp) const
StackSpace::StackSpace()
: base_(NULL),
#ifdef XP_WIN
commitEnd_(NULL),
#endif
end_(NULL),
seg_(NULL)
{
@ -188,14 +186,14 @@ StackSpace::init()
DosAllocMem(&p, CAPACITY_BYTES, PAG_COMMIT | PAG_READ | PAG_WRITE))
return false;
base_ = reinterpret_cast<Value *>(p);
end_ = base_ + CAPACITY_VALS;
end_ = commitEnd_ = base_ + CAPACITY_VALS;
#else
JS_ASSERT(CAPACITY_BYTES % getpagesize() == 0);
p = mmap(NULL, CAPACITY_BYTES, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
return false;
base_ = reinterpret_cast<Value *>(p);
end_ = base_ + CAPACITY_VALS;
end_ = commitEnd_ = base_ + CAPACITY_VALS;
#endif
return true;
}
@ -356,6 +354,12 @@ StackSpace::pushSegment(StackSegment &seg)
seg_ = &seg;
}
size_t
StackSpace::committedSize()
{
return (commitEnd_ - base_) * sizeof(Value);
}
/*****************************************************************************/
ContextStack::ContextStack(JSContext *cx)

View File

@ -1046,10 +1046,8 @@ struct StackOverride
class StackSpace
{
Value *base_;
#ifdef XP_WIN
mutable Value *commitEnd_;
#endif
Value *end_;
Value *end_;
StackSegment *seg_;
StackOverride override_;
@ -1124,6 +1122,9 @@ class StackSpace
/* Called during GC: mark segments, frames, and slots under firstUnused. */
void mark(JSTracer *trc);
/* We only report the committed size; uncommitted size is uninteresting. */
JS_FRIEND_API(size_t) committedSize();
};
/*****************************************************************************/

View File

@ -1286,6 +1286,25 @@ GetPerCompartmentSize(PRInt64 (*f)(JSCompartment *c))
return n;
}
static PRInt64
GetJSStack(void *data)
{
JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->GetJSRuntime();
PRInt64 n = 0;
for (js::ThreadDataIter i(rt); !i.empty(); i.popFront())
n += i.threadData()->stackSpace.committedSize();
return n;
}
NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSStack,
"explicit/js/stack",
MR_MAPPED,
"Memory used for the JavaScript stack. This is the committed portion "
"of the stack; any uncommitted portion is not measured because it "
"hardly costs anything.",
GetJSStack,
NULL)
#ifdef JS_METHODJIT
static PRInt64
@ -1458,6 +1477,7 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
mJSRuntime->setCustomGCChunkAllocator(&gXPCJSChunkAllocator);
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSGCHeap));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSStack));
#ifdef JS_METHODJIT
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSMjitCode));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSMjitData));