@@ -322,7 +322,7 @@ PCODE MethodDesc::PrepareInitialCode(CallerGCMode callerGCMode)
322
322
return PrepareCode (&config);
323
323
}
324
324
325
- PCODE MethodDesc::PrepareCode (PrepareCodeConfig* pConfig)
325
+ PCODE MethodDesc::PrepareCode (PrepareCodeConfig* pConfig, Module* pModule )
326
326
{
327
327
STANDARD_VM_CONTRACT;
328
328
@@ -333,7 +333,7 @@ PCODE MethodDesc::PrepareCode(PrepareCodeConfig* pConfig)
333
333
// If other kinds of code need multi-versioning we could add more cases here,
334
334
// but for now generation of all other code/stubs occurs in other code paths
335
335
_ASSERTE (IsIL () || IsNoMetadata ());
336
- PCODE pCode = PrepareILBasedCode (pConfig);
336
+ PCODE pCode = PrepareILBasedCode (pConfig, pModule );
337
337
338
338
#if defined(FEATURE_GDBJIT) && defined(TARGET_UNIX) && !defined(CROSSGEN_COMPILE)
339
339
NotifyGdb::MethodPrepared (this );
@@ -356,7 +356,7 @@ bool MayUsePrecompiledILStub()
356
356
return true ;
357
357
}
358
358
359
- PCODE MethodDesc::PrepareILBasedCode (PrepareCodeConfig* pConfig)
359
+ PCODE MethodDesc::PrepareILBasedCode (PrepareCodeConfig* pConfig, Module* pModule )
360
360
{
361
361
STANDARD_VM_CONTRACT;
362
362
PCODE pCode = NULL ;
@@ -406,7 +406,7 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
406
406
MethodDesc* pTargetMD = stubMethodDesc->GetILStubResolver ()->GetStubTargetMethodDesc ();
407
407
if (pTargetMD != NULL )
408
408
{
409
- pCode = pTargetMD->GetPrecompiledR2RCode (pConfig);
409
+ pCode = pTargetMD->GetPrecompiledR2RCode (pConfig, pModule );
410
410
if (pCode != NULL )
411
411
{
412
412
LOG_USING_R2R_CODE (this );
@@ -421,7 +421,7 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
421
421
422
422
if (pCode == NULL )
423
423
{
424
- pCode = GetPrecompiledCode (pConfig, shouldTier);
424
+ pCode = GetPrecompiledCode (pConfig, shouldTier, pModule );
425
425
}
426
426
427
427
#ifdef FEATURE_PERFMAP
@@ -447,7 +447,7 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig)
447
447
return pCode;
448
448
}
449
449
450
- PCODE MethodDesc::GetPrecompiledCode (PrepareCodeConfig* pConfig, bool shouldTier)
450
+ PCODE MethodDesc::GetPrecompiledCode (PrepareCodeConfig* pConfig, bool shouldTier, Module* pModule )
451
451
{
452
452
STANDARD_VM_CONTRACT;
453
453
PCODE pCode = NULL ;
@@ -465,7 +465,7 @@ PCODE MethodDesc::GetPrecompiledCode(PrepareCodeConfig* pConfig, bool shouldTier
465
465
#ifdef FEATURE_READYTORUN
466
466
else
467
467
{
468
- pCode = GetPrecompiledR2RCode (pConfig);
468
+ pCode = GetPrecompiledR2RCode (pConfig, pModule );
469
469
if (pCode != NULL )
470
470
{
471
471
LOG_USING_R2R_CODE (this );
@@ -578,7 +578,7 @@ PCODE MethodDesc::GetPrecompiledNgenCode(PrepareCodeConfig* pConfig)
578
578
}
579
579
580
580
581
- PCODE MethodDesc::GetPrecompiledR2RCode (PrepareCodeConfig* pConfig)
581
+ PCODE MethodDesc::GetPrecompiledR2RCode (PrepareCodeConfig* pConfig, Module* pModule_probe )
582
582
{
583
583
STANDARD_VM_CONTRACT;
584
584
@@ -600,6 +600,20 @@ PCODE MethodDesc::GetPrecompiledR2RCode(PrepareCodeConfig* pConfig)
600
600
{
601
601
pCode = pModule->GetReadyToRunInfo ()->GetEntryPoint (this , pConfig, TRUE /* fFixups */ );
602
602
}
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
+ }
603
617
}
604
618
#endif
605
619
return pCode;
@@ -1852,7 +1866,8 @@ extern "C" MethodDesc * STDCALL PreStubGetMethodDescForCompactEntryPoint (PCODE
1852
1866
static PCODE PreStubWorker_Preemptive (
1853
1867
_In_ TransitionBlock* pTransitionBlock,
1854
1868
_In_ MethodDesc* pMD,
1855
- _In_opt_ Thread* currentThread)
1869
+ _In_opt_ Thread* currentThread,
1870
+ Module* pModule = NULL )
1856
1871
{
1857
1872
_ASSERTE (pMD->HasUnmanagedCallersOnlyAttribute ());
1858
1873
@@ -1885,7 +1900,7 @@ static PCODE PreStubWorker_Preemptive(
1885
1900
pMD->CheckRestore ();
1886
1901
CONSISTENCY_CHECK (GetAppDomain ()->CheckCanExecuteManagedCode (pMD));
1887
1902
1888
- pbRetVal = pMD->DoPrestub (NULL , CallerGCMode::Preemptive);
1903
+ pbRetVal = pMD->DoPrestub (NULL , CallerGCMode::Preemptive, pModule );
1889
1904
1890
1905
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER;
1891
1906
UNINSTALL_MANAGED_EXCEPTION_DISPATCHER;
@@ -1910,6 +1925,11 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method
1910
1925
{
1911
1926
PCODE pbRetVal = NULL ;
1912
1927
1928
+ Module* pModule = NULL ;
1929
+ FrameWithCookie<ExternalMethodFrame> frame (pTransitionBlock);
1930
+ ExternalMethodFrame * pEMFrame = &frame;
1931
+ pModule = ExecutionManager::FindReadyToRunModule ((TADDR)(((BYTE*)pEMFrame->GetReturnAddress ())-1 ));
1932
+
1913
1933
BEGIN_PRESERVE_LAST_ERROR;
1914
1934
1915
1935
STATIC_CONTRACT_THROWS;
@@ -1927,7 +1947,7 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method
1927
1947
if (CURRENT_THREAD == NULL
1928
1948
|| !CURRENT_THREAD->PreemptiveGCDisabled ())
1929
1949
{
1930
- pbRetVal = PreStubWorker_Preemptive (pTransitionBlock, pMD, CURRENT_THREAD);
1950
+ pbRetVal = PreStubWorker_Preemptive (pTransitionBlock, pMD, CURRENT_THREAD, pModule );
1931
1951
}
1932
1952
else
1933
1953
{
@@ -1995,7 +2015,7 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method
1995
2015
auto jitWriteEnableHolder = PAL_JITWriteEnable (true );
1996
2016
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
1997
2017
1998
- pbRetVal = pMD->DoPrestub (pDispatchingMT, CallerGCMode::Coop);
2018
+ pbRetVal = pMD->DoPrestub (pDispatchingMT, CallerGCMode::Coop, pModule );
1999
2019
}
2000
2020
2001
2021
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER;
@@ -2064,7 +2084,7 @@ static void TestSEHGuardPageRestore()
2064
2084
// the case of methods that require stubs to be executed first (e.g., remoted methods
2065
2085
// that require remoting stubs to be executed first), this stable entrypoint would be a
2066
2086
// 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 )
2068
2088
{
2069
2089
CONTRACT (PCODE)
2070
2090
{
@@ -2169,7 +2189,7 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMo
2169
2189
{
2170
2190
bool doBackpatch = true ;
2171
2191
bool doFullBackpatch = false ;
2172
- pCode = GetCodeVersionManager ()->PublishVersionableCodeIfNecessary (this , callerGCMode, &doBackpatch, &doFullBackpatch);
2192
+ pCode = GetCodeVersionManager ()->PublishVersionableCodeIfNecessary (this , callerGCMode, &doBackpatch, &doFullBackpatch, pModule );
2173
2193
2174
2194
if (doBackpatch)
2175
2195
{
0 commit comments