#ifndef TypeProfiler_h
#define TypeProfiler_h
#include "CodeBlock.h"
#include "TypeLocation.h"
#include "TypeLocationCache.h"
#include <wtf/Bag.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace Inspector { namespace Protocol { namespace Runtime {
class TypeDescription;
}}}
namespace JSC {
struct QueryKey {
QueryKey()
: m_sourceID(0)
, m_divot(0)
{ }
QueryKey(intptr_t sourceID, unsigned divot)
: m_sourceID(sourceID)
, m_divot(divot)
{ }
QueryKey(WTF::HashTableDeletedValueType)
: m_sourceID(INTPTR_MAX)
, m_divot(UINT_MAX)
{ }
bool isHashTableDeletedValue() const { return m_sourceID == INTPTR_MAX && m_divot == UINT_MAX; }
bool operator==(const QueryKey& other) const { return m_sourceID == other.m_sourceID && m_divot == other.m_divot; }
unsigned hash() const { return m_sourceID + m_divot; }
intptr_t m_sourceID;
unsigned m_divot;
};
struct QueryKeyHash {
static unsigned hash(const QueryKey& key) { return key.hash(); }
static bool equal(const QueryKey& a, const QueryKey& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
}
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<JSC::QueryKey> {
typedef JSC::QueryKeyHash Hash;
};
template<typename T> struct HashTraits;
template<> struct HashTraits<JSC::QueryKey> : SimpleClassHashTraits<JSC::QueryKey> { };
}
namespace JSC {
class VM;
enum TypeProfilerSearchDescriptor {
TypeProfilerSearchDescriptorNormal = 1,
TypeProfilerSearchDescriptorFunctionReturn = 2
};
class TypeProfiler {
public:
TypeProfiler();
void logTypesForTypeLocation(TypeLocation*, VM&);
JS_EXPORT_PRIVATE String typeInformationForExpressionAtOffset(TypeProfilerSearchDescriptor, unsigned offset, intptr_t sourceID, VM&);
void insertNewLocation(TypeLocation*);
TypeLocationCache* typeLocationCache() { return &m_typeLocationCache; }
TypeLocation* findLocation(unsigned divot, intptr_t sourceID, TypeProfilerSearchDescriptor, VM&);
GlobalVariableID getNextUniqueVariableID() { return m_nextUniqueVariableID++; }
TypeLocation* nextTypeLocation();
void invalidateTypeSetCache();
void dumpTypeProfilerData(VM&);
private:
typedef HashMap<intptr_t, Vector<TypeLocation*>> SourceIDToLocationBucketMap;
SourceIDToLocationBucketMap m_bucketMap;
TypeLocationCache m_typeLocationCache;
typedef HashMap<QueryKey, TypeLocation*> TypeLocationQueryCache;
TypeLocationQueryCache m_queryCache;
GlobalVariableID m_nextUniqueVariableID;
Bag<TypeLocation> m_typeLocationInfo;
};
}
#endif // TypeProfiler_h