2013-04-17 00:47:10 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-24 12:27:39 +04:00
|
|
|
|
|
|
|
#ifndef js_MemoryMetrics_h
|
|
|
|
#define js_MemoryMetrics_h
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
// These declarations are highly likely to change in the future. Depend on them
|
|
|
|
// at your own risk.
|
2011-12-24 12:27:39 +04:00
|
|
|
|
2013-06-23 15:21:01 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-09-19 23:24:53 +04:00
|
|
|
#include "mozilla/NullPtr.h"
|
2013-08-06 03:33:00 +04:00
|
|
|
#include "mozilla/PodOperations.h"
|
2013-06-23 15:21:01 +04:00
|
|
|
|
2012-01-11 12:23:08 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-01-11 12:23:08 +04:00
|
|
|
#include "jsalloc.h"
|
2011-12-24 12:27:39 +04:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
#include "js/HashTable.h"
|
2011-12-24 12:27:39 +04:00
|
|
|
#include "js/Utility.h"
|
2012-01-11 12:23:08 +04:00
|
|
|
#include "js/Vector.h"
|
2011-12-24 12:27:39 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
class nsISupports; // Needed for ObjectPrivateVisitor.
|
2013-01-07 08:43:54 +04:00
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
struct TabSizes
|
|
|
|
{
|
|
|
|
enum Kind {
|
|
|
|
Objects,
|
|
|
|
Strings,
|
|
|
|
Private,
|
|
|
|
Other
|
|
|
|
};
|
|
|
|
|
|
|
|
TabSizes() { mozilla::PodZero(this); }
|
|
|
|
|
|
|
|
void add(Kind kind, size_t n) {
|
|
|
|
switch (kind) {
|
|
|
|
case Objects: objects += n; break;
|
|
|
|
case Strings: strings += n; break;
|
|
|
|
case Private: private_ += n; break;
|
|
|
|
case Other: other += n; break;
|
|
|
|
default: MOZ_CRASH("bad TabSizes kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t objects;
|
|
|
|
size_t strings;
|
|
|
|
size_t private_;
|
|
|
|
size_t other;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace JS
|
|
|
|
|
2012-10-17 18:44:31 +04:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
// In memory reporting, we have concept of "sundries", line items which are too
|
|
|
|
// small to be worth reporting individually. Under some circumstances, a memory
|
|
|
|
// reporter gets tossed into the sundries bucket if it's smaller than
|
|
|
|
// MemoryReportingSundriesThreshold() bytes.
|
|
|
|
//
|
|
|
|
// We need to define this value here, rather than in the code which actually
|
2013-08-06 03:33:00 +04:00
|
|
|
// generates the memory reports, because NotableStringInfo uses this value.
|
2012-10-17 18:44:31 +04:00
|
|
|
JS_FRIEND_API(size_t) MemoryReportingSundriesThreshold();
|
|
|
|
|
2013-08-22 22:54:34 +04:00
|
|
|
// This hash policy avoids flattening ropes (which perturbs the site being
|
|
|
|
// measured and requires a JSContext) at the expense of doing a FULL ROPE COPY
|
|
|
|
// on every hash and match! Beware.
|
|
|
|
struct InefficientNonFlatteningStringHashPolicy
|
2013-08-06 03:33:00 +04:00
|
|
|
{
|
|
|
|
typedef JSString *Lookup;
|
|
|
|
static HashNumber hash(const Lookup &l);
|
|
|
|
static bool match(const JSString *const &k, const Lookup &l);
|
|
|
|
};
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
// This file features many classes with numerous size_t fields, and each such
|
|
|
|
// class has one or more methods that need to operate on all of these fields.
|
|
|
|
// Writing these individually is error-prone -- it's easy to add a new field
|
|
|
|
// without updating all the required methods. So we define a single macro list
|
|
|
|
// in each class to name the fields (and notable characteristics of them), and
|
|
|
|
// then use the following macros to transform those lists into the required
|
|
|
|
// methods.
|
|
|
|
//
|
|
|
|
// In some classes, one or more of the macro arguments aren't used. We use '_'
|
|
|
|
// for those.
|
|
|
|
//
|
2013-10-23 01:53:26 +04:00
|
|
|
#define DECL_SIZE(kind, gc, mSize) size_t mSize;
|
|
|
|
#define ZERO_SIZE(kind, gc, mSize) mSize(0),
|
|
|
|
#define COPY_OTHER_SIZE(kind, gc, mSize) mSize(other.mSize),
|
|
|
|
#define ADD_OTHER_SIZE(kind, gc, mSize) mSize += other.mSize;
|
|
|
|
#define ADD_SIZE_TO_N_IF_LIVE_GC_THING(kind, gc, mSize) n += (js::gc == js::IsLiveGCThing) ? mSize : 0;
|
|
|
|
#define ADD_TO_TAB_SIZES(kind, gc, mSize) sizes->add(JS::TabSizes::kind, mSize);
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
// Used to annotate which size_t fields measure live GC things and which don't.
|
|
|
|
enum {
|
2013-10-09 01:15:59 +04:00
|
|
|
NotLiveGCThing = false,
|
|
|
|
IsLiveGCThing = true
|
2013-09-25 10:24:28 +04:00
|
|
|
};
|
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
struct ZoneStatsPod
|
|
|
|
{
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(macro) \
|
2013-10-23 01:53:26 +04:00
|
|
|
macro(Other, NotLiveGCThing, gcHeapArenaAdmin) \
|
|
|
|
macro(Other, NotLiveGCThing, unusedGCThings) \
|
|
|
|
macro(Other, IsLiveGCThing, lazyScriptsGCHeap) \
|
|
|
|
macro(Other, NotLiveGCThing, lazyScriptsMallocHeap) \
|
|
|
|
macro(Other, IsLiveGCThing, ionCodesGCHeap) \
|
|
|
|
macro(Other, IsLiveGCThing, typeObjectsGCHeap) \
|
|
|
|
macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \
|
|
|
|
macro(Other, NotLiveGCThing, typePool) \
|
|
|
|
macro(Strings, IsLiveGCThing, stringsShortGCHeap) \
|
|
|
|
macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \
|
|
|
|
macro(Strings, NotLiveGCThing, stringsNormalMallocHeap)
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
ZoneStatsPod()
|
|
|
|
: FOR_EACH_SIZE(ZERO_SIZE)
|
|
|
|
extra()
|
|
|
|
{}
|
2013-08-06 03:33:00 +04:00
|
|
|
|
|
|
|
void add(const ZoneStatsPod &other) {
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE)
|
|
|
|
// Do nothing with |extra|.
|
2013-08-06 03:33:00 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = 0;
|
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING)
|
|
|
|
// Do nothing with |extra|.
|
|
|
|
return n;
|
|
|
|
}
|
2013-08-06 03:33:00 +04:00
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
void addToTabSizes(JS::TabSizes *sizes) const {
|
|
|
|
FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
|
|
|
|
// Do nothing with |extra|.
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE)
|
|
|
|
void *extra; // This field can be used by embedders.
|
2013-08-06 03:33:00 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
#undef FOR_EACH_SIZE
|
2013-08-06 03:33:00 +04:00
|
|
|
};
|
|
|
|
|
2012-10-17 18:44:31 +04:00
|
|
|
} // namespace js
|
|
|
|
|
2011-12-24 12:27:39 +04:00
|
|
|
namespace JS {
|
|
|
|
|
2012-11-22 05:07:42 +04:00
|
|
|
// Data for tracking memory usage of things hanging off objects.
|
2013-03-17 07:36:37 +04:00
|
|
|
struct ObjectsExtraSizes
|
|
|
|
{
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(macro) \
|
2013-10-23 01:53:26 +04:00
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapSlots) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \
|
|
|
|
macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \
|
|
|
|
macro(Objects, NotLiveGCThing, nonHeapCodeAsmJS) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapAsmJSModuleData) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapArgumentsData) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapRegExpStatics) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapPropertyIteratorData) \
|
|
|
|
macro(Objects, NotLiveGCThing, mallocHeapCtypesData)
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
ObjectsExtraSizes()
|
|
|
|
: FOR_EACH_SIZE(ZERO_SIZE)
|
|
|
|
dummy()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void add(const ObjectsExtraSizes &other) {
|
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE)
|
2012-11-22 05:07:42 +04:00
|
|
|
}
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = 0;
|
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING)
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
void addToTabSizes(TabSizes *sizes) const {
|
|
|
|
FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE)
|
|
|
|
int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE)
|
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
2012-11-22 05:07:42 +04:00
|
|
|
};
|
|
|
|
|
2013-03-20 14:24:17 +04:00
|
|
|
// Data for tracking JIT-code memory usage.
|
|
|
|
struct CodeSizes
|
|
|
|
{
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(macro) \
|
2013-10-23 01:53:26 +04:00
|
|
|
macro(_, _, ion) \
|
|
|
|
macro(_, _, baseline) \
|
|
|
|
macro(_, _, regexp) \
|
|
|
|
macro(_, _, other) \
|
|
|
|
macro(_, _, unused)
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
CodeSizes()
|
|
|
|
: FOR_EACH_SIZE(ZERO_SIZE)
|
|
|
|
dummy()
|
|
|
|
{}
|
2013-03-20 14:24:17 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE)
|
|
|
|
int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE)
|
2013-03-20 14:24:17 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
2013-08-06 03:33:00 +04:00
|
|
|
|
|
|
|
// This class holds information about the memory taken up by identical copies of
|
|
|
|
// a particular string. Multiple JSStrings may have their sizes aggregated
|
|
|
|
// together into one StringInfo object.
|
|
|
|
struct StringInfo
|
2012-10-17 18:44:31 +04:00
|
|
|
{
|
2013-08-06 03:33:00 +04:00
|
|
|
StringInfo()
|
2013-09-25 10:24:28 +04:00
|
|
|
: length(0), numCopies(0), shortGCHeap(0), normalGCHeap(0), normalMallocHeap(0)
|
2013-08-06 03:33:00 +04:00
|
|
|
{}
|
2012-10-17 18:44:31 +04:00
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
StringInfo(size_t len, size_t shorts, size_t normals, size_t chars)
|
|
|
|
: length(len),
|
|
|
|
numCopies(1),
|
2013-09-25 10:24:28 +04:00
|
|
|
shortGCHeap(shorts),
|
|
|
|
normalGCHeap(normals),
|
|
|
|
normalMallocHeap(chars)
|
2013-08-06 03:33:00 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
void add(size_t shorts, size_t normals, size_t chars) {
|
2013-09-25 10:24:28 +04:00
|
|
|
shortGCHeap += shorts;
|
|
|
|
normalGCHeap += normals;
|
|
|
|
normalMallocHeap += chars;
|
2013-08-06 03:33:00 +04:00
|
|
|
numCopies++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(const StringInfo& info) {
|
|
|
|
MOZ_ASSERT(length == info.length);
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
shortGCHeap += info.shortGCHeap;
|
|
|
|
normalGCHeap += info.normalGCHeap;
|
|
|
|
normalMallocHeap += info.normalMallocHeap;
|
2013-08-06 03:33:00 +04:00
|
|
|
numCopies += info.numCopies;
|
2012-10-17 18:44:31 +04:00
|
|
|
}
|
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
size_t totalSizeOf() const {
|
2013-09-25 10:24:28 +04:00
|
|
|
return shortGCHeap + normalGCHeap + normalMallocHeap;
|
2013-08-06 03:33:00 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t totalGCHeapSizeOf() const {
|
|
|
|
return shortGCHeap + normalGCHeap;
|
2013-08-06 03:33:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The string's length, excluding the null-terminator.
|
2012-10-17 18:44:31 +04:00
|
|
|
size_t length;
|
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
// How many copies of the string have we seen?
|
|
|
|
size_t numCopies;
|
|
|
|
|
|
|
|
// These are all totals across all copies of the string we've seen.
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t shortGCHeap;
|
|
|
|
size_t normalGCHeap;
|
|
|
|
size_t normalMallocHeap;
|
2013-08-06 03:33:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Holds data about a notable string (one which uses more than
|
|
|
|
// NotableStringInfo::notableSize() bytes of memory), so we can report it
|
|
|
|
// individually.
|
|
|
|
//
|
|
|
|
// Essentially the only difference between this class and StringInfo is that
|
|
|
|
// NotableStringInfo holds a copy of the string's chars.
|
|
|
|
struct NotableStringInfo : public StringInfo
|
|
|
|
{
|
|
|
|
NotableStringInfo();
|
|
|
|
NotableStringInfo(JSString *str, const StringInfo &info);
|
|
|
|
NotableStringInfo(const NotableStringInfo& info);
|
|
|
|
NotableStringInfo(mozilla::MoveRef<NotableStringInfo> info);
|
|
|
|
NotableStringInfo &operator=(mozilla::MoveRef<NotableStringInfo> info);
|
|
|
|
|
|
|
|
~NotableStringInfo() {
|
|
|
|
js_free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// A string needs to take up this many bytes of storage before we consider
|
|
|
|
// it to be "notable".
|
|
|
|
static size_t notableSize() {
|
|
|
|
return js::MemoryReportingSundriesThreshold();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The amount of memory we requested for |buffer|; i.e.
|
|
|
|
// buffer = malloc(bufferSize).
|
|
|
|
size_t bufferSize;
|
|
|
|
char *buffer;
|
2012-10-17 18:44:31 +04:00
|
|
|
};
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
// These measurements relate directly to the JSRuntime, and not to zones and
|
2012-05-16 06:29:14 +04:00
|
|
|
// compartments within it.
|
|
|
|
struct RuntimeSizes
|
|
|
|
{
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(macro) \
|
2013-10-23 01:53:26 +04:00
|
|
|
macro(_, _, object) \
|
|
|
|
macro(_, _, atomsTable) \
|
|
|
|
macro(_, _, contexts) \
|
|
|
|
macro(_, _, dtoa) \
|
|
|
|
macro(_, _, temporary) \
|
|
|
|
macro(_, _, regexpData) \
|
|
|
|
macro(_, _, interpreterStack) \
|
|
|
|
macro(_, _, gcMarker) \
|
|
|
|
macro(_, _, mathCache) \
|
|
|
|
macro(_, _, scriptData) \
|
|
|
|
macro(_, _, scriptSources)
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
RuntimeSizes()
|
|
|
|
: FOR_EACH_SIZE(ZERO_SIZE)
|
|
|
|
code()
|
|
|
|
{}
|
2013-03-20 14:24:17 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE)
|
2013-03-20 14:24:17 +04:00
|
|
|
CodeSizes code;
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
2012-05-16 06:29:14 +04:00
|
|
|
};
|
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
struct ZoneStats : js::ZoneStatsPod
|
2013-03-17 07:36:37 +04:00
|
|
|
{
|
2013-08-06 03:33:00 +04:00
|
|
|
ZoneStats() {
|
|
|
|
strings.init();
|
2013-03-17 07:36:37 +04:00
|
|
|
}
|
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
ZoneStats(mozilla::MoveRef<ZoneStats> other)
|
|
|
|
: ZoneStatsPod(other),
|
2013-08-29 22:54:14 +04:00
|
|
|
strings(mozilla::OldMove(other->strings)),
|
|
|
|
notableStrings(mozilla::OldMove(other->notableStrings))
|
2013-08-06 03:33:00 +04:00
|
|
|
{}
|
2013-03-17 07:36:37 +04:00
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
// Add other's numbers to this object's numbers. Both objects'
|
|
|
|
// notableStrings vectors must be empty at this point, because we can't
|
|
|
|
// merge them. (A NotableStringInfo contains only a prefix of the string,
|
|
|
|
// so we can't tell whether two NotableStringInfo objects correspond to the
|
|
|
|
// same string.)
|
|
|
|
void add(const ZoneStats &other) {
|
|
|
|
ZoneStatsPod::add(other);
|
|
|
|
|
|
|
|
MOZ_ASSERT(notableStrings.empty());
|
|
|
|
MOZ_ASSERT(other.notableStrings.empty());
|
|
|
|
|
|
|
|
for (StringsHashMap::Range r = other.strings.all(); !r.empty(); r.popFront()) {
|
|
|
|
StringsHashMap::AddPtr p = strings.lookupForAdd(r.front().key);
|
|
|
|
if (p) {
|
|
|
|
// We've seen this string before; add its size to our tally.
|
|
|
|
p->value.add(r.front().value);
|
|
|
|
} else {
|
|
|
|
// We haven't seen this string before; add it to the hashtable.
|
|
|
|
strings.add(p, r.front().key, r.front().value);
|
|
|
|
}
|
|
|
|
}
|
2013-03-17 07:36:37 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:29 +04:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = ZoneStatsPod::sizeOfLiveGCThings();
|
|
|
|
for (size_t i = 0; i < notableStrings.length(); i++) {
|
|
|
|
const JS::NotableStringInfo& info = notableStrings[i];
|
|
|
|
n += info.totalGCHeapSizeOf();
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-08-22 22:54:34 +04:00
|
|
|
typedef js::HashMap<JSString*,
|
|
|
|
StringInfo,
|
|
|
|
js::InefficientNonFlatteningStringHashPolicy,
|
|
|
|
js::SystemAllocPolicy> StringsHashMap;
|
2013-03-17 07:36:37 +04:00
|
|
|
|
2013-08-06 03:33:00 +04:00
|
|
|
StringsHashMap strings;
|
|
|
|
js::Vector<NotableStringInfo, 0, js::SystemAllocPolicy> notableStrings;
|
2013-03-17 07:36:37 +04:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:23:08 +04:00
|
|
|
struct CompartmentStats
|
|
|
|
{
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(macro) \
|
2013-10-23 01:53:26 +04:00
|
|
|
macro(Objects, IsLiveGCThing, objectsGCHeapOrdinary) \
|
|
|
|
macro(Objects, IsLiveGCThing, objectsGCHeapFunction) \
|
|
|
|
macro(Objects, IsLiveGCThing, objectsGCHeapDenseArray) \
|
|
|
|
macro(Objects, IsLiveGCThing, objectsGCHeapSlowArray) \
|
|
|
|
macro(Objects, IsLiveGCThing, objectsGCHeapCrossCompartmentWrapper) \
|
|
|
|
macro(Private, NotLiveGCThing, objectsPrivate) \
|
|
|
|
macro(Other, IsLiveGCThing, shapesGCHeapTreeGlobalParented) \
|
|
|
|
macro(Other, IsLiveGCThing, shapesGCHeapTreeNonGlobalParented) \
|
|
|
|
macro(Other, IsLiveGCThing, shapesGCHeapDict) \
|
|
|
|
macro(Other, IsLiveGCThing, shapesGCHeapBase) \
|
|
|
|
macro(Other, NotLiveGCThing, shapesMallocHeapTreeTables) \
|
|
|
|
macro(Other, NotLiveGCThing, shapesMallocHeapDictTables) \
|
|
|
|
macro(Other, NotLiveGCThing, shapesMallocHeapTreeShapeKids) \
|
|
|
|
macro(Other, NotLiveGCThing, shapesMallocHeapCompartmentTables) \
|
|
|
|
macro(Other, IsLiveGCThing, scriptsGCHeap) \
|
|
|
|
macro(Other, NotLiveGCThing, scriptsMallocHeapData) \
|
|
|
|
macro(Other, NotLiveGCThing, baselineData) \
|
|
|
|
macro(Other, NotLiveGCThing, baselineStubsFallback) \
|
|
|
|
macro(Other, NotLiveGCThing, baselineStubsOptimized) \
|
|
|
|
macro(Other, NotLiveGCThing, ionData) \
|
|
|
|
macro(Other, NotLiveGCThing, typeInferenceTypeScripts) \
|
|
|
|
macro(Other, NotLiveGCThing, typeInferencePendingArrays) \
|
|
|
|
macro(Other, NotLiveGCThing, typeInferenceAllocationSiteTables) \
|
|
|
|
macro(Other, NotLiveGCThing, typeInferenceArrayTypeTables) \
|
|
|
|
macro(Other, NotLiveGCThing, typeInferenceObjectTypeTables) \
|
|
|
|
macro(Other, NotLiveGCThing, compartmentObject) \
|
|
|
|
macro(Other, NotLiveGCThing, crossCompartmentWrappersTable) \
|
|
|
|
macro(Other, NotLiveGCThing, regexpCompartment) \
|
|
|
|
macro(Other, NotLiveGCThing, debuggeesSet)
|
2013-09-25 10:24:28 +04:00
|
|
|
|
2012-10-17 18:44:31 +04:00
|
|
|
CompartmentStats()
|
2013-09-25 10:24:28 +04:00
|
|
|
: FOR_EACH_SIZE(ZERO_SIZE)
|
2013-03-17 07:36:37 +04:00
|
|
|
objectsExtra(),
|
2013-09-25 10:24:28 +04:00
|
|
|
extra()
|
2012-10-17 18:44:31 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
CompartmentStats(const CompartmentStats &other)
|
2013-09-25 10:24:28 +04:00
|
|
|
: FOR_EACH_SIZE(COPY_OTHER_SIZE)
|
2013-03-17 07:36:37 +04:00
|
|
|
objectsExtra(other.objectsExtra),
|
2013-09-25 10:24:28 +04:00
|
|
|
extra(other.extra)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void add(const CompartmentStats &other) {
|
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE)
|
|
|
|
objectsExtra.add(other.objectsExtra);
|
|
|
|
// Do nothing with |extra|.
|
2012-01-11 12:23:08 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = 0;
|
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING)
|
|
|
|
n += objectsExtra.sizeOfLiveGCThings();
|
|
|
|
// Do nothing with |extra|.
|
|
|
|
return n;
|
|
|
|
}
|
2012-05-03 11:12:47 +04:00
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
void addToTabSizes(TabSizes *sizes) const {
|
|
|
|
FOR_EACH_SIZE(ADD_TO_TAB_SIZES);
|
|
|
|
objectsExtra.addToTabSizes(sizes);
|
|
|
|
// Do nothing with |extra|.
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE)
|
|
|
|
ObjectsExtraSizes objectsExtra;
|
|
|
|
void *extra; // This field can be used by embedders.
|
2012-06-26 04:08:59 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
#undef FOR_EACH_SIZE
|
2012-01-11 12:23:08 +04:00
|
|
|
};
|
|
|
|
|
2012-01-30 02:11:32 +04:00
|
|
|
struct RuntimeStats
|
2012-01-11 12:23:08 +04:00
|
|
|
{
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(macro) \
|
2013-10-23 01:53:26 +04:00
|
|
|
macro(_, _, gcHeapChunkTotal) \
|
|
|
|
macro(_, _, gcHeapDecommittedArenas) \
|
|
|
|
macro(_, _, gcHeapUnusedChunks) \
|
|
|
|
macro(_, _, gcHeapUnusedArenas) \
|
|
|
|
macro(_, _, gcHeapChunkAdmin) \
|
|
|
|
macro(_, _, gcHeapGCThings) \
|
2013-09-25 10:24:28 +04:00
|
|
|
|
2013-06-23 15:21:01 +04:00
|
|
|
RuntimeStats(mozilla::MallocSizeOf mallocSizeOf)
|
2013-09-25 10:24:28 +04:00
|
|
|
: FOR_EACH_SIZE(ZERO_SIZE)
|
|
|
|
runtime(),
|
2013-03-17 07:36:37 +04:00
|
|
|
cTotals(),
|
|
|
|
zTotals(),
|
|
|
|
compartmentStatsVector(),
|
|
|
|
zoneStatsVector(),
|
2013-09-19 23:24:53 +04:00
|
|
|
currZoneStats(nullptr),
|
2013-03-17 07:36:37 +04:00
|
|
|
mallocSizeOf_(mallocSizeOf)
|
2012-01-11 12:23:08 +04:00
|
|
|
{}
|
|
|
|
|
2012-06-26 04:08:59 +04:00
|
|
|
// Here's a useful breakdown of the GC heap.
|
|
|
|
//
|
|
|
|
// - rtStats.gcHeapChunkTotal
|
|
|
|
// - decommitted bytes
|
2012-06-26 04:09:00 +04:00
|
|
|
// - rtStats.gcHeapDecommittedArenas (decommitted arenas in non-empty chunks)
|
2012-06-26 04:08:59 +04:00
|
|
|
// - unused bytes
|
|
|
|
// - rtStats.gcHeapUnusedChunks (empty chunks)
|
|
|
|
// - rtStats.gcHeapUnusedArenas (empty arenas within non-empty chunks)
|
2013-09-25 10:24:28 +04:00
|
|
|
// - rtStats.zTotals.unusedGCThings (empty GC thing slots within non-empty arenas)
|
2012-06-26 04:08:59 +04:00
|
|
|
// - used bytes
|
|
|
|
// - rtStats.gcHeapChunkAdmin
|
2013-09-25 10:24:28 +04:00
|
|
|
// - rtStats.zTotals.gcHeapArenaAdmin
|
2013-09-25 10:24:29 +04:00
|
|
|
// - rtStats.gcHeapGCThings (in-use GC things)
|
|
|
|
// == rtStats.zTotals.sizeOfLiveGCThings() + rtStats.cTotals.sizeOfLiveGCThings()
|
2012-06-26 04:09:00 +04:00
|
|
|
//
|
|
|
|
// It's possible that some arenas in empty chunks may be decommitted, but
|
|
|
|
// we don't count those under rtStats.gcHeapDecommittedArenas because (a)
|
|
|
|
// it's rare, and (b) this means that rtStats.gcHeapUnusedChunks is a
|
|
|
|
// multiple of the chunk size, which is good.
|
2012-06-26 04:08:59 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE)
|
2012-01-11 12:23:08 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
RuntimeSizes runtime;
|
|
|
|
|
|
|
|
CompartmentStats cTotals; // The sum of this runtime's compartments' measurements.
|
|
|
|
ZoneStats zTotals; // The sum of this runtime's zones' measurements.
|
2013-03-17 07:36:37 +04:00
|
|
|
|
2012-01-11 12:23:08 +04:00
|
|
|
js::Vector<CompartmentStats, 0, js::SystemAllocPolicy> compartmentStatsVector;
|
2013-03-17 07:36:37 +04:00
|
|
|
js::Vector<ZoneStats, 0, js::SystemAllocPolicy> zoneStatsVector;
|
|
|
|
|
|
|
|
ZoneStats *currZoneStats;
|
2012-01-11 12:23:08 +04:00
|
|
|
|
2013-06-23 15:21:01 +04:00
|
|
|
mozilla::MallocSizeOf mallocSizeOf_;
|
2012-03-09 13:48:50 +04:00
|
|
|
|
|
|
|
virtual void initExtraCompartmentStats(JSCompartment *c, CompartmentStats *cstats) = 0;
|
2013-03-17 07:36:37 +04:00
|
|
|
virtual void initExtraZoneStats(JS::Zone *zone, ZoneStats *zstats) = 0;
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
2012-01-11 12:23:08 +04:00
|
|
|
};
|
|
|
|
|
2012-04-20 08:01:33 +04:00
|
|
|
class ObjectPrivateVisitor
|
|
|
|
{
|
2013-03-17 07:36:37 +04:00
|
|
|
public:
|
2012-04-20 08:01:33 +04:00
|
|
|
// Within CollectRuntimeStats, this method is called for each JS object
|
2013-01-07 08:43:54 +04:00
|
|
|
// that has an nsISupports pointer.
|
|
|
|
virtual size_t sizeOfIncludingThis(nsISupports *aSupports) = 0;
|
|
|
|
|
|
|
|
// A callback that gets a JSObject's nsISupports pointer, if it has one.
|
|
|
|
// Note: this function does *not* addref |iface|.
|
2013-08-09 02:53:04 +04:00
|
|
|
typedef bool(*GetISupportsFun)(JSObject *obj, nsISupports **iface);
|
2013-02-18 10:56:32 +04:00
|
|
|
GetISupportsFun getISupports_;
|
2013-01-07 08:43:54 +04:00
|
|
|
|
|
|
|
ObjectPrivateVisitor(GetISupportsFun getISupports)
|
2013-02-18 10:56:32 +04:00
|
|
|
: getISupports_(getISupports)
|
2013-01-07 08:43:54 +04:00
|
|
|
{}
|
2012-04-20 08:01:33 +04:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:23:08 +04:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-04-20 08:01:33 +04:00
|
|
|
CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats, ObjectPrivateVisitor *opv);
|
2012-01-11 12:23:08 +04:00
|
|
|
|
2011-12-24 12:27:39 +04:00
|
|
|
extern JS_PUBLIC_API(size_t)
|
2013-03-17 07:36:37 +04:00
|
|
|
SystemCompartmentCount(JSRuntime *rt);
|
2011-12-24 12:27:39 +04:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(size_t)
|
2013-03-17 07:36:37 +04:00
|
|
|
UserCompartmentCount(JSRuntime *rt);
|
2011-12-24 12:27:39 +04:00
|
|
|
|
2013-03-07 08:40:36 +04:00
|
|
|
extern JS_PUBLIC_API(size_t)
|
|
|
|
PeakSizeOfTemporary(const JSRuntime *rt);
|
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
AddSizeOfTab(JSRuntime *rt, JSObject *obj, mozilla::MallocSizeOf mallocSizeOf,
|
|
|
|
ObjectPrivateVisitor *opv, TabSizes *sizes);
|
|
|
|
|
2011-12-24 12:27:39 +04:00
|
|
|
} // namespace JS
|
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
#undef DECL_SIZE
|
|
|
|
#undef ZERO_SIZE
|
|
|
|
#undef COPY_OTHER_SIZE
|
|
|
|
#undef ADD_OTHER_SIZE
|
|
|
|
#undef ADD_SIZE_TO_N_IF_LIVE_GC_THING
|
|
|
|
#undef ADD_TO_TAB_SIZES
|
|
|
|
|
2013-06-20 04:59:09 +04:00
|
|
|
#endif /* js_MemoryMetrics_h */
|