Skip to content

Commit 62fc740

Browse files
committed
[MERGE #1716 @MikeHolman] move building JIT FunctionBody data from WI creation to JIT time
Merge pull request #1716 from MikeHolman:bgbody
2 parents 96675a7 + c16bfa6 commit 62fc740

11 files changed

+63
-60
lines changed

lib/Backend/FunctionJITTimeInfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ FunctionJITTimeInfo::BuildJITTimeData(
2121
bool isInlinee,
2222
bool isForegroundJIT)
2323
{
24-
jitData->bodyData = codeGenData->GetJITBody();
2524
jitData->functionInfoAddr = (intptr_t)codeGenData->GetFunctionInfo();
2625

26+
if (codeGenData->GetFunctionBody() && codeGenData->GetFunctionBody()->GetByteCode())
27+
{
28+
Js::FunctionBody * body = codeGenData->GetFunctionInfo()->GetParseableFunctionInfo()->GetFunctionBody();
29+
jitData->bodyData = AnewStructZ(alloc, FunctionBodyDataIDL);
30+
JITTimeFunctionBody::InitializeJITFunctionData(alloc, body, jitData->bodyData);
31+
}
32+
2733
jitData->localFuncId = codeGenData->GetFunctionInfo()->GetLocalFunctionId();
2834
jitData->isAggressiveInliningEnabled = codeGenData->GetIsAggressiveInliningEnabled();
2935
jitData->isInlined = codeGenData->GetIsInlined();

lib/Backend/IRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ IRBuilder::DoBailOnNoProfile()
9393
}
9494

9595
Func *const topFunc = m_func->GetTopFunc();
96-
if(topFunc->GetJITFunctionBody()->GetProfiledIterations() == 0)
96+
if(topFunc->GetWorkItem()->GetProfiledIterations() == 0)
9797
{
9898
// The top function has not been profiled yet. Some switch must have been used to force jitting. This is not a
9999
// real-world case, but for the purpose of testing the JIT, it's beneficial to generate code in unprofiled paths.

lib/Backend/JITTimeFunctionBody.cpp

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ JITTimeFunctionBody::JITTimeFunctionBody(FunctionBodyDataIDL * bodyData) :
1414
/* static */
1515
void
1616
JITTimeFunctionBody::InitializeJITFunctionData(
17-
__in Recycler * recycler,
17+
__in ArenaAllocator * arena,
1818
__in Js::FunctionBody *functionBody,
1919
__out FunctionBodyDataIDL * jitBody)
2020
{
@@ -27,9 +27,9 @@ JITTimeFunctionBody::InitializeJITFunctionData(
2727
jitBody->constTable = (intptr_t *)functionBody->GetConstTable();
2828
if (!functionBody->GetIsAsmJsFunction())
2929
{
30-
jitBody->constTableContent = RecyclerNewStructZ(recycler, ConstTableContentIDL);
30+
jitBody->constTableContent = AnewStructZ(arena, ConstTableContentIDL);
3131
jitBody->constTableContent->count = functionBody->GetConstantCount();
32-
jitBody->constTableContent->content = RecyclerNewArrayZ(recycler, RecyclableObjectIDL*, functionBody->GetConstantCount());
32+
jitBody->constTableContent->content = AnewArrayZ(arena, RecyclableObjectIDL*, functionBody->GetConstantCount());
3333

3434
for (Js::RegSlot reg = Js::FunctionBody::FirstRegSlot; reg < functionBody->GetConstantCount(); ++reg)
3535
{
@@ -68,7 +68,7 @@ JITTimeFunctionBody::InitializeJITFunctionData(
6868

6969
auto fullStatementMaps = functionBody->GetStatementMaps();
7070
jitBody->fullStatementMapCount = fullStatementMaps->Count();
71-
jitBody->fullStatementMaps = RecyclerNewArrayZ(recycler, StatementMapIDL, jitBody->fullStatementMapCount);
71+
jitBody->fullStatementMaps = AnewArrayZ(arena, StatementMapIDL, jitBody->fullStatementMapCount);
7272
fullStatementMaps->Map([jitBody](int index, Js::FunctionBody::StatementMap * map) {
7373

7474
jitBody->fullStatementMaps[index] = *(StatementMapIDL*)map;
@@ -80,10 +80,11 @@ JITTimeFunctionBody::InitializeJITFunctionData(
8080
Assert((jitBody->fullStatementMaps[index].isSubExpression != FALSE) == map->isSubexpression);
8181
});
8282

83-
if (functionBody->GetPropertyIdOnRegSlotsContainer())
83+
Js::PropertyIdOnRegSlotsContainer * propOnRegSlots = functionBody->GetPropertyIdOnRegSlotsContainerWithLock();
84+
if (propOnRegSlots)
8485
{
85-
jitBody->propertyIdsForRegSlotsCount = functionBody->GetPropertyIdOnRegSlotsContainer()->length;
86-
jitBody->propertyIdsForRegSlots = functionBody->GetPropertyIdOnRegSlotsContainer()->propertyIdsForRegSlots;
86+
jitBody->propertyIdsForRegSlotsCount = propOnRegSlots->length;
87+
jitBody->propertyIdsForRegSlots = propOnRegSlots->propertyIdsForRegSlots;
8788
}
8889
}
8990
else
@@ -93,7 +94,7 @@ JITTimeFunctionBody::InitializeJITFunctionData(
9394
jitBody->byteCodeLength = functionBody->GetByteCode()->GetLength();
9495
jitBody->byteCodeBuffer = functionBody->GetByteCode()->GetBuffer();
9596

96-
jitBody->statementMap = RecyclerNewStructZ(recycler, SmallSpanSequenceIDL);
97+
jitBody->statementMap = AnewStructZ(arena, SmallSpanSequenceIDL);
9798
jitBody->statementMap->baseValue = statementMap->baseValue;
9899

99100
if (statementMap->pActualOffsetList)
@@ -143,18 +144,19 @@ JITTimeFunctionBody::InitializeJITFunctionData(
143144
jitBody->nonLoadByteCodeCount = functionBody->GetByteCodeWithoutLDACount();
144145
jitBody->loopCount = functionBody->GetLoopCount();
145146

146-
if (functionBody->GetHasAllocatedLoopHeaders())
147+
Js::LoopHeader * loopHeaders = functionBody->GetLoopHeaderArrayWithLock();
148+
if (loopHeaders != nullptr)
147149
{
148-
jitBody->loopHeaderArrayAddr = (intptr_t)functionBody->GetLoopHeaderArrayPtr();
150+
jitBody->loopHeaderArrayAddr = (intptr_t)loopHeaders;
149151
jitBody->loopHeaderArrayLength = functionBody->GetLoopCount();
150-
jitBody->loopHeaders = RecyclerNewArray(recycler, JITLoopHeaderIDL, functionBody->GetLoopCount());
152+
jitBody->loopHeaders = AnewArray(arena, JITLoopHeaderIDL, functionBody->GetLoopCount());
151153
for (uint i = 0; i < functionBody->GetLoopCount(); ++i)
152154
{
153-
jitBody->loopHeaders[i].startOffset = functionBody->GetLoopHeader(i)->startOffset;
154-
jitBody->loopHeaders[i].endOffset = functionBody->GetLoopHeader(i)->endOffset;
155-
jitBody->loopHeaders[i].isNested = functionBody->GetLoopHeader(i)->isNested;
156-
jitBody->loopHeaders[i].isInTry = functionBody->GetLoopHeader(i)->isInTry;
157-
jitBody->loopHeaders[i].interpretCount = functionBody->GetLoopInterpretCount(functionBody->GetLoopHeader(i));
155+
jitBody->loopHeaders[i].startOffset = loopHeaders[i].startOffset;
156+
jitBody->loopHeaders[i].endOffset = loopHeaders[i].endOffset;
157+
jitBody->loopHeaders[i].isNested = loopHeaders[i].isNested;
158+
jitBody->loopHeaders[i].isInTry = loopHeaders[i].isInTry;
159+
jitBody->loopHeaders[i].interpretCount = functionBody->GetLoopInterpretCount(&loopHeaders[i]);
158160
}
159161
}
160162

@@ -169,7 +171,6 @@ JITTimeFunctionBody::InitializeJITFunctionData(
169171
jitBody->firstInnerScopeReg = functionBody->GetFirstInnerScopeRegister();
170172
}
171173
jitBody->envDepth = functionBody->GetEnvDepth();
172-
jitBody->profiledIterations = functionBody->GetProfiledIterations();
173174
jitBody->profiledCallSiteCount = functionBody->GetProfiledCallSiteCount();
174175
jitBody->inParamCount = functionBody->GetInParamsCount();
175176
jitBody->thisRegisterForEventHandler = functionBody->GetThisRegisterForEventHandler();
@@ -209,17 +210,18 @@ JITTimeFunctionBody::InitializeJITFunctionData(
209210
jitBody->hasNonBuiltInCallee = functionBody->HasNonBuiltInCallee();
210211
}
211212

212-
if (functionBody->GetAuxiliaryData() != nullptr)
213+
Js::ByteBlock * auxData = functionBody->GetAuxiliaryDataWithLock();
214+
if (auxData != nullptr)
213215
{
214-
jitBody->auxDataCount = functionBody->GetAuxiliaryData()->GetLength();
215-
jitBody->auxData = functionBody->GetAuxiliaryData()->GetBuffer();
216-
jitBody->auxDataBufferAddr = (intptr_t)functionBody->GetAuxiliaryData()->GetBuffer();
216+
jitBody->auxDataCount = auxData->GetLength();
217+
jitBody->auxData = auxData->GetBuffer();
218+
jitBody->auxDataBufferAddr = (intptr_t)auxData->GetBuffer();
217219
}
218-
219-
if (functionBody->GetAuxiliaryContextData() != nullptr)
220+
Js::ByteBlock * auxContextData = functionBody->GetAuxiliaryContextDataWithLock();
221+
if (auxContextData != nullptr)
220222
{
221-
jitBody->auxContextDataCount = functionBody->GetAuxiliaryContextData()->GetLength();
222-
jitBody->auxContextData = functionBody->GetAuxiliaryContextData()->GetBuffer();
223+
jitBody->auxContextDataCount = auxContextData->GetLength();
224+
jitBody->auxContextData = auxContextData->GetBuffer();
223225
}
224226

225227
jitBody->scriptIdAddr = (intptr_t)functionBody->GetAddressOfScriptId();
@@ -230,19 +232,19 @@ JITTimeFunctionBody::InitializeJITFunctionData(
230232
jitBody->callCountStatsAddr = (intptr_t)&functionBody->callCountStats;
231233

232234
jitBody->referencedPropertyIdCount = functionBody->GetReferencedPropertyIdCount();
233-
jitBody->referencedPropertyIdMap = functionBody->GetReferencedPropertyIdMap();
235+
jitBody->referencedPropertyIdMap = functionBody->GetReferencedPropertyIdMapWithLock();
234236
jitBody->hasFinally = functionBody->GetHasFinally();
235237

236238
jitBody->nameLength = functionBody->GetDisplayNameLength() + 1; // +1 for null terminator
237239
jitBody->displayName = (char16 *)functionBody->GetDisplayName();
238-
jitBody->objectLiteralTypesAddr = (intptr_t)functionBody->GetObjectLiteralTypes();
240+
jitBody->objectLiteralTypesAddr = (intptr_t)functionBody->GetObjectLiteralTypesWithLock();
239241
jitBody->literalRegexCount = functionBody->GetLiteralRegexCount();
240-
jitBody->literalRegexes = (intptr_t*)functionBody->GetLiteralRegexes();
242+
jitBody->literalRegexes = (intptr_t*)functionBody->GetLiteralRegexesWithLock();
241243

242244
if (functionBody->GetIsAsmJsFunction())
243245
{
244-
jitBody->asmJsData = RecyclerNew(recycler, AsmJsDataIDL);
245-
Js::AsmJsFunctionInfo * asmFuncInfo = functionBody->GetAsmJsFunctionInfo();
246+
jitBody->asmJsData = Anew(arena, AsmJsDataIDL);
247+
Js::AsmJsFunctionInfo * asmFuncInfo = functionBody->GetAsmJsFunctionInfoWithLock();
246248
jitBody->asmJsData->intConstCount = asmFuncInfo->GetIntConstCount();
247249
jitBody->asmJsData->doubleConstCount = asmFuncInfo->GetDoubleConstCount();
248250
jitBody->asmJsData->floatConstCount = asmFuncInfo->GetFloatConstCount();
@@ -504,12 +506,6 @@ JITTimeFunctionBody::GetEnvDepth() const
504506
return m_bodyData.envDepth;
505507
}
506508

507-
uint16
508-
JITTimeFunctionBody::GetProfiledIterations() const
509-
{
510-
return m_bodyData.profiledIterations;
511-
}
512-
513509
Js::ProfileId
514510
JITTimeFunctionBody::GetProfiledCallSiteCount() const
515511
{

lib/Backend/JITTimeFunctionBody.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class JITTimeFunctionBody
1717
JITTimeFunctionBody(FunctionBodyDataIDL * bodyData);
1818

1919
static void InitializeJITFunctionData(
20-
__in Recycler * recycler,
20+
__in ArenaAllocator * arena,
2121
__in Js::FunctionBody * functionBody,
2222
__out FunctionBodyDataIDL * jitBody);
2323

@@ -58,7 +58,6 @@ class JITTimeFunctionBody
5858
Js::PropertyId GetReferencedPropertyId(uint index) const;
5959

6060
uint16 GetEnvDepth() const;
61-
uint16 GetProfiledIterations() const;
6261
uint16 GetArgUsedForBranch() const;
6362
Js::ProfileId GetProfiledCallSiteCount() const;
6463
Js::ArgSlot GetInParamsCount() const;

lib/Backend/JITTimeWorkItem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ JITTimeWorkItem::GetJITFunctionBody()
123123
return &m_jitBody;
124124
}
125125

126+
uint16
127+
JITTimeWorkItem::GetProfiledIterations() const
128+
{
129+
return m_workItemData->profiledIterations;
130+
}
131+
126132
CodeGenWorkItemIDL *
127133
JITTimeWorkItem::GetWorkItemData()
128134
{

lib/Backend/JITTimeWorkItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class JITTimeWorkItem
3030
Js::StatementReader<Js::FunctionBody::ArenaStatementMapList> * statementReader, ArenaAllocator* alloc);
3131

3232
JITTimeFunctionBody * GetJITFunctionBody();
33+
uint16 GetProfiledIterations() const;
3334

3435
CodeGenWorkItemIDL* GetWorkItemData();
35-
3636
JITTimePolymorphicInlineCacheInfo * GetPolymorphicInlineCacheInfo();
3737
JITTimePolymorphicInlineCacheInfo * GetInlineePolymorphicInlineCacheInfo(intptr_t funcBodyAddr);
3838

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
869869
auto& jitData = workItem->GetJITData()->jitData;
870870
jitData = AnewStructZ(&alloc, FunctionJITTimeDataIDL);
871871
FunctionJITTimeInfo::BuildJITTimeData(&alloc, workItem->RecyclableData()->JitTimeData(), nullptr, workItem->GetJITData()->jitData, false, foreground);
872-
872+
workItem->GetJITData()->profiledIterations = workItem->RecyclableData()->JitTimeData()->GetProfiledIterations();
873873
Js::EntryPointInfo * epInfo = workItem->GetEntryPoint();
874874
if (workItem->Type() == JsFunctionType)
875875
{

lib/JITIDL/JITTypes.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,9 @@ typedef struct FunctionBodyDataIDL
482482

483483
unsigned short envDepth;
484484
unsigned short inParamCount;
485-
unsigned short profiledIterations;
486485
unsigned short argUsedForBranch;
487486
unsigned short profiledCallSiteCount;
488487

489-
IDL_PAD2(0)
490-
491488
unsigned int funcNumber;
492489
unsigned int sourceContextId;
493490
unsigned int nestedCount;
@@ -524,8 +521,6 @@ typedef struct FunctionBodyDataIDL
524521
unsigned int fullStatementMapCount;
525522
unsigned int propertyIdsForRegSlotsCount;
526523

527-
X64_PAD4(1)
528-
529524
IDL_DEF([size_is(propertyIdsForRegSlotsCount)]) int * propertyIdsForRegSlots;
530525

531526
SmallSpanSequenceIDL * statementMap;
@@ -648,9 +643,12 @@ typedef struct CodeGenWorkItemIDL
648643
byte type;
649644
char jitMode;
650645

646+
unsigned short profiledIterations;
647+
IDL_PAD2(0)
651648
unsigned int loopNumber;
652649
unsigned int inlineeInfoCount;
653650
unsigned int symIdToValueTypeMapCount;
651+
X64_PAD4(1)
654652
XProcNumberPageSegment * xProcNumberPageSegment;
655653

656654
PolymorphicInlineCacheInfoIDL * selfInfo;

lib/Runtime/Base/FunctionBody.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,10 +3099,10 @@ namespace Js
30993099
#endif
31003100
void SetLiteralRegex(const uint index, UnifiedRegex::RegexPattern *const pattern);
31013101
DynamicType** GetObjectLiteralTypes() const { return static_cast<DynamicType**>(this->GetAuxPtr(AuxPointerType::ObjLiteralTypes)); }
3102+
DynamicType** GetObjectLiteralTypesWithLock() const { return static_cast<DynamicType**>(this->GetAuxPtrWithLock(AuxPointerType::ObjLiteralTypes)); }
31023103
private:
31033104
void ResetLiteralRegexes();
31043105
void ResetObjectLiteralTypes();
3105-
DynamicType** GetObjectLiteralTypesWithLock() const { return static_cast<DynamicType**>(this->GetAuxPtrWithLock(AuxPointerType::ObjLiteralTypes)); }
31063106
void SetObjectLiteralTypes(DynamicType** objLiteralTypes) { this->SetAuxPtr(AuxPointerType::ObjLiteralTypes, objLiteralTypes); };
31073107
public:
31083108

lib/Runtime/Language/FunctionCodeGenJitTimeData.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,18 @@ namespace Js
1616
#endif
1717
next(0),
1818
ldFldInlinees(nullptr),
19-
bodyData(nullptr)
19+
profiledIterations(GetFunctionBody() && GetFunctionBody()->GetByteCode() ? GetFunctionBody()->GetProfiledIterations() : 0)
2020
{
21-
if (GetFunctionInfo()->HasBody())
22-
{
23-
Recycler * recycler = functionInfo->GetFunctionProxy()->GetScriptContext()->GetRecycler();
24-
this->bodyData = RecyclerNewStructZ(recycler, FunctionBodyDataIDL);
25-
JITTimeFunctionBody::InitializeJITFunctionData(recycler, GetFunctionBody(), this->bodyData);
26-
}
2721
}
2822

29-
FunctionInfo *FunctionCodeGenJitTimeData::GetFunctionInfo() const
23+
uint16 FunctionCodeGenJitTimeData::GetProfiledIterations() const
3024
{
31-
return this->functionInfo;
25+
return profiledIterations;
3226
}
3327

34-
FunctionBodyDataIDL *FunctionCodeGenJitTimeData::GetJITBody() const
28+
FunctionInfo *FunctionCodeGenJitTimeData::GetFunctionInfo() const
3529
{
36-
return this->bodyData;
30+
return this->functionInfo;
3731
}
3832

3933
FunctionBody *FunctionCodeGenJitTimeData::GetFunctionBody() const

0 commit comments

Comments
 (0)