#ifndef HeapVerifier_h
#define HeapVerifier_h
#include "Heap.h"
#include <wtf/Vector.h>
namespace JSC {
class JSObject;
class MarkedBlock;
struct LiveObjectData {
LiveObjectData(JSObject* obj, bool isConfirmedDead = false)
: obj(obj)
, isConfirmedDead(isConfirmedDead)
{
}
JSObject* obj;
bool isConfirmedDead;
};
struct LiveObjectList {
LiveObjectList(const char* name)
: name(name)
, hasLiveObjects(true)
{
}
void reset()
{
liveObjects.clear();
hasLiveObjects = true; }
LiveObjectData* findObject(JSObject*);
const char* name;
Vector<LiveObjectData> liveObjects;
bool hasLiveObjects;
};
class HeapVerifier {
public:
enum class Phase {
BeforeGC,
BeforeMarking,
AfterMarking,
AfterGC
};
HeapVerifier(Heap*, unsigned numberOfGCCyclesToRecord);
void initializeGCCycle();
void gatherLiveObjects(Phase);
void trimDeadObjects();
void verify(Phase);
JS_EXPORT_PRIVATE void checkIfRecorded(JSObject*);
static const char* collectionTypeName(HeapOperation);
static const char* phaseName(Phase);
private:
struct GCCycle {
GCCycle()
: before("Before Marking")
, after("After Marking")
{
}
HeapOperation collectionType;
LiveObjectList before;
LiveObjectList after;
const char* collectionTypeName() const
{
return HeapVerifier::collectionTypeName(collectionType);
}
};
void incrementCycle() { m_currentCycle = (m_currentCycle + 1) % m_numberOfCycles; }
GCCycle& currentCycle() { return m_cycles[m_currentCycle]; }
GCCycle& cycleForIndex(int cycleIndex)
{
ASSERT(cycleIndex <= 0 && cycleIndex > -m_numberOfCycles);
cycleIndex += m_currentCycle;
if (cycleIndex < 0)
cycleIndex += m_numberOfCycles;
ASSERT(cycleIndex < m_numberOfCycles);
return m_cycles[cycleIndex];
}
LiveObjectList* liveObjectListForGathering(Phase);
bool verifyButterflyIsInStorageSpace(Phase, LiveObjectList&);
static void reportObject(LiveObjectData&, int cycleIndex, HeapVerifier::GCCycle&, LiveObjectList&);
Heap* m_heap;
int m_currentCycle;
int m_numberOfCycles;
std::unique_ptr<GCCycle[]> m_cycles;
};
}
#endif // HeapVerifier