Files
palemoon27/js/src/gc/Statistics.h
T
roytam1 39770f3213 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1274192 part 1 - make the MediaDecoderReaderWrapper as a proxy of WaitForData(); r=jwwang (9debdca9a9)
- Bug 1274192 part 2 - make MDSM and SeekTask to adopt new MediaDecoderReaderWrapper API; r=jwwang (156f924dc9)
- Bug 1276495: Don't reset audio promises for video only seek. r=jwwang,jya (c4632c7ff6)
- Bug 1276318, part 1 - Fix leading tabs in ipc/glue. r=billm (46bcc4ccb3)
- Bug 1035125 Part 6: Take Chromium commit 3181ba39ee787e1b40f4aea4be23f4f666ad0945 to add Windows 10 version to enumeration. r=aklotz (af62c8065f)
- Bug 1270752 - Fix lifetime of buffer passed to PR_SetEnv(). r=jduell (bfce06ebea)
- Bug 1275117 - Fix static strings leaks when mozlogging is on. r=jduell (8e9066c5d7)
- Bug 1273048 - Add MOZ_GCC_VERSION_AT_MOST macro. r=froydnj (cfb5acdbe6)
- Bug 1269968 - Remove unnecessary deduction on RefPtr.h. r=froydnj (30cf9bbf47)
- Bug 525063 - add attribute to mark member variables that should be skipped by clang plugin initialization checker. r=nfroyd (78aa863f88)
- Bug 1278391 - add move constructor to EnumeratedArray (r=njn) (5effe4e473)
- Bug 1268518: Update basic-integer tests for rotations + clean up; r=sunfish (46827b6211)
- Bug 1270370 - Part 1: Move SetIteratorObject to MapObject.h; r=jorendorff (01a27fbd50)
- Bug 1270370 - Part 2: Expose MapIterator and SetIterator through ESClassValues; r=jorendorff (3edb3c7551)
- Bug 1267551 (part 3) - Use MOZ_MUST_USE more in js/src/builtin/. r=jonco. (ea96d0fae0)
- Bug 1267551 (part 4) - Use MOZ_MUST_USE more in js/src/asmjs/. r=bbouvier. (3e622c736d)
- Bug 1268910: Refactor WebAssembly trap handling; r=luke (b59394a287)
- Bug 1268910: Trap on edge cases for integer div/mod; r=sunfish (3d85230cc8)
- Bug 1267551 (part 5) - Use MOZ_MUST_USE more in js/src/ctypes/. r=sfink. (e6580fb645)
- Bug 1267551 (part 6) - Remove dead GenerateBlockId declaration. r=jorendorff. (74afcc549e)
- Bug 1240072 - Add public JS APIs related to modules r=shu Bug 1267551 (part 7) - Use MOZ_MUST_USE more in js/src/frontend/. r=jorendorff. (5275c57768)
- Bug 1267551 (part 8) - Use MOZ_MUST_USE more in js/src/gc/. r=terrence. (2572cc1c58)
- Bug 1261063 - Part 1 - Remove public Telemetry functions that return raw histogram instances. r=chutten (3a68653c8f)
- Bug 1261063 - Part 2 - Expose C++ function to clear Telemetry histograms. r=chutten (1f42f6aa1e)
- Bug 1261063 - Part 3 - Make RasterImage use the public Telemetry API. r=tnikkel (0f564f3836)
- Bug 1261063 - Part 4 - Use a count histogram for WebRTC call counts. r=jesup (b6b7b649e0)
- Bug 1270073 - Point to Telemetry documentation in Telemetry.h. r=chutten (517279b284)
- Bug 1261052 - Move C++ histogram implementation code into a separate module. r=gfritzsche. (66bcb1e167)
- Bug 1145164 - Allow non-unitary increments to count histograms. r=gfritzsche (507e076e28)
- Bug 1173447 - Add test for incremental pre-barriers when storing things under roots, r=jonco (caf8bd16be)
- Bug 1267551 (part 10) - Use MOZ_MUST_USE in AutoVectorRooterBase. r=terrence. (2c5ed87a9f)
- This catches a missing check. (b2fcd30fc5)
- Bug 1267551 (part 11b) - Follow-up to fix Android bustage. r=me (f464ca7b98)
- Bug 1271854 - Part 1: Allow specifying multiple GC zeal levels; r=terrence (da3c3e1281)
- Bug 1271854 - Part 2: Allow specifying zeal modes by name as well; r=terrence (f63926e45b)
- Bug 1271854 - Part 3: Avoid saving the GC zeal string inside the JS shell; r=terrence (f09b262e55)
- Bug 1270062 - Unbust Windows full duplex. a=Tomcat (3c8b5887b6)
- Bug 1270062 - Update libcubeb. rs=jesup (71805cb0e0)
- Bug 1270004 - Update libcubeb. rs=jesup (2d90b9662f)
- Bug 1280280 - Update cubeb to 073c9f011114. r=kinetik (6bee6a7f21)
- Bug 1280280 - Update media/libcube/update.sh to add cubeb_jack.cpp, and sort the list of files. r=kinetik (430b7533c4)
- Bug 1272604 - Add a zeal mode to check the heap after a moving GC r=terrence (85c018d71f)
- Bug 1272604 - Fix bad implicit conversion constructor build error r=me (5c4e1dbc44)
- Bug 1272604 - Fix hazard analysis failure r=me (0591aa2dca)
- Bug 1232417 - Use a Variant to represent the CrossCompartmentWrapperMap key; r=jonco (512da0bab3)
- Bug 1269928 - Fold DirectProxyHandler into Wrapper, which is now its only (non-test) consumer. r=efaust (7c6bb6e898)
- Bug 1273639 - Add a nonunified spidermonkey build, r=terrence (d6fa13545c)
- Bug 1273639 - Fix nonunified spidermonkey builds, r=terrence (3e0544510d)
- Bug 1273180 - Trigger major GC if necessary after minor GC r=terrence (a9a9be8b17)
- Bug 1268992 - Assert that the heap is empty after a shutdown GC; r=jonco (fe3ac5bdd6)
- Bug 1273908 - Refactor GC to make it easier to add new kinds of GC thing r=terrence (51c92e1b05)
2024-10-09 21:36:44 +08:00

440 lines
13 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
* 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/. */
#ifndef gc_Statistics_h
#define gc_Statistics_h
#include "mozilla/IntegerRange.h"
#include "mozilla/PodOperations.h"
#include "jsalloc.h"
#include "jsgc.h"
#include "jspubtd.h"
#include "js/GCAPI.h"
#include "js/Vector.h"
namespace js {
class GCParallelTask;
namespace gcstats {
enum Phase : uint8_t {
PHASE_MUTATOR,
PHASE_GC_BEGIN,
PHASE_WAIT_BACKGROUND_THREAD,
PHASE_MARK_DISCARD_CODE,
PHASE_RELAZIFY_FUNCTIONS,
PHASE_PURGE,
PHASE_MARK,
PHASE_UNMARK,
PHASE_MARK_DELAYED,
PHASE_SWEEP,
PHASE_SWEEP_MARK,
PHASE_SWEEP_MARK_TYPES,
PHASE_SWEEP_MARK_INCOMING_BLACK,
PHASE_SWEEP_MARK_WEAK,
PHASE_SWEEP_MARK_INCOMING_GRAY,
PHASE_SWEEP_MARK_GRAY,
PHASE_SWEEP_MARK_GRAY_WEAK,
PHASE_FINALIZE_START,
PHASE_WEAK_ZONEGROUP_CALLBACK,
PHASE_WEAK_COMPARTMENT_CALLBACK,
PHASE_SWEEP_ATOMS,
PHASE_SWEEP_SYMBOL_REGISTRY,
PHASE_SWEEP_COMPARTMENTS,
PHASE_SWEEP_DISCARD_CODE,
PHASE_SWEEP_INNER_VIEWS,
PHASE_SWEEP_CC_WRAPPER,
PHASE_SWEEP_BASE_SHAPE,
PHASE_SWEEP_INITIAL_SHAPE,
PHASE_SWEEP_TYPE_OBJECT,
PHASE_SWEEP_BREAKPOINT,
PHASE_SWEEP_REGEXP,
PHASE_SWEEP_MISC,
PHASE_SWEEP_TYPES,
PHASE_SWEEP_TYPES_BEGIN,
PHASE_SWEEP_TYPES_END,
PHASE_SWEEP_OBJECT,
PHASE_SWEEP_STRING,
PHASE_SWEEP_SCRIPT,
PHASE_SWEEP_SHAPE,
PHASE_SWEEP_JITCODE,
PHASE_FINALIZE_END,
PHASE_DESTROY,
PHASE_COMPACT,
PHASE_COMPACT_MOVE,
PHASE_COMPACT_UPDATE,
PHASE_COMPACT_UPDATE_CELLS,
PHASE_GC_END,
PHASE_MINOR_GC,
PHASE_EVICT_NURSERY,
PHASE_TRACE_HEAP,
PHASE_BARRIER,
PHASE_UNMARK_GRAY,
PHASE_MARK_ROOTS,
PHASE_BUFFER_GRAY_ROOTS,
PHASE_MARK_CCWS,
PHASE_MARK_ROOTERS,
PHASE_MARK_RUNTIME_DATA,
PHASE_MARK_EMBEDDING,
PHASE_MARK_COMPARTMENTS,
PHASE_LIMIT,
PHASE_NONE = PHASE_LIMIT,
PHASE_MULTI_PARENTS
};
enum Stat {
STAT_NEW_CHUNK,
STAT_DESTROY_CHUNK,
STAT_MINOR_GC,
// Number of times a 'put' into a storebuffer overflowed, triggering a
// compaction
STAT_STOREBUFFER_OVERFLOW,
// Number of arenas relocated by compacting GC.
STAT_ARENA_RELOCATED,
STAT_LIMIT
};
struct ZoneGCStats
{
/* Number of zones collected in this GC. */
int collectedZoneCount;
/* Total number of zones in the Runtime at the start of this GC. */
int zoneCount;
/* Total number of comaprtments in all zones collected. */
int collectedCompartmentCount;
/* Total number of compartments in the Runtime at the start of this GC. */
int compartmentCount;
bool isCollectingAllZones() const { return collectedZoneCount == zoneCount; }
ZoneGCStats()
: collectedZoneCount(0), zoneCount(0), collectedCompartmentCount(0), compartmentCount(0)
{}
};
/*
* Struct for collecting timing statistics on a "phase tree". The tree is
* specified as a limited DAG, but the timings are collected for the whole tree
* that you would get by expanding out the DAG by duplicating subtrees rooted
* at nodes with multiple parents.
*
* During execution, a child phase can be activated multiple times, and the
* total time will be accumulated. (So for example, you can start and end
* PHASE_MARK_ROOTS multiple times before completing the parent phase.)
*
* Incremental GC is represented by recording separate timing results for each
* slice within the overall GC.
*/
struct Statistics
{
/*
* Phases are allowed to have multiple parents, though any path from root
* to leaf is allowed at most one multi-parented phase. We keep a full set
* of timings for each of the multi-parented phases, to be able to record
* all the timings in the expanded tree induced by our dag.
*
* Note that this wastes quite a bit of space, since we have a whole
* separate array of timing data containing all the phases. We could be
* more clever and keep an array of pointers biased by the offset of the
* multi-parented phase, and thereby preserve the simple
* timings[slot][PHASE_*] indexing. But the complexity doesn't seem worth
* the few hundred bytes of savings. If we want to extend things to full
* DAGs, this decision should be reconsidered.
*/
static const size_t MaxMultiparentPhases = 6;
static const size_t NumTimingArrays = MaxMultiparentPhases + 1;
/* Create a convenient type for referring to tables of phase times. */
using PhaseTimeTable = int64_t[NumTimingArrays][PHASE_LIMIT];
static MOZ_MUST_USE bool initialize();
explicit Statistics(JSRuntime* rt);
~Statistics();
void beginPhase(Phase phase);
void endPhase(Phase phase);
void endParallelPhase(Phase phase, const GCParallelTask* task);
void beginSlice(const ZoneGCStats& zoneStats, JSGCInvocationKind gckind,
SliceBudget budget, JS::gcreason::Reason reason);
void endSlice();
void setSliceCycleCount(unsigned cycleCount);
MOZ_MUST_USE bool startTimingMutator();
MOZ_MUST_USE bool stopTimingMutator(double& mutator_ms, double& gc_ms);
void reset(const char* reason) {
if (!aborted)
slices.back().resetReason = reason;
}
void nonincremental(const char* reason) { nonincrementalReason_ = reason; }
const char* nonincrementalReason() const { return nonincrementalReason_; }
void count(Stat s) {
MOZ_ASSERT(s < STAT_LIMIT);
counts[s]++;
}
void beginNurseryCollection(JS::gcreason::Reason reason) {
count(STAT_MINOR_GC);
if (nurseryCollectionCallback) {
(*nurseryCollectionCallback)(runtime,
JS::GCNurseryProgress::GC_NURSERY_COLLECTION_START,
reason);
}
}
void endNurseryCollection(JS::gcreason::Reason reason) {
if (nurseryCollectionCallback) {
(*nurseryCollectionCallback)(runtime,
JS::GCNurseryProgress::GC_NURSERY_COLLECTION_END,
reason);
}
}
int64_t beginSCC();
void endSCC(unsigned scc, int64_t start);
UniqueChars formatCompactSliceMessage() const;
UniqueChars formatCompactSummaryMessage() const;
UniqueChars formatJsonMessage(uint64_t timestamp);
UniqueChars formatDetailedMessage();
JS::GCSliceCallback setSliceCallback(JS::GCSliceCallback callback);
JS::GCNurseryCollectionCallback setNurseryCollectionCallback(
JS::GCNurseryCollectionCallback callback);
int64_t clearMaxGCPauseAccumulator();
int64_t getMaxGCPauseSinceClear();
// Return the current phase, suppressing the synthetic PHASE_MUTATOR phase.
Phase currentPhase() {
if (phaseNestingDepth == 0)
return PHASE_NONE;
if (phaseNestingDepth == 1)
return phaseNesting[0] == PHASE_MUTATOR ? PHASE_NONE : phaseNesting[0];
return phaseNesting[phaseNestingDepth - 1];
}
static const size_t MAX_NESTING = 20;
struct SliceData {
SliceData(SliceBudget budget, JS::gcreason::Reason reason, int64_t start,
double startTimestamp, size_t startFaults, gc::State initialState)
: budget(budget), reason(reason),
initialState(initialState),
finalState(gc::NO_INCREMENTAL),
resetReason(nullptr),
start(start), startTimestamp(startTimestamp),
startFaults(startFaults),
cycleCount(0)
{
for (auto i : mozilla::MakeRange(NumTimingArrays))
mozilla::PodArrayZero(phaseTimes[i]);
}
SliceBudget budget;
JS::gcreason::Reason reason;
gc::State initialState, finalState;
const char* resetReason;
int64_t start, end;
double startTimestamp, endTimestamp;
size_t startFaults, endFaults;
PhaseTimeTable phaseTimes;
unsigned cycleCount;
int64_t duration() const { return end - start; }
};
typedef Vector<SliceData, 8, SystemAllocPolicy> SliceDataVector;
typedef SliceDataVector::ConstRange SliceRange;
SliceRange sliceRange() const { return slices.all(); }
size_t slicesLength() const { return slices.length(); }
private:
JSRuntime* runtime;
int64_t startupTime;
/* File pointer used for MOZ_GCTIMER output. */
FILE* fp;
/*
* GCs can't really nest, but a second GC can be triggered from within the
* JSGC_END callback.
*/
int gcDepth;
ZoneGCStats zoneStats;
JSGCInvocationKind gckind;
const char* nonincrementalReason_;
SliceDataVector slices;
/* Most recent time when the given phase started. */
int64_t phaseStartTimes[PHASE_LIMIT];
/* Bookkeeping for GC timings when timingMutator is true */
int64_t timedGCStart;
int64_t timedGCTime;
/* Total time in a given phase for this GC. */
PhaseTimeTable phaseTimes;
/* Total time in a given phase over all GCs. */
PhaseTimeTable phaseTotals;
/* Number of events of this type for this GC. */
unsigned int counts[STAT_LIMIT];
/* Allocated space before the GC started. */
size_t preBytes;
/* Records the maximum GC pause in an API-controlled interval (in us). */
mutable int64_t maxPauseInInterval;
/* Phases that are currently on stack. */
Phase phaseNesting[MAX_NESTING];
size_t phaseNestingDepth;
size_t activeDagSlot;
/*
* To avoid recursive nesting, we discontinue a callback phase when any
* other phases are started. Remember what phase to resume when the inner
* phases are complete. (And because GCs can nest within the callbacks any
* number of times, we need a whole stack of of phases to resume.)
*/
Phase suspendedPhases[MAX_NESTING];
size_t suspendedPhaseNestingDepth;
/* Sweep times for SCCs of compartments. */
Vector<int64_t, 0, SystemAllocPolicy> sccTimes;
JS::GCSliceCallback sliceCallback;
JS::GCNurseryCollectionCallback nurseryCollectionCallback;
/*
* True if we saw an OOM while allocating slices. The statistics for this
* GC will be invalid.
*/
bool aborted;
void beginGC(JSGCInvocationKind kind);
void endGC();
void recordPhaseEnd(Phase phase);
void gcDuration(int64_t* total, int64_t* maxPause) const;
void sccDurations(int64_t* total, int64_t* maxPause);
void printStats();
UniqueChars formatCompactSlicePhaseTimes(const PhaseTimeTable phaseTimes) const;
UniqueChars formatDetailedDescription();
UniqueChars formatDetailedSliceDescription(unsigned i, const SliceData& slice);
UniqueChars formatDetailedPhaseTimes(const PhaseTimeTable phaseTimes);
UniqueChars formatDetailedTotals();
UniqueChars formatJsonDescription(uint64_t timestamp);
UniqueChars formatJsonSliceDescription(unsigned i, const SliceData& slice);
UniqueChars formatJsonPhaseTimes(const PhaseTimeTable phaseTimes);
double computeMMU(int64_t resolution) const;
};
struct MOZ_RAII AutoGCSlice
{
AutoGCSlice(Statistics& stats, const ZoneGCStats& zoneStats, JSGCInvocationKind gckind,
SliceBudget budget, JS::gcreason::Reason reason)
: stats(stats)
{
stats.beginSlice(zoneStats, gckind, budget, reason);
}
~AutoGCSlice() { stats.endSlice(); }
void setCycleCount(unsigned cycleCount) {
stats.setSliceCycleCount(cycleCount);
}
Statistics& stats;
};
struct MOZ_RAII AutoPhase
{
AutoPhase(Statistics& stats, Phase phase)
: stats(stats), task(nullptr), phase(phase), enabled(true)
{
stats.beginPhase(phase);
}
AutoPhase(Statistics& stats, bool condition, Phase phase)
: stats(stats), task(nullptr), phase(phase), enabled(condition)
{
if (enabled)
stats.beginPhase(phase);
}
AutoPhase(Statistics& stats, const GCParallelTask& task, Phase phase)
: stats(stats), task(&task), phase(phase), enabled(true)
{
if (enabled)
stats.beginPhase(phase);
}
~AutoPhase() {
if (enabled) {
if (task)
stats.endParallelPhase(phase, task);
else
stats.endPhase(phase);
}
}
Statistics& stats;
const GCParallelTask* task;
Phase phase;
bool enabled;
};
struct MOZ_RAII AutoSCC
{
AutoSCC(Statistics& stats, unsigned scc)
: stats(stats), scc(scc)
{
start = stats.beginSCC();
}
~AutoSCC() {
stats.endSCC(scc, start);
}
Statistics& stats;
unsigned scc;
int64_t start;
};
const char* ExplainInvocationKind(JSGCInvocationKind gckind);
} /* namespace gcstats */
} /* namespace js */
#endif /* gc_Statistics_h */