Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise redeferral heuristic #1786

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/Backend/BailOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ void BailOutRecord::ScheduleFunctionCodeGen(Js::ScriptFunction * function, Js::S
bailOutRecordNotConst->bailOutCount++;

Js::FunctionEntryPointInfo *entryPointInfo = function->GetFunctionEntryPointInfo();
uint8 callsCount = entryPointInfo->callsCount;
uint32 callsCount = entryPointInfo->callsCount;
RejitReason rejitReason = RejitReason::None;
bool reThunk = false;

Expand Down Expand Up @@ -2297,11 +2297,7 @@ void BailOutRecord::ScheduleLoopBodyCodeGen(Js::ScriptFunction * function, Js::S

entryPointInfo->totalJittedLoopIterations += entryPointInfo->jittedLoopIterationsSinceLastBailout;
entryPointInfo->jittedLoopIterationsSinceLastBailout = 0;
if (entryPointInfo->totalJittedLoopIterations > UINT8_MAX)
{
entryPointInfo->totalJittedLoopIterations = UINT8_MAX;
}
uint8 totalJittedLoopIterations = (uint8)entryPointInfo->totalJittedLoopIterations;
uint32 totalJittedLoopIterations = (uint8)entryPointInfo->totalJittedLoopIterations;
totalJittedLoopIterations = totalJittedLoopIterations <= Js::LoopEntryPointInfo::GetDecrLoopCountPerBailout() ? 0 : totalJittedLoopIterations - Js::LoopEntryPointInfo::GetDecrLoopCountPerBailout();

CheckPreemptiveRejit(executeFunction, bailOutKind, bailOutRecordNotConst, totalJittedLoopIterations, interpreterFrame->GetCurrentLoopNum());
Expand Down Expand Up @@ -2583,7 +2579,7 @@ void BailOutRecord::ScheduleLoopBodyCodeGen(Js::ScriptFunction * function, Js::S
}
}

void BailOutRecord::CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint8& callsOrIterationsCount, int loopNumber)
void BailOutRecord::CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint32& callsOrIterationsCount, int loopNumber)
{
if (bailOutKind == IR::BailOutOnNoProfile && executeFunction->IncrementBailOnMisingProfileCount() > CONFIG_FLAG(BailOnNoProfileLimit))
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/BailOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class BailOutRecord

static void ScheduleFunctionCodeGen(Js::ScriptFunction * function, Js::ScriptFunction * innerMostInlinee, BailOutRecord const * bailOutRecord, IR::BailOutKind bailOutKind, Js::ImplicitCallFlags savedImplicitCallFlags, void * returnAddress);
static void ScheduleLoopBodyCodeGen(Js::ScriptFunction * function, Js::ScriptFunction * innerMostInlinee, BailOutRecord const * bailOutRecord, IR::BailOutKind bailOutKind);
static void CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint8& callsOrIterationsCount, int loopNumber);
static void CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint32& callsOrIterationsCount, int loopNumber);
void RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStackLayout * layout, Js::InterpreterStackFrame * newInstance, Js::ScriptContext * scriptContext,
bool fromLoopBody, Js::Var * registerSaves, BailOutReturnValue * returnValue, Js::Var* pArgumentsObject, Js::Var branchValue = nullptr, void* returnAddress = nullptr, bool useStartCall = true, void * argoutRestoreAddress = nullptr) const;
void RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStackLayout * layout, uint count, __in_ecount_opt(count) int * offsets, int argOutSlotId,
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ Func::CreateInlineeStackSym()
return stackSym;
}

uint8 *
uint32 *
Func::GetCallsCountAddress() const
{
Assert(this->m_workItem->Type() == JsFunctionType);
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/Func.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
StackSym *GetLocalFrameDisplaySym() const { return m_localFrameDisplaySym; }
void SetLocalFrameDisplaySym(StackSym *sym) { m_localFrameDisplaySym = sym; }

uint8 *GetCallsCountAddress() const;
uint32 *GetCallsCountAddress() const;
uint *GetJittedLoopIterationsSinceLastBailoutAddress() const;

void EnsurePinnedTypeRefs();
Expand Down
45 changes: 25 additions & 20 deletions lib/Backend/Inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ uint Inline::FillInlineesDataArray(
}

Js::FunctionBody *inlineeFunctionBody = inlineeJitTimeData->GetFunctionBody();
if (!PHASE_OFF(Js::PolymorphicInlinePhase, inlineeFunctionBody))
if (inlineeFunctionBody && !PHASE_OFF(Js::PolymorphicInlinePhase, inlineeFunctionBody))
{
const Js::FunctionCodeGenJitTimeData* rightInlineeJitTimeData = inlineeJitTimeData->GetJitTimeDataFromFunctionInfo(inlineeFunctionBody);
const Js::FunctionCodeGenRuntimeData* rightInlineeRuntimeData = inlineeRuntimeData->GetRuntimeDataFromFunctionInfo(inlineeFunctionBody);
const Js::FunctionCodeGenJitTimeData* rightInlineeJitTimeData = inlineeJitTimeData->GetJitTimeDataFromFunctionInfo(inlineeFunctionBody->GetFunctionInfo());
const Js::FunctionCodeGenRuntimeData* rightInlineeRuntimeData = inlineeRuntimeData->GetRuntimeDataFromFunctionInfo(inlineeFunctionBody->GetFunctionInfo());

if (rightInlineeJitTimeData)
{
Expand Down Expand Up @@ -549,17 +549,18 @@ void Inline::FillInlineesDataArrayUsingFixedMethods(
while (inlineeJitTimeData)
{
inlineeFuncBody = inlineeJitTimeData->GetFunctionBody();
if (!PHASE_OFF(Js::PolymorphicInlinePhase, inlineeFuncBody) && !PHASE_OFF(Js::PolymorphicInlineFixedMethodsPhase, inlineeFuncBody))
if (inlineeFuncBody && !PHASE_OFF(Js::PolymorphicInlinePhase, inlineeFuncBody) && !PHASE_OFF(Js::PolymorphicInlineFixedMethodsPhase, inlineeFuncBody))
{
const Js::FunctionCodeGenJitTimeData* jitTimeData = inlineeJitTimeData->GetJitTimeDataFromFunctionInfo(inlineeFuncBody);
const Js::FunctionCodeGenJitTimeData* jitTimeData = inlineeJitTimeData->GetJitTimeDataFromFunctionInfo(inlineeFuncBody->GetFunctionInfo());
if (jitTimeData)
{
for (uint16 i = 0; i < cachedFixedInlineeCount; i++)
{
if (inlineeFuncBody == ((Js::JavascriptFunction*)(fixedFieldInfoArray[i].fieldValue))->GetFunctionBody())
Js::ParseableFunctionInfo *info = ((Js::JavascriptFunction*)(fixedFieldInfoArray[i].fieldValue))->GetParseableFunctionInfo();
if (info->IsFunctionBody() && inlineeFuncBody == info->GetFunctionBody())
{
inlineesDataArray[i].inlineeJitTimeData = inlineeJitTimeData->GetJitTimeDataFromFunctionInfo(inlineeFuncBody);
inlineesDataArray[i].inlineeRuntimeData = inlineeRuntimeData->GetRuntimeDataFromFunctionInfo(inlineeFuncBody);
inlineesDataArray[i].inlineeJitTimeData = inlineeJitTimeData->GetJitTimeDataFromFunctionInfo(inlineeFuncBody->GetFunctionInfo());
inlineesDataArray[i].inlineeRuntimeData = inlineeRuntimeData->GetRuntimeDataFromFunctionInfo(inlineeFuncBody->GetFunctionInfo());
inlineesDataArray[i].functionBody = inlineeFuncBody;
break;
}
Expand Down Expand Up @@ -759,7 +760,7 @@ Inline::InlinePolymorphicFunctionUsingFixedMethods(IR::Instr *callInstr, const J
if (i == 0)
{
// Do all the general, non-function-object-specific checks just once.
if (!TryOptimizeCallInstrWithFixedMethod(callInstr, (Js::FunctionInfo*)(inlineesDataArray[i].functionBody), true, false, false, true /*isInlined*/, safeThis, true /*dontOptimizeJustCheck*/, i))
if (!TryOptimizeCallInstrWithFixedMethod(callInstr, inlineesDataArray[i].functionBody->GetFunctionInfo(), true, false, false, true /*isInlined*/, safeThis, true /*dontOptimizeJustCheck*/, i))
{
POLYMORPHIC_INLINE_TESTTRACE(_u("INLINING (Polymorphic; Using Fixed Methods): Skip Inline: can't optimize using Fixed Methods %d (Max: %d)\tInlinee: %s (%s):\tCaller: %s (%s)\n"),
inlineeCount, Js::DynamicProfileInfo::maxPolymorphicInliningSize,
Expand All @@ -771,7 +772,7 @@ Inline::InlinePolymorphicFunctionUsingFixedMethods(IR::Instr *callInstr, const J
else
{
if (methodPropertyOpnd->GetFieldValueAsFixedFunction(i) &&
methodPropertyOpnd->GetFieldValueAsFixedFunction(i)->GetFunctionInfo() != (Js::FunctionInfo*)(inlineesDataArray[i].functionBody))
methodPropertyOpnd->GetFieldValueAsFixedFunction(i)->GetFunctionInfo() != inlineesDataArray[i].functionBody->GetFunctionInfo())
{
POLYMORPHIC_INLINE_TESTTRACE(_u("INLINING (Polymorphic; Using Fixed Methods): Skip Inline: can't optimize using Fixed Methods %d (Max: %d)\tInlinee: %s (%s):\tCaller: %s (%s)\n"),
inlineeCount, Js::DynamicProfileInfo::maxPolymorphicInliningSize,
Expand Down Expand Up @@ -1012,7 +1013,7 @@ Inline::InlinePolymorphicFunction(IR::Instr *callInstr, const Js::FunctionCodeGe
IR::RegOpnd* functionObject = callInstr->GetSrc1()->AsRegOpnd();
dispatchStartLabel->InsertBefore(IR::BranchInstr::New(Js::OpCode::BrAddr_A, inlineeStartLabel,
IR::IndirOpnd::New(functionObject, Js::JavascriptFunction::GetOffsetOfFunctionInfo(), TyMachPtr, dispatchStartLabel->m_func),
IR::AddrOpnd::New(inlineesDataArray[i].functionBody, IR::AddrOpndKindDynamicFunctionBody, dispatchStartLabel->m_func), dispatchStartLabel->m_func));
IR::AddrOpnd::New(inlineesDataArray[i].functionBody->GetFunctionInfo(), IR::AddrOpndKindDynamicFunctionInfo, dispatchStartLabel->m_func), dispatchStartLabel->m_func));
}

CompletePolymorphicInlining(callInstr, returnValueOpnd, doneLabel, dispatchStartLabel, /*ldMethodFldInstr*/nullptr, IR::BailOutOnPolymorphicInlineFunction);
Expand Down Expand Up @@ -3440,11 +3441,11 @@ Inline::InlineFunctionCommon(IR::Instr *callInstr, StackSym* originalCallTargetS
#endif
if (callInstr->m_opcode == Js::OpCode::CallIFixed)
{
Assert(callInstr->GetFixedFunction()->GetFunctionInfo() == funcBody);
Assert(callInstr->GetFixedFunction()->GetFunctionInfo() == funcBody->GetFunctionInfo());
}
else
{
PrepareInsertionPoint(callInstr, funcBody, inlineBailoutChecksBeforeInstr);
PrepareInsertionPoint(callInstr, funcBody->GetFunctionInfo(), inlineBailoutChecksBeforeInstr);
}

Assert(formalCount <= Js::InlineeCallInfo::MaxInlineeArgoutCount);
Expand Down Expand Up @@ -3961,14 +3962,14 @@ Inline::InsertJsFunctionCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr
}

void
Inline::InsertFunctionBodyCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr, IR::Instr* bailoutInstr, Js::FunctionInfo *funcInfo)
Inline::InsertFunctionInfoCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr, IR::Instr* bailoutInstr, Js::FunctionInfo *funcInfo)
{
// if (JavascriptFunction::FromVar(r1)->functionInfo != funcInfo) goto noInlineLabel
// BrNeq_I4 noInlineLabel, r1->functionInfo, funcInfo
IR::IndirOpnd* funcBody = IR::IndirOpnd::New(callInstr->GetSrc1()->AsRegOpnd(), Js::JavascriptFunction::GetOffsetOfFunctionInfo(), TyMachPtr, callInstr->m_func);
IR::AddrOpnd* inlinedFuncBody = IR::AddrOpnd::New(funcInfo, IR::AddrOpndKindDynamicFunctionBody, callInstr->m_func);
bailoutInstr->SetSrc1(funcBody);
bailoutInstr->SetSrc2(inlinedFuncBody);
IR::IndirOpnd* opndFuncInfo = IR::IndirOpnd::New(callInstr->GetSrc1()->AsRegOpnd(), Js::JavascriptFunction::GetOffsetOfFunctionInfo(), TyMachPtr, callInstr->m_func);
IR::AddrOpnd* inlinedFuncInfo = IR::AddrOpnd::New(funcInfo, IR::AddrOpndKindDynamicFunctionInfo, callInstr->m_func);
bailoutInstr->SetSrc1(opndFuncInfo);
bailoutInstr->SetSrc2(inlinedFuncInfo);

insertBeforeInstr->InsertBefore(bailoutInstr);
}
Expand All @@ -3987,6 +3988,10 @@ Inline::InsertFunctionObjectCheck(IR::Instr *callInstr, IR::Instr *insertBeforeI
IR::Instr *
Inline::PrepareInsertionPoint(IR::Instr *callInstr, Js::FunctionInfo *funcInfo, IR::Instr *insertBeforeInstr, IR::BailOutKind bailOutKind)
{
if (callInstr->m_func == this->topFunc && this->topFunc->GetLocalFunctionId()==160 && callInstr->GetByteCodeOffset()==0x1f)
{
*(volatile int*)this;
}
Assert(insertBeforeInstr);
Assert(insertBeforeInstr->m_func == callInstr->m_func);
Assert(bailOutKind == IR::BailOutOnInlineFunction);
Expand All @@ -4006,7 +4011,7 @@ Inline::PrepareInsertionPoint(IR::Instr *callInstr, Js::FunctionInfo *funcInfo,
InsertFunctionTypeIdCheck(callInstr, insertBeforeInstr, bailOutIfNotJsFunction);

// 3. Bailout if function body doesn't match funcInfo
InsertFunctionBodyCheck(callInstr, insertBeforeInstr, primaryBailOutInstr, funcInfo);
InsertFunctionInfoCheck(callInstr, insertBeforeInstr, primaryBailOutInstr, funcInfo);

return primaryBailOutInstr;
}
Expand Down Expand Up @@ -5369,4 +5374,4 @@ Inline::Simd128FixLoadStoreInstr(Js::BuiltinFunction builtInId, IR::Instr * call

}
}
#endif
#endif
2 changes: 1 addition & 1 deletion lib/Backend/Inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Inline
void InsertObjectCheck(IR::Instr *callInstr, IR::Instr* insertBeforeInstr, IR::Instr*bailOutInstr);
void InsertFunctionTypeIdCheck(IR::Instr *callInstr, IR::Instr* insertBeforeInstr, IR::Instr*bailOutInstr);
void InsertJsFunctionCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr, IR::BailOutKind bailOutKind);
void InsertFunctionBodyCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr, IR::Instr* bailoutInstr, Js::FunctionInfo *funcInfo);
void InsertFunctionInfoCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr, IR::Instr* bailoutInstr, Js::FunctionInfo *funcInfo);
void InsertFunctionObjectCheck(IR::Instr *callInstr, IR::Instr *insertBeforeInstr, IR::Instr* bailoutInstr, Js::FunctionInfo *funcInfo);

void TryResetObjTypeSpecFldInfoOn(IR::PropertySymOpnd* propertySymOpnd);
Expand Down
4 changes: 2 additions & 2 deletions lib/Backend/InliningDecider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ uint InliningDecider::InlinePolymorphicCallSite(Js::FunctionBody *const inliner,
AssertMsg(inlineeCount >= 2, "There are at least two polymorphic call site");
break;
}
if (Inline(inliner, functionBodyArray[inlineeCount], isConstructorCall, true /*isPolymorphicCall*/, 0, profiledCallSiteId, recursiveInlineDepth, false))
if (Inline(inliner, functionBodyArray[inlineeCount]->GetFunctionInfo(), isConstructorCall, true /*isPolymorphicCall*/, 0, profiledCallSiteId, recursiveInlineDepth, false))
{
canInlineArray[inlineeCount] = true;
actualInlineeCount++;
Expand Down Expand Up @@ -272,7 +272,7 @@ Js::FunctionInfo *InliningDecider::Inline(Js::FunctionBody *const inliner, Js::F
#endif

this->bytecodeInlinedCount += inlinee->GetByteCodeCount();
return inlinee;
return inlinee->GetFunctionInfo();
}

Js::OpCode builtInInlineCandidateOpCode;
Expand Down
Loading