ObjectAllocationProfile.h [plain text]
#pragma once
#include "VM.h"
#include "JSGlobalObject.h"
#include "ObjectPrototype.h"
#include "SlotVisitor.h"
#include "WriteBarrier.h"
namespace JSC {
class FunctionRareData;
template<typename Derived>
class ObjectAllocationProfileBase {
friend class LLIntOffsetsExtractor;
public:
static ptrdiff_t offsetOfAllocator() { return OBJECT_OFFSETOF(ObjectAllocationProfileBase, m_allocator); }
static ptrdiff_t offsetOfStructure() { return OBJECT_OFFSETOF(ObjectAllocationProfileBase, m_structure); }
ObjectAllocationProfileBase() = default;
bool isNull() { return !m_structure; }
void initializeProfile(VM&, JSGlobalObject*, JSCell* owner, JSObject* prototype, unsigned inferredInlineCapacity, JSFunction* constructor = nullptr, FunctionRareData* = nullptr);
Structure* structure()
{
Structure* structure = m_structure.get();
WTF::loadLoadFence();
return structure;
}
protected:
void clear()
{
m_allocator = Allocator();
m_structure.clear();
ASSERT(isNull());
}
void visitAggregate(SlotVisitor& visitor)
{
visitor.append(m_structure);
}
private:
unsigned possibleDefaultPropertyCount(VM&, JSObject* prototype);
Allocator m_allocator; WriteBarrier<Structure> m_structure;
};
class ObjectAllocationProfile : public ObjectAllocationProfileBase<ObjectAllocationProfile> {
public:
using Base = ObjectAllocationProfileBase<ObjectAllocationProfile>;
ObjectAllocationProfile() = default;
using Base::clear;
using Base::visitAggregate;
void setPrototype(VM&, JSCell*, JSObject*) { }
};
class ObjectAllocationProfileWithPrototype : public ObjectAllocationProfileBase<ObjectAllocationProfileWithPrototype> {
public:
using Base = ObjectAllocationProfileBase<ObjectAllocationProfileWithPrototype>;
static ptrdiff_t offsetOfPrototype() { return OBJECT_OFFSETOF(ObjectAllocationProfileWithPrototype, m_prototype); }
ObjectAllocationProfileWithPrototype() = default;
JSObject* prototype()
{
JSObject* prototype = m_prototype.get();
WTF::loadLoadFence();
return prototype;
}
void clear()
{
Base::clear();
m_prototype.clear();
ASSERT(isNull());
}
void visitAggregate(SlotVisitor& visitor)
{
Base::visitAggregate(visitor);
visitor.append(m_prototype);
}
void setPrototype(VM& vm, JSCell* owner, JSObject* object)
{
m_prototype.set(vm, owner, object);
}
private:
WriteBarrier<JSObject> m_prototype;
};
}