forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathilstubcache.cpp
658 lines (564 loc) · 21 KB
/
ilstubcache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// File: ILStubCache.cpp
//
//
#include "common.h"
#include "ilstubcache.h"
#include "dllimport.h"
#include <formattype.h>
#include "jitinterface.h"
#include "sigbuilder.h"
#include "eventtrace.h"
const char* FormatSig(MethodDesc* pMD, LoaderHeap *pHeap, AllocMemTracker *pamTracker);
ILStubCache::ILStubCache(LoaderAllocator *pAllocator)
: m_crst(CrstStubCache, CRST_UNSAFE_ANYMODE)
, m_pAllocator(pAllocator)
, m_pStubMT(NULL)
{
WRAPPER_NO_CONTRACT;
}
void ILStubCache::Init(LoaderAllocator* pAllocator)
{
LIMITED_METHOD_CONTRACT;
CONSISTENCY_CHECK(NULL == m_pAllocator);
m_pAllocator = pAllocator;
}
#ifndef DACCESS_COMPILE
void CreateModuleIndependentSignature(LoaderHeap* pCreationHeap,
AllocMemTracker* pamTracker,
Module* pSigModule,
PCCOR_SIGNATURE pSig, DWORD cbSig,
SigTypeContext *pTypeContext,
PCCOR_SIGNATURE* ppNewSig, DWORD* pcbNewSig)
{
CONTRACTL
{
STANDARD_VM_CHECK;
PRECONDITION(CheckPointer(pSigModule, NULL_NOT_OK));
PRECONDITION(CheckPointer(ppNewSig, NULL_NOT_OK));
PRECONDITION(CheckPointer(pcbNewSig, NULL_NOT_OK));
}
CONTRACTL_END;
SigPointer sigPtr(pSig, cbSig);
SigBuilder sigBuilder;
sigPtr.ConvertToInternalSignature(pSigModule, pTypeContext, &sigBuilder, /* bSkipCustomModifier */ FALSE);
DWORD cbNewSig;
PVOID pConvertedSig = sigBuilder.GetSignature(&cbNewSig);
PVOID pNewSig = pamTracker->Track(pCreationHeap->AllocMem(S_SIZE_T(cbNewSig)));
memcpy(pNewSig, pConvertedSig, cbNewSig);
*ppNewSig = (PCCOR_SIGNATURE)pNewSig;
*pcbNewSig = cbNewSig;
}
// static
MethodDesc* ILStubCache::CreateAndLinkNewILStubMethodDesc(LoaderAllocator* pAllocator, MethodTable* pMT, DWORD dwStubFlags,
Module* pSigModule, PCCOR_SIGNATURE pSig, DWORD cbSig, SigTypeContext *pTypeContext,
ILStubLinker* pStubLinker)
{
CONTRACT (MethodDesc*)
{
STANDARD_VM_CHECK;
PRECONDITION(CheckPointer(pMT, NULL_NOT_OK));
POSTCONDITION(CheckPointer(RETVAL));
}
CONTRACT_END;
AllocMemTracker amTracker;
MethodDesc *pStubMD = ILStubCache::CreateNewMethodDesc(pAllocator->GetHighFrequencyHeap(),
pMT,
dwStubFlags,
pSigModule,
pSig, cbSig,
pTypeContext,
&amTracker);
amTracker.SuppressRelease();
pStubLinker->SetStubMethodDesc(pStubMD);
ILStubResolver *pResolver = pStubMD->AsDynamicMethodDesc()->GetILStubResolver();
pResolver->SetStubMethodDesc(pStubMD);
{
UINT maxStack;
size_t cbCode = pStubLinker->Link(&maxStack);
DWORD cbSig = pStubLinker->GetLocalSigSize();
COR_ILMETHOD_DECODER * pILHeader = pResolver->AllocGeneratedIL(cbCode, cbSig, maxStack);
BYTE * pbBuffer = (BYTE *)pILHeader->Code;
BYTE * pbLocalSig = (BYTE *)pILHeader->LocalVarSig;
_ASSERTE(cbSig == pILHeader->cbLocalVarSig);
size_t numEH = pStubLinker->GetNumEHClauses();
if (numEH > 0)
{
pStubLinker->WriteEHClauses(pResolver->AllocEHSect(numEH));
}
pStubLinker->GenerateCode(pbBuffer, cbCode);
pStubLinker->GetLocalSig(pbLocalSig, cbSig);
pResolver->SetJitFlags(CORJIT_FLAGS(CORJIT_FLAGS::CORJIT_FLAG_IL_STUB));
}
pResolver->SetTokenLookupMap(pStubLinker->GetTokenLookupMap());
RETURN pStubMD;
}
namespace
{
LPCUTF8 GetStubMethodName(DynamicMethodDesc::ILStubType type)
{
CONTRACTL
{
MODE_ANY;
GC_NOTRIGGER;
NOTHROW;
}
CONTRACTL_END;
switch (type)
{
case DynamicMethodDesc::StubCLRToNativeInterop: return "IL_STUB_PInvoke";
case DynamicMethodDesc::StubCLRToCOMInterop: return "IL_STUB_CLRtoCOM";
case DynamicMethodDesc::StubNativeToCLRInterop: return "IL_STUB_ReversePInvoke";
case DynamicMethodDesc::StubCOMToCLRInterop: return "IL_STUB_COMtoCLR";
case DynamicMethodDesc::StubStructMarshalInterop: return "IL_STUB_StructMarshal";
case DynamicMethodDesc::StubArrayOp: return "IL_STUB_Array";
case DynamicMethodDesc::StubMulticastDelegate: return "IL_STUB_MulticastDelegate_Invoke";
case DynamicMethodDesc::StubDelegateInvokeMethod: return "IL_STUB_Delegate_Invoke";
#ifdef FEATURE_INSTANTIATINGSTUB_AS_IL
case DynamicMethodDesc::StubUnboxingIL: return "IL_STUB_UnboxingStub";
case DynamicMethodDesc::StubInstantiating: return "IL_STUB_InstantiatingStub";
#endif
case DynamicMethodDesc::StubWrapperDelegate: return "IL_STUB_WrapperDelegate_Invoke";
case DynamicMethodDesc::StubTailCallStoreArgs: return "IL_STUB_StoreTailCallArgs";
case DynamicMethodDesc::StubTailCallCallTarget: return "IL_STUB_CallTailCallTarget";
case DynamicMethodDesc::StubVirtualStaticMethodDispatch: return "IL_STUB_VirtualStaticMethodDispatch";
case DynamicMethodDesc::StubDelegateShuffleThunk: return "IL_STUB_DelegateShuffleThunk";
default:
UNREACHABLE_MSG("Unknown stub type");
}
}
}
// static
MethodDesc* ILStubCache::CreateNewMethodDesc(LoaderHeap* pCreationHeap, MethodTable* pMT, DWORD dwStubFlags,
Module* pSigModule, PCCOR_SIGNATURE pSig, DWORD cbSig, SigTypeContext *pTypeContext,
AllocMemTracker* pamTracker)
{
CONTRACT (MethodDesc*)
{
STANDARD_VM_CHECK;
PRECONDITION(CheckPointer(pMT, NULL_NOT_OK));
POSTCONDITION(CheckPointer(RETVAL));
}
CONTRACT_END;
// @TODO: reuse the same chunk for multiple methods
MethodDescChunk* pChunk = MethodDescChunk::CreateChunk(pCreationHeap,
1,
mcDynamic,
TRUE /* fNonVtableSlot */,
TRUE /* fNativeCodeSlot */,
pMT,
pamTracker);
// Note: The method desc memory is zero initialized
DynamicMethodDesc* pMD = (DynamicMethodDesc*)pChunk->GetFirstMethodDesc();
pMD->SetMemberDef(0);
pMD->SetSlot(MethodTable::NO_SLOT); // we can't ever use the slot for dynamic methods
// the no metadata part of the method desc
pMD->m_pszMethodName = (PTR_CUTF8)"IL_STUB";
pMD->InitializeFlags(DynamicMethodDesc::FlagPublic | DynamicMethodDesc::FlagIsILStub);
pMD->SetTemporaryEntryPoint(pamTracker);
//
// convert signature to a compatible signature if needed
//
PCCOR_SIGNATURE pNewSig;
DWORD cbNewSig;
// If we are in the same module and don't have any generics, we can use the incoming signature.
// Note that pTypeContext may be non-empty and the signature can still have no E_T_(M)VAR in it.
// We could do a more precise check if we cared.
if (pMT->GetModule() == pSigModule && (pTypeContext == NULL || pTypeContext->IsEmpty()))
{
pNewSig = pSig;
cbNewSig = cbSig;
}
else
{
CreateModuleIndependentSignature(pCreationHeap, pamTracker, pSigModule, pSig, cbSig, pTypeContext, &pNewSig, &cbNewSig);
}
pMD->SetStoredMethodSig(pNewSig, cbNewSig);
SigPointer sigPtr(pNewSig, cbNewSig);
uint32_t callConvInfo;
IfFailThrow(sigPtr.GetCallingConvInfo(&callConvInfo));
if (!(callConvInfo & CORINFO_CALLCONV_HASTHIS))
{
pMD->SetFlags(DynamicMethodDesc::FlagStatic);
pMD->SetStatic();
}
pMD->m_pResolver = (ILStubResolver*)pamTracker->Track(pCreationHeap->AllocMem(S_SIZE_T(sizeof(ILStubResolver))));
#ifdef _DEBUG
// Poison the ILStubResolver storage
memset((void*)pMD->m_pResolver, 0xCC, sizeof(ILStubResolver));
#endif // _DEBUG
pMD->m_pResolver = new (pMD->m_pResolver) ILStubResolver();
if (SF_IsArrayOpStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubArrayOp);
}
else
if (SF_IsMulticastDelegateStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubMulticastDelegate);
}
else
if (SF_IsDelegateInvokeMethod(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubDelegateInvokeMethod);
}
else
if (SF_IsWrapperDelegateStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubWrapperDelegate);
}
else
#ifdef FEATURE_INSTANTIATINGSTUB_AS_IL
if (SF_IsUnboxingILStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubUnboxingIL);
}
else
if (SF_IsInstantiatingStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubInstantiating);
}
else
#endif
if (SF_IsTailCallStoreArgsStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubTailCallStoreArgs);
}
else
if (SF_IsTailCallCallTargetStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubTailCallCallTarget);
}
else
#ifdef FEATURE_COMINTEROP
if (SF_IsCOMStub(dwStubFlags))
{
// mark certain types of stub MDs with random flags so ILStubManager recognizes them
if (SF_IsReverseStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubCOMToCLRInterop);
}
else
{
pMD->SetILStubType(DynamicMethodDesc::StubCLRToCOMInterop);
}
}
else
#endif
if (SF_IsStructMarshalStub(dwStubFlags))
{
// Struct marshal stub MethodDescs might be directly called from `call` IL instructions
// so we want to keep their compile time data alive as long as the LoaderAllocator in case they're used again.
pMD->GetILStubResolver()->SetLoaderHeap(pCreationHeap);
pMD->SetILStubType(DynamicMethodDesc::StubStructMarshalInterop);
}
else
if (SF_IsVirtualStaticMethodDispatchStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubVirtualStaticMethodDispatch);
}
else
if (SF_IsDelegateShuffleThunk(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubDelegateShuffleThunk);
}
else
{
// mark certain types of stub MDs with random flags so ILStubManager recognizes them
if (SF_IsReverseStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubNativeToCLRInterop);
}
else
{
if (SF_IsDelegateStub(dwStubFlags))
{
pMD->SetFlags(DynamicMethodDesc::FlagIsDelegate);
}
else if (SF_IsCALLIStub(dwStubFlags))
{
pMD->SetFlags(DynamicMethodDesc::FlagIsCALLI);
}
pMD->SetILStubType(DynamicMethodDesc::StubCLRToNativeInterop);
}
}
// if we made it this far, we can set a more descriptive stub name
if (SF_IsArrayOpStub(dwStubFlags))
{
switch(dwStubFlags)
{
case ILSTUB_ARRAYOP_GET: pMD->m_pszMethodName = (PTR_CUTF8)"IL_STUB_Array_Get";
break;
case ILSTUB_ARRAYOP_SET: pMD->m_pszMethodName = (PTR_CUTF8)"IL_STUB_Array_Set";
break;
case ILSTUB_ARRAYOP_ADDRESS: pMD->m_pszMethodName = (PTR_CUTF8)"IL_STUB_Array_Address";
break;
default: _ASSERTE(!"Unknown array il stub");
}
}
else
{
pMD->m_pszMethodName = GetStubMethodName(pMD->GetILStubType());
}
#ifdef _DEBUG
pMD->m_pszDebugMethodName = pMD->m_pszMethodName;
pMD->m_pszDebugClassName = ILStubResolver::GetStubClassName(pMD); // must be called after type is set
pMD->m_pszDebugMethodSignature = FormatSig(pMD, pCreationHeap, pamTracker);
pMD->m_pDebugMethodTable = pMT;
#endif // _DEBUG
RETURN pMD;
}
//
// This will get or create a MethodTable in the Module/AppDomain on which
// we can place a new IL stub MethodDesc.
//
MethodTable* ILStubCache::GetOrCreateStubMethodTable(Module* pModule)
{
CONTRACT (MethodTable*)
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
INJECT_FAULT(COMPlusThrowOM());
POSTCONDITION(CheckPointer(RETVAL));
}
CONTRACT_END;
#ifdef _DEBUG
if (pModule->IsSystem())
{
// in the shared domain and compilation AD we are associated with the module
CONSISTENCY_CHECK(pModule->GetILStubCache() == this);
}
else
{
// otherwise we are associated with the LoaderAllocator
LoaderAllocator* pStubLoaderAllocator = LoaderAllocator::GetLoaderAllocator(this);
CONSISTENCY_CHECK(pStubLoaderAllocator == pModule->GetLoaderAllocator());
}
#endif // _DEBUG
if (NULL == m_pStubMT)
{
CrstHolder ch(&m_crst);
if (NULL == m_pStubMT)
{
AllocMemTracker amt;
MethodTable* pNewMT = CreateMinimalMethodTable(pModule, m_pAllocator, &amt);
amt.SuppressRelease();
VolatileStore<MethodTable*>(&m_pStubMT, pNewMT);
}
}
RETURN m_pStubMT;
}
MethodDesc* ILStubCache::LookupStubMethodDesc(ILStubHashBlob* pHashBlob)
{
CrstHolder ch(&m_crst);
// Try to find the stub
const ILStubCacheEntry* phe = m_hashMap.LookupPtr(pHashBlob);
if (phe)
{
return phe->m_pMethodDesc;
}
return NULL;
}
MethodDesc* ILStubCache::InsertStubMethodDesc(MethodDesc *pMD, ILStubHashBlob* pHashBlob)
{
size_t cbSizeOfBlob = pHashBlob->m_cbSizeOfBlob;
CrstHolder ch(&m_crst);
const ILStubCacheEntry* phe = m_hashMap.LookupPtr(pHashBlob);
if (phe == NULL)
{
AllocMemHolder<ILStubHashBlob> pBlobHolder( m_pAllocator->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(cbSizeOfBlob)) );
ILStubHashBlob* pBlob = pBlobHolder;
_ASSERTE(pHashBlob->m_cbSizeOfBlob == cbSizeOfBlob);
memcpy(pBlob, pHashBlob, cbSizeOfBlob);
m_hashMap.Add(ILStubCacheEntry{ pMD, pBlob });
pBlobHolder.SuppressRelease();
return pMD;
}
else
{
return phe->m_pMethodDesc;
}
}
#endif // DACCESS_COMPILE
//
// NGEN'ed IL stubs
//
// - We will never NGEN a CALLI pinvoke or vararg pinvoke
//
// - We will always place the IL stub MethodDesc on the same MethodTable that the
// PInvoke or COM Interop call declaration lives on.
//
// - We will not pre-populate our runtime ILStubCache with compile-time
// information (i.e. NGENed stubs are only reachable from the same NGEN image.)
//
// JIT'ed IL stubs
//
// - The ILStubCache is per-LoaderAllocator
//
// - Each LoaderAllocator's ILStubCache will lazily create a "minimal MethodTable" to
// serve as the home for IL stub MethodDescs
//
// - The created MethodTables will use the Module belonging to one of the
// following, based on what type of interop stub we need to create first.
//
// - If that stub is for a static-sig-based pinvoke, we will use the
// Module belonging to that pinvoke's MethodDesc.
//
// - If that stub is for a CALLI or vararg pinvoke, we will use the
// Module belonging to the VASigCookie that the caller supplied to us.
//
// It's important to point out that the Module we latch onto here has no knowledge
// of the MethodTable that we've just "added" to it. There only exists a "back
// pointer" to the Module from the MethodTable itself.
//
// We're relying on the fact that a VASigCookie may only mention types within the
// corresponding module used to qualify the signature and the fact that interop
// stubs may only reference CoreLib code or code related to a type mentioned in
// the signature. Both of these are true unless the sig is allowed to contain
// ELEMENT_TYPE_INTERNAL, which may refer to any type.
//
// We can only access E_T_INTERNAL through LCG, which does not permit referring
// to types in other AppDomains.
//
MethodDesc* ILStubCache::GetStubMethodDesc(
MethodDesc* pTargetMD,
ILStubHashBlob* pHashBlob,
DWORD dwStubFlags,
Module* pSigModule,
Module* pSigLoaderModule,
PCCOR_SIGNATURE pSig,
DWORD cbSig,
SigTypeContext* pTypeContext,
AllocMemTracker* pamTracker,
bool& bILStubCreator,
MethodDesc *pLastMD)
{
CONTRACT (MethodDesc*)
{
STANDARD_VM_CHECK;
POSTCONDITION(CheckPointer(RETVAL));
}
CONTRACT_END;
MethodDesc* pMD = NULL;
#ifndef DACCESS_COMPILE
ILStubHashBlob* pBlob = NULL;
INDEBUG(LPCSTR pszResult = "[hit cache]");
if (SF_IsSharedStub(dwStubFlags))
{
CrstHolder ch(&m_crst);
// Try to find the stub
const ILStubCacheEntry* phe = m_hashMap.LookupPtr(pHashBlob);
if (phe)
{
pMD = phe->m_pMethodDesc;
}
}
if (!pMD)
{
//
// Couldn't find it, let's make a new one.
//
if (pSigLoaderModule == NULL)
{
pSigLoaderModule = (pTargetMD != NULL) ? pTargetMD->GetLoaderModule() : pSigModule;
}
SigTypeContext typeContext;
if (pTypeContext == NULL)
{
if (pTargetMD != NULL)
{
SigTypeContext::InitTypeContext(pTargetMD, &typeContext);
}
pTypeContext = &typeContext;
}
MethodTable *pStubMT = GetOrCreateStubMethodTable(pSigLoaderModule);
pMD = ILStubCache::CreateNewMethodDesc(m_pAllocator->GetHighFrequencyHeap(), pStubMT, dwStubFlags, pSigModule, pSig, cbSig, pTypeContext, pamTracker);
if (SF_IsSharedStub(dwStubFlags))
{
size_t cbSizeOfBlob = pHashBlob->m_cbSizeOfBlob;
CrstHolder ch(&m_crst);
const ILStubCacheEntry* phe = m_hashMap.LookupPtr(pHashBlob);
if (phe == NULL)
{
AllocMemHolder<ILStubHashBlob> pBlobHolder( m_pAllocator->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(cbSizeOfBlob)) );
pBlob = pBlobHolder;
_ASSERTE(pHashBlob->m_cbSizeOfBlob == cbSizeOfBlob);
memcpy(pBlob, pHashBlob, cbSizeOfBlob);
m_hashMap.Add(ILStubCacheEntry{ pMD, pBlob });
pBlobHolder.SuppressRelease();
INDEBUG(pszResult = "[missed cache]");
bILStubCreator = true;
}
else
{
INDEBUG(pszResult = "[hit cache][wasted new MethodDesc due to race]");
pMD = phe->m_pMethodDesc;
}
}
else
{
INDEBUG(pszResult = "[cache disabled for COM->CLR field access stubs]");
}
}
#ifdef _DEBUG
CQuickBytes qbManaged;
PrettyPrintSig(pSig, cbSig, "*", &qbManaged, pSigModule->GetMDImport(), NULL);
LOG((LF_STUBS, LL_INFO1000, "ILSTUBCACHE: ILStubCache::GetStubMethodDesc %s StubMD: %p module: %p blob: %p sig: %s\n", pszResult, pMD, pSigModule, pBlob, qbManaged.Ptr()));
#endif // _DEBUG
#endif // DACCESS_COMPILE
RETURN pMD;
}
void ILStubCache::DeleteEntry(ILStubHashBlob* pHashBlob)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
CrstHolder ch(&m_crst);
const ILStubCacheEntry *phe = m_hashMap.LookupPtr(pHashBlob);
if (phe != NULL)
{
#ifdef _DEBUG
LOG((LF_STUBS, LL_INFO1000, "ILSTUBCACHE: ILStubCache::DeleteEntry StubMD: %p\n", phe->m_pMethodDesc));
#endif
m_hashMap.Remove(pHashBlob);
}
}
void ILStubCache::AddMethodDescChunkWithLockTaken(MethodDesc *pMD)
{
CONTRACTL
{
STANDARD_VM_CHECK;
PRECONDITION(CheckPointer(pMD));
}
CONTRACTL_END;
#ifndef DACCESS_COMPILE
CrstHolder ch(&m_crst);
pMD->GetMethodTable()->GetClass()->AddChunkIfItHasNotBeenAdded(pMD->GetMethodDescChunk());
#endif // DACCESS_COMPILE
}
ILStubCache::ILStubCacheTraits::count_t ILStubCache::ILStubCacheTraits::Hash(_In_ key_t key)
{
LIMITED_METHOD_CONTRACT;
size_t cb = key->m_cbSizeOfBlob - sizeof(ILStubHashBlobBase);
int hash = 0;
for (size_t i = 0; i < cb; i++)
{
hash = _rotl(hash, 1) + key->m_rgbBlobData[i];
}
return hash;
}
bool ILStubCache::ILStubCacheTraits::Equals(_In_ key_t lhs, _In_ key_t rhs)
{
LIMITED_METHOD_CONTRACT;
if (lhs->m_cbSizeOfBlob != rhs->m_cbSizeOfBlob)
return false;
size_t blobDataSize = lhs->m_cbSizeOfBlob - sizeof(ILStubHashBlobBase);
return memcmp(lhs->m_rgbBlobData, rhs->m_rgbBlobData, blobDataSize) == 0;
}