-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathFunctionJITTimeInfo.cpp
492 lines (430 loc) · 17.7 KB
/
FunctionJITTimeInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
FunctionJITTimeInfo::FunctionJITTimeInfo(FunctionJITTimeDataIDL * data) : m_data(*data)
{
// we will cast the data (i.e. midl struct) pointers into info pointers so we can extend with methods
CompileAssert(sizeof(FunctionJITTimeDataIDL) == sizeof(FunctionJITTimeInfo));
}
/* static */
void
FunctionJITTimeInfo::BuildJITTimeData(
__in ArenaAllocator * alloc,
__in const Js::FunctionCodeGenJitTimeData * codeGenData,
__in_opt const Js::FunctionCodeGenRuntimeData * runtimeData,
__out FunctionJITTimeDataIDL * jitData,
bool isInlinee,
bool isForegroundJIT)
{
jitData->functionInfoAddr = (intptr_t)codeGenData->GetFunctionInfo();
jitData->localFuncId = codeGenData->GetFunctionInfo()->GetLocalFunctionId();
jitData->isAggressiveInliningEnabled = codeGenData->GetIsAggressiveInliningEnabled();
jitData->isInlined = codeGenData->GetIsInlined();
jitData->weakFuncRef = (intptr_t)codeGenData->GetWeakFuncRef();
jitData->inlineesBv = (BVFixedIDL*)(const BVFixed*)codeGenData->inlineesBv;
jitData->entryPointInfoAddr = (intptr_t)codeGenData->GetEntryPointInfo();
if (!codeGenData->GetFunctionBody() || !codeGenData->GetFunctionBody()->GetByteCode())
{
// outermost function must have a body, but inlinees may not (if they are builtins)
Assert(isInlinee);
return;
}
Js::FunctionBody * body = codeGenData->GetFunctionInfo()->GetParseableFunctionInfo()->GetFunctionBody();
jitData->bodyData = AnewStructZ(alloc, FunctionBodyDataIDL);
JITTimeFunctionBody::InitializeJITFunctionData(alloc, body, jitData->bodyData);
Assert(isInlinee == !!runtimeData);
const Js::FunctionCodeGenRuntimeData * targetRuntimeData = nullptr;
if (runtimeData)
{
// may be polymorphic, so seek the runtime data matching our JIT time data
targetRuntimeData = runtimeData->GetForTarget(codeGenData->GetFunctionInfo()->GetFunctionBody());
}
Js::FunctionBody * functionBody = codeGenData->GetFunctionBody();
if (functionBody->HasDynamicProfileInfo())
{
ProfileDataIDL * profileData = AnewStruct(alloc, ProfileDataIDL);
JITTimeProfileInfo::InitializeJITProfileData(alloc, functionBody->GetAnyDynamicProfileInfo(), functionBody, profileData, isForegroundJIT);
jitData->bodyData->profileData = profileData;
if (isInlinee)
{
// if not inlinee, NativeCodeGenerator will provide the address
// REVIEW: OOP JIT, for inlinees, is this actually necessary?
Js::ProxyEntryPointInfo *defaultEntryPointInfo = functionBody->GetDefaultEntryPointInfo();
Assert(defaultEntryPointInfo->IsFunctionEntryPointInfo());
Js::FunctionEntryPointInfo *functionEntryPointInfo = static_cast<Js::FunctionEntryPointInfo*>(defaultEntryPointInfo);
jitData->callsCountAddress = (intptr_t)&functionEntryPointInfo->callsCount;
jitData->sharedPropertyGuards = codeGenData->sharedPropertyGuards;
jitData->sharedPropGuardCount = codeGenData->sharedPropertyGuardCount;
}
}
if (jitData->bodyData->profiledCallSiteCount > 0)
{
jitData->inlineeCount = jitData->bodyData->profiledCallSiteCount;
// using arena because we can't recycler allocate (may be on background), and heap freeing this is slightly complicated
jitData->inlinees = AnewArrayZ(alloc, FunctionJITTimeDataIDL*, jitData->bodyData->profiledCallSiteCount);
jitData->inlineesRecursionFlags = AnewArrayZ(alloc, boolean, jitData->bodyData->profiledCallSiteCount);
for (Js::ProfileId i = 0; i < jitData->bodyData->profiledCallSiteCount; ++i)
{
const Js::FunctionCodeGenJitTimeData * inlineeJITData = codeGenData->GetInlinee(i);
if (inlineeJITData == codeGenData)
{
jitData->inlineesRecursionFlags[i] = TRUE;
}
else if (inlineeJITData != nullptr)
{
const Js::FunctionCodeGenRuntimeData * inlineeRuntimeData = nullptr;
if (inlineeJITData->GetFunctionInfo()->HasBody())
{
inlineeRuntimeData = isInlinee ? targetRuntimeData->GetInlinee(i) : functionBody->GetInlineeCodeGenRuntimeData(i);
}
jitData->inlinees[i] = AnewStructZ(alloc, FunctionJITTimeDataIDL);
BuildJITTimeData(alloc, inlineeJITData, inlineeRuntimeData, jitData->inlinees[i], true, isForegroundJIT);
}
}
jitData->callbackInlinees = AnewArrayZ(alloc, FunctionJITTimeDataIDL*, jitData->bodyData->profiledCallSiteCount);
for (Js::ProfileId i = 0; i < jitData->bodyData->profiledCallSiteCount; ++i)
{
const Js::FunctionCodeGenJitTimeData * inlineeJITData = codeGenData->GetCallbackInlinee(i);
if (inlineeJITData != nullptr)
{
const Js::FunctionCodeGenRuntimeData * inlineeRuntimeData = nullptr;
if (inlineeJITData->GetFunctionInfo()->HasBody())
{
inlineeRuntimeData = isInlinee ? targetRuntimeData->GetCallbackInlinee(i) : functionBody->GetCallbackInlineeCodeGenRuntimeData(i);
}
jitData->callbackInlinees[i] = AnewStructZ(alloc, FunctionJITTimeDataIDL);
BuildJITTimeData(alloc, inlineeJITData, inlineeRuntimeData, jitData->callbackInlinees[i], true, isForegroundJIT);
}
}
jitData->callApplyTargetInlineeCount = jitData->bodyData->profiledCallApplyCallSiteCount;
if (jitData->bodyData->profiledCallApplyCallSiteCount > 0)
{
jitData->callApplyTargetInlinees = AnewArrayZ(alloc, FunctionJITTimeDataIDL*, jitData->bodyData->profiledCallApplyCallSiteCount);
}
for (Js::ProfileId i = 0; i < jitData->bodyData->profiledCallApplyCallSiteCount; ++i)
{
const Js::FunctionCodeGenJitTimeData * inlineeJITData = codeGenData->GetCallApplyTargetInlinee(i);
if (inlineeJITData != nullptr)
{
const Js::FunctionCodeGenRuntimeData * inlineeRuntimeData = nullptr;
if (inlineeJITData->GetFunctionInfo()->HasBody())
{
inlineeRuntimeData = isInlinee ? targetRuntimeData->GetCallApplyTargetInlinee(i) : functionBody->GetCallApplyTargetInlineeCodeGenRuntimeData(i);
}
jitData->callApplyTargetInlinees[i] = AnewStructZ(alloc, FunctionJITTimeDataIDL);
BuildJITTimeData(alloc, inlineeJITData, inlineeRuntimeData, jitData->callApplyTargetInlinees[i], true, isForegroundJIT);
}
}
}
jitData->profiledRuntimeData = AnewStructZ(alloc, FunctionJITRuntimeIDL);
if (isInlinee && targetRuntimeData->ClonedInlineCaches()->HasInlineCaches())
{
jitData->profiledRuntimeData->clonedCacheCount = jitData->bodyData->inlineCacheCount;
jitData->profiledRuntimeData->clonedInlineCaches = AnewArray(alloc, intptr_t, jitData->profiledRuntimeData->clonedCacheCount);
for (uint j = 0; j < jitData->bodyData->inlineCacheCount; ++j)
{
jitData->profiledRuntimeData->clonedInlineCaches[j] = (intptr_t)targetRuntimeData->ClonedInlineCaches()->GetInlineCache(j);
}
}
if (jitData->bodyData->inlineCacheCount > 0)
{
jitData->ldFldInlineeCount = jitData->bodyData->inlineCacheCount;
jitData->ldFldInlinees = AnewArrayZ(alloc, FunctionJITTimeDataIDL*, jitData->bodyData->inlineCacheCount);
Field(ObjTypeSpecFldInfo*)* objTypeSpecInfo = codeGenData->GetObjTypeSpecFldInfoArray()->GetInfoArray();
if(objTypeSpecInfo)
{
jitData->objTypeSpecFldInfoCount = jitData->bodyData->inlineCacheCount;
jitData->objTypeSpecFldInfoArray = unsafe_write_barrier_cast<ObjTypeSpecFldIDL**>(objTypeSpecInfo);
}
for (Js::InlineCacheIndex i = 0; i < jitData->bodyData->inlineCacheCount; ++i)
{
const Js::FunctionCodeGenJitTimeData * inlineeJITData = codeGenData->GetLdFldInlinee(i);
const Js::FunctionCodeGenRuntimeData * inlineeRuntimeData = isInlinee ? targetRuntimeData->GetLdFldInlinee(i) : functionBody->GetLdFldInlineeCodeGenRuntimeData(i);
if (inlineeJITData != nullptr)
{
jitData->ldFldInlinees[i] = AnewStructZ(alloc, FunctionJITTimeDataIDL);
BuildJITTimeData(alloc, inlineeJITData, inlineeRuntimeData, jitData->ldFldInlinees[i], true, isForegroundJIT);
}
}
}
if (!isInlinee && codeGenData->GetGlobalObjTypeSpecFldInfoCount() > 0)
{
Field(ObjTypeSpecFldInfo*)* globObjTypeSpecInfo = codeGenData->GetGlobalObjTypeSpecFldInfoArray();
Assert(globObjTypeSpecInfo != nullptr);
jitData->globalObjTypeSpecFldInfoCount = codeGenData->GetGlobalObjTypeSpecFldInfoCount();
jitData->globalObjTypeSpecFldInfoArray = unsafe_write_barrier_cast<ObjTypeSpecFldIDL**>(globObjTypeSpecInfo);
}
const Js::FunctionCodeGenJitTimeData * nextJITData = codeGenData->GetNext();
if (nextJITData != nullptr)
{
// only inlinee should be polymorphic
Assert(isInlinee);
jitData->next = AnewStructZ(alloc, FunctionJITTimeDataIDL);
BuildJITTimeData(alloc, nextJITData, runtimeData, jitData->next, true, isForegroundJIT);
}
}
uint
FunctionJITTimeInfo::GetInlineeCount() const
{
return m_data.inlineeCount;
}
bool
FunctionJITTimeInfo::IsLdFldInlineePresent() const
{
return m_data.ldFldInlineeCount != 0;
}
bool
FunctionJITTimeInfo::HasSharedPropertyGuards() const
{
return m_data.sharedPropGuardCount != 0;
}
bool
FunctionJITTimeInfo::HasSharedPropertyGuard(Js::PropertyId id) const
{
for (uint i = 0; i < m_data.sharedPropGuardCount; ++i)
{
if (m_data.sharedPropertyGuards[i] == id)
{
return true;
}
}
return false;
}
bool FunctionJITTimeInfo::IsJsBuiltInForceInline() const
{
return this->GetBody()->GetSourceContextId() == Js::Constants::JsBuiltInSourceContextId;
}
intptr_t
FunctionJITTimeInfo::GetFunctionInfoAddr() const
{
return m_data.functionInfoAddr;
}
intptr_t
FunctionJITTimeInfo::GetEntryPointInfoAddr() const
{
return m_data.entryPointInfoAddr;
}
intptr_t
FunctionJITTimeInfo::GetWeakFuncRef() const
{
return m_data.weakFuncRef;
}
uint
FunctionJITTimeInfo::GetLocalFunctionId() const
{
return m_data.localFuncId;
}
bool
FunctionJITTimeInfo::IsAggressiveInliningEnabled() const
{
return m_data.isAggressiveInliningEnabled != FALSE;
}
bool
FunctionJITTimeInfo::IsInlined() const
{
return m_data.isInlined != FALSE;
}
const BVFixed *
FunctionJITTimeInfo::GetInlineesBV() const
{
return reinterpret_cast<const BVFixed *>(m_data.inlineesBv);
}
const FunctionJITTimeInfo *
FunctionJITTimeInfo::GetJitTimeDataFromFunctionInfoAddr(intptr_t polyFuncInfo) const
{
const FunctionJITTimeInfo *next = this;
while (next && next->GetFunctionInfoAddr() != polyFuncInfo)
{
next = next->GetNext();
}
return next;
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetInlineeForTargetInlineeRuntimeData(const Js::ProfileId profiledCallSiteId, intptr_t inlineeFuncBodyAddr) const
{
const FunctionJITTimeInfo *inlineeData = GetInlinee(profiledCallSiteId);
while (inlineeData && inlineeData->GetBody()->GetAddr() != inlineeFuncBodyAddr)
{
inlineeData = inlineeData->GetNext();
}
__analysis_assume(inlineeData != nullptr);
return inlineeData->GetRuntimeInfo();
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetInlineeRuntimeData(const Js::ProfileId profiledCallSiteId) const
{
return GetInlinee(profiledCallSiteId) ? GetInlinee(profiledCallSiteId)->GetRuntimeInfo() : nullptr;
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetLdFldInlineeRuntimeData(const Js::InlineCacheIndex inlineCacheIndex) const
{
return GetLdFldInlinee(inlineCacheIndex) ? GetLdFldInlinee(inlineCacheIndex)->GetRuntimeInfo() : nullptr;
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetCallbackInlineeRuntimeData(const Js::ProfileId profiledCallSiteId) const
{
return GetCallbackInlinee(profiledCallSiteId) ? GetCallbackInlinee(profiledCallSiteId)->GetRuntimeInfo() : nullptr;
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetInlineeForCallbackInlineeRuntimeData(const Js::ProfileId profiledCallSiteId, intptr_t inlineeFuncBodyAddr) const
{
const FunctionJITTimeInfo *inlineeData = GetCallbackInlinee(profiledCallSiteId);
while (inlineeData && inlineeData->GetBody()->GetAddr() != inlineeFuncBodyAddr)
{
inlineeData = inlineeData->GetNext();
}
__analysis_assume(inlineeData != nullptr);
return inlineeData->GetRuntimeInfo();
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetCallApplyTargetInlineeRuntimeData(const Js::ProfileId callApplyCallSiteId) const
{
return GetCallApplyTargetInlinee(callApplyCallSiteId) ? GetCallApplyTargetInlinee(callApplyCallSiteId)->GetRuntimeInfo() : nullptr;
}
const FunctionJITRuntimeInfo *
FunctionJITTimeInfo::GetRuntimeInfo() const
{
return reinterpret_cast<const FunctionJITRuntimeInfo*>(m_data.profiledRuntimeData);
}
ObjTypeSpecFldInfo *
FunctionJITTimeInfo::GetObjTypeSpecFldInfo(uint index) const
{
if (m_data.objTypeSpecFldInfoArray == nullptr)
{
return nullptr;
}
AssertOrFailFast(index < m_data.objTypeSpecFldInfoCount);
return reinterpret_cast<ObjTypeSpecFldInfo *>(m_data.objTypeSpecFldInfoArray[index]);
}
void
FunctionJITTimeInfo::ClearObjTypeSpecFldInfo(uint index)
{
if (m_data.objTypeSpecFldInfoArray == nullptr)
{
return;
}
AssertOrFailFast(index < m_data.objTypeSpecFldInfoCount);
m_data.objTypeSpecFldInfoArray[index] = nullptr;
}
ObjTypeSpecFldInfo *
FunctionJITTimeInfo::GetGlobalObjTypeSpecFldInfo(uint index) const
{
AssertOrFailFast(index < m_data.globalObjTypeSpecFldInfoCount);
return reinterpret_cast<ObjTypeSpecFldInfo *>(m_data.globalObjTypeSpecFldInfoArray[index]);
}
uint
FunctionJITTimeInfo::GetGlobalObjTypeSpecFldInfoCount() const
{
return m_data.globalObjTypeSpecFldInfoCount;
}
uint
FunctionJITTimeInfo::GetSourceContextId() const
{
Assert(HasBody());
return GetBody()->GetSourceContextId();
}
const FunctionJITTimeInfo *
FunctionJITTimeInfo::GetCallbackInlinee(Js::ProfileId profileId) const
{
Assert(profileId < m_data.bodyData->profiledCallSiteCount);
if (!m_data.callbackInlinees)
{
return nullptr;
}
AssertOrFailFast(profileId < m_data.inlineeCount);
return reinterpret_cast<const FunctionJITTimeInfo *>(m_data.callbackInlinees[profileId]);
}
const FunctionJITTimeInfo *
FunctionJITTimeInfo::GetCallApplyTargetInlinee(Js::ProfileId callApplyCallSiteId) const
{
if (!m_data.callApplyTargetInlinees)
{
return nullptr;
}
AssertOrFailFast(callApplyCallSiteId < m_data.bodyData->profiledCallApplyCallSiteCount);
return reinterpret_cast<const FunctionJITTimeInfo *>(m_data.callApplyTargetInlinees[callApplyCallSiteId]);
}
const FunctionJITTimeInfo *
FunctionJITTimeInfo::GetLdFldInlinee(Js::InlineCacheIndex inlineCacheIndex) const
{
Assert(inlineCacheIndex < m_data.bodyData->inlineCacheCount);
if (!m_data.ldFldInlinees)
{
return nullptr;
}
AssertOrFailFast(inlineCacheIndex < m_data.ldFldInlineeCount);
return reinterpret_cast<const FunctionJITTimeInfo*>(m_data.ldFldInlinees[inlineCacheIndex]);
}
const FunctionJITTimeInfo *
FunctionJITTimeInfo::GetInlinee(Js::ProfileId profileId) const
{
Assert(profileId < m_data.bodyData->profiledCallSiteCount);
if (!m_data.inlinees)
{
return nullptr;
}
AssertOrFailFast(profileId < m_data.inlineeCount);
auto inlinee = reinterpret_cast<const FunctionJITTimeInfo *>(m_data.inlinees[profileId]);
if (inlinee == nullptr && m_data.inlineesRecursionFlags[profileId])
{
inlinee = this;
}
return inlinee;
}
const FunctionJITTimeInfo *
FunctionJITTimeInfo::GetNext() const
{
return reinterpret_cast<const FunctionJITTimeInfo *>(m_data.next);
}
JITTimeFunctionBody *
FunctionJITTimeInfo::GetBody() const
{
return reinterpret_cast<JITTimeFunctionBody *>(m_data.bodyData);
}
bool
FunctionJITTimeInfo::HasBody() const
{
return m_data.bodyData != nullptr;
}
bool
FunctionJITTimeInfo::IsPolymorphicCallSite(Js::ProfileId profiledCallSiteId) const
{
Assert(profiledCallSiteId < m_data.bodyData->profiledCallSiteCount);
if (!m_data.inlinees)
{
return false;
}
Assert(profiledCallSiteId < m_data.inlineeCount);
return ((FunctionJITTimeDataIDL*)this->GetInlinee(profiledCallSiteId))->next != nullptr;
}
bool
FunctionJITTimeInfo::ForceJITLoopBody() const
{
return
!PHASE_OFF(Js::JITLoopBodyPhase, this) &&
!PHASE_OFF(Js::FullJitPhase, this) &&
!GetBody()->IsGenerator() &&
!GetBody()->HasTry() &&
(
PHASE_FORCE(Js::JITLoopBodyPhase, this)
#ifdef ENABLE_PREJIT
|| Js::Configuration::Global.flags.Prejit
#endif
);
}
char16*
FunctionJITTimeInfo::GetDisplayName() const
{
return GetBody()->GetDisplayName();
}
char16*
FunctionJITTimeInfo::GetDebugNumberSet(wchar(&bufferToWriteTo)[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE]) const
{
// (#%u.%u), #%u --> (source file Id . function Id) , function Number
int len = swprintf_s(bufferToWriteTo, MAX_FUNCTION_BODY_DEBUG_STRING_SIZE, _u(" (#%d.%u), #%u"),
(int)GetSourceContextId(), GetLocalFunctionId(), GetBody()->GetFunctionNumber());
Assert(len > 8);
return bufferToWriteTo;
}