@@ -1506,6 +1506,20 @@ DWORD MethodDesc::GetImplAttrs()
1506
1506
return props;
1507
1507
}
1508
1508
1509
+ PTR_Module MethodDescChunk::GetLoaderModule ()
1510
+ {
1511
+ LIMITED_METHOD_DAC_CONTRACT;
1512
+ if (IsLoaderModuleAttachedToChunk ())
1513
+ {
1514
+ TADDR ppLoaderModule = dac_cast<TADDR>(this ) + SizeOf () - sizeof (PTR_Module);
1515
+ return *dac_cast<DPTR (PTR_Module)>(ppLoaderModule);
1516
+ }
1517
+ else
1518
+ {
1519
+ return GetMethodTable ()->GetLoaderModule ();
1520
+ }
1521
+ }
1522
+
1509
1523
// *******************************************************************************
1510
1524
Module* MethodDesc::GetLoaderModule ()
1511
1525
{
@@ -1517,17 +1531,24 @@ Module* MethodDesc::GetLoaderModule()
1517
1531
}
1518
1532
CONTRACTL_END;
1519
1533
1534
+ Module* pLoaderModule = GetMethodDescChunk ()->GetLoaderModule ();
1535
+
1536
+ #ifdef _DEBUG
1537
+ // Verify that the LoaderModule stored in the MethodDescChunk matches the result achieved by computation
1520
1538
if (HasMethodInstantiation () && !IsGenericMethodDefinition ())
1521
1539
{
1522
- Module *retVal = ClassLoader::ComputeLoaderModule (GetMethodTable (),
1540
+ Module *computeLoaderModuleAlgorithmResult = ClassLoader::ComputeLoaderModule (GetMethodTable (),
1523
1541
GetMemberDef (),
1524
1542
GetMethodInstantiation ());
1525
- return retVal ;
1543
+ _ASSERTE (computeLoaderModuleAlgorithmResult == pLoaderModule) ;
1526
1544
}
1527
1545
else
1528
1546
{
1529
- return GetMethodTable ()->GetLoaderModule ();
1547
+ _ASSERTE (pLoaderModule == GetMethodTable ()->GetLoaderModule () );
1530
1548
}
1549
+ #endif // _DEBUG
1550
+
1551
+ return pLoaderModule;
1531
1552
}
1532
1553
1533
1554
// *******************************************************************************
@@ -1845,7 +1866,7 @@ MethodDesc* MethodDesc::StripMethodInstantiation()
1845
1866
1846
1867
// *******************************************************************************
1847
1868
MethodDescChunk *MethodDescChunk::CreateChunk (LoaderHeap *pHeap, DWORD methodDescCount,
1848
- DWORD classification, BOOL fNonVtableSlot , BOOL fNativeCodeSlot , MethodTable *pInitialMT, AllocMemTracker *pamTracker)
1869
+ DWORD classification, BOOL fNonVtableSlot , BOOL fNativeCodeSlot , MethodTable *pInitialMT, AllocMemTracker *pamTracker, Module *pLoaderModule )
1849
1870
{
1850
1871
CONTRACT (MethodDescChunk *)
1851
1872
{
@@ -1878,18 +1899,28 @@ MethodDescChunk *MethodDescChunk::CreateChunk(LoaderHeap *pHeap, DWORD methodDes
1878
1899
1879
1900
MethodDescChunk * pFirstChunk = NULL ;
1880
1901
1902
+ bool needsExplicitLoaderModule = false ;
1903
+ if (pLoaderModule != NULL && pLoaderModule != pInitialMT->GetLoaderModule ())
1904
+ {
1905
+ needsExplicitLoaderModule = true ;
1906
+ }
1907
+
1881
1908
do
1882
1909
{
1883
1910
DWORD count = min (methodDescCount, maxMethodDescsPerChunk);
1884
1911
1885
1912
void * pMem = pamTracker->Track (
1886
- pHeap->AllocMem (S_SIZE_T (sizeof (MethodDescChunk) + oneSize * count)));
1913
+ pHeap->AllocMem (S_SIZE_T (sizeof (MethodDescChunk) + oneSize * count + (needsExplicitLoaderModule ? sizeof (Module *) : 0 ) )));
1887
1914
1888
1915
// Skip pointer to temporary entrypoints
1889
1916
MethodDescChunk * pChunk = (MethodDescChunk *)((BYTE*)pMem);
1890
1917
1891
1918
pChunk->SetSizeAndCount (oneSize * count, count);
1892
1919
pChunk->SetMethodTable (pInitialMT);
1920
+ if (needsExplicitLoaderModule)
1921
+ {
1922
+ pChunk->SetLoaderModuleAttachedToChunk (pLoaderModule);
1923
+ }
1893
1924
1894
1925
MethodDesc * pMD = pChunk->GetFirstMethodDesc ();
1895
1926
for (DWORD i = 0 ; i < count; i++)
0 commit comments