#include "config.h"
#include "FTLOperations.h"
#if ENABLE(FTL_JIT)
#include "ClonedArguments.h"
#include "DirectArguments.h"
#include "JSCInlines.h"
#include "JSLexicalEnvironment.h"
namespace JSC { namespace FTL {
using namespace JSC::DFG;
extern "C" JSCell* JIT_OPERATION operationNewObjectWithButterfly(ExecState* exec, Structure* structure)
{
VM& vm = exec->vm();
NativeCallFrameTracer tracer(&vm, exec);
Butterfly* butterfly = Butterfly::create(
vm, nullptr, 0, structure->outOfLineCapacity(), false, IndexingHeader(), 0);
return JSFinalObject::create(exec, structure, butterfly);
}
extern "C" JSCell* JIT_OPERATION operationMaterializeObjectInOSR(
ExecState* exec, ExitTimeObjectMaterialization* materialization, EncodedJSValue* values)
{
VM& vm = exec->vm();
CodeBlock* codeBlock = exec->codeBlock();
DeferGCForAWhile deferGC(vm.heap);
switch (materialization->type()) {
case PhantomNewObject: {
Structure* structure = nullptr;
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location() != PromotedLocationDescriptor(StructurePLoc))
continue;
structure = jsCast<Structure*>(JSValue::decode(values[i]));
break;
}
RELEASE_ASSERT(structure);
JSFinalObject* result = JSFinalObject::create(vm, structure);
for (PropertyMapEntry entry : structure->getPropertiesConcurrently()) {
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location().kind() != NamedPropertyPLoc)
continue;
if (codeBlock->identifier(property.location().info()).impl() != entry.key)
continue;
result->putDirect(vm, entry.offset, JSValue::decode(values[i]));
}
}
return result;
}
case PhantomNewFunction: {
FunctionExecutable* executable = nullptr;
JSScope* activation = nullptr;
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location() == PromotedLocationDescriptor(FunctionExecutablePLoc))
executable = jsCast<FunctionExecutable*>(JSValue::decode(values[i]));
if (property.location() == PromotedLocationDescriptor(FunctionActivationPLoc))
activation = jsCast<JSScope*>(JSValue::decode(values[i]));
}
RELEASE_ASSERT(executable && activation);
JSFunction* result = JSFunction::createWithInvalidatedReallocationWatchpoint(vm, executable, activation);
return result;
}
case PhantomCreateActivation: {
JSScope* scope = nullptr;
SymbolTable* table = nullptr;
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location() == PromotedLocationDescriptor(ActivationScopePLoc))
scope = jsCast<JSScope*>(JSValue::decode(values[i]));
else if (property.location() == PromotedLocationDescriptor(ActivationSymbolTablePLoc))
table = jsCast<SymbolTable*>(JSValue::decode(values[i]));
}
RELEASE_ASSERT(scope);
RELEASE_ASSERT(table);
CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock(
materialization->origin(), exec->codeBlock());
Structure* structure = codeBlock->globalObject()->activationStructure();
JSLexicalEnvironment* result = JSLexicalEnvironment::create(vm, structure, scope, table);
RELEASE_ASSERT(materialization->properties().size() - 2 == table->scopeSize());
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location().kind() != ClosureVarPLoc)
continue;
result->variableAt(ScopeOffset(property.location().info())).set(exec->vm(), result, JSValue::decode(values[i]));
}
if (validationEnabled()) {
ConcurrentJITLocker locker(table->m_lock);
for (auto iter = table->begin(locker), end = table->end(locker); iter != end; ++iter) {
bool found = false;
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location().kind() != ClosureVarPLoc)
continue;
if (ScopeOffset(property.location().info()) == iter->value.scopeOffset()) {
found = true;
break;
}
}
ASSERT_UNUSED(found, found);
}
unsigned numberOfClosureVarPloc = 0;
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location().kind() == ClosureVarPLoc)
numberOfClosureVarPloc++;
}
ASSERT(numberOfClosureVarPloc == table->scopeSize());
}
return result;
}
case PhantomDirectArguments:
case PhantomClonedArguments: {
if (!materialization->origin().inlineCallFrame) {
switch (materialization->type()) {
case PhantomDirectArguments:
return DirectArguments::createByCopying(exec);
case PhantomClonedArguments:
return ClonedArguments::createWithMachineFrame(exec, exec, ArgumentsMode::Cloned);
default:
RELEASE_ASSERT_NOT_REACHED();
return nullptr;
}
}
unsigned argumentCount = 0;
if (materialization->origin().inlineCallFrame->isVarargs()) {
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location() != PromotedLocationDescriptor(ArgumentCountPLoc))
continue;
argumentCount = JSValue::decode(values[i]).asUInt32();
RELEASE_ASSERT(argumentCount);
break;
}
RELEASE_ASSERT(argumentCount);
} else
argumentCount = materialization->origin().inlineCallFrame->arguments.size();
JSFunction* callee = nullptr;
if (materialization->origin().inlineCallFrame->isClosureCall) {
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location() != PromotedLocationDescriptor(ArgumentsCalleePLoc))
continue;
callee = jsCast<JSFunction*>(JSValue::decode(values[i]));
break;
}
} else
callee = materialization->origin().inlineCallFrame->calleeConstant();
RELEASE_ASSERT(callee);
CodeBlock* codeBlock = baselineCodeBlockForOriginAndBaselineCodeBlock(
materialization->origin(), exec->codeBlock());
switch (materialization->type()) {
case PhantomDirectArguments: {
unsigned length = argumentCount - 1;
unsigned capacity = std::max(length, static_cast<unsigned>(codeBlock->numParameters() - 1));
DirectArguments* result = DirectArguments::create(
vm, codeBlock->globalObject()->directArgumentsStructure(), length, capacity);
result->callee().set(vm, result, callee);
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location().kind() != ArgumentPLoc)
continue;
unsigned index = property.location().info();
if (index >= capacity)
continue;
result->argument(DirectArgumentsOffset(index)).set(
vm, result, JSValue::decode(values[i]));
}
return result;
}
case PhantomClonedArguments: {
unsigned length = argumentCount - 1;
ClonedArguments* result = ClonedArguments::createEmpty(
vm, codeBlock->globalObject()->outOfBandArgumentsStructure(), callee);
for (unsigned i = materialization->properties().size(); i--;) {
const ExitPropertyValue& property = materialization->properties()[i];
if (property.location().kind() != ArgumentPLoc)
continue;
unsigned index = property.location().info();
if (index >= length)
continue;
result->putDirectIndex(exec, index, JSValue::decode(values[i]));
}
result->putDirect(vm, vm.propertyNames->length, jsNumber(length));
return result;
}
default:
RELEASE_ASSERT_NOT_REACHED();
return nullptr;
}
}
default:
RELEASE_ASSERT_NOT_REACHED();
return nullptr;
}
}
} }
#endif // ENABLE(FTL_JIT)