Skip to content

Commit c2405ae

Browse files
committed
[MERGE #1925 @MikeHolman] Short circuit IsNativeAddress for Chakra.dll functions when OOP
Merge pull request #1925 from MikeHolman:oopwalkperf In case all code is not in prereserved code segment or on platforms where prereserved code segment is not available, stack walking requires RPC for each frame to check if an address is JIT code. If an address is in Chakra, we know it isn't JIT code. A large majority of functions on the stack at any time are interpreter frames, so by checking this we dramatically reduce the frequency of these calls. Improves Octane CodeLoad perf by 20% on ARM, bringing it back to par with in-proc perf.
2 parents b937753 + e5a7f3f commit c2405ae

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

lib/Backend/ServerThreadContext.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ ServerThreadContext::ServerThreadContext(ThreadContextDataIDL * data) :
2424
PageAllocator::DefaultLowMaxFreePageCount :
2525
PageAllocator::DefaultMaxFreePageCount
2626
),
27-
// TODO: OOP JIT, don't hardcode name
28-
#ifdef NTBUILD
29-
m_jitChakraBaseAddress((intptr_t)GetModuleHandle(_u("Chakra.dll"))),
30-
#else
31-
m_jitChakraBaseAddress((intptr_t)GetModuleHandle(_u("ChakraCore.dll"))),
32-
#endif
3327
m_jitCRTBaseAddress((intptr_t)GetModuleHandle(UCrtC99MathApis::LibraryName))
3428
{
3529
#if ENABLE_OOP_NATIVE_CODEGEN
@@ -68,7 +62,11 @@ ServerThreadContext::GetBailOutRegisterSaveSpaceAddr() const
6862
ptrdiff_t
6963
ServerThreadContext::GetChakraBaseAddressDifference() const
7064
{
71-
return GetRuntimeChakraBaseAddress() - m_jitChakraBaseAddress;
65+
#if ENABLE_OOP_NATIVE_CODEGEN
66+
return GetRuntimeChakraBaseAddress() - (intptr_t)AutoSystemInfo::Data.GetChakraBaseAddr();
67+
#else
68+
return 0;
69+
#endif
7270
}
7371

7472
ptrdiff_t

lib/Backend/ServerThreadContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class ServerThreadContext : public ThreadContextInfo
7171

7272
DWORD m_pid; //save client process id for easier diagnose
7373

74-
intptr_t m_jitChakraBaseAddress;
7574
intptr_t m_jitCRTBaseAddress;
7675
uint m_refCount;
7776
};

lib/Common/Core/SysInfo.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ AutoSystemInfo::VirtualSseAvailable(const int sseLevel) const
212212
}
213213
#endif
214214

215+
216+
#ifdef ENABLE_OOP_NATIVE_CODEGEN
217+
bool
218+
AutoSystemInfo::IsChakraAddress(void * addr) const
219+
{
220+
return addr >= this->chakraBaseAddress && addr < (this->chakraBaseAddress + this->chakraSize);
221+
}
222+
void *
223+
AutoSystemInfo::GetChakraBaseAddr() const
224+
{
225+
return this->chakraBaseAddress;
226+
}
227+
#endif
228+
215229
BOOL
216230
AutoSystemInfo::SSE2Available() const
217231
{
@@ -356,7 +370,17 @@ AutoSystemInfo::IsWinThresholdOrLater()
356370

357371
DWORD AutoSystemInfo::SaveModuleFileName(HANDLE hMod)
358372
{
359-
return ::GetModuleFileNameW((HMODULE)hMod, Data.binaryName, MAX_PATH);
373+
DWORD result = ::GetModuleFileNameW((HMODULE)hMod, Data.binaryName, MAX_PATH);
374+
375+
#ifdef ENABLE_OOP_NATIVE_CODEGEN
376+
Data.chakraBaseAddress = GetModuleHandle(Data.binaryName);
377+
AnalysisAssert(Data.chakraBaseAddress != nullptr);
378+
MODULEINFO chakraInfo = { 0 };
379+
GetModuleInformation(GetCurrentProcess(), Data.chakraBaseAddress, &chakraInfo, sizeof(chakraInfo));
380+
Data.chakraSize = chakraInfo.SizeOfImage;
381+
#endif
382+
383+
return result;
360384
}
361385

362386
LPCWSTR AutoSystemInfo::GetJscriptDllFileName()

lib/Common/Core/SysInfo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class AutoSystemInfo : public SYSTEM_INFO
3939
DWORD GetNumberOfLogicalProcessors() const { return this->dwNumberOfProcessors; }
4040
DWORD GetNumberOfPhysicalProcessors() const { return this->dwNumberOfPhysicalProcessors; }
4141

42+
#ifdef ENABLE_OOP_NATIVE_CODEGEN
43+
bool IsChakraAddress(void * addr) const;
44+
void * GetChakraBaseAddr() const;
45+
#endif
46+
4247
#if defined(_M_ARM32_OR_ARM64)
4348
bool ArmDivAvailable() const { return this->armDivAvailable; }
4449
#endif
@@ -108,6 +113,9 @@ class AutoSystemInfo : public SYSTEM_INFO
108113

109114
static const DWORD INVALID_VERSION = (DWORD)-1;
110115

116+
HMODULE chakraBaseAddress;
117+
size_t chakraSize;
118+
111119
ULONG64 availableCommit;
112120
bool shouldQCMoreFrequently;
113121
bool supportsOnlyMultiThreadedCOM;

lib/Runtime/Base/ThreadContext.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,7 @@ ThreadContext::SetJITConnectionInfo(HANDLE processHandle, void* serverSecurityDe
19681968
void
19691969
ThreadContext::EnsureJITThreadContext(bool allowPrereserveAlloc)
19701970
{
1971+
#if ENABLE_OOP_NATIVE_CODEGEN
19711972
Assert(JITManager::GetJITManager()->IsOOPJITEnabled());
19721973
Assert(JITManager::GetJITManager()->IsConnected());
19731974

@@ -1979,12 +1980,7 @@ ThreadContext::EnsureJITThreadContext(bool allowPrereserveAlloc)
19791980
ThreadContextDataIDL contextData;
19801981
contextData.processHandle = (intptr_t)JITManager::GetJITManager()->GetJITTargetHandle();
19811982

1982-
// TODO: OOP JIT, use more generic method for getting name, e.g. in case of ChakraTest.dll
1983-
#ifdef NTBUILD
1984-
contextData.chakraBaseAddress = (intptr_t)GetModuleHandle(_u("Chakra.dll"));
1985-
#else
1986-
contextData.chakraBaseAddress = (intptr_t)GetModuleHandle(_u("ChakraCore.dll"));
1987-
#endif
1983+
contextData.chakraBaseAddress = (intptr_t)AutoSystemInfo::Data.GetChakraBaseAddr();
19881984
contextData.crtBaseAddress = (intptr_t)GetModuleHandle(UCrtC99MathApis::LibraryName);
19891985
contextData.threadStackLimitAddr = reinterpret_cast<intptr_t>(GetAddressOfStackLimitForCurrentThread());
19901986
contextData.bailOutRegisterSaveSpaceAddr = (intptr_t)bailOutRegisterSaveSpace;
@@ -2010,6 +2006,8 @@ ThreadContext::EnsureJITThreadContext(bool allowPrereserveAlloc)
20102006

20112007
HRESULT hr = JITManager::GetJITManager()->InitializeThreadContext(&contextData, &m_remoteThreadContextInfo, &m_prereservedRegionAddr);
20122008
JITManager::HandleServerCallResult(hr);
2009+
2010+
#endif
20132011
}
20142012
#endif
20152013

@@ -3862,6 +3860,7 @@ void DumpRecyclerObjectGraph()
38623860
BOOL ThreadContext::IsNativeAddress(void * pCodeAddr)
38633861
{
38643862
boolean result;
3863+
#if ENABLE_OOP_NATIVE_CODEGEN
38653864
if (JITManager::GetJITManager()->IsOOPJITEnabled())
38663865
{
38673866
if (PreReservedVirtualAllocWrapper::IsInRange((void*)m_prereservedRegionAddr, pCodeAddr))
@@ -3872,13 +3871,19 @@ BOOL ThreadContext::IsNativeAddress(void * pCodeAddr)
38723871
{
38733872
return false;
38743873
}
3874+
if (AutoSystemInfo::Data.IsChakraAddress(pCodeAddr))
3875+
{
3876+
return false;
3877+
}
3878+
38753879
HRESULT hr = JITManager::GetJITManager()->IsNativeAddr(this->m_remoteThreadContextInfo, (intptr_t)pCodeAddr, &result);
38763880

38773881
// TODO: OOP JIT, can we throw here?
38783882
JITManager::HandleServerCallResult(hr);
38793883
return result;
38803884
}
38813885
else
3886+
#endif
38823887
{
38833888
PreReservedVirtualAllocWrapper *preReservedVirtualAllocWrapper = this->GetPreReservedVirtualAllocator();
38843889
if (preReservedVirtualAllocWrapper->IsInRange(pCodeAddr))

0 commit comments

Comments
 (0)