Skip to content

Commit a235573

Browse files
committed
make struct layouts more conformant
1 parent 0967b4a commit a235573

12 files changed

+66
-37
lines changed

lib/Backend/CodeGenNumberAllocator.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,13 @@ CodeGenNumberChunk* ::XProcNumberPageSegmentManager::RegisterSegments(XProcNumbe
431431
return chunk;
432432
}
433433

434-
void XProcNumberPageSegmentManager::GetFreeSegment(XProcNumberPageSegment& seg)
434+
void XProcNumberPageSegmentManager::GetFreeSegment(XProcNumberPageSegment * seg)
435435
{
436436
AutoCriticalSection autoCS(&cs);
437437

438-
memset(&seg, 0, sizeof(seg));
439-
440438
if (segmentsList == nullptr)
441439
{
442-
new (&seg) XProcNumberPageSegmentImpl();
440+
new (seg) XProcNumberPageSegmentImpl();
443441
return;
444442
}
445443

@@ -452,7 +450,7 @@ void XProcNumberPageSegmentManager::GetFreeSegment(XProcNumberPageSegment& seg)
452450
*prev = (XProcNumberPageSegmentImpl*)temp->nextSegment;
453451

454452
// remove from the list
455-
memcpy(&seg, temp, sizeof(seg));
453+
memcpy(seg, temp, sizeof(XProcNumberPageSegment));
456454
midl_user_free(temp);
457455
return;
458456
}

lib/Backend/CodeGenNumberAllocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct XProcNumberPageSegmentManager
181181

182182
~XProcNumberPageSegmentManager();
183183

184-
void GetFreeSegment(XProcNumberPageSegment& seg);
184+
void GetFreeSegment(XProcNumberPageSegment * seg);
185185
CodeGenNumberChunk* RegisterSegments(XProcNumberPageSegment* segments);
186186

187187
void Integrate();

lib/Backend/FunctionJITTimeInfo.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,28 @@ FunctionJITTimeInfo::GetRuntimeInfo() const
238238
JITObjTypeSpecFldInfo *
239239
FunctionJITTimeInfo::GetObjTypeSpecFldInfo(uint index) const
240240
{
241-
if (m_data.objTypeSpecFldInfoArray == nullptr)
241+
Assert(index < GetBody()->GetInlineCacheCount());
242+
if (m_data.objTypeSpecFldInfoArray == nullptr)
242243
{
243244
return nullptr;
244245
}
245-
246-
Assert(index < GetBody()->GetInlineCacheCount());
247-
if (m_data.objTypeSpecFldInfoArray == nullptr)
246+
if (!m_data.objTypeSpecFldInfoArray[index].inUse)
248247
{
249248
return nullptr;
250249
}
250+
251251
return reinterpret_cast<JITObjTypeSpecFldInfo *>(&m_data.objTypeSpecFldInfoArray[index]);
252252
}
253253

254254
JITObjTypeSpecFldInfo *
255255
FunctionJITTimeInfo::GetGlobalObjTypeSpecFldInfo(uint index) const
256256
{
257257
Assert(index < m_data.globalObjTypeSpecFldInfoCount);
258+
if (!m_data.globalObjTypeSpecFldInfoArray[index].inUse)
259+
{
260+
return nullptr;
261+
}
262+
258263
return reinterpret_cast<JITObjTypeSpecFldInfo *>(&m_data.globalObjTypeSpecFldInfoArray[index]);
259264
}
260265

@@ -282,6 +287,11 @@ FunctionJITTimeInfo::GetLdFldInlinee(Js::InlineCacheIndex inlineCacheIndex) cons
282287
}
283288
Assert(inlineCacheIndex < m_data.ldFldInlineeCount);
284289

290+
if (!m_data.ldFldInlinees[inlineCacheIndex].functionInfoAddr)
291+
{
292+
return nullptr;
293+
}
294+
285295
return reinterpret_cast<const FunctionJITTimeInfo*>(&m_data.ldFldInlinees[inlineCacheIndex]);
286296
}
287297

@@ -295,6 +305,11 @@ FunctionJITTimeInfo::GetInlinee(Js::ProfileId profileId) const
295305
}
296306
Assert(profileId < m_data.inlineeCount);
297307

308+
if (!m_data.inlinees[profileId].functionInfoAddr)
309+
{
310+
return nullptr;
311+
}
312+
298313
auto inlinee = reinterpret_cast<const FunctionJITTimeInfo *>(&m_data.inlinees[profileId]);
299314
if (inlinee == nullptr && m_data.inlineesRecursionFlags[profileId])
300315
{

lib/Backend/JITObjTypeSpecFldInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ JITObjTypeSpecFldInfo::BuildObjTypeSpecFldInfoArray(
262262
{
263263
continue;
264264
}
265+
jitData[i].inUse = TRUE;
265266
if (objTypeSpecInfo[i]->IsLoadedFromProto())
266267
{
267268
jitData[i].protoObjectAddr = (intptr_t)objTypeSpecInfo[i]->GetProtoObject();

lib/Backend/JITTimeFunctionBody.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ JITTimeFunctionBody::InitializeJITFunctionData(
2828
jitBody->constCount = functionBody->GetConstantCount();
2929
if (functionBody->GetConstantCount() > 0)
3030
{
31-
// TODO (michhol): OOP JIT, will be different for asm.js
3231
jitBody->constTable = (intptr_t *)functionBody->GetConstTable();
33-
34-
jitBody->constTableContent = RecyclerNewArrayZ(recycler, RecyclableObjectIDL*, functionBody->GetConstantCount());
35-
// TODO: asm.js has const table structured differently and doesn't need type info, so don't allocate it
3632
if (!functionBody->GetIsAsmJsFunction())
3733
{
34+
jitBody->constTableContent = RecyclerNewStructZ(recycler, ConstTableContentIDL);
35+
jitBody->constTableContent->count = functionBody->GetConstantCount();
36+
jitBody->constTableContent->content = RecyclerNewArrayZ(recycler, RecyclableObjectIDL*, functionBody->GetConstantCount());
37+
3838
for (Js::RegSlot reg = Js::FunctionBody::FirstRegSlot; reg < functionBody->GetConstantCount(); ++reg)
3939
{
4040
Js::Var varConst = functionBody->GetConstantVar(reg);
@@ -59,7 +59,7 @@ JITTimeFunctionBody::InitializeJITFunctionData(
5959
|| VirtualTableInfo<Js::PropertyString>::HasVirtualTable(varConst)
6060
|| VirtualTableInfo<Js::SingleCharString>::HasVirtualTable(varConst));
6161

62-
jitBody->constTableContent[reg - Js::FunctionBody::FirstRegSlot] = (RecyclableObjectIDL*)varConst;
62+
jitBody->constTableContent->content[reg - Js::FunctionBody::FirstRegSlot] = (RecyclableObjectIDL*)varConst;
6363
}
6464
}
6565
}
@@ -803,10 +803,10 @@ Js::TypeId
803803
JITTimeFunctionBody::GetConstantType(Js::RegSlot location) const
804804
{
805805
Assert(m_bodyData.constTable != nullptr);
806+
Assert(m_bodyData.constTableContent != nullptr);
806807
Assert(location < GetConstCount());
807808
Assert(location != 0);
808-
809-
auto obj = m_bodyData.constTableContent[location - Js::FunctionBody::FirstRegSlot];
809+
auto obj = m_bodyData.constTableContent->content[location - Js::FunctionBody::FirstRegSlot];
810810

811811
if (obj == nullptr)
812812
{
@@ -841,7 +841,7 @@ JITTimeFunctionBody::GetConstTable() const
841841
bool
842842
JITTimeFunctionBody::IsConstRegPropertyString(Js::RegSlot reg, ScriptContextInfo * context) const
843843
{
844-
RecyclableObjectIDL * content = m_bodyData.constTableContent[reg - Js::FunctionBody::FirstRegSlot];
844+
RecyclableObjectIDL * content = m_bodyData.constTableContent->content[reg - Js::FunctionBody::FirstRegSlot];
845845
if (content != nullptr && content->vtbl == context->GetVTableAddress(VtablePropertyString))
846846
{
847847
return true;

lib/Backend/JITTimeFunctionBody.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ class JITTimeFunctionBody
103103
T* GetConstAsT(Js::RegSlot location) const
104104
{
105105
Assert(m_bodyData.constTableContent != nullptr);
106+
Assert(m_bodyData.constTableContent->content != nullptr);
106107
Assert(location < GetConstCount());
107108
Assert(location != 0);
108109

109-
auto obj = m_bodyData.constTableContent[location - Js::FunctionBody::FirstRegSlot];
110+
auto obj = m_bodyData.constTableContent->content[location - Js::FunctionBody::FirstRegSlot];
110111
Assert(obj);
111112
obj->vtbl = VirtualTableInfo<T>::Address;
112113
//Assert(T::Is(obj));
@@ -117,11 +118,12 @@ class JITTimeFunctionBody
117118
Js::JavascriptNumber* GetConstAsT<Js::JavascriptNumber>(Js::RegSlot location) const
118119
{
119120
Assert(m_bodyData.constTableContent != nullptr);
121+
Assert(m_bodyData.constTableContent->content != nullptr);
120122
Assert(location < GetConstCount());
121123
Assert(location != 0);
122124

123125
#if !FLOATVAR
124-
auto obj = m_bodyData.constTableContent[location - Js::FunctionBody::FirstRegSlot];
126+
auto obj = m_bodyData.constTableContent->content[location - Js::FunctionBody::FirstRegSlot];
125127
if (!obj)
126128
{
127129
#endif

lib/Backend/JITTimePolymorphicInlineCacheInfo.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ JITTimePolymorphicInlineCacheInfo::InitializePolymorphicInlineCacheInfo(
5959
if (runtimeInfo->GetPolymorphicInlineCaches()->HasInlineCaches())
6060
{
6161
jitInfo->polymorphicInlineCacheCount = runtimeInfo->GetFunctionBody()->GetInlineCacheCount();
62-
jitInfo->polymorphicInlineCaches = RecyclerNewArrayZ(recycler, PolymorphicInlineCacheIDL*, jitInfo->polymorphicInlineCacheCount);
62+
jitInfo->polymorphicInlineCaches = RecyclerNewArrayZ(recycler, PolymorphicInlineCacheIDL, jitInfo->polymorphicInlineCacheCount);
6363
for (uint j = 0; j < jitInfo->polymorphicInlineCacheCount; ++j)
6464
{
6565
Js::PolymorphicInlineCache * pic = runtimeInfo->GetPolymorphicInlineCaches()->GetInlineCache(j);
6666
if (pic != nullptr)
6767
{
68-
jitInfo->polymorphicInlineCaches[j] = RecyclerNewStructLeaf(recycler, PolymorphicInlineCacheIDL);
69-
jitInfo->polymorphicInlineCaches[j]->size = pic->GetSize();
70-
jitInfo->polymorphicInlineCaches[j]->addr = (intptr_t)pic;
71-
jitInfo->polymorphicInlineCaches[j]->inlineCachesAddr = (intptr_t)pic->GetInlineCaches();
68+
jitInfo->polymorphicInlineCaches[j].size = pic->GetSize();
69+
jitInfo->polymorphicInlineCaches[j].addr = (intptr_t)pic;
70+
jitInfo->polymorphicInlineCaches[j].inlineCachesAddr = (intptr_t)pic->GetInlineCaches();
7271
}
7372
}
7473
}
@@ -78,7 +77,11 @@ JITTimePolymorphicInlineCache *
7877
JITTimePolymorphicInlineCacheInfo::GetInlineCache(uint index) const
7978
{
8079
Assert(index < m_data.polymorphicInlineCacheCount);
81-
return (JITTimePolymorphicInlineCache *)m_data.polymorphicInlineCaches[index];
80+
if (!m_data.polymorphicInlineCaches[index].addr)
81+
{
82+
return nullptr;
83+
}
84+
return (JITTimePolymorphicInlineCache *)&m_data.polymorphicInlineCaches[index];
8285
}
8386

8487
bool

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
889889
jitData->sharedPropertyGuards = epInfo->GetSharedPropertyGuardsWithLock(&alloc, jitData->sharedPropGuardCount);
890890

891891
JITOutputIDL jitWriteData = {0};
892-
892+
workItem->GetJITData()->xProcNumberPageSegment = AnewStructZ(&alloc, XProcNumberPageSegment);
893893
threadContext->GetXProcNumberPageSegmentManager()->GetFreeSegment(workItem->GetJITData()->xProcNumberPageSegment);
894894

895895
if (JITManager::GetJITManager()->IsOOPJITEnabled())

lib/JITIDL/Chakra.JITIDL.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
2222
<Midl>
2323
<HeaderFileName>%(Filename).h</HeaderFileName>
24+
<AdditionalOptions>-savePP %(AdditionalOptions)</AdditionalOptions>
2425
</Midl>
2526
</ItemDefinitionGroup>
2627
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

lib/JITIDL/ChakraJIT.idl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ typedef struct RecyclableObjectIDL
365365
[switch_is(*typeId)] RecyclableObjectContent x;
366366
} RecyclableObjectIDL;
367367

368+
// to avoid rpc considering FunctionBodyDataIDL complex, move this to its own struct
369+
typedef struct ConstTableContentIDL
370+
{
371+
unsigned int count;
372+
[size_is(count)] RecyclableObjectIDL** content;
373+
} ConstTableContentIDL;
374+
368375
// FunctionBody fields, read only in JIT, gathered in foreground
369376
typedef struct FunctionBodyDataIDL
370377
{
@@ -427,7 +434,7 @@ typedef struct FunctionBodyDataIDL
427434

428435
unsigned int constCount;
429436
[size_is(constCount)] CHAKRA_PTR * constTable;
430-
[size_is(constCount)] RecyclableObjectIDL** constTableContent;
437+
ConstTableContentIDL * constTableContent;
431438

432439
unsigned int inlineCacheCount;
433440
[size_is(inlineCacheCount)] int * cacheIdToPropertyIdMap;
@@ -492,9 +499,6 @@ typedef struct FunctionJITTimeDataIDL
492499
boolean isAggressiveInliningEnabled;
493500
boolean isInlined;
494501
unsigned int localFuncId;
495-
CHAKRA_PTR functionInfoAddr;
496-
CHAKRA_PTR callsCountAddress;
497-
CHAKRA_PTR weakFuncRef;
498502
FunctionBodyDataIDL * bodyData; // TODO: oop jit, can these repeat, should we share?
499503

500504
BVFixedIDL * inlineesBv;
@@ -517,18 +521,23 @@ typedef struct FunctionJITTimeDataIDL
517521
FunctionJITRuntimeIDL * profiledRuntimeData;
518522

519523
struct FunctionJITTimeDataIDL * next;
524+
525+
CHAKRA_PTR functionInfoAddr;
526+
CHAKRA_PTR callsCountAddress;
527+
CHAKRA_PTR weakFuncRef;
520528
} FunctionJITTimeDataIDL;
521529

522530
typedef struct XProcNumberPageSegment
523531
{
532+
struct XProcNumberPageSegment* nextSegment;
533+
524534
unsigned int committedEnd;
525535
unsigned int blockIntegratedSize;
526536
CHAKRA_PTR pageAddress;
527537
CHAKRA_PTR allocStartAddress;
528538
CHAKRA_PTR allocEndAddress;
529539
CHAKRA_PTR pageSegment;
530540
CHAKRA_PTR chunkAllocator;
531-
struct XProcNumberPageSegment* nextSegment;
532541
} XProcNumberPageSegment;
533542

534543
typedef struct PolymorphicInlineCacheIDL
@@ -542,7 +551,7 @@ typedef struct PolymorphicInlineCacheInfoIDL
542551
{
543552
unsigned int polymorphicInlineCacheCount;
544553
[size_is(polymorphicInlineCacheCount)] byte * polymorphicCacheUtilizationArray;
545-
[size_is(polymorphicInlineCacheCount)] PolymorphicInlineCacheIDL ** polymorphicInlineCaches;
554+
[size_is(polymorphicInlineCacheCount)] PolymorphicInlineCacheIDL * polymorphicInlineCaches;
546555

547556
CHAKRA_PTR functionBodyAddr;
548557
} PolymorphicInlineCacheInfoIDL;
@@ -556,7 +565,7 @@ typedef struct CodeGenWorkItemIDL
556565
char jitMode;
557566

558567
unsigned int loopNumber;
559-
XProcNumberPageSegment xProcNumberPageSegment;
568+
XProcNumberPageSegment * xProcNumberPageSegment;
560569

561570
PolymorphicInlineCacheInfoIDL * selfInfo;
562571

lib/JITServer/JITServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ ServerRemoteCodeGen(
330330
JITTimeWorkItem * jitWorkItem = Anew(&jitArena, JITTimeWorkItem, workItemData);
331331

332332
jitData->numberPageSegments = (XProcNumberPageSegment*)midl_user_allocate(sizeof(XProcNumberPageSegment));
333-
memcpy_s(jitData->numberPageSegments, sizeof(XProcNumberPageSegment), &jitWorkItem->GetWorkItemData()->xProcNumberPageSegment, sizeof(XProcNumberPageSegment));
333+
memcpy_s(jitData->numberPageSegments, sizeof(XProcNumberPageSegment), jitWorkItem->GetWorkItemData()->xProcNumberPageSegment, sizeof(XProcNumberPageSegment));
334334

335335
Func::Codegen(&jitArena, jitWorkItem, threadContextInfo, scriptContextInfo, jitData, nullptr, nullptr, jitWorkItem->GetPolymorphicInlineCacheInfo(), threadContextInfo->GetCodeGenAllocators(), nullptr, nullptr, true);
336336

lib/Runtime/Language/FunctionCodeGenJitTimeData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Js
3636

3737
PolymorphicInlineCacheInfoIDL* inlineeInfo;
3838
PolymorphicInlineCacheInfoIDL* selfInfo;
39-
PolymorphicInlineCacheIDL** polymorphicInlineCaches;
39+
PolymorphicInlineCacheIDL* polymorphicInlineCaches;
4040

4141
// Number of functions that are to be inlined (this is not the length of the 'inlinees' array above, includes getter setter inlinee count)
4242
uint inlineeCount;
@@ -96,7 +96,7 @@ namespace Js
9696
this->weakFuncRef = weakFuncRef;
9797
}
9898

99-
void SetPolymorphicInlineInfo(PolymorphicInlineCacheInfoIDL* inlineeInfo, PolymorphicInlineCacheInfoIDL* selfInfo, PolymorphicInlineCacheIDL** polymorphicInlineCaches)
99+
void SetPolymorphicInlineInfo(PolymorphicInlineCacheInfoIDL* inlineeInfo, PolymorphicInlineCacheInfoIDL* selfInfo, PolymorphicInlineCacheIDL* polymorphicInlineCaches)
100100
{
101101
this->inlineeInfo = inlineeInfo;
102102
this->selfInfo = selfInfo;

0 commit comments

Comments
 (0)