Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit cc8b45c

Browse files
committed
Bug 854763 - Add a memory reporter for asm.js array buffers. r=luke.
--HG-- extra : rebase_source : 7710041552c96677344c85849cb6a7409a95edd2
1 parent ea912ef commit cc8b45c

5 files changed

Lines changed: 67 additions & 44 deletions

File tree

js/public/MemoryMetrics.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ namespace JS {
4040
struct ObjectsExtraSizes
4141
{
4242
size_t slots;
43-
size_t elements;
43+
size_t elementsNonAsmJS;
44+
size_t elementsAsmJSHeap;
45+
size_t elementsAsmJSNonHeap;
4446
size_t argumentsData;
4547
size_t regExpStatics;
4648
size_t propertyIteratorData;
@@ -52,7 +54,9 @@ struct ObjectsExtraSizes
5254

5355
void add(ObjectsExtraSizes &sizes) {
5456
this->slots += sizes.slots;
55-
this->elements += sizes.elements;
57+
this->elementsNonAsmJS += sizes.elementsNonAsmJS;
58+
this->elementsAsmJSHeap += sizes.elementsAsmJSHeap;
59+
this->elementsAsmJSNonHeap += sizes.elementsAsmJSNonHeap;
5660
this->argumentsData += sizes.argumentsData;
5761
this->regExpStatics += sizes.regExpStatics;
5862
this->propertyIteratorData += sizes.propertyIteratorData;

js/src/jsobj.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5040,3 +5040,40 @@ js_DumpBacktrace(JSContext *cx)
50405040
fprintf(stdout, "%s", sprinter.string());
50415041
}
50425042

5043+
void
5044+
JSObject::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, JS::ObjectsExtraSizes *sizes)
5045+
{
5046+
if (hasDynamicSlots())
5047+
sizes->slots = mallocSizeOf(slots);
5048+
5049+
if (hasDynamicElements()) {
5050+
js::ObjectElements *elements = getElementsHeader();
5051+
if (JS_UNLIKELY(elements->isAsmJSArrayBuffer())) {
5052+
#if defined (JS_CPU_X64)
5053+
// On x64, ArrayBufferObject::prepareForAsmJS switches the
5054+
// ArrayBufferObject to use mmap'd storage.
5055+
sizes->elementsAsmJSNonHeap = asArrayBuffer().byteLength();
5056+
#else
5057+
sizes->elementsAsmJSHeap = mallocSizeOf(elements);
5058+
#endif
5059+
} else {
5060+
sizes->elementsNonAsmJS = mallocSizeOf(elements);
5061+
}
5062+
}
5063+
5064+
// Other things may be measured in the future if DMD indicates it is worthwhile.
5065+
// Note that sizes->private_ is measured elsewhere.
5066+
if (isArguments()) {
5067+
sizes->argumentsData = asArguments().sizeOfMisc(mallocSizeOf);
5068+
} else if (isRegExpStatics()) {
5069+
sizes->regExpStatics = js::SizeOfRegExpStaticsData(this, mallocSizeOf);
5070+
} else if (isPropertyIterator()) {
5071+
sizes->propertyIteratorData = asPropertyIterator().sizeOfMisc(mallocSizeOf);
5072+
#ifdef JS_HAS_CTYPES
5073+
} else {
5074+
// This must be the last case.
5075+
sizes->ctypesData = js::SizeOfDataIfCDataObject(mallocSizeOf, const_cast<JSObject *>(this));
5076+
#endif
5077+
}
5078+
}
5079+

js/src/jsobj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class JSObject : public js::ObjectImpl
370370

371371
inline bool hasShapeTable() const;
372372

373-
inline void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, JS::ObjectsExtraSizes *sizes);
373+
void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, JS::ObjectsExtraSizes *sizes);
374374

375375
bool hasIdempotentProtoChain() const;
376376

js/src/jsobjinlines.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,42 +1077,6 @@ JSObject::hasShapeTable() const
10771077
return lastProperty()->hasTable();
10781078
}
10791079

1080-
inline void
1081-
JSObject::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, JS::ObjectsExtraSizes *sizes)
1082-
{
1083-
if (hasDynamicSlots())
1084-
sizes->slots = mallocSizeOf(slots);
1085-
1086-
if (hasDynamicElements()) {
1087-
js::ObjectElements *elements = getElementsHeader();
1088-
#if defined (JS_CPU_X64)
1089-
// On x64, ArrayBufferObject::prepareForAsmJS switches the
1090-
// ArrayBufferObject to use mmap'd storage. This is not included in the
1091-
// total 'explicit' figure and thus we must not include it here.
1092-
// TODO: include it somewhere else.
1093-
if (JS_LIKELY(!elements->isAsmJSArrayBuffer()))
1094-
sizes->elements = mallocSizeOf(elements);
1095-
#else
1096-
sizes->elements = mallocSizeOf(elements);
1097-
#endif
1098-
}
1099-
1100-
// Other things may be measured in the future if DMD indicates it is worthwhile.
1101-
// Note that sizes->private_ is measured elsewhere.
1102-
if (isArguments()) {
1103-
sizes->argumentsData = asArguments().sizeOfMisc(mallocSizeOf);
1104-
} else if (isRegExpStatics()) {
1105-
sizes->regExpStatics = js::SizeOfRegExpStaticsData(this, mallocSizeOf);
1106-
} else if (isPropertyIterator()) {
1107-
sizes->propertyIteratorData = asPropertyIterator().sizeOfMisc(mallocSizeOf);
1108-
#ifdef JS_HAS_CTYPES
1109-
} else {
1110-
// This must be the last case.
1111-
sizes->ctypesData = js::SizeOfDataIfCDataObject(mallocSizeOf, const_cast<JSObject *>(this));
1112-
#endif
1113-
}
1114-
}
1115-
11161080
/* static */ inline JSBool
11171081
JSObject::lookupGeneric(JSContext *cx, js::HandleObject obj, js::HandleId id,
11181082
js::MutableHandleObject objp, js::MutableHandleShape propp)

js/xpconnect/src/XPCJSRuntime.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,11 +1763,29 @@ ReportCompartmentStats(const JS::CompartmentStats &cStats,
17631763
"stored on the JavaScript heap; those slots "
17641764
"are not counted here, but in 'gc-heap/objects' instead.");
17651765

1766-
ZCREPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/elements"),
1767-
cStats.objectsExtra.elements,
1768-
"Memory allocated for object element "
1769-
"arrays, which are used to represent indexed object "
1770-
"properties.");
1766+
ZCREPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/elements/non-asm.js"),
1767+
cStats.objectsExtra.elementsNonAsmJS,
1768+
"Memory allocated for non-asm.js object element arrays, "
1769+
"which are used to represent indexed object properties.");
1770+
1771+
// asm.js arrays are heap-allocated on some platforms and
1772+
// non-heap-allocated on others. We never put them under sundries,
1773+
// because (a) in practice they're almost always larger than the sundries
1774+
// threshold, and (b) we'd need a third category of non-heap, non-GC
1775+
// sundries, which would be a pain.
1776+
#define ASM_JS_DESC "Memory allocated for object element " \
1777+
"arrays used as asm.js array buffers."
1778+
size_t asmJSHeap = cStats.objectsExtra.elementsAsmJSHeap;
1779+
size_t asmJSNonHeap = cStats.objectsExtra.elementsAsmJSNonHeap;
1780+
JS_ASSERT(asmJSHeap == 0 || asmJSNonHeap == 0);
1781+
if (asmJSHeap > 0) {
1782+
REPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/elements/asm.js"),
1783+
nsIMemoryReporter::KIND_HEAP, asmJSHeap, ASM_JS_DESC);
1784+
}
1785+
if (asmJSNonHeap > 0) {
1786+
REPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/elements/asm.js"),
1787+
nsIMemoryReporter::KIND_NONHEAP, asmJSNonHeap, ASM_JS_DESC);
1788+
}
17711789

17721790
ZCREPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/arguments-data"),
17731791
cStats.objectsExtra.argumentsData,

0 commit comments

Comments
 (0)