#ifndef FTLAbstractHeap_h
#define FTLAbstractHeap_h
#if ENABLE(FTL_JIT)
#include "FTLAbbreviations.h"
#include "JSCJSValue.h"
#include <array>
#include <wtf/FastMalloc.h>
#include <wtf/HashMap.h>
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
#include <wtf/text/CString.h>
namespace JSC { namespace FTL {
class AbstractHeapRepository;
class Output;
class TypedPointer;
class AbstractHeap {
WTF_MAKE_NONCOPYABLE(AbstractHeap); WTF_MAKE_FAST_ALLOCATED;
public:
AbstractHeap()
: m_parent(0)
, m_heapName(0)
, m_tbaaMetadata(0)
{
}
AbstractHeap(AbstractHeap* parent, const char* heapName)
: m_parent(parent)
, m_heapName(heapName)
, m_tbaaMetadata(0)
{
}
bool isInitialized() const { return !!m_heapName; }
void initialize(AbstractHeap* parent, const char* heapName)
{
m_parent = parent;
m_heapName = heapName;
}
void changeParent(AbstractHeap* parent)
{
m_parent = parent;
}
AbstractHeap* parent() const
{
ASSERT(isInitialized());
return m_parent;
}
const char* heapName() const
{
ASSERT(isInitialized());
return m_heapName;
}
LValue tbaaMetadata(const AbstractHeapRepository& repository) const
{
ASSERT(isInitialized());
if (LIKELY(!!m_tbaaMetadata))
return m_tbaaMetadata;
return tbaaMetadataSlow(repository);
}
void decorateInstruction(LValue instruction, const AbstractHeapRepository&) const;
void dump(PrintStream&) const;
private:
friend class AbstractHeapRepository;
LValue tbaaMetadataSlow(const AbstractHeapRepository&) const;
AbstractHeap* m_parent;
const char* m_heapName;
mutable LValue m_tbaaMetadata;
};
class AbstractField : public AbstractHeap {
public:
AbstractField()
{
}
AbstractField(AbstractHeap* parent, const char* heapName, ptrdiff_t offset)
: AbstractHeap(parent, heapName)
, m_offset(offset)
{
}
void initialize(AbstractHeap* parent, const char* heapName, ptrdiff_t offset)
{
AbstractHeap::initialize(parent, heapName);
m_offset = offset;
}
ptrdiff_t offset() const
{
ASSERT(isInitialized());
return m_offset;
}
void dump(PrintStream&) const;
private:
ptrdiff_t m_offset;
};
class IndexedAbstractHeap {
public:
IndexedAbstractHeap(LContext, AbstractHeap* parent, const char* heapName, ptrdiff_t offset, size_t elementSize);
~IndexedAbstractHeap();
const AbstractHeap& atAnyIndex() const { return m_heapForAnyIndex; }
const AbstractField& at(ptrdiff_t index)
{
if (static_cast<size_t>(index) < m_smallIndices.size())
return returnInitialized(m_smallIndices[index], index);
return atSlow(index);
}
const AbstractField& operator[](ptrdiff_t index) { return at(index); }
TypedPointer baseIndex(Output& out, LValue base, LValue index, JSValue indexAsConstant = JSValue(), ptrdiff_t offset = 0);
void dump(PrintStream&) const;
private:
const AbstractField& returnInitialized(AbstractField& field, ptrdiff_t index)
{
if (UNLIKELY(!field.isInitialized()))
initialize(field, index);
return field;
}
const AbstractField& atSlow(ptrdiff_t index);
void initialize(AbstractField& field, ptrdiff_t index);
AbstractHeap m_heapForAnyIndex;
size_t m_heapNameLength;
ptrdiff_t m_offset;
size_t m_elementSize;
LValue m_scaleTerm;
bool m_canShift;
std::array<AbstractField, 16> m_smallIndices;
struct WithoutZeroOrOneHashTraits : WTF::GenericHashTraits<ptrdiff_t> {
static void constructDeletedValue(ptrdiff_t& slot) { slot = 1; }
static bool isDeletedValue(ptrdiff_t value) { return value == 1; }
};
typedef HashMap<ptrdiff_t, std::unique_ptr<AbstractField>, WTF::IntHash<ptrdiff_t>, WithoutZeroOrOneHashTraits> MapType;
std::unique_ptr<MapType> m_largeIndices;
Vector<CString, 16> m_largeIndexNames;
};
class NumberedAbstractHeap {
public:
NumberedAbstractHeap(LContext, AbstractHeap* parent, const char* heapName);
~NumberedAbstractHeap();
const AbstractHeap& atAnyNumber() const { return m_indexedHeap.atAnyIndex(); }
const AbstractHeap& at(unsigned number) { return m_indexedHeap.at(number); }
const AbstractHeap& operator[](unsigned number) { return at(number); }
void dump(PrintStream&) const;
private:
IndexedAbstractHeap m_indexedHeap;
};
class AbsoluteAbstractHeap {
public:
AbsoluteAbstractHeap(LContext, AbstractHeap* parent, const char* heapName);
~AbsoluteAbstractHeap();
const AbstractHeap& atAnyAddress() const { return m_indexedHeap.atAnyIndex(); }
const AbstractHeap& at(void* address)
{
return m_indexedHeap.at(bitwise_cast<ptrdiff_t>(address));
}
const AbstractHeap& operator[](void* address) { return at(address); }
void dump(PrintStream&) const;
private:
IndexedAbstractHeap m_indexedHeap;
};
} }
#endif // ENABLE(FTL_JIT)
#endif // FTLAbstractHeap_h