2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
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
|
|
|
|
2019-07-18 16:17:10 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 15:21:01 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
|
2012-01-11 12:23:08 +04:00
|
|
|
#include <string.h>
|
2020-03-21 18:08:24 +03:00
|
|
|
#include <type_traits>
|
2012-01-11 12:23:08 +04:00
|
|
|
|
2011-12-24 12:27:39 +04:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
2018-02-21 19:30:19 +03:00
|
|
|
#include "js/AllocPolicy.h"
|
2020-07-23 05:31:57 +03:00
|
|
|
#include "js/GCAPI.h"
|
2013-08-06 03:33:00 +04:00
|
|
|
#include "js/HashTable.h"
|
2015-03-04 20:32:02 +03:00
|
|
|
#include "js/TracingAPI.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 {
|
2019-07-16 01:48:49 +03:00
|
|
|
TabSizes() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-19 01:23:05 +03:00
|
|
|
enum Kind { Objects, Strings, Private, Other };
|
|
|
|
|
2018-03-13 12:57:49 +03:00
|
|
|
void add(Kind kind, size_t n) {
|
2013-10-23 01:53:26 +04:00
|
|
|
switch (kind) {
|
|
|
|
case Objects:
|
2019-07-19 01:23:05 +03:00
|
|
|
objects_ += n;
|
2013-10-23 01:53:26 +04:00
|
|
|
break;
|
|
|
|
case Strings:
|
2019-07-19 01:23:05 +03:00
|
|
|
strings_ += n;
|
2013-10-23 01:53:26 +04:00
|
|
|
break;
|
|
|
|
case Private:
|
|
|
|
private_ += n;
|
|
|
|
break;
|
|
|
|
case Other:
|
2019-07-19 01:23:05 +03:00
|
|
|
other_ += n;
|
2013-10-23 01:53:26 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("bad TabSizes kind");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-10-23 01:53:26 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-19 01:23:05 +03:00
|
|
|
size_t objects_ = 0;
|
|
|
|
size_t strings_ = 0;
|
2019-07-16 01:48:49 +03:00
|
|
|
size_t private_ = 0;
|
2019-07-19 01:23:05 +03:00
|
|
|
size_t other_ = 0;
|
2013-10-23 01:53:26 +04:00
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/** These are the measurements used by Servo. */
|
2015-07-08 09:18:44 +03:00
|
|
|
struct ServoSizes {
|
2019-07-19 01:23:05 +03:00
|
|
|
ServoSizes() = default;
|
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
enum Kind {
|
|
|
|
GCHeapUsed,
|
|
|
|
GCHeapUnused,
|
|
|
|
GCHeapAdmin,
|
|
|
|
GCHeapDecommitted,
|
|
|
|
MallocHeap,
|
|
|
|
NonHeap,
|
|
|
|
Ignore
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void add(Kind kind, size_t n) {
|
|
|
|
switch (kind) {
|
|
|
|
case GCHeapUsed:
|
|
|
|
gcHeapUsed += n;
|
|
|
|
break;
|
|
|
|
case GCHeapUnused:
|
|
|
|
gcHeapUnused += n;
|
|
|
|
break;
|
|
|
|
case GCHeapAdmin:
|
|
|
|
gcHeapAdmin += n;
|
|
|
|
break;
|
|
|
|
case GCHeapDecommitted:
|
|
|
|
gcHeapDecommitted += n;
|
|
|
|
break;
|
|
|
|
case MallocHeap:
|
|
|
|
mallocHeap += n;
|
|
|
|
break;
|
|
|
|
case NonHeap:
|
|
|
|
nonHeap += n;
|
|
|
|
break;
|
|
|
|
case Ignore: /* do nothing */
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2015-07-08 09:18:44 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("bad ServoSizes kind");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:31:24 +03:00
|
|
|
size_t gcHeapUsed = 0;
|
|
|
|
size_t gcHeapUnused = 0;
|
|
|
|
size_t gcHeapAdmin = 0;
|
|
|
|
size_t gcHeapDecommitted = 0;
|
|
|
|
size_t mallocHeap = 0;
|
|
|
|
size_t nonHeap = 0;
|
2015-07-08 09:18:44 +03:00
|
|
|
};
|
|
|
|
|
2013-10-23 01:53:26 +04:00
|
|
|
} // namespace JS
|
|
|
|
|
2012-10-17 18:44:31 +04:00
|
|
|
namespace js {
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* generates the memory reports, because NotableStringInfo uses this value.
|
|
|
|
*/
|
2018-11-19 20:02:47 +03:00
|
|
|
JS_FRIEND_API size_t MemoryReportingSundriesThreshold();
|
2012-10-17 18:44:31 +04:00
|
|
|
|
2015-10-17 20:27:16 +03: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.
|
|
|
|
*/
|
2013-08-22 22:54:34 +04:00
|
|
|
struct InefficientNonFlatteningStringHashPolicy {
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef JSString* Lookup;
|
|
|
|
static HashNumber hash(const Lookup& l);
|
|
|
|
static bool match(const JSString* const& k, const Lookup& l);
|
2013-08-06 03:33:00 +04:00
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
//
|
2015-07-08 09:18:44 +03:00
|
|
|
// - The |tabKind| value is used when measuring TabSizes.
|
|
|
|
//
|
|
|
|
// - The |servoKind| value is used when measuring ServoSizes and also for
|
|
|
|
// the various sizeOfLiveGCThings() methods.
|
|
|
|
//
|
2013-09-25 10:24:28 +04:00
|
|
|
// In some classes, one or more of the macro arguments aren't used. We use '_'
|
|
|
|
// for those.
|
|
|
|
//
|
2019-07-16 01:48:49 +03:00
|
|
|
#define DECL_SIZE_ZERO(tabKind, servoKind, mSize) size_t mSize = 0;
|
2015-07-08 09:18:44 +03:00
|
|
|
#define ADD_OTHER_SIZE(tabKind, servoKind, mSize) mSize += other.mSize;
|
2015-07-21 01:17:25 +03:00
|
|
|
#define SUB_OTHER_SIZE(tabKind, servoKind, mSize) \
|
|
|
|
MOZ_ASSERT(mSize >= other.mSize); \
|
|
|
|
mSize -= other.mSize;
|
2015-07-08 09:18:44 +03:00
|
|
|
#define ADD_SIZE_TO_N(tabKind, servoKind, mSize) n += mSize;
|
2015-07-21 01:17:25 +03:00
|
|
|
#define ADD_SIZE_TO_N_IF_LIVE_GC_THING(tabKind, servoKind, mSize) \
|
|
|
|
/* Avoid self-comparison warnings by comparing enums indirectly. */ \
|
2020-03-21 18:08:24 +03:00
|
|
|
n += (std::is_same_v<int[ServoSizes::servoKind], \
|
|
|
|
int[ServoSizes::GCHeapUsed]>) \
|
2015-07-21 01:17:25 +03:00
|
|
|
? mSize \
|
|
|
|
: 0;
|
2015-07-08 09:18:44 +03:00
|
|
|
#define ADD_TO_TAB_SIZES(tabKind, servoKind, mSize) \
|
|
|
|
sizes->add(JS::TabSizes::tabKind, mSize);
|
|
|
|
#define ADD_TO_SERVO_SIZES(tabKind, servoKind, mSize) \
|
|
|
|
sizes->add(JS::ServoSizes::servoKind, mSize);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-10-17 18:44:31 +04:00
|
|
|
} // namespace js
|
|
|
|
|
2011-12-24 12:27:39 +04:00
|
|
|
namespace JS {
|
|
|
|
|
2014-04-16 06:43:18 +04:00
|
|
|
struct ClassInfo {
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Objects, GCHeapUsed, objectsGCHeap) \
|
|
|
|
MACRO(Objects, MallocHeap, objectsMallocHeapSlots) \
|
2016-02-12 01:18:46 +03:00
|
|
|
MACRO(Objects, MallocHeap, objectsMallocHeapElementsNormal) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Objects, MallocHeap, objectsMallocHeapElementsAsmJS) \
|
2016-09-19 20:39:50 +03:00
|
|
|
MACRO(Objects, MallocHeap, objectsMallocHeapMisc) \
|
2016-02-12 01:18:46 +03:00
|
|
|
MACRO(Objects, NonHeap, objectsNonHeapElementsNormal) \
|
|
|
|
MACRO(Objects, NonHeap, objectsNonHeapElementsShared) \
|
2016-09-19 20:39:50 +03:00
|
|
|
MACRO(Objects, NonHeap, objectsNonHeapElementsWasm) \
|
2016-10-14 15:53:08 +03:00
|
|
|
MACRO(Objects, NonHeap, objectsNonHeapCodeWasm)
|
2013-09-25 10:24:28 +04:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
ClassInfo() = default;
|
2014-04-16 06:43:18 +04:00
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void add(const ClassInfo& other) { FOR_EACH_SIZE(ADD_OTHER_SIZE); }
|
2015-04-02 04:04:53 +03:00
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void subtract(const ClassInfo& other) { FOR_EACH_SIZE(SUB_OTHER_SIZE); }
|
2014-04-16 06:43:18 +04:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t sizeOfAllThings() const {
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N);
|
2013-09-25 10:24:28 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
bool isNotable() const {
|
|
|
|
static const size_t NotabilityThreshold = 16 * 1024;
|
2013-10-23 01:53:26 +04:00
|
|
|
return sizeOfAllThings() >= NotabilityThreshold;
|
|
|
|
}
|
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING);
|
2015-04-02 04:04:53 +03:00
|
|
|
return n;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void addToTabSizes(TabSizes* sizes) const { FOR_EACH_SIZE(ADD_TO_TAB_SIZES); }
|
2015-07-08 09:18:44 +03:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
|
|
|
|
|
|
|
size_t wasmGuardPages = 0;
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
2012-11-22 05:07:42 +04:00
|
|
|
};
|
|
|
|
|
2016-08-23 12:25:54 +03:00
|
|
|
struct ShapeInfo {
|
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
|
|
|
MACRO(Other, GCHeapUsed, shapesGCHeapTree) \
|
|
|
|
MACRO(Other, GCHeapUsed, shapesGCHeapDict) \
|
|
|
|
MACRO(Other, GCHeapUsed, shapesGCHeapBase) \
|
|
|
|
MACRO(Other, MallocHeap, shapesMallocHeapTreeTables) \
|
|
|
|
MACRO(Other, MallocHeap, shapesMallocHeapDictTables) \
|
2019-11-20 14:56:16 +03:00
|
|
|
MACRO(Other, MallocHeap, shapesMallocHeapTreeChildren)
|
2016-08-23 12:25:54 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
ShapeInfo() = default;
|
2016-08-23 12:25:54 +03:00
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void add(const ShapeInfo& other) { FOR_EACH_SIZE(ADD_OTHER_SIZE); }
|
2016-08-23 12:25:54 +03:00
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void subtract(const ShapeInfo& other) { FOR_EACH_SIZE(SUB_OTHER_SIZE); }
|
2016-08-23 12:25:54 +03:00
|
|
|
|
|
|
|
size_t sizeOfAllThings() const {
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N);
|
2016-08-23 12:25:54 +03:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING);
|
2016-08-23 12:25:54 +03:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void addToTabSizes(TabSizes* sizes) const { FOR_EACH_SIZE(ADD_TO_TAB_SIZES); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-23 12:25:54 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
2016-08-23 12:25:54 +03:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
|
|
|
* Holds data about a notable class (one whose combined object and shape
|
|
|
|
* instances use more than a certain amount of memory) so we can report it
|
|
|
|
* individually.
|
|
|
|
*
|
|
|
|
* The only difference between this class and ClassInfo is that this class
|
|
|
|
* holds a copy of the filename.
|
|
|
|
*/
|
2014-04-16 06:43:18 +04:00
|
|
|
struct NotableClassInfo : public ClassInfo {
|
2019-07-22 17:15:58 +03:00
|
|
|
NotableClassInfo() = default;
|
|
|
|
NotableClassInfo(NotableClassInfo&&) = default;
|
|
|
|
NotableClassInfo(const NotableClassInfo& info) = delete;
|
2014-04-16 06:43:18 +04:00
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
NotableClassInfo(const char* className, const ClassInfo& info);
|
2014-04-16 06:43:18 +04:00
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
UniqueChars className_ = nullptr;
|
2014-04-16 06:43:18 +04:00
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/** Data for tracking JIT-code memory usage. */
|
2013-03-20 14:24:17 +04:00
|
|
|
struct CodeSizes {
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(_, NonHeap, ion) \
|
|
|
|
MACRO(_, NonHeap, baseline) \
|
|
|
|
MACRO(_, NonHeap, regexp) \
|
|
|
|
MACRO(_, NonHeap, other) \
|
|
|
|
MACRO(_, NonHeap, unused)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
CodeSizes() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
}
|
2015-07-08 09:18:44 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
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
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/** Data for tracking GC memory usage. */
|
2014-01-22 05:17:02 +04:00
|
|
|
struct GCSizes {
|
2015-07-08 09:18:44 +03:00
|
|
|
// |nurseryDecommitted| is marked as NonHeap rather than GCHeapDecommitted
|
|
|
|
// because we don't consider the nursery to be part of the GC heap.
|
2014-01-22 05:17:02 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(_, MallocHeap, marker) \
|
|
|
|
MACRO(_, NonHeap, nurseryCommitted) \
|
|
|
|
MACRO(_, MallocHeap, nurseryMallocedBuffers) \
|
|
|
|
MACRO(_, MallocHeap, storeBufferVals) \
|
|
|
|
MACRO(_, MallocHeap, storeBufferCells) \
|
|
|
|
MACRO(_, MallocHeap, storeBufferSlots) \
|
|
|
|
MACRO(_, MallocHeap, storeBufferWholeCells) \
|
|
|
|
MACRO(_, MallocHeap, storeBufferGenerics)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
GCSizes() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
2014-01-22 05:17:02 +04:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03: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. Note that two strings with identical
|
|
|
|
* chars will not be aggregated together if one is a short string and the other
|
|
|
|
* is not.
|
|
|
|
*/
|
2013-08-06 03:33:00 +04:00
|
|
|
struct StringInfo {
|
2014-02-27 06:11:01 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Strings, GCHeapUsed, gcHeapLatin1) \
|
|
|
|
MACRO(Strings, GCHeapUsed, gcHeapTwoByte) \
|
|
|
|
MACRO(Strings, MallocHeap, mallocHeapLatin1) \
|
|
|
|
MACRO(Strings, MallocHeap, mallocHeapTwoByte)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
StringInfo() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void add(const StringInfo& other) {
|
2014-02-27 06:11:01 +04:00
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE);
|
2013-08-06 03:33:00 +04:00
|
|
|
numCopies++;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void subtract(const StringInfo& other) {
|
2014-02-27 06:11:01 +04:00
|
|
|
FOR_EACH_SIZE(SUB_OTHER_SIZE);
|
|
|
|
numCopies--;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
bool isNotable() const {
|
|
|
|
static const size_t NotabilityThreshold = 16 * 1024;
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N);
|
2014-02-27 06:11:01 +04:00
|
|
|
return n >= NotabilityThreshold;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING);
|
2014-02-27 06:11:01 +04:00
|
|
|
return n;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void addToTabSizes(TabSizes* sizes) const { FOR_EACH_SIZE(ADD_TO_TAB_SIZES); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
|
|
|
|
|
|
|
uint32_t numCopies = 0; // How many copies of the string have we seen?
|
2013-08-06 03:33:00 +04:00
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
#undef FOR_EACH_SIZE
|
2013-08-06 03:33:00 +04:00
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
|
|
|
* Holds data about a notable string (one which, counting all duplicates, uses
|
|
|
|
* more than a certain amount of memory) so we can report it individually.
|
|
|
|
*
|
|
|
|
* The only difference between this class and StringInfo is that
|
|
|
|
* NotableStringInfo holds a copy of some or all of the string's chars.
|
|
|
|
*/
|
2013-08-06 03:33:00 +04:00
|
|
|
struct NotableStringInfo : public StringInfo {
|
2014-02-27 06:11:01 +04:00
|
|
|
static const size_t MAX_SAVED_CHARS = 1024;
|
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
NotableStringInfo() = default;
|
|
|
|
NotableStringInfo(NotableStringInfo&&) = default;
|
|
|
|
NotableStringInfo(const NotableStringInfo&) = delete;
|
2013-08-06 03:33:00 +04:00
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
NotableStringInfo(JSString* str, const StringInfo& info);
|
2013-11-19 01:48:45 +04:00
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
UniqueChars buffer = nullptr;
|
|
|
|
size_t length = 0;
|
2012-10-17 18:44:31 +04:00
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
|
|
|
* This class holds information about the memory taken up by script sources
|
|
|
|
* from a particular file.
|
|
|
|
*/
|
2014-02-14 08:03:07 +04:00
|
|
|
struct ScriptSourceInfo {
|
|
|
|
#define FOR_EACH_SIZE(MACRO) MACRO(_, MallocHeap, misc)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
ScriptSourceInfo() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void add(const ScriptSourceInfo& other) {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE);
|
2014-02-14 08:03:07 +04:00
|
|
|
numScripts++;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void subtract(const ScriptSourceInfo& other) {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(SUB_OTHER_SIZE);
|
2014-02-14 08:03:07 +04:00
|
|
|
numScripts--;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
2015-07-08 09:18:44 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-14 08:03:07 +04:00
|
|
|
bool isNotable() const {
|
|
|
|
static const size_t NotabilityThreshold = 16 * 1024;
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N);
|
2014-02-14 08:03:07 +04:00
|
|
|
return n >= NotabilityThreshold;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
|
|
|
|
|
|
|
uint32_t numScripts = 0; // How many ScriptSources come from this file? (It
|
|
|
|
// can be more than one in XML files that have
|
|
|
|
// multiple scripts in CDATA sections.)
|
2014-02-14 08:03:07 +04:00
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
|
|
|
* Holds data about a notable script source file (one whose combined
|
|
|
|
* script sources use more than a certain amount of memory) so we can report it
|
|
|
|
* individually.
|
|
|
|
*
|
|
|
|
* The only difference between this class and ScriptSourceInfo is that this
|
|
|
|
* class holds a copy of the filename.
|
|
|
|
*/
|
2014-02-14 08:03:07 +04:00
|
|
|
struct NotableScriptSourceInfo : public ScriptSourceInfo {
|
2019-07-22 17:15:58 +03:00
|
|
|
NotableScriptSourceInfo() = default;
|
|
|
|
NotableScriptSourceInfo(NotableScriptSourceInfo&&) = default;
|
|
|
|
NotableScriptSourceInfo(const NotableScriptSourceInfo&) = delete;
|
2014-02-14 08:03:07 +04:00
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
NotableScriptSourceInfo(const char* filename, const ScriptSourceInfo& info);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-22 17:15:58 +03:00
|
|
|
UniqueChars filename_ = nullptr;
|
2014-02-14 08:03:07 +04:00
|
|
|
};
|
|
|
|
|
2018-04-11 21:30:46 +03:00
|
|
|
struct HelperThreadStats {
|
2020-02-10 11:50:51 +03:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
|
|
|
MACRO(_, MallocHeap, stateData) \
|
|
|
|
MACRO(_, MallocHeap, parseTask) \
|
|
|
|
MACRO(_, MallocHeap, ionCompileTask) \
|
2020-06-09 12:07:07 +03:00
|
|
|
MACRO(_, MallocHeap, wasmCompile) \
|
|
|
|
MACRO(_, MallocHeap, contexts)
|
2018-04-11 21:30:46 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
HelperThreadStats() = default;
|
2018-04-11 21:30:46 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
2018-04-11 21:30:46 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
unsigned idleThreadCount = 0;
|
|
|
|
unsigned activeThreadCount = 0;
|
2018-04-11 21:30:46 +03:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
|
|
|
|
2018-03-24 18:50:47 +03:00
|
|
|
/**
|
|
|
|
* Measurements that not associated with any individual runtime.
|
|
|
|
*/
|
|
|
|
struct GlobalStats {
|
|
|
|
#define FOR_EACH_SIZE(MACRO) MACRO(_, MallocHeap, tracelogger)
|
|
|
|
|
|
|
|
explicit GlobalStats(mozilla::MallocSizeOf mallocSizeOf)
|
2019-07-16 01:48:49 +03:00
|
|
|
: mallocSizeOf_(mallocSizeOf) {}
|
2018-03-24 18:50:47 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
2018-03-24 18:50:47 +03:00
|
|
|
|
2018-04-11 21:30:46 +03:00
|
|
|
HelperThreadStats helperThread;
|
|
|
|
|
2018-03-24 18:50:47 +03:00
|
|
|
mozilla::MallocSizeOf mallocSizeOf_;
|
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
|
|
|
|
2015-10-17 20:27:16 +03:00
|
|
|
/**
|
2017-06-28 22:31:53 +03:00
|
|
|
* These measurements relate directly to the JSRuntime, and not to zones,
|
|
|
|
* compartments, and realms within it.
|
2015-10-17 20:27:16 +03:00
|
|
|
*/
|
2012-05-16 06:29:14 +04:00
|
|
|
struct RuntimeSizes {
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(_, MallocHeap, object) \
|
|
|
|
MACRO(_, MallocHeap, atomsTable) \
|
2017-01-30 16:31:47 +03:00
|
|
|
MACRO(_, MallocHeap, atomsMarkBitmaps) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(_, MallocHeap, contexts) \
|
|
|
|
MACRO(_, MallocHeap, temporary) \
|
|
|
|
MACRO(_, MallocHeap, interpreterStack) \
|
2016-05-07 02:53:45 +03:00
|
|
|
MACRO(_, MallocHeap, sharedImmutableStringsCache) \
|
2016-11-18 01:40:18 +03:00
|
|
|
MACRO(_, MallocHeap, sharedIntlData) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(_, MallocHeap, uncompressedSourceCache) \
|
2017-04-21 20:37:04 +03:00
|
|
|
MACRO(_, MallocHeap, scriptData) \
|
2018-03-12 23:10:06 +03:00
|
|
|
MACRO(_, MallocHeap, tracelogger) \
|
2018-04-11 21:01:11 +03:00
|
|
|
MACRO(_, MallocHeap, wasmRuntime) \
|
|
|
|
MACRO(_, MallocHeap, jitLazyLink)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
RuntimeSizes() { allScriptSources.emplace(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
2015-07-08 09:18:44 +03:00
|
|
|
scriptSourceInfo.addToServoSizes(sizes);
|
|
|
|
gc.addToServoSizes(sizes);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
|
|
|
|
2014-02-14 08:03:07 +04:00
|
|
|
// The script source measurements in |scriptSourceInfo| are initially for
|
|
|
|
// all script sources. At the end, if the measurement granularity is
|
|
|
|
// FineGrained, we subtract the measurements of the notable script sources
|
|
|
|
// and move them into |notableScriptSources|.
|
2015-07-08 09:18:44 +03:00
|
|
|
ScriptSourceInfo scriptSourceInfo;
|
|
|
|
GCSizes gc;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-14 08:03:07 +04:00
|
|
|
typedef js::HashMap<const char*, ScriptSourceInfo, mozilla::CStringHasher,
|
|
|
|
js::SystemAllocPolicy>
|
|
|
|
ScriptSourcesHashMap;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-14 08:03:07 +04:00
|
|
|
// |allScriptSources| is only used transiently. During the reporting phase
|
|
|
|
// it is filled with info about every script source in the runtime. It's
|
|
|
|
// then used to fill in |notableScriptSources| (which actually gets
|
|
|
|
// reported), and immediately discarded afterwards.
|
2019-07-18 16:17:10 +03:00
|
|
|
mozilla::Maybe<ScriptSourcesHashMap> allScriptSources;
|
2014-02-14 08:03:07 +04:00
|
|
|
js::Vector<NotableScriptSourceInfo, 0, js::SystemAllocPolicy>
|
|
|
|
notableScriptSources;
|
2013-09-25 10:24:28 +04:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
2012-05-16 06:29:14 +04:00
|
|
|
};
|
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
struct UnusedGCThingSizes {
|
2015-02-19 14:56:00 +03:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, GCHeapUnused, object) \
|
|
|
|
MACRO(Other, GCHeapUnused, script) \
|
|
|
|
MACRO(Other, GCHeapUnused, shape) \
|
|
|
|
MACRO(Other, GCHeapUnused, baseShape) \
|
|
|
|
MACRO(Other, GCHeapUnused, objectGroup) \
|
|
|
|
MACRO(Other, GCHeapUnused, string) \
|
|
|
|
MACRO(Other, GCHeapUnused, symbol) \
|
2019-02-14 18:03:44 +03:00
|
|
|
MACRO(Other, GCHeapUnused, bigInt) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, GCHeapUnused, jitcode) \
|
2017-03-27 12:38:29 +03:00
|
|
|
MACRO(Other, GCHeapUnused, scope) \
|
|
|
|
MACRO(Other, GCHeapUnused, regExpShared)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
UnusedGCThingSizes() = default;
|
|
|
|
UnusedGCThingSizes(UnusedGCThingSizes&& other) = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 20:40:24 +03:00
|
|
|
void addToKind(JS::TraceKind kind, intptr_t n) {
|
2015-02-19 14:56:00 +03:00
|
|
|
switch (kind) {
|
2017-03-27 12:38:29 +03:00
|
|
|
case JS::TraceKind::Object:
|
|
|
|
object += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::String:
|
|
|
|
string += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::Symbol:
|
|
|
|
symbol += n;
|
|
|
|
break;
|
Bug 1366287 - Part 1.0: Define a new BigInt primitive type, with a GDB prettyprinter, Rust binding support, and a new out-of-line TraceKind. (Disabled by default, implemented only incompletely, currently passing --enable-bigint will disable JITs, will be flipped on Eventually once every sub-aspect is in place, Don't Have A Cow, Man.) r=jwalden, r=Ms2ger, r=sfink
--HG--
extra : rebase_source : aa13bd94bc6157ff8134894e3ba2e7a2b53e28d9
2018-05-24 21:26:09 +03:00
|
|
|
case JS::TraceKind::BigInt:
|
|
|
|
bigInt += n;
|
|
|
|
break;
|
2017-03-27 12:38:29 +03:00
|
|
|
case JS::TraceKind::Script:
|
|
|
|
script += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::Shape:
|
|
|
|
shape += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::BaseShape:
|
|
|
|
baseShape += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::JitCode:
|
|
|
|
jitcode += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::ObjectGroup:
|
|
|
|
objectGroup += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::Scope:
|
|
|
|
scope += n;
|
|
|
|
break;
|
|
|
|
case JS::TraceKind::RegExpShared:
|
|
|
|
regExpShared += n;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2015-02-19 14:56:00 +03:00
|
|
|
default:
|
2015-07-08 09:18:44 +03:00
|
|
|
MOZ_CRASH("Bad trace kind for UnusedGCThingSizes");
|
2015-02-19 14:56:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-07-16 01:43:50 +03:00
|
|
|
void addSizes(const UnusedGCThingSizes& other) {
|
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-19 14:56:00 +03:00
|
|
|
size_t totalSize() const {
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N);
|
2015-02-19 14:56:00 +03:00
|
|
|
return n;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToTabSizes(JS::TabSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_TAB_SIZES);
|
2015-07-08 09:18:44 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(JS::ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
2015-02-19 14:56:00 +03:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
|
|
|
};
|
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
struct ZoneStats {
|
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, GCHeapUsed, symbolsGCHeap) \
|
2019-02-14 18:03:44 +03:00
|
|
|
MACRO(Other, GCHeapUsed, bigIntsGCHeap) \
|
|
|
|
MACRO(Other, MallocHeap, bigIntsMallocHeap) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, GCHeapAdmin, gcHeapArenaAdmin) \
|
|
|
|
MACRO(Other, GCHeapUsed, jitCodesGCHeap) \
|
|
|
|
MACRO(Other, GCHeapUsed, objectGroupsGCHeap) \
|
|
|
|
MACRO(Other, MallocHeap, objectGroupsMallocHeap) \
|
2016-08-25 11:28:47 +03:00
|
|
|
MACRO(Other, GCHeapUsed, scopesGCHeap) \
|
|
|
|
MACRO(Other, MallocHeap, scopesMallocHeap) \
|
2017-03-27 12:38:29 +03:00
|
|
|
MACRO(Other, GCHeapUsed, regExpSharedsGCHeap) \
|
|
|
|
MACRO(Other, MallocHeap, regExpSharedsMallocHeap) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, MallocHeap, typePool) \
|
2017-07-06 17:40:39 +03:00
|
|
|
MACRO(Other, MallocHeap, regexpZone) \
|
2017-04-24 13:41:04 +03:00
|
|
|
MACRO(Other, MallocHeap, jitZone) \
|
2015-08-27 00:51:43 +03:00
|
|
|
MACRO(Other, MallocHeap, baselineStubsOptimized) \
|
2016-08-23 12:25:54 +03:00
|
|
|
MACRO(Other, MallocHeap, uniqueIdMap) \
|
2018-06-06 15:30:52 +03:00
|
|
|
MACRO(Other, MallocHeap, shapeTables) \
|
|
|
|
MACRO(Other, MallocHeap, compartmentObjects) \
|
|
|
|
MACRO(Other, MallocHeap, crossCompartmentWrappersTables) \
|
2019-08-30 01:28:20 +03:00
|
|
|
MACRO(Other, MallocHeap, compartmentsPrivateData) \
|
|
|
|
MACRO(Other, MallocHeap, scriptCountsMap)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
ZoneStats() = default;
|
|
|
|
ZoneStats(ZoneStats&& other) = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-18 16:17:10 +03:00
|
|
|
void initStrings();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void addSizes(const ZoneStats& other) {
|
2014-02-27 06:11:01 +04:00
|
|
|
MOZ_ASSERT(isTotals);
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE);
|
2015-02-19 14:56:00 +03:00
|
|
|
unusedGCThings.addSizes(other.unusedGCThings);
|
2014-02-27 06:11:01 +04:00
|
|
|
stringInfo.add(other.stringInfo);
|
2016-08-23 12:25:54 +03:00
|
|
|
shapeInfo.add(other.shapeInfo);
|
2013-03-17 07:36:37 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-25 10:24:29 +04:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
2014-02-27 06:11:01 +04:00
|
|
|
MOZ_ASSERT(isTotals);
|
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING);
|
2014-02-27 06:11:01 +04:00
|
|
|
n += stringInfo.sizeOfLiveGCThings();
|
2016-08-23 12:25:54 +03:00
|
|
|
n += shapeInfo.sizeOfLiveGCThings();
|
2013-09-25 10:24:29 +04:00
|
|
|
return n;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void addToTabSizes(JS::TabSizes* sizes) const {
|
2014-02-27 06:11:01 +04:00
|
|
|
MOZ_ASSERT(isTotals);
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_TAB_SIZES);
|
2015-07-08 09:18:44 +03:00
|
|
|
unusedGCThings.addToTabSizes(sizes);
|
2014-02-27 06:11:01 +04:00
|
|
|
stringInfo.addToTabSizes(sizes);
|
2016-08-23 12:25:54 +03:00
|
|
|
shapeInfo.addToTabSizes(sizes);
|
2014-02-27 06:11:01 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(JS::ServoSizes* sizes) const {
|
|
|
|
MOZ_ASSERT(isTotals);
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
2015-07-08 09:18:44 +03:00
|
|
|
unusedGCThings.addToServoSizes(sizes);
|
|
|
|
stringInfo.addToServoSizes(sizes);
|
2016-08-23 12:25:54 +03:00
|
|
|
shapeInfo.addToServoSizes(sizes);
|
2019-11-14 13:20:02 +03:00
|
|
|
code.addToServoSizes(sizes);
|
2015-07-08 09:18:44 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
// These string measurements are initially for all strings. At the end,
|
|
|
|
// if the measurement granularity is FineGrained, we subtract the
|
|
|
|
// measurements of the notable script sources and move them into
|
|
|
|
// |notableStrings|.
|
2015-07-08 09:18:44 +03:00
|
|
|
UnusedGCThingSizes unusedGCThings;
|
2014-02-27 06:11:01 +04:00
|
|
|
StringInfo stringInfo;
|
2016-08-23 12:25:54 +03:00
|
|
|
ShapeInfo shapeInfo;
|
2019-11-14 13:20:02 +03:00
|
|
|
CodeSizes code;
|
2019-07-16 01:48:49 +03:00
|
|
|
void* extra = nullptr; // This field can be used by embedders.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
typedef js::HashMap<JSString*, StringInfo,
|
2013-08-22 22:54:34 +04:00
|
|
|
js::InefficientNonFlatteningStringHashPolicy,
|
|
|
|
js::SystemAllocPolicy>
|
|
|
|
StringsHashMap;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-27 06:11:01 +04:00
|
|
|
// |allStrings| is only used transiently. During the zone traversal it is
|
2013-12-04 15:54:54 +04:00
|
|
|
// filled with info about every string in the zone. It's then used to fill
|
|
|
|
// in |notableStrings| (which actually gets reported), and immediately
|
|
|
|
// discarded afterwards.
|
2019-07-18 16:17:10 +03:00
|
|
|
mozilla::Maybe<StringsHashMap> allStrings;
|
2013-08-06 03:33:00 +04:00
|
|
|
js::Vector<NotableStringInfo, 0, js::SystemAllocPolicy> notableStrings;
|
2019-07-16 01:48:49 +03:00
|
|
|
bool isTotals = true;
|
2014-02-27 06:11:01 +04:00
|
|
|
|
|
|
|
#undef FOR_EACH_SIZE
|
2013-03-17 07:36:37 +04:00
|
|
|
};
|
|
|
|
|
2018-05-17 17:15:18 +03:00
|
|
|
struct RealmStats {
|
2015-07-08 09:18:44 +03:00
|
|
|
// We assume that |objectsPrivate| is on the malloc heap, but it's not
|
|
|
|
// actually guaranteed. But for Servo, at least, it's a moot point because
|
|
|
|
// it doesn't provide an ObjectPrivateVisitor so the value will always be
|
|
|
|
// zero.
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Private, MallocHeap, objectsPrivate) \
|
|
|
|
MACRO(Other, GCHeapUsed, scriptsGCHeap) \
|
|
|
|
MACRO(Other, MallocHeap, scriptsMallocHeapData) \
|
|
|
|
MACRO(Other, MallocHeap, baselineData) \
|
|
|
|
MACRO(Other, MallocHeap, baselineStubsFallback) \
|
|
|
|
MACRO(Other, MallocHeap, ionData) \
|
2019-05-23 10:28:00 +03:00
|
|
|
MACRO(Other, MallocHeap, jitScripts) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, MallocHeap, typeInferenceAllocationSiteTables) \
|
|
|
|
MACRO(Other, MallocHeap, typeInferenceArrayTypeTables) \
|
|
|
|
MACRO(Other, MallocHeap, typeInferenceObjectTypeTables) \
|
2018-05-17 17:15:18 +03:00
|
|
|
MACRO(Other, MallocHeap, realmObject) \
|
|
|
|
MACRO(Other, MallocHeap, realmTables) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(Other, MallocHeap, innerViewsTable) \
|
|
|
|
MACRO(Other, MallocHeap, objectMetadataTable) \
|
2015-10-07 00:00:29 +03:00
|
|
|
MACRO(Other, MallocHeap, savedStacksSet) \
|
2016-08-25 11:28:47 +03:00
|
|
|
MACRO(Other, MallocHeap, varNamesSet) \
|
2016-02-04 09:36:06 +03:00
|
|
|
MACRO(Other, MallocHeap, nonSyntacticLexicalScopesTable) \
|
2019-08-30 01:28:20 +03:00
|
|
|
MACRO(Other, MallocHeap, jitRealm)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
RealmStats() = default;
|
|
|
|
RealmStats(RealmStats&& other) = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-17 17:15:18 +03:00
|
|
|
RealmStats(const RealmStats&) = delete; // disallow copying
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-18 16:17:10 +03:00
|
|
|
void initClasses();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-17 17:15:18 +03:00
|
|
|
void addSizes(const RealmStats& other) {
|
2014-04-16 06:43:18 +04:00
|
|
|
MOZ_ASSERT(isTotals);
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_OTHER_SIZE);
|
2014-04-16 06:43:18 +04:00
|
|
|
classInfo.add(other.classInfo);
|
2012-01-11 12:23:08 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t sizeOfLiveGCThings() const {
|
2014-04-16 06:43:18 +04:00
|
|
|
MOZ_ASSERT(isTotals);
|
2013-09-25 10:24:28 +04:00
|
|
|
size_t n = 0;
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING);
|
2014-04-16 06:43:18 +04:00
|
|
|
n += classInfo.sizeOfLiveGCThings();
|
2013-09-25 10:24:28 +04:00
|
|
|
return n;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void addToTabSizes(TabSizes* sizes) const {
|
2014-04-16 06:43:18 +04:00
|
|
|
MOZ_ASSERT(isTotals);
|
2013-10-23 01:53:26 +04:00
|
|
|
FOR_EACH_SIZE(ADD_TO_TAB_SIZES);
|
2014-04-16 06:43:18 +04:00
|
|
|
classInfo.addToTabSizes(sizes);
|
2013-10-23 01:53:26 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
|
|
|
MOZ_ASSERT(isTotals);
|
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
|
|
|
classInfo.addToServoSizes(sizes);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
|
|
|
|
2014-04-16 06:43:18 +04:00
|
|
|
// The class measurements in |classInfo| are initially for all classes. At
|
|
|
|
// the end, if the measurement granularity is FineGrained, we subtract the
|
|
|
|
// measurements of the notable classes and move them into |notableClasses|.
|
2015-07-08 09:18:44 +03:00
|
|
|
ClassInfo classInfo;
|
2019-07-16 01:48:49 +03:00
|
|
|
void* extra = nullptr; // This field can be used by embedders.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-16 06:43:18 +04:00
|
|
|
typedef js::HashMap<const char*, ClassInfo, mozilla::CStringHasher,
|
|
|
|
js::SystemAllocPolicy>
|
|
|
|
ClassesHashMap;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-16 06:43:18 +04:00
|
|
|
// These are similar to |allStrings| and |notableStrings| in ZoneStats.
|
2019-07-18 16:17:10 +03:00
|
|
|
mozilla::Maybe<ClassesHashMap> allClasses;
|
2014-04-16 06:43:18 +04:00
|
|
|
js::Vector<NotableClassInfo, 0, js::SystemAllocPolicy> notableClasses;
|
2019-07-16 01:48:49 +03:00
|
|
|
bool isTotals = true;
|
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
|
|
|
};
|
|
|
|
|
2018-05-17 17:15:18 +03:00
|
|
|
typedef js::Vector<RealmStats, 0, js::SystemAllocPolicy> RealmStatsVector;
|
2013-12-04 15:54:54 +04:00
|
|
|
typedef js::Vector<ZoneStats, 0, js::SystemAllocPolicy> ZoneStatsVector;
|
|
|
|
|
2012-01-30 02:11:32 +04:00
|
|
|
struct RuntimeStats {
|
2015-07-08 09:18:44 +03:00
|
|
|
// |gcHeapChunkTotal| is ignored because it's the sum of all the other
|
|
|
|
// values. |gcHeapGCThings| is ignored because it's the sum of some of the
|
|
|
|
// values from the zones and compartments. Both of those values are not
|
|
|
|
// reported directly, but are just present for sanity-checking other
|
|
|
|
// values.
|
2013-09-25 10:24:28 +04:00
|
|
|
#define FOR_EACH_SIZE(MACRO) \
|
2015-07-08 09:18:44 +03:00
|
|
|
MACRO(_, Ignore, gcHeapChunkTotal) \
|
|
|
|
MACRO(_, GCHeapDecommitted, gcHeapDecommittedArenas) \
|
|
|
|
MACRO(_, GCHeapUnused, gcHeapUnusedChunks) \
|
|
|
|
MACRO(_, GCHeapUnused, gcHeapUnusedArenas) \
|
|
|
|
MACRO(_, GCHeapAdmin, gcHeapChunkAdmin) \
|
|
|
|
MACRO(_, Ignore, gcHeapGCThings)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-26 05:46:24 +04:00
|
|
|
explicit RuntimeStats(mozilla::MallocSizeOf mallocSizeOf)
|
2019-07-16 01:48:49 +03:00
|
|
|
: mallocSizeOf_(mallocSizeOf) {}
|
2018-11-30 13:46:48 +03: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)
|
2015-07-08 09:18:44 +03:00
|
|
|
// - rtStats.zTotals.unusedGCThings.totalSize()
|
|
|
|
// (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.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-08 09:18:44 +03:00
|
|
|
void addToServoSizes(ServoSizes* sizes) const {
|
2019-07-16 01:43:50 +03:00
|
|
|
FOR_EACH_SIZE(ADD_TO_SERVO_SIZES);
|
2015-07-08 09:18:44 +03:00
|
|
|
runtime.addToServoSizes(sizes);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
FOR_EACH_SIZE(DECL_SIZE_ZERO);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-25 10:24:28 +04:00
|
|
|
RuntimeSizes runtime;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-17 17:15:18 +03:00
|
|
|
RealmStats realmTotals; // The sum of this runtime's realms' measurements.
|
2013-09-25 10:24:28 +04:00
|
|
|
ZoneStats zTotals; // The sum of this runtime's zones' measurements.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-17 17:15:18 +03:00
|
|
|
RealmStatsVector realmStatsVector;
|
2013-12-04 15:54:54 +04:00
|
|
|
ZoneStatsVector zoneStatsVector;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
ZoneStats* currZoneStats = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-06-23 15:21:01 +04:00
|
|
|
mozilla::MallocSizeOf mallocSizeOf_;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-07-23 05:31:57 +03:00
|
|
|
virtual void initExtraRealmStats(JS::Realm* realm, RealmStats* rstats,
|
|
|
|
const JS::AutoRequireNoGC& nogc) = 0;
|
|
|
|
virtual void initExtraZoneStats(JS::Zone* zone, ZoneStats* zstats,
|
|
|
|
const JS::AutoRequireNoGC& nogc) = 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.
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual size_t sizeOfIncludingThis(nsISupports* aSupports) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-07 08:43:54 +04:00
|
|
|
// A callback that gets a JSObject's nsISupports pointer, if it has one.
|
|
|
|
// Note: this function does *not* addref |iface|.
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef bool (*GetISupportsFun)(JSObject* obj, nsISupports** iface);
|
2013-02-18 10:56:32 +04:00
|
|
|
GetISupportsFun getISupports_;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-26 05:46:24 +04:00
|
|
|
explicit ObjectPrivateVisitor(GetISupportsFun getISupports)
|
2013-02-18 10:56:32 +04:00
|
|
|
: getISupports_(getISupports) {}
|
2012-04-20 08:01:33 +04:00
|
|
|
};
|
|
|
|
|
2018-03-24 18:50:47 +03:00
|
|
|
extern JS_PUBLIC_API bool CollectGlobalStats(GlobalStats* gStats);
|
|
|
|
|
2016-07-07 10:56:09 +03:00
|
|
|
extern JS_PUBLIC_API bool CollectRuntimeStats(JSContext* cx,
|
|
|
|
RuntimeStats* rtStats,
|
|
|
|
ObjectPrivateVisitor* opv,
|
|
|
|
bool anonymize);
|
2012-01-11 12:23:08 +04:00
|
|
|
|
2019-01-08 18:11:08 +03:00
|
|
|
extern JS_PUBLIC_API size_t SystemCompartmentCount(JSContext* cx);
|
|
|
|
extern JS_PUBLIC_API size_t UserCompartmentCount(JSContext* cx);
|
2011-12-24 12:27:39 +04:00
|
|
|
|
2019-01-08 18:11:08 +03:00
|
|
|
extern JS_PUBLIC_API size_t SystemRealmCount(JSContext* cx);
|
2018-05-17 17:15:18 +03:00
|
|
|
extern JS_PUBLIC_API size_t UserRealmCount(JSContext* cx);
|
2011-12-24 12:27:39 +04:00
|
|
|
|
2016-08-11 15:39:22 +03:00
|
|
|
extern JS_PUBLIC_API size_t PeakSizeOfTemporary(const JSContext* cx);
|
2013-03-07 08:40:36 +04:00
|
|
|
|
2016-07-07 10:56:09 +03:00
|
|
|
extern JS_PUBLIC_API bool AddSizeOfTab(JSContext* cx, JS::HandleObject obj,
|
|
|
|
mozilla::MallocSizeOf mallocSizeOf,
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectPrivateVisitor* opv,
|
|
|
|
TabSizes* sizes);
|
2013-10-23 01:53:26 +04:00
|
|
|
|
2016-07-07 10:56:09 +03:00
|
|
|
extern JS_PUBLIC_API bool AddServoSizeOf(JSContext* cx,
|
|
|
|
mozilla::MallocSizeOf mallocSizeOf,
|
2017-04-21 20:37:04 +03:00
|
|
|
ObjectPrivateVisitor* opv,
|
|
|
|
ServoSizes* sizes);
|
|
|
|
|
2011-12-24 12:27:39 +04:00
|
|
|
} // namespace JS
|
|
|
|
|
2019-07-16 01:48:49 +03:00
|
|
|
#undef DECL_SIZE_ZERO
|
2013-10-23 01:53:26 +04:00
|
|
|
#undef ADD_OTHER_SIZE
|
2014-02-27 06:11:01 +04:00
|
|
|
#undef SUB_OTHER_SIZE
|
|
|
|
#undef ADD_SIZE_TO_N
|
2013-10-23 01:53:26 +04:00
|
|
|
#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 */
|