mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1053932: Require all Debugger.Memory Assorters to provide a running total. r=terrence
This commit is contained in:
parent
07083974cb
commit
7971b7b249
@ -280,6 +280,9 @@ struct Census {
|
||||
// bool count(Census &census, const Node &node);
|
||||
// Categorize and count |node| as appropriate for this kind of assorter.
|
||||
//
|
||||
// size_t total() const;
|
||||
// Return the number of times 'count' has been called.
|
||||
//
|
||||
// bool report(Census &census, MutableHandleValue report);
|
||||
// Construct a JavaScript object reporting the counts this assorter has
|
||||
// seen, and store it in |report|.
|
||||
@ -289,23 +292,25 @@ struct Census {
|
||||
|
||||
// The simplest assorter: count everything, and return a tally form.
|
||||
class Tally {
|
||||
size_t counter;
|
||||
size_t total_;
|
||||
|
||||
public:
|
||||
Tally(Census &census) : counter(0) { }
|
||||
Tally(Tally &&rhs) : counter(rhs.counter) { }
|
||||
Tally &operator=(Tally &&rhs) { counter = rhs.counter; return *this; }
|
||||
Tally(Census &census) : total_(0) { }
|
||||
Tally(Tally &&rhs) : total_(rhs.total_) { }
|
||||
Tally &operator=(Tally &&rhs) { total_ = rhs.total_; return *this; }
|
||||
|
||||
bool init(Census &census) { return true; }
|
||||
|
||||
bool count(Census &census, const Node &node) {
|
||||
counter++;
|
||||
total_++;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t total() const { return total_; }
|
||||
|
||||
bool report(Census &census, MutableHandleValue report) {
|
||||
RootedObject obj(census.cx, NewBuiltinClassInstance(census.cx, &JSObject::class_));
|
||||
RootedValue countValue(census.cx, NumberValue(counter));
|
||||
RootedValue countValue(census.cx, NumberValue(total_));
|
||||
if (!obj ||
|
||||
!JSObject::defineProperty(census.cx, obj, census.cx->names().count, countValue))
|
||||
{
|
||||
@ -327,6 +332,7 @@ template<typename EachObject = Tally,
|
||||
typename EachString = Tally,
|
||||
typename EachOther = Tally>
|
||||
class ByJSType {
|
||||
size_t total_;
|
||||
EachObject objects;
|
||||
EachScript scripts;
|
||||
EachString strings;
|
||||
@ -334,13 +340,15 @@ class ByJSType {
|
||||
|
||||
public:
|
||||
ByJSType(Census &census)
|
||||
: objects(census),
|
||||
: total_(0),
|
||||
objects(census),
|
||||
scripts(census),
|
||||
strings(census),
|
||||
other(census)
|
||||
{ }
|
||||
ByJSType(ByJSType &&rhs)
|
||||
: objects(Move(rhs.objects)),
|
||||
: total_(rhs.total_),
|
||||
objects(Move(rhs.objects)),
|
||||
scripts(move(rhs.scripts)),
|
||||
strings(move(rhs.strings)),
|
||||
other(move(rhs.other))
|
||||
@ -360,6 +368,7 @@ class ByJSType {
|
||||
}
|
||||
|
||||
bool count(Census &census, const Node &node) {
|
||||
total_++;
|
||||
if (node.is<JSObject>())
|
||||
return objects.count(census, node);
|
||||
if (node.is<JSScript>() || node.is<LazyScript>() || node.is<jit::JitCode>())
|
||||
@ -409,6 +418,8 @@ class ByJSType {
|
||||
template<typename EachClass = Tally,
|
||||
typename EachOther = Tally>
|
||||
class ByObjectClass {
|
||||
size_t total_;
|
||||
|
||||
// A hash policy that compares js::Classes by name.
|
||||
struct HashPolicy {
|
||||
typedef const js::Class *Lookup;
|
||||
@ -428,8 +439,10 @@ class ByObjectClass {
|
||||
EachOther other;
|
||||
|
||||
public:
|
||||
ByObjectClass(Census &census) : other(census) { }
|
||||
ByObjectClass(ByObjectClass &&rhs) : table(Move(rhs.table)), other(Move(rhs.other)) { }
|
||||
ByObjectClass(Census &census) : total_(0), other(census) { }
|
||||
ByObjectClass(ByObjectClass &&rhs)
|
||||
: total_(rhs.total_), table(Move(rhs.table)), other(Move(rhs.other))
|
||||
{ }
|
||||
ByObjectClass &operator=(ByObjectClass &&rhs) {
|
||||
MOZ_ASSERT(&rhs != this);
|
||||
this->~ByObjectClass();
|
||||
@ -440,6 +453,7 @@ class ByObjectClass {
|
||||
bool init(Census &census) { return table.init() && other.init(census); }
|
||||
|
||||
bool count(Census &census, const Node &node) {
|
||||
total_++;
|
||||
if (!node.is<JSObject>())
|
||||
return other.count(census, node);
|
||||
|
||||
@ -454,6 +468,8 @@ class ByObjectClass {
|
||||
return p->value().count(census, node);
|
||||
}
|
||||
|
||||
size_t total() const { return total_; }
|
||||
|
||||
bool report(Census &census, MutableHandleValue report) {
|
||||
JSContext *cx = census.cx;
|
||||
|
||||
@ -501,6 +517,8 @@ class ByObjectClass {
|
||||
// An assorter that categorizes nodes by their ubi::Node::typeName.
|
||||
template<typename EachType = Tally>
|
||||
class ByUbinodeType {
|
||||
size_t total_;
|
||||
|
||||
// Note that, because ubi::Node::typeName promises to return a specific
|
||||
// pointer, not just any string whose contents are correct, we can use their
|
||||
// addresses as hash table keys.
|
||||
@ -508,8 +526,8 @@ class ByUbinodeType {
|
||||
Table table;
|
||||
|
||||
public:
|
||||
ByUbinodeType(Census &census) { }
|
||||
ByUbinodeType(ByUbinodeType &&rhs) : table(Move(rhs.table)) { }
|
||||
ByUbinodeType(Census &census) : total_(0) { }
|
||||
ByUbinodeType(ByUbinodeType &&rhs) : total_(rhs.total_), table(Move(rhs.table)) { }
|
||||
ByUbinodeType &operator=(ByUbinodeType &&rhs) {
|
||||
MOZ_ASSERT(&rhs != this);
|
||||
this->~ByUbinodeType();
|
||||
@ -520,6 +538,7 @@ class ByUbinodeType {
|
||||
bool init(Census &census) { return table.init(); }
|
||||
|
||||
bool count(Census &census, const Node &node) {
|
||||
total_++;
|
||||
const jschar *key = node.typeName();
|
||||
typename Table::AddPtr p = table.lookupForAdd(key);
|
||||
if (!p) {
|
||||
@ -531,6 +550,8 @@ class ByUbinodeType {
|
||||
return p->value().count(census, node);
|
||||
}
|
||||
|
||||
size_t total() const { return total_; }
|
||||
|
||||
bool report(Census &census, MutableHandleValue report) {
|
||||
JSContext *cx = census.cx;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user