InferredTypeTable.cpp [plain text]
#include "config.h"
#include "InferredTypeTable.h"
#include "JSCInlines.h"
namespace JSC {
const ClassInfo InferredTypeTable::s_info = { "InferredTypeTable", 0, 0, CREATE_METHOD_TABLE(InferredTypeTable) };
InferredTypeTable* InferredTypeTable::create(VM& vm)
{
InferredTypeTable* result = new (NotNull, allocateCell<InferredTypeTable>(vm.heap)) InferredTypeTable(vm);
result->finishCreation(vm);
return result;
}
void InferredTypeTable::destroy(JSCell* cell)
{
InferredTypeTable* inferredTypeTable = static_cast<InferredTypeTable*>(cell);
inferredTypeTable->InferredTypeTable::~InferredTypeTable();
}
Structure* InferredTypeTable::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
}
void InferredTypeTable::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
InferredTypeTable* inferredTypeTable = jsCast<InferredTypeTable*>(cell);
ConcurrentJITLocker locker(inferredTypeTable->m_lock);
for (auto& entry : inferredTypeTable->m_table) {
if (!entry.value)
continue;
if (entry.value->isRelevant())
visitor.append(&entry.value);
else
entry.value.clear();
}
}
InferredType* InferredTypeTable::get(const ConcurrentJITLocker&, UniquedStringImpl* uid)
{
auto iter = m_table.find(uid);
if (iter == m_table.end() || !iter->value)
return nullptr;
if (!iter->value->isRelevant()) {
iter->value.clear();
return nullptr;
}
return iter->value.get();
}
InferredType* InferredTypeTable::get(UniquedStringImpl* uid)
{
ConcurrentJITLocker locker(m_lock);
return get(locker, uid);
}
InferredType* InferredTypeTable::get(PropertyName propertyName)
{
return get(propertyName.uid());
}
bool InferredTypeTable::willStoreValue(
VM& vm, PropertyName propertyName, JSValue value, StoredPropertyAge age)
{
if (age == OldProperty) {
TableType::iterator iter = m_table.find(propertyName.uid());
if (iter == m_table.end() || !iter->value)
return false;
if (iter->value->willStoreValue(vm, propertyName, value))
return true;
iter->value.clear();
return false;
}
TableType::AddResult result;
{
ConcurrentJITLocker locker(m_lock);
result = m_table.add(propertyName.uid(), WriteBarrier<InferredType>());
}
if (result.isNewEntry) {
InferredType* inferredType = InferredType::create(vm);
WTF::storeStoreFence();
result.iterator->value.set(vm, this, inferredType);
} else if (!result.iterator->value)
return false;
if (result.iterator->value->willStoreValue(vm, propertyName, value))
return true;
result.iterator->value.clear();
return false;
}
void InferredTypeTable::makeTop(VM& vm, PropertyName propertyName, StoredPropertyAge age)
{
if (age == OldProperty) {
TableType::iterator iter = m_table.find(propertyName.uid());
if (iter == m_table.end() || !iter->value)
return;
iter->value->makeTop(vm, propertyName);
iter->value.clear();
return;
}
TableType::AddResult result;
{
ConcurrentJITLocker locker(m_lock);
result = m_table.add(propertyName.uid(), WriteBarrier<InferredType>());
}
if (!result.iterator->value)
return;
result.iterator->value->makeTop(vm, propertyName);
result.iterator->value.clear();
}
InferredTypeTable::InferredTypeTable(VM& vm)
: Base(vm, vm.inferredTypeTableStructure.get())
{
}
InferredTypeTable::~InferredTypeTable()
{
}
}