Skip to content

Commit 660c697

Browse files
committed
probing R2R code in caller modules
1 parent ddb88a4 commit 660c697

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

src/coreclr/vm/codeversion.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,8 @@ PCODE CodeVersionManager::PublishVersionableCodeIfNecessary(
16371637
MethodDesc* pMethodDesc,
16381638
CallerGCMode callerGCMode,
16391639
bool *doBackpatchRef,
1640-
bool *doFullBackpatchRef)
1640+
bool *doFullBackpatchRef,
1641+
Module* pModule)
16411642
{
16421643
STANDARD_VM_CONTRACT;
16431644
_ASSERTE(!IsLockOwnedByCurrentThread());
@@ -1698,7 +1699,7 @@ PCODE CodeVersionManager::PublishVersionableCodeIfNecessary(
16981699

16991700
// Record the caller's GC mode.
17001701
config->SetCallerGCMode(callerGCMode);
1701-
pCode = pMethodDesc->PrepareCode(config);
1702+
pCode = pMethodDesc->PrepareCode(config, pModule);
17021703

17031704
#ifdef FEATURE_CODE_VERSIONING
17041705
if (config->ProfilerMayHaveActivatedNonDefaultCodeVersion())

src/coreclr/vm/codeversion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ class CodeVersionManager
594594
MethodDesc* pMethodDesc,
595595
CallerGCMode callerGCMode,
596596
bool *doBackpatchRef,
597-
bool *doFullBackpatchRef);
597+
bool *doFullBackpatchRef,
598+
Module* pModule = NULL);
598599
HRESULT PublishNativeCodeVersion(MethodDesc* pMethodDesc, NativeCodeVersion nativeCodeVersion);
599600
HRESULT GetOrCreateMethodDescVersioningState(MethodDesc* pMethod, MethodDescVersioningState** ppMethodDescVersioningState);
600601
HRESULT GetOrCreateILCodeVersioningState(Module* pModule, mdMethodDef methodDef, ILCodeVersioningState** ppILCodeVersioningState);

src/coreclr/vm/method.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ class MethodDesc
17921792
//
17931793
PCODE DoBackpatch(MethodTable * pMT, MethodTable * pDispatchingMT, BOOL fFullBackPatch);
17941794

1795-
PCODE DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMode = CallerGCMode::Unknown);
1795+
PCODE DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMode = CallerGCMode::Unknown, Module* pModule = NULL);
17961796

17971797
VOID GetMethodInfo(SString &namespaceOrClassName, SString &methodName, SString &methodSignature);
17981798
VOID GetMethodInfoWithNewSig(SString &namespaceOrClassName, SString &methodName, SString &methodSignature);
@@ -2019,13 +2019,13 @@ class MethodDesc
20192019
#ifndef DACCESS_COMPILE
20202020
public:
20212021
PCODE PrepareInitialCode(CallerGCMode callerGCMode = CallerGCMode::Unknown);
2022-
PCODE PrepareCode(PrepareCodeConfig* pConfig);
2022+
PCODE PrepareCode(PrepareCodeConfig* pConfig, Module* pModule = NULL);
20232023

20242024
private:
2025-
PCODE PrepareILBasedCode(PrepareCodeConfig* pConfig);
2026-
PCODE GetPrecompiledCode(PrepareCodeConfig* pConfig, bool shouldTier);
2025+
PCODE PrepareILBasedCode(PrepareCodeConfig* pConfig, Module* pModule = NULL);
2026+
PCODE GetPrecompiledCode(PrepareCodeConfig* pConfig, bool shouldTier, Module* pModule = NULL);
20272027
PCODE GetPrecompiledNgenCode(PrepareCodeConfig* pConfig);
2028-
PCODE GetPrecompiledR2RCode(PrepareCodeConfig* pConfig);
2028+
PCODE GetPrecompiledR2RCode(PrepareCodeConfig* pConfig, Module* pModule_probe = NULL);
20292029
PCODE GetMulticoreJitCode(PrepareCodeConfig* pConfig, bool* pWasTier0Jit);
20302030
COR_ILMETHOD_DECODER* GetAndVerifyILHeader(PrepareCodeConfig* pConfig, COR_ILMETHOD_DECODER* pIlDecoderMemory);
20312031
COR_ILMETHOD_DECODER* GetAndVerifyMetadataILHeader(PrepareCodeConfig* pConfig, COR_ILMETHOD_DECODER* pIlDecoderMemory);

src/coreclr/vm/prestub.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ PCODE MethodDesc::PrepareInitialCode(CallerGCMode callerGCMode)
322322
return PrepareCode(&config);
323323
}
324324

325-
PCODE MethodDesc::PrepareCode(PrepareCodeConfig* pConfig)
325+
PCODE MethodDesc::PrepareCode(PrepareCodeConfig* pConfig, Module* pModule)
326326
{
327327
STANDARD_VM_CONTRACT;
328328

@@ -333,7 +333,7 @@ PCODE MethodDesc::PrepareCode(PrepareCodeConfig* pConfig)
333333
// If other kinds of code need multi-versioning we could add more cases here,
334334
// but for now generation of all other code/stubs occurs in other code paths
335335
_ASSERTE(IsIL() || IsNoMetadata());
336-
PCODE pCode = PrepareILBasedCode(pConfig);
336+
PCODE pCode = PrepareILBasedCode(pConfig, pModule);
337337

338338
#if defined(FEATURE_GDBJIT) && defined(TARGET_UNIX) && !defined(CROSSGEN_COMPILE)
339339
NotifyGdb::MethodPrepared(this);
@@ -356,7 +356,7 @@ bool MayUsePrecompiledILStub()
356356
return true;
357357
}
358358

359-
PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
359+
PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig, Module* pModule)
360360
{
361361
STANDARD_VM_CONTRACT;
362362
PCODE pCode = NULL;
@@ -406,7 +406,7 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
406406
MethodDesc* pTargetMD = stubMethodDesc->GetILStubResolver()->GetStubTargetMethodDesc();
407407
if (pTargetMD != NULL)
408408
{
409-
pCode = pTargetMD->GetPrecompiledR2RCode(pConfig);
409+
pCode = pTargetMD->GetPrecompiledR2RCode(pConfig, pModule);
410410
if (pCode != NULL)
411411
{
412412
LOG_USING_R2R_CODE(this);
@@ -421,7 +421,7 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
421421

422422
if (pCode == NULL)
423423
{
424-
pCode = GetPrecompiledCode(pConfig, shouldTier);
424+
pCode = GetPrecompiledCode(pConfig, shouldTier, pModule);
425425
}
426426

427427
#ifdef FEATURE_PERFMAP
@@ -447,7 +447,7 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
447447
return pCode;
448448
}
449449

450-
PCODE MethodDesc::GetPrecompiledCode(PrepareCodeConfig* pConfig, bool shouldTier)
450+
PCODE MethodDesc::GetPrecompiledCode(PrepareCodeConfig* pConfig, bool shouldTier, Module* pModule)
451451
{
452452
STANDARD_VM_CONTRACT;
453453
PCODE pCode = NULL;
@@ -465,7 +465,7 @@ PCODE MethodDesc::GetPrecompiledCode(PrepareCodeConfig* pConfig, bool shouldTier
465465
#ifdef FEATURE_READYTORUN
466466
else
467467
{
468-
pCode = GetPrecompiledR2RCode(pConfig);
468+
pCode = GetPrecompiledR2RCode(pConfig, pModule);
469469
if (pCode != NULL)
470470
{
471471
LOG_USING_R2R_CODE(this);
@@ -578,7 +578,7 @@ PCODE MethodDesc::GetPrecompiledNgenCode(PrepareCodeConfig* pConfig)
578578
}
579579

580580

581-
PCODE MethodDesc::GetPrecompiledR2RCode(PrepareCodeConfig* pConfig)
581+
PCODE MethodDesc::GetPrecompiledR2RCode(PrepareCodeConfig* pConfig, Module* pModule_probe)
582582
{
583583
STANDARD_VM_CONTRACT;
584584

@@ -600,6 +600,20 @@ PCODE MethodDesc::GetPrecompiledR2RCode(PrepareCodeConfig* pConfig)
600600
{
601601
pCode = pModule->GetReadyToRunInfo()->GetEntryPoint(this, pConfig, TRUE /* fFixups */);
602602
}
603+
604+
if (!pCode)
605+
{
606+
if (pModule_probe)
607+
{
608+
if (pModule_probe->IsReadyToRun())
609+
{
610+
if (pModule_probe->IsInSameVersionBubble(GetModule()))
611+
{
612+
pCode = pModule_probe->GetReadyToRunInfo()->GetEntryPoint(this, pConfig, TRUE /* fFixups */);
613+
}
614+
}
615+
}
616+
}
603617
}
604618
#endif
605619
return pCode;
@@ -1852,7 +1866,8 @@ extern "C" MethodDesc * STDCALL PreStubGetMethodDescForCompactEntryPoint (PCODE
18521866
static PCODE PreStubWorker_Preemptive(
18531867
_In_ TransitionBlock* pTransitionBlock,
18541868
_In_ MethodDesc* pMD,
1855-
_In_opt_ Thread* currentThread)
1869+
_In_opt_ Thread* currentThread,
1870+
Module* pModule = NULL)
18561871
{
18571872
_ASSERTE(pMD->HasUnmanagedCallersOnlyAttribute());
18581873

@@ -1885,7 +1900,7 @@ static PCODE PreStubWorker_Preemptive(
18851900
pMD->CheckRestore();
18861901
CONSISTENCY_CHECK(GetAppDomain()->CheckCanExecuteManagedCode(pMD));
18871902

1888-
pbRetVal = pMD->DoPrestub(NULL, CallerGCMode::Preemptive);
1903+
pbRetVal = pMD->DoPrestub(NULL, CallerGCMode::Preemptive, pModule);
18891904

18901905
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER;
18911906
UNINSTALL_MANAGED_EXCEPTION_DISPATCHER;
@@ -1910,6 +1925,11 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method
19101925
{
19111926
PCODE pbRetVal = NULL;
19121927

1928+
Module* pModule = NULL;
1929+
FrameWithCookie<ExternalMethodFrame> frame(pTransitionBlock);
1930+
ExternalMethodFrame * pEMFrame = &frame;
1931+
pModule = ExecutionManager::FindReadyToRunModule((TADDR)(((BYTE*)pEMFrame->GetReturnAddress())-1));
1932+
19131933
BEGIN_PRESERVE_LAST_ERROR;
19141934

19151935
STATIC_CONTRACT_THROWS;
@@ -1927,7 +1947,7 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method
19271947
if (CURRENT_THREAD == NULL
19281948
|| !CURRENT_THREAD->PreemptiveGCDisabled())
19291949
{
1930-
pbRetVal = PreStubWorker_Preemptive(pTransitionBlock, pMD, CURRENT_THREAD);
1950+
pbRetVal = PreStubWorker_Preemptive(pTransitionBlock, pMD, CURRENT_THREAD, pModule);
19311951
}
19321952
else
19331953
{
@@ -1995,7 +2015,7 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method
19952015
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
19962016
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
19972017

1998-
pbRetVal = pMD->DoPrestub(pDispatchingMT, CallerGCMode::Coop);
2018+
pbRetVal = pMD->DoPrestub(pDispatchingMT, CallerGCMode::Coop, pModule);
19992019
}
20002020

20012021
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER;
@@ -2064,7 +2084,7 @@ static void TestSEHGuardPageRestore()
20642084
// the case of methods that require stubs to be executed first (e.g., remoted methods
20652085
// that require remoting stubs to be executed first), this stable entrypoint would be a
20662086
// pointer to the stub, and not a pointer directly to the JITted code.
2067-
PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMode)
2087+
PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMode, Module* pModule)
20682088
{
20692089
CONTRACT(PCODE)
20702090
{
@@ -2169,7 +2189,7 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMo
21692189
{
21702190
bool doBackpatch = true;
21712191
bool doFullBackpatch = false;
2172-
pCode = GetCodeVersionManager()->PublishVersionableCodeIfNecessary(this, callerGCMode, &doBackpatch, &doFullBackpatch);
2192+
pCode = GetCodeVersionManager()->PublishVersionableCodeIfNecessary(this, callerGCMode, &doBackpatch, &doFullBackpatch, pModule);
21732193

21742194
if (doBackpatch)
21752195
{

0 commit comments

Comments
 (0)