Skip to content

Commit fe8f981

Browse files
pleathMikeHolman
authored andcommitted
1 parent 1e5d3f5 commit fe8f981

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

lib/Backend/BackwardPass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5422,7 +5422,14 @@ BackwardPass::TrackObjTypeSpecProperties(IR::PropertySymOpnd *opnd, BasicBlock *
54225422
// Some instr protected by this one requires a monomorphic type check. (E.g., final type opt,
54235423
// fixed field not loaded from prototype.) Note the IsTypeAvailable test above: only do this at
54245424
// the initial type check that protects this path.
5425-
opnd->SetMonoGuardType(bucket->GetMonoGuardType());
5425+
if (!opnd->SetMonoGuardType(bucket->GetMonoGuardType()))
5426+
{
5427+
// We can't safely check for the required type here. Clear the objtypespec info to disable optimization
5428+
// using this inline cache, since there appears to be a mismatch, and re-jit.
5429+
// (Dead store pass is too late to generate the bailout points we need to use this type correctly.)
5430+
this->currentInstr->m_func->ClearObjTypeSpecFldInfo(opnd->m_inlineCacheIndex);
5431+
throw Js::RejitException(RejitReason::FailedEquivalentTypeCheck);
5432+
}
54265433
this->currentInstr->ChangeEquivalentToMonoTypeCheckBailOut();
54275434
}
54285435
bucket->SetMonoGuardType(nullptr);

lib/Backend/Func.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ Func::Codegen(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
348348
case RejitReason::MemOpDisabled:
349349
outputData->disableMemOp = TRUE;
350350
break;
351+
case RejitReason::FailedEquivalentTypeCheck:
352+
// No disable flag. The thrower of the re-jit exception must guarantee that objtypespec is disabled where appropriate.
353+
break;
351354
default:
352355
Assume(UNREACHED);
353356
}
@@ -1521,6 +1524,12 @@ Func::GetObjTypeSpecFldInfo(const uint index) const
15211524
return GetWorkItem()->GetJITTimeInfo()->GetObjTypeSpecFldInfo(index);
15221525
}
15231526

1527+
void
1528+
Func::ClearObjTypeSpecFldInfo(const uint index)
1529+
{
1530+
GetWorkItem()->GetJITTimeInfo()->ClearObjTypeSpecFldInfo(index);
1531+
}
1532+
15241533
ObjTypeSpecFldInfo*
15251534
Func::GetGlobalObjTypeSpecFldInfo(uint propertyInfoId) const
15261535
{

lib/Backend/Func.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
579579
Js::Var AllocateNumber(double value);
580580

581581
ObjTypeSpecFldInfo* GetObjTypeSpecFldInfo(const uint index) const;
582+
void ClearObjTypeSpecFldInfo(const uint index);
582583
ObjTypeSpecFldInfo* GetGlobalObjTypeSpecFldInfo(uint propertyInfoId) const;
583584

584585
// Gets an inline cache pointer to use in jitted code. Cached data may not be stable while jitting. Does not return null.

lib/Backend/FunctionJITTimeInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ FunctionJITTimeInfo::GetObjTypeSpecFldInfo(uint index) const
311311
return reinterpret_cast<ObjTypeSpecFldInfo *>(m_data.objTypeSpecFldInfoArray[index]);
312312
}
313313

314+
void
315+
FunctionJITTimeInfo::ClearObjTypeSpecFldInfo(uint index)
316+
{
317+
if (m_data.objTypeSpecFldInfoArray == nullptr)
318+
{
319+
return;
320+
}
321+
AssertOrFailFast(index < m_data.objTypeSpecFldInfoCount);
322+
323+
m_data.objTypeSpecFldInfoArray[index] = nullptr;
324+
}
325+
314326
ObjTypeSpecFldInfo *
315327
FunctionJITTimeInfo::GetGlobalObjTypeSpecFldInfo(uint index) const
316328
{

lib/Backend/FunctionJITTimeInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class FunctionJITTimeInfo
3838
const BVFixed * GetInlineesBV() const;
3939
const FunctionJITTimeInfo * GetJitTimeDataFromFunctionInfoAddr(intptr_t polyFuncInfo) const;
4040
ObjTypeSpecFldInfo * GetObjTypeSpecFldInfo(uint index) const;
41+
void ClearObjTypeSpecFldInfo(uint index);
4142
ObjTypeSpecFldInfo * GetGlobalObjTypeSpecFldInfo(uint index) const;
4243
uint GetGlobalObjTypeSpecFldInfoCount() const;
4344
const FunctionJITRuntimeInfo * GetInlineeForTargetInlineeRuntimeData(const Js::ProfileId profiledCallSiteId, intptr_t inlineeFuncBodyAddr) const;

lib/Backend/Opnd.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,17 @@ class PropertySymOpnd sealed : public SymOpnd
799799
return this->monoGuardType;
800800
}
801801

802-
void SetMonoGuardType(JITTypeHolder type)
802+
bool SetMonoGuardType(JITTypeHolder type)
803803
{
804+
if (!(this->monoGuardType == nullptr || this->monoGuardType == type) ||
805+
!((HasEquivalentTypeSet() && GetEquivalentTypeSet()->Contains(type)) ||
806+
(!HasEquivalentTypeSet() && GetType() == type)))
807+
{
808+
// Required type is not in the available set, or we already set the type to something else. Inform the caller.
809+
return false;
810+
}
804811
this->monoGuardType = type;
812+
return true;
805813
}
806814

807815
bool NeedsMonoCheck() const

0 commit comments

Comments
 (0)