Skip to content

Commit d278ce5

Browse files
committed
[MERGE chakra-core#3172 @leirocks] fix etw logging for very long name function loop body
Merge pull request chakra-core#3172 from leirocks:auxptr_etw_loop if a function has very long name(longer than 256), we calculate the loop body name from a loop number, the loop number is calculated from loop header, which is not necessary because after loop body code gen we already know the loop number. while calculating the loop number we access auxPtrs to get the loop header array in background thread, which is not allowed after JIT on the function is started. the fix is to just not calculate the loop number again.
2 parents 0f822f4 + 484fae8 commit d278ce5

5 files changed

Lines changed: 16 additions & 60 deletions

File tree

lib/Runtime/Base/EtwTrace.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ void EtwTrace::PerformRundown(bool start)
192192
{
193193
if (start)
194194
{
195-
LogLoopBodyEventBG(EventWriteMethodDCStart, body, header, entryPoint, ((uint16)body->GetLoopNumberWithLock(header)));
195+
LogLoopBodyEvent(EventWriteMethodDCStart, body, entryPoint, ((uint16)body->GetLoopNumberWithLock(header)));
196196
}
197197
else
198198
{
199-
LogLoopBodyEventBG(EventWriteMethodDCEnd, body, header, entryPoint, ((uint16)body->GetLoopNumberWithLock(header)));
199+
LogLoopBodyEvent(EventWriteMethodDCEnd, body, entryPoint, ((uint16)body->GetLoopNumberWithLock(header)));
200200
}
201201
}
202202
});
@@ -288,10 +288,10 @@ void EtwTrace::LogMethodNativeLoadEvent(FunctionBody* body, FunctionEntryPointIn
288288
#endif
289289
}
290290

291-
void EtwTrace::LogLoopBodyLoadEvent(FunctionBody* body, LoopHeader* loopHeader, LoopEntryPointInfo* entryPoint, uint16 loopNumber)
291+
void EtwTrace::LogLoopBodyLoadEvent(FunctionBody* body, LoopEntryPointInfo* entryPoint, uint16 loopNumber)
292292
{
293293
#if ENABLE_NATIVE_CODEGEN
294-
LogLoopBodyEventBG(EventWriteMethodLoad, body, loopHeader, entryPoint, loopNumber);
294+
LogLoopBodyEvent(EventWriteMethodLoad, body, entryPoint, loopNumber);
295295
#else
296296
Assert(false); // Caller should not be enabled if JIT is disabled
297297
#endif
@@ -316,10 +316,10 @@ void EtwTrace::LogMethodNativeUnloadEvent(FunctionBody* body, FunctionEntryPoint
316316
#endif
317317
}
318318

319-
void EtwTrace::LogLoopBodyUnloadEvent(FunctionBody* body, LoopHeader* loopHeader, LoopEntryPointInfo* entryPoint)
319+
void EtwTrace::LogLoopBodyUnloadEvent(FunctionBody* body, LoopEntryPointInfo* entryPoint, uint loopNumber)
320320
{
321321
#if ENABLE_NATIVE_CODEGEN
322-
LogLoopBodyEvent(EventWriteMethodUnload, body, loopHeader, entryPoint);
322+
LogLoopBodyEvent(EventWriteMethodUnload, body, entryPoint, loopNumber);
323323
#else
324324
Assert(false); // Caller should not be enabled if JIT is disabled
325325
#endif

lib/Runtime/Base/EtwTrace.h

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -165,53 +165,8 @@ enum MethodType : uint16
165165
Body->GetColumnNumber(), \
166166
GetFunctionName(Body))
167167

168-
#define LogLoopBodyEvent(Function, Body, loopHeader, entryPoint) \
169-
Assert(entryPoint->GetNativeAddress() != NULL); \
170-
Assert(entryPoint->GetCodeSize() > 0); \
171-
WCHAR loopBodyNameArray[NameBufferLength]; \
172-
WCHAR* loopBodyName = loopBodyNameArray; \
173-
size_t bufferSize = GetLoopBodyName(Body, loopHeader, loopBodyName, NameBufferLength); \
174-
if(bufferSize > NameBufferLength) /* insufficient buffer space*/ \
175-
{ \
176-
loopBodyName = HeapNewNoThrowArray(WCHAR, bufferSize); \
177-
if(loopBodyName) \
178-
{ \
179-
GetLoopBodyName(Body, loopHeader, loopBodyName, bufferSize); \
180-
} \
181-
else \
182-
{ \
183-
loopBodyNameArray[0] = _u('\0'); \
184-
loopBodyName = loopBodyNameArray; \
185-
} \
186-
} \
187-
JS_ETW(Function(Body->GetScriptContext(), \
188-
(void *)entryPoint->GetNativeAddress(), \
189-
entryPoint->GetCodeSize(), \
190-
GetFunctionId(Body), \
191-
0 /* methodFlags - for future use*/, \
192-
MethodType_LoopBody + (uint16)Body->GetLoopNumber(loopHeader), \
193-
GetSourceId(Body), \
194-
/*line*/ 0, \
195-
/*column*/ 0, \
196-
loopBodyName)); \
197-
WriteMethodEvent(STRINGIZEW(Function), \
198-
Body->GetScriptContext(), \
199-
(void *)entryPoint->GetNativeAddress(), \
200-
entryPoint->GetCodeSize(), \
201-
GetFunctionId(Body), \
202-
0 /* methodFlags - for future use*/, \
203-
MethodType_LoopBody + (uint16)Body->GetLoopNumber(loopHeader), \
204-
GetSourceId(Body), \
205-
/*line*/ 0, \
206-
/*column*/ 0, \
207-
loopBodyName); \
208-
if(loopBodyNameArray != loopBodyName) \
209-
{ \
210-
HeapDeleteArray(bufferSize, loopBodyName); \
211-
}
212-
213168

214-
#define LogLoopBodyEventBG(Function, Body, loopHeader, entryPoint, loopNumber) \
169+
#define LogLoopBodyEvent(Function, Body, entryPoint, loopNumber) \
215170
Assert(entryPoint->GetNativeAddress() != NULL); \
216171
Assert(entryPoint->GetCodeSize() > 0); \
217172
WCHAR loopBodyNameArray[NameBufferLength]; \
@@ -222,7 +177,7 @@ enum MethodType : uint16
222177
loopBodyName = HeapNewNoThrowArray(WCHAR, bufferSize); \
223178
if(loopBodyName) \
224179
{ \
225-
GetLoopBodyName(Body, loopHeader, loopBodyName, bufferSize); \
180+
Body->GetLoopBodyName(loopNumber, loopBodyName, NameBufferLength); \
226181
} \
227182
else \
228183
{ \
@@ -274,14 +229,14 @@ class EtwTrace
274229
static void LogSourceUnloadEvents(Js::ScriptContext* scriptContext);
275230
static void LogMethodNativeUnloadEvent(Js::FunctionBody* body, Js::FunctionEntryPointInfo* entryPoint);
276231
static void LogMethodInterpreterThunkUnloadEvent(Js::FunctionBody* body);
277-
static void LogLoopBodyUnloadEvent(Js::FunctionBody* body, Js::LoopHeader* loopHeader, Js::LoopEntryPointInfo* entryPoint);
232+
static void LogLoopBodyUnloadEvent(Js::FunctionBody* body, Js::LoopEntryPointInfo* entryPoint, uint loopNumber);
278233

279234
/* Load events */
280235
static void LogMethodInterpreterThunkLoadEvent(Js::FunctionBody* body);
281236
static void LogMethodNativeLoadEvent(Js::FunctionBody* body, Js::FunctionEntryPointInfo* entryPoint);
282237

283238

284-
static void LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopHeader* loopHeader, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber);
239+
static void LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber);
285240
static void LogScriptContextLoadEvent(Js::ScriptContext* scriptContext);
286241
static void LogSourceModuleLoadEvent(Js::ScriptContext* scriptContext, DWORD_PTR sourceContext, _In_z_ const char16* url);
287242

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,9 +3833,9 @@ namespace Js
38333833
{
38343834
loopHeader->interpretCount = entryPointInfo->GetFunctionBody()->GetLoopInterpretCount(loopHeader) - 1;
38353835
}
3836-
JS_ETW(EtwTrace::LogLoopBodyLoadEvent(this, loopHeader, ((LoopEntryPointInfo*)entryPointInfo), ((uint16)loopNum)));
3836+
JS_ETW(EtwTrace::LogLoopBodyLoadEvent(this, ((LoopEntryPointInfo*)entryPointInfo), ((uint16)loopNum)));
38373837
#ifdef VTUNE_PROFILING
3838-
VTuneChakraProfile::LogLoopBodyLoadEvent(this, loopHeader, ((LoopEntryPointInfo*)entryPointInfo), ((uint16)loopNum));
3838+
VTuneChakraProfile::LogLoopBodyLoadEvent(this, ((LoopEntryPointInfo*)entryPointInfo), ((uint16)loopNum));
38393839
#endif
38403840
}
38413841
#endif
@@ -9986,7 +9986,8 @@ namespace Js
99869986
if (this->IsCodeGenDone())
99879987
#endif
99889988
{
9989-
JS_ETW(EtwTrace::LogLoopBodyUnloadEvent(this->loopHeader->functionBody, this->loopHeader, this));
9989+
uint loopNumber = this->loopHeader->functionBody->GetLoopNumber(this->loopHeader);
9990+
JS_ETW(EtwTrace::LogLoopBodyUnloadEvent(this->loopHeader->functionBody, this, loopNumber));
99909991

99919992
#if ENABLE_NATIVE_CODEGEN
99929993
if (nullptr != this->inlineeFrameMap)

lib/Runtime/Base/VTuneChakraProfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void VTuneChakraProfile::LogMethodNativeLoadEvent(Js::FunctionBody* body, Js::Fu
116116
//
117117
// Log loop body load event to VTune
118118
//
119-
void VTuneChakraProfile::LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopHeader* loopHeader, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber)
119+
void VTuneChakraProfile::LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber)
120120
{
121121
#if ENABLE_NATIVE_CODEGEN
122122
if (isJitProfilingActive)

lib/Runtime/Base/VTuneChakraProfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class VTuneChakraProfile
1616
static void UnRegister();
1717

1818
static void LogMethodNativeLoadEvent(Js::FunctionBody* body, Js::FunctionEntryPointInfo* entryPoint);
19-
static void LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopHeader* loopHeader, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber);
19+
static void LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber);
2020

2121
static const utf8char_t DynamicCode[];
2222
static bool isJitProfilingActive;

0 commit comments

Comments
 (0)