#ifndef DFGExitProfile_h
#define DFGExitProfile_h
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
#include <wtf/Vector.h>
namespace JSC { namespace DFG {
enum ExitKind {
ExitKindUnset,
BadType, BadCache, Overflow, NegativeZero, InadequateCoverage, Uncountable, };
inline const char* exitKindToString(ExitKind kind)
{
switch (kind) {
case ExitKindUnset:
return "Unset";
case BadType:
return "BadType";
case BadCache:
return "BadCache";
case Overflow:
return "Overflow";
case NegativeZero:
return "NegativeZero";
case InadequateCoverage:
return "InadequateCoverage";
default:
return "Unknown";
}
}
inline bool exitKindIsCountable(ExitKind kind)
{
switch (kind) {
case ExitKindUnset:
ASSERT_NOT_REACHED();
case BadType:
case Uncountable:
return false;
default:
return true;
}
}
class FrequentExitSite {
public:
FrequentExitSite()
: m_bytecodeOffset(0) , m_kind(ExitKindUnset)
{
}
FrequentExitSite(WTF::HashTableDeletedValueType)
: m_bytecodeOffset(1) , m_kind(ExitKindUnset)
{
}
explicit FrequentExitSite(unsigned bytecodeOffset, ExitKind kind)
: m_bytecodeOffset(bytecodeOffset)
, m_kind(kind)
{
ASSERT(exitKindIsCountable(kind));
}
bool operator!() const
{
return m_kind == ExitKindUnset;
}
bool operator==(const FrequentExitSite& other) const
{
return m_bytecodeOffset == other.m_bytecodeOffset
&& m_kind == other.m_kind;
}
unsigned hash() const
{
return WTF::intHash(m_bytecodeOffset) + m_kind;
}
unsigned bytecodeOffset() const { return m_bytecodeOffset; }
ExitKind kind() const { return m_kind; }
bool isHashTableDeletedValue() const
{
return m_kind == ExitKindUnset && m_bytecodeOffset;
}
private:
unsigned m_bytecodeOffset;
ExitKind m_kind;
};
struct FrequentExitSiteHash {
static unsigned hash(const FrequentExitSite& key) { return key.hash(); }
static bool equal(const FrequentExitSite& a, const FrequentExitSite& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
} }
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<JSC::DFG::FrequentExitSite> {
typedef JSC::DFG::FrequentExitSiteHash Hash;
};
template<typename T> struct HashTraits;
template<> struct HashTraits<JSC::DFG::FrequentExitSite> : SimpleClassHashTraits<JSC::DFG::FrequentExitSite> { };
}
namespace JSC { namespace DFG {
class QueryableExitProfile;
class ExitProfile {
public:
ExitProfile();
~ExitProfile();
bool add(const FrequentExitSite&);
private:
friend class QueryableExitProfile;
OwnPtr<Vector<FrequentExitSite> > m_frequentExitSites;
};
class QueryableExitProfile {
public:
explicit QueryableExitProfile(const ExitProfile&);
~QueryableExitProfile();
bool hasExitSite(const FrequentExitSite& site) const
{
return m_frequentExitSites.find(site) != m_frequentExitSites.end();
}
bool hasExitSite(unsigned bytecodeIndex, ExitKind kind) const
{
return hasExitSite(FrequentExitSite(bytecodeIndex, kind));
}
private:
HashSet<FrequentExitSite> m_frequentExitSites;
};
} }
#endif // DFGExitProfile_h