Skip to content

Commit c0723f4

Browse files
committed
Moving RS4 changes to master
This change includes the following fixes - Added a new mechanism to mark reentrancy. When a helper calls into user code we will have to explicitly either set the implicit call flags or mark that call as reentrancy safe - Added checks in lowerer to confirm that we emit an implicit call bailout check after a helper call - Added failfasts, under a config flag, to validate the int range assumptions made in Globopt - Added check to make sure an opcode that can't have implicit call do not lower a helper call that can have implicit calls - Moved the reentrancy lock assert to Recycler right before dispose - Fixed an issue where during expression evaluation we were not restoring the updated block id in case of a parenthesis in destructed params - Along with ignoring null valuetype bit, also ignore undefined bit in the IsSimilar function as ToDefinite() strips out the undefined bit - Assert that we don't have a reentrancy lock when calling Dispose in a deterministic way.
1 parent e74bc9f commit c0723f4

File tree

130 files changed

+3573
-1679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+3573
-1679
lines changed

Build/Common.Build.ProjectConfiguration.props

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@
4242
<Platform>ARM</Platform>
4343
</ProjectConfiguration>
4444
</ItemGroup>
45+
<ItemGroup Label="ProjectConfigurations">
46+
<ProjectConfiguration Include="Debug|CHPE">
47+
<Configuration>Debug</Configuration>
48+
<Platform>CHPE</Platform>
49+
</ProjectConfiguration>
50+
<ProjectConfiguration Include="Test|CHPE">
51+
<Configuration>Test</Configuration>
52+
<Platform>CHPE</Platform>
53+
</ProjectConfiguration>
54+
<ProjectConfiguration Include="Release|CHPE">
55+
<Configuration>Release</Configuration>
56+
<Platform>CHPE</Platform>
57+
</ProjectConfiguration>
58+
</ItemGroup>
4559
<ItemGroup Label="ProjectConfigurations">
4660
<ProjectConfiguration Include="Debug|ARM64">
4761
<Configuration>Debug</Configuration>

bin/NativeTests/JsRTApiTest.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,9 +2488,12 @@ namespace JsRTApiTest
24882488
{
24892489
errorCode = JsInitializeModuleRecord(referencingModule, specifier, &moduleRecord);
24902490
REQUIRE(errorCode == JsNoError);
2491+
*dependentModuleRecord = moduleRecord;
2492+
}
2493+
else
2494+
{
2495+
*dependentModuleRecord = nullptr;
24912496
}
2492-
2493-
*dependentModuleRecord = moduleRecord;
24942497
return JsNoError;
24952498
}
24962499

lib/Backend/BailOut.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ void BailOutRecord::CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::
26452645

26462646
Js::Var BailOutRecord::BailOutForElidedYield(void * framePointer)
26472647
{
2648+
JIT_HELPER_REENTRANT_HEADER(NoSaveRegistersBailOutForElidedYield);
26482649
Js::JavascriptCallStackLayout * const layout = Js::JavascriptCallStackLayout::FromFramePointer(framePointer);
26492650
Js::ScriptFunction ** functionRef = (Js::ScriptFunction **)&layout->functionObject;
26502651
Js::ScriptFunction * function = *functionRef;
@@ -2689,6 +2690,7 @@ Js::Var BailOutRecord::BailOutForElidedYield(void * framePointer)
26892690
}
26902691

26912692
return aReturn;
2693+
JIT_HELPER_END(NoSaveRegistersBailOutForElidedYield);
26922694
}
26932695

26942696
BranchBailOutRecord::BranchBailOutRecord(uint32 trueBailOutOffset, uint32 falseBailOutOffset, Js::RegSlot resultByteCodeReg, IR::BailOutKind kind, Func * bailOutFunc)
@@ -2875,3 +2877,4 @@ void GlobalBailOutRecordDataTable::AddOrUpdateRow(JitArenaAllocator *allocator,
28752877
rowToInsert->regSlot = regSlot;
28762878
*lastUpdatedRowIndex = length++;
28772879
}
2880+

lib/Backend/Chakra.Backend.vcxproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Condition="'$(ChakraBuildPathImported)'!='true'" Project="$(SolutionDir)Chakra.Build.Paths.props" />
44
<Import Project="$(BuildConfigPropsPath)Chakra.Build.ProjectConfiguration.props" />
@@ -40,8 +40,6 @@
4040
</AdditionalIncludeDirectories>
4141
<PrecompiledHeader>Use</PrecompiledHeader>
4242
<PrecompiledHeaderFile>BackEnd.h</PrecompiledHeaderFile>
43-
<!-- # Check out https://osgwiki.com/wiki/Dev_14_Migration for more details about -Zc:implicitNoexcept- -->
44-
<AdditionalOptions>-Zc:implicitNoexcept- %(AdditionalOptions)</AdditionalOptions>
4543
</ClCompile>
4644
</ItemDefinitionGroup>
4745
<ItemDefinitionGroup Condition="'$(OptimizedBuild)'!='true'">

lib/Backend/Chakra.Backend.vcxproj.filters

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<ClCompile Include="$(MSBuildThisFileDirectory)IntConstMath.cpp" />
149149
<ClCompile Include="$(MSBuildThisFileDirectory)JavascriptNativeOperators.cpp" />
150150
<ClCompile Include="$(MSBuildThisFileDirectory)EquivalentTypeSet.cpp" />
151+
<ClCompile Include="$(MSBuildThisFileDirectory)IntConstMath.cpp" />
151152
<ClCompile Include="$(MSBuildThisFileDirectory)arm64\ARM64UnwindEncoder.cpp">
152153
<Filter>arm64</Filter>
153154
</ClCompile>
@@ -374,6 +375,7 @@
374375
<ClInclude Include="IntConstMath.h" />
375376
<ClInclude Include="JavascriptNativeOperators.h" />
376377
<ClInclude Include="EquivalentTypeSet.h" />
378+
<ClInclude Include="IntConstMath.h" />
377379
<ClInclude Include="arm64\MdOpCodes.h">
378380
<Filter>arm64</Filter>
379381
</ClInclude>

lib/Backend/CodeGenWorkItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void CodeGenWorkItem::OnWorkItemProcessFail(NativeCodeGenerator* codeGen)
218218
{
219219
if (!DelayDeletingFunctionTable::AddEntry(functionTable))
220220
{
221-
PHASE_PRINT_TESTTRACE1(Js::XDataPhase, _u("OnWorkItemProcessFail: Failed to add to slist, table: %llx\n"), functionTable);
221+
PHASE_PRINT_TESTTRACE1(Js::XDataPhase, _u("[%d]OnWorkItemProcessFail: Failed to add to slist, table: %llx\n"), GetCurrentThreadId(), functionTable);
222222
DelayDeletingFunctionTable::DeleteFunctionTable(functionTable);
223223
}
224224
}

lib/Backend/Func.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ Func::GetOrCreateSingleTypeGuard(intptr_t typeAddr)
15721572
void
15731573
Func::EnsureEquivalentTypeGuards()
15741574
{
1575+
AssertMsg(!PHASE_OFF(Js::EquivObjTypeSpecPhase, this), "Why do we have equivalent type guards if we don't do equivalent object type spec?");
15751576
if (this->equivalentTypeGuards == nullptr)
15761577
{
15771578
this->equivalentTypeGuards = JitAnew(this->m_alloc, EquivalentTypeGuardList, this->m_alloc);

lib/Backend/GlobOpt.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,15 @@ GlobOpt::OptInstr(IR::Instr *&instr, bool* isInstrRemoved)
27102710
this->CommitCapturedValuesCandidate();
27112711
}
27122712

2713+
#if DBG
2714+
if (CONFIG_FLAG(ValidateIntRanges) && !IsLoopPrePass())
2715+
{
2716+
if (instr->ShouldEmitIntRangeCheck())
2717+
{
2718+
this->EmitIntRangeChecks(instr);
2719+
}
2720+
}
2721+
#endif
27132722
return instrNext;
27142723
}
27152724

lib/Backend/GlobOpt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ class GlobOpt
921921
bool IsPropertySymId(SymID symId) const;
922922

923923
static void AssertCanCopyPropOrCSEFieldLoad(IR::Instr * instr);
924+
void EmitIntRangeChecks(IR::Instr* instr);
925+
void EmitIntRangeChecks(IR::Instr* instr, IR::Opnd* opnd);
924926
#endif
925927

926928
StackSym * EnsureObjectTypeSym(StackSym * objectSym);

lib/Backend/GlobOptIntBounds.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,3 +3164,82 @@ void GlobOpt::DetermineArrayBoundCheckHoistability(
31643164
upperHoistInfo.SetLoopCount(loopCount, maxMagnitudeChange);
31653165
}
31663166
}
3167+
3168+
#if DBG
3169+
void
3170+
GlobOpt::EmitIntRangeChecks(IR::Instr* instr, IR::Opnd* opnd)
3171+
{
3172+
if (!opnd ||
3173+
(!opnd->IsRegOpnd() && !opnd->IsIndirOpnd()) ||
3174+
(opnd->IsIndirOpnd() && !opnd->AsIndirOpnd()->GetIndexOpnd()))
3175+
{
3176+
return;
3177+
}
3178+
3179+
IR::RegOpnd * regOpnd = opnd->IsRegOpnd() ? opnd->AsRegOpnd() : opnd->AsIndirOpnd()->GetIndexOpnd();
3180+
if (!(regOpnd->IsInt32() || regOpnd->IsUInt32()))
3181+
{
3182+
return;
3183+
}
3184+
3185+
StackSym * sym = regOpnd->GetStackSym();
3186+
if (sym->IsTypeSpec())
3187+
{
3188+
sym = sym->GetVarEquivSym_NoCreate();
3189+
}
3190+
3191+
Value * value = CurrentBlockData()->FindValue(sym);
3192+
3193+
if (!value)
3194+
{
3195+
return;
3196+
}
3197+
3198+
int32 lowerBound = INT_MIN;
3199+
int32 upperBound = INT_MAX;
3200+
3201+
if (value->GetValueInfo()->IsIntBounded())
3202+
{
3203+
lowerBound = value->GetValueInfo()->AsIntBounded()->Bounds()->ConstantLowerBound();
3204+
upperBound = value->GetValueInfo()->AsIntBounded()->Bounds()->ConstantUpperBound();
3205+
}
3206+
else if (value->GetValueInfo()->IsIntRange())
3207+
{
3208+
lowerBound = value->GetValueInfo()->AsIntRange()->LowerBound();
3209+
upperBound = value->GetValueInfo()->AsIntRange()->UpperBound();
3210+
}
3211+
else
3212+
{
3213+
return;
3214+
}
3215+
3216+
const auto EmitBoundCheck = [&](Js::OpCode opcode, int32 bound)
3217+
{
3218+
IR::Opnd * boundOpnd = IR::IntConstOpnd::New(bound, TyInt32, instr->m_func, true /*dontEncode*/);
3219+
IR::Instr * boundCheckInstr = IR::Instr::New(opcode, instr->m_func);
3220+
boundCheckInstr->SetSrc1(regOpnd);
3221+
boundCheckInstr->SetSrc2(boundOpnd);
3222+
instr->InsertBefore(boundCheckInstr);
3223+
};
3224+
3225+
if (lowerBound > INT_MIN)
3226+
{
3227+
EmitBoundCheck(Js::OpCode::CheckLowerIntBound, lowerBound);
3228+
}
3229+
if (upperBound < INT_MAX)
3230+
{
3231+
EmitBoundCheck(Js::OpCode::CheckUpperIntBound, upperBound);
3232+
}
3233+
}
3234+
3235+
void
3236+
GlobOpt::EmitIntRangeChecks(IR::Instr* instr)
3237+
{
3238+
// currently validating for dst only if its IndirOpnd
3239+
EmitIntRangeChecks(instr, instr->GetSrc1());
3240+
if (instr->GetDst()->IsIndirOpnd())
3241+
{
3242+
EmitIntRangeChecks(instr, instr->GetDst());
3243+
}
3244+
}
3245+
#endif

lib/Backend/IR.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,10 @@ Instr::IsRealInstr() const
26492649
case Js::OpCode::StatementBoundary:
26502650
case Js::OpCode::NoImplicitCallUses:
26512651
case Js::OpCode::NoIntOverflowBoundary:
2652+
#if DBG
2653+
case Js::OpCode::CheckLowerIntBound:
2654+
case Js::OpCode::CheckUpperIntBound:
2655+
#endif
26522656
return false;
26532657

26542658
default:
@@ -3526,7 +3530,7 @@ uint Instr::GetAsmJsArgOutSize()
35263530
Assert(UNREACHED);
35273531
return 0;
35283532
}
3529-
}
3533+
}
35303534

35313535
uint Instr::GetArgOutSize(bool getInterpreterArgOutCount)
35323536
{
@@ -4593,6 +4597,19 @@ Instr::Dump(IRDumpFlags flags)
45934597
}
45944598
}
45954599

4600+
#if DBG
4601+
bool
4602+
Instr::ShouldEmitIntRangeCheck()
4603+
{
4604+
// currently only emitting int range check for opnds of instructions with following opcodes:
4605+
return m_opcode == Js::OpCode::ToVar ||
4606+
m_opcode == Js::OpCode::LdElemI_A ||
4607+
m_opcode == Js::OpCode::LdMethodElem ||
4608+
m_opcode == Js::OpCode::StElemI_A ||
4609+
m_opcode == Js::OpCode::StElemI_A_Strict ||
4610+
m_opcode == Js::OpCode::StElemC;
4611+
}
4612+
#endif
45964613
///----------------------------------------------------------------------------
45974614
///
45984615
/// LabelInstr::Dump

lib/Backend/IR.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ class Instr
367367
bool BinaryCalculatorT(T src1Const, T src2Const, int64 *pResult, bool checkWouldTrap);
368368
bool UnaryCalculator(IntConstType src1Const, IntConstType *pResult, IRType type);
369369
IR::Instr* GetNextArg();
370-
370+
#if DBG
371+
bool ShouldEmitIntRangeCheck();
372+
#endif
371373
// Iterates argument chain
372374
template<class Fn>
373375
bool IterateArgInstrs(Fn callback)

lib/Backend/Inline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ Inline::Optimize(Func *func, __in_ecount_opt(callerArgOutCount) IR::Instr *calle
405405
instrNext = builtInInlineCandidateOpCode != 0 ?
406406
this->InlineBuiltInFunction(instr, inlineeData, builtInInlineCandidateOpCode, inlinerData, symThis, &isInlined, profileId, recursiveInlineDepth) :
407407
this->InlineScriptFunction(instr, inlineeData, symThis, profileId, &isInlined, callbackDefInstr, recursiveInlineDepth);
408-
if (!isInlined && hasDstUsedBuiltInReturnType)
408+
if (!isInlined && hasDstUsedBuiltInReturnType)
409409
{
410410
// We haven't actually inlined the builtin, we need to revert the value type to likely
411411
instr->GetDst()->UnsetValueTypeFixed();

0 commit comments

Comments
 (0)