Skip to content

Commit 7ae084e

Browse files
rajatdpleath
authored andcommitted
Fix jitted initialization of StackScriptFunction.
(This is a fix that Rajat implemented and I'm pushing through in his absence.) The -oopjit- code gen for StackScriptFuntion initialization assumes that the deferred prototype type can be loaded directly from the FunctionProxy that is available at JIT time. The problem is that the proxy may be redeferred and reallocated, and the type pointer may now be referring to something entirely different. To solve this, generate the same code for OOPJIT and -oopjit-, reloading the FunctionProxy from the parent's nested array at execution time.
1 parent fc8d026 commit 7ae084e

1 file changed

Lines changed: 23 additions & 60 deletions

File tree

lib/Backend/Lower.cpp

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6583,73 +6583,36 @@ Lowerer::GenerateScriptFunctionInit(IR::RegOpnd * regOpnd, IR::Opnd * vtableAddr
65836583
Js::FunctionInfoPtrPtr nestedInfo, IR::Opnd * envOpnd, IR::Instr * insertBeforeInstr, bool isZeroed)
65846584
{
65856585
Func * func = this->m_func;
6586-
IR::Opnd * functionProxyOpnd;
6587-
IR::Opnd * functionInfoOpnd = nullptr;
6588-
IR::Opnd * typeOpnd = nullptr;
6589-
bool doCheckTypeOpnd = true;
6590-
if (m_func->IsOOPJIT() || !CONFIG_FLAG(OOPJITMissingOpts) || (*nestedInfo)->IsDeferred())
6591-
{
6592-
functionInfoOpnd = IR::RegOpnd::New(TyMachPtr, func);
6593-
InsertMove(functionInfoOpnd, IR::MemRefOpnd::New(nestedInfo, TyMachPtr, func), insertBeforeInstr);
6594-
functionProxyOpnd = IR::RegOpnd::New(TyMachPtr, func);
6595-
InsertMove(functionProxyOpnd, IR::IndirOpnd::New(functionInfoOpnd->AsRegOpnd(), Js::FunctionInfo::GetOffsetOfFunctionProxy(), TyMachPtr, func), insertBeforeInstr);
6596-
typeOpnd = IR::RegOpnd::New(TyMachPtr, func);
6597-
InsertMove(typeOpnd, IR::IndirOpnd::New(functionProxyOpnd->AsRegOpnd(), Js::FunctionProxy::GetOffsetOfDeferredPrototypeType(),
6598-
TyMachPtr, func), insertBeforeInstr);
6599-
}
6600-
else
6601-
{
6602-
Js::FunctionBody * functionBody = (*nestedInfo)->GetFunctionBody();
6603-
functionProxyOpnd = CreateFunctionBodyOpnd(functionBody);
6604-
Js::ScriptFunctionType * type = functionBody->GetDeferredPrototypeType();
6605-
if (type != nullptr)
6606-
{
6607-
typeOpnd = IR::AddrOpnd::New(type, IR::AddrOpndKindDynamicType, func);
6608-
doCheckTypeOpnd = false;
6609-
}
6610-
else
6611-
{
6612-
typeOpnd = IR::RegOpnd::New(TyMachPtr, func);
6613-
InsertMove(typeOpnd,
6614-
IR::MemRefOpnd::New(((byte *)functionBody) + Js::FunctionProxy::GetOffsetOfDeferredPrototypeType(), TyMachPtr, func),
6615-
insertBeforeInstr);
6616-
}
6617-
}
6618-
6619-
if (doCheckTypeOpnd)
6620-
{
6621-
IR::LabelInstr * labelHelper = IR::LabelInstr::New(Js::OpCode::Label, func, true);
6622-
InsertTestBranch(typeOpnd, typeOpnd, Js::OpCode::BrEq_A, labelHelper, insertBeforeInstr);
6623-
IR::LabelInstr * labelDone = IR::LabelInstr::New(Js::OpCode::Label, func, false);
6624-
InsertBranch(Js::OpCode::Br, labelDone, insertBeforeInstr);
6625-
insertBeforeInstr->InsertBefore(labelHelper);
6626-
m_lowererMD.LoadHelperArgument(insertBeforeInstr, functionProxyOpnd);
6627-
6628-
IR::Instr * callHelperInstr = IR::Instr::New(Js::OpCode::Call, typeOpnd,
6629-
IR::HelperCallOpnd::New(IR::JnHelperMethod::HelperEnsureFunctionProxyDeferredPrototypeType, func), func);
6630-
insertBeforeInstr->InsertBefore(callHelperInstr);
6631-
m_lowererMD.LowerCall(callHelperInstr, 0);
6632-
insertBeforeInstr->InsertBefore(labelDone);
6633-
}
66346586

6587+
IR::Opnd * functionInfoOpnd = IR::RegOpnd::New(TyMachPtr, func);
6588+
InsertMove(functionInfoOpnd, IR::MemRefOpnd::New(nestedInfo, TyMachPtr, func), insertBeforeInstr);
6589+
IR::Opnd * functionProxyOpnd = IR::RegOpnd::New(TyMachPtr, func);
6590+
InsertMove(functionProxyOpnd, IR::IndirOpnd::New(functionInfoOpnd->AsRegOpnd(), Js::FunctionInfo::GetOffsetOfFunctionProxy(), TyMachPtr, func), insertBeforeInstr);
6591+
IR::Opnd * typeOpnd = IR::RegOpnd::New(TyMachPtr, func);
6592+
InsertMove(typeOpnd, IR::IndirOpnd::New(functionProxyOpnd->AsRegOpnd(), Js::FunctionProxy::GetOffsetOfDeferredPrototypeType(),
6593+
TyMachPtr, func), insertBeforeInstr);
6594+
6595+
IR::LabelInstr * labelHelper = IR::LabelInstr::New(Js::OpCode::Label, func, true);
6596+
InsertTestBranch(typeOpnd, typeOpnd, Js::OpCode::BrEq_A, labelHelper, insertBeforeInstr);
6597+
IR::LabelInstr * labelDone = IR::LabelInstr::New(Js::OpCode::Label, func, false);
6598+
InsertBranch(Js::OpCode::Br, labelDone, insertBeforeInstr);
6599+
insertBeforeInstr->InsertBefore(labelHelper);
6600+
m_lowererMD.LoadHelperArgument(insertBeforeInstr, functionProxyOpnd);
6601+
6602+
IR::Instr * callHelperInstr = IR::Instr::New(Js::OpCode::Call, typeOpnd,
6603+
IR::HelperCallOpnd::New(IR::JnHelperMethod::HelperEnsureFunctionProxyDeferredPrototypeType, func), func);
6604+
insertBeforeInstr->InsertBefore(callHelperInstr);
6605+
m_lowererMD.LowerCall(callHelperInstr, 0);
6606+
insertBeforeInstr->InsertBefore(labelDone);
6607+
66356608
GenerateMemInit(regOpnd, 0, vtableAddressOpnd, insertBeforeInstr, isZeroed);
66366609
GenerateMemInit(regOpnd, Js::ScriptFunction::GetOffsetOfType(), typeOpnd, insertBeforeInstr, isZeroed);
66376610
GenerateMemInitNull(regOpnd, Js::ScriptFunction::GetOffsetOfAuxSlots(), insertBeforeInstr, isZeroed);
66386611
GenerateMemInitNull(regOpnd, Js::ScriptFunction::GetOffsetOfObjectArray(), insertBeforeInstr, isZeroed);
66396612
GenerateMemInit(regOpnd, Js::ScriptFunction::GetOffsetOfConstructorCache(),
6640-
LoadLibraryValueOpnd(insertBeforeInstr, LibraryValue::ValueConstructorCacheDefaultInstance),
6613+
LoadLibraryValueOpnd(insertBeforeInstr, LibraryValue::ValueConstructorCacheDefaultInstance),
66416614
insertBeforeInstr, isZeroed);
6642-
if (!functionInfoOpnd)
6643-
{
6644-
if (functionProxyOpnd->IsRegOpnd())
6645-
{
6646-
functionInfoOpnd = IR::IndirOpnd::New(functionProxyOpnd->AsRegOpnd(), Js::FunctionProxy::GetOffsetOfFunctionInfo(), TyMachReg, func);
6647-
}
6648-
else
6649-
{
6650-
functionInfoOpnd = IR::MemRefOpnd::New((BYTE*)functionProxyOpnd->AsAddrOpnd()->m_address + Js::FunctionProxy::GetOffsetOfFunctionInfo(), TyMachReg, func);
6651-
}
6652-
}
6615+
66536616
GenerateMemInit(regOpnd, Js::ScriptFunction::GetOffsetOfFunctionInfo(), functionInfoOpnd, insertBeforeInstr, isZeroed);
66546617
GenerateMemInit(regOpnd, Js::ScriptFunction::GetOffsetOfEnvironment(), envOpnd, insertBeforeInstr, isZeroed);
66556618
GenerateMemInitNull(regOpnd, Js::ScriptFunction::GetOffsetOfCachedScopeObj(), insertBeforeInstr, isZeroed);

0 commit comments

Comments
 (0)