-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathmethod.hpp
3659 lines (3017 loc) · 121 KB
/
method.hpp
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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// method.hpp
//
//
// See the book of the runtime entry for overall design:
// file:../../doc/BookOfTheRuntime/ClassLoader/MethodDescDesign.doc
//
#ifndef _METHOD_H
#define _METHOD_H
#include "cor.h"
#include "util.hpp"
#include "clsload.hpp"
#include "class.h"
#include "siginfo.hpp"
#include "methodimpl.h"
#include "typedesc.h"
#include <stddef.h>
#include "eeconfig.h"
#include "precode.h"
class Stub;
class FCallMethodDesc;
class FieldDesc;
class NDirect;
class MethodDescChunk;
struct LayoutRawFieldInfo;
class InstantiatedMethodDesc;
class DictionaryLayout;
class Dictionary;
class GCCoverageInfo;
class DynamicMethodDesc;
class ReJitManager;
class PrepareCodeConfig;
typedef DPTR(FCallMethodDesc) PTR_FCallMethodDesc;
typedef DPTR(ArrayMethodDesc) PTR_ArrayMethodDesc;
typedef DPTR(DynamicMethodDesc) PTR_DynamicMethodDesc;
typedef DPTR(InstantiatedMethodDesc) PTR_InstantiatedMethodDesc;
typedef DPTR(GCCoverageInfo) PTR_GCCoverageInfo; // see code:GCCoverageInfo::savedCode
#ifdef FEATURE_MINIMETADATA_IN_TRIAGEDUMPS
GVAL_DECL(DWORD, g_MiniMetaDataBuffMaxSize);
GVAL_DECL(TADDR, g_MiniMetaDataBuffAddress);
#endif // FEATURE_MINIMETADATA_IN_TRIAGEDUMPS
EXTERN_C VOID STDCALL NDirectImportThunk();
#define METHOD_TOKEN_REMAINDER_BIT_COUNT 12
#define METHOD_TOKEN_REMAINDER_MASK ((1 << METHOD_TOKEN_REMAINDER_BIT_COUNT) - 1)
#define METHOD_TOKEN_RANGE_BIT_COUNT (24 - METHOD_TOKEN_REMAINDER_BIT_COUNT)
#define METHOD_TOKEN_RANGE_MASK ((1 << METHOD_TOKEN_RANGE_BIT_COUNT) - 1)
//=============================================================
// Splits methoddef token into two pieces for
// storage inside a methoddesc.
//=============================================================
FORCEINLINE UINT16 GetTokenRange(mdToken tok)
{
LIMITED_METHOD_CONTRACT;
return (UINT16)((tok>>METHOD_TOKEN_REMAINDER_BIT_COUNT) & METHOD_TOKEN_RANGE_MASK);
}
FORCEINLINE VOID SplitToken(mdToken tok, UINT16 *ptokrange, UINT16 *ptokremainder)
{
LIMITED_METHOD_CONTRACT;
*ptokrange = (UINT16)((tok>>METHOD_TOKEN_REMAINDER_BIT_COUNT) & METHOD_TOKEN_RANGE_MASK);
*ptokremainder = (UINT16)(tok & METHOD_TOKEN_REMAINDER_MASK);
}
FORCEINLINE mdToken MergeToken(UINT16 tokrange, UINT16 tokremainder)
{
LIMITED_METHOD_DAC_CONTRACT;
return (tokrange << METHOD_TOKEN_REMAINDER_BIT_COUNT) | tokremainder | mdtMethodDef;
}
// The MethodDesc is a union of several types. The following
// 3-bit field determines which type it is. Note that JIT'ed/non-JIT'ed
// is not represented here because this isn't known until the
// method is executed for the first time. Because any thread could
// change this bit, it has to be done in a place where access is
// synchronized.
// **** NOTE: if you add any new flags, make sure you add them to ClearFlagsOnUpdate
// so that when a method is replaced its relevant flags are updated
// Used in MethodDesc
enum MethodClassification
{
mcIL = 0, // IL
mcFCall = 1, // FCall (also includes tlbimped ctor, Delegate ctor)
mcPInvoke = 2, // PInvoke method also known as N/Direct in this codebase
mcEEImpl = 3, // special method; implementation provided by EE (like Delegate Invoke)
mcArray = 4, // Array ECall
mcInstantiated = 5, // Instantiated generic methods, including descriptors
// for both shared and unshared code (see InstantiatedMethodDesc)
#ifdef FEATURE_COMINTEROP
mcComInterop = 6,
#endif // FEATURE_COMINTEROP
mcDynamic = 7, // for method desc with no metadata behind
mcCount,
};
// All flags in the MethodDesc now reside in a single 16-bit field.
enum MethodDescFlags
{
// Method is IL, FCall etc., see MethodClassification above.
mdfClassification = 0x0007,
mdfClassificationCount = mdfClassification+1,
// Note that layout of code:MethodDesc::s_ClassificationSizeTable depends on the exact values
// of mdfHasNonVtableSlot and mdfMethodImpl
// Has local slot (vs. has real slot in MethodTable)
mdfHasNonVtableSlot = 0x0008,
// Method is a body for a method impl (MI_MethodDesc, MI_NDirectMethodDesc, etc)
// where the function explicitly implements IInterface.foo() instead of foo().
mdfMethodImpl = 0x0010,
// Has slot for native code
mdfHasNativeCodeSlot = 0x0020,
// Method was added via Edit And Continue
mdfEnCAddedMethod = 0x0040,
// Method is static
mdfStatic = 0x0080,
mdfValueTypeParametersWalked = 0x0100, // Indicates that all typeref's in the signature of the method have been resolved
// to typedefs (or that process failed).
mdfValueTypeParametersLoaded = 0x0200, // Indicates if the valuetype parameter types have been loaded.
// Duplicate method. When a method needs to be placed in multiple slots in the
// method table, because it could not be packed into one slot. For eg, a method
// providing implementation for two interfaces, MethodImpl, etc
mdfDuplicate = 0x0400,
mdfDoesNotHaveEquivalentValuetypeParameters = 0x0800, // Indicates that we have verified that there are no equivalent valuetype parameters
// for this method.
mdfRequiresCovariantReturnTypeChecking = 0x1000,
// Is this method ineligible for inlining?
mdfNotInline = 0x2000,
// Is the method synchronized
mdfSynchronized = 0x4000,
mdfIsIntrinsic = 0x8000 // Jit may expand method as an intrinsic
};
// Used for storing additional items related to native code
struct MethodDescCodeData final
{
PTR_MethodDescVersioningState VersioningState;
PCODE TemporaryEntryPoint;
};
using PTR_MethodDescCodeData = DPTR(MethodDescCodeData);
// The size of this structure needs to be a multiple of MethodDesc::ALIGNMENT
//
// @GENERICS:
// Method descriptors for methods belonging to instantiated types may be shared between compatible instantiations
// Hence for reflection and elsewhere where exact types are important it's necessary to pair a method desc
// with the exact owning type handle.
//
// See genmeth.cpp for details of instantiated generic method descriptors.
//
// A MethodDesc is the representation of a method of a type. These live in code:MethodDescChunk which in
// turn lives in code:EEClass. They are conceptually cold (we do not expect to access them in normal
// program execution, but we often fall short of that goal.
//
// A Method desc knows how to get at its metadata token code:GetMemberDef, its chunk
// code:MethodDescChunk, which in turns knows how to get at its type code:MethodTable.
// It also knows how to get at its IL code (code:IMAGE_COR_ILMETHOD)
class MethodDesc
{
public:
#ifdef TARGET_64BIT
static const int ALIGNMENT_SHIFT = 3;
#else
static const int ALIGNMENT_SHIFT = 2;
#endif
static const size_t ALIGNMENT = (1 << ALIGNMENT_SHIFT);
static const size_t ALIGNMENT_MASK = (ALIGNMENT - 1);
inline BOOL HasStableEntryPoint()
{
LIMITED_METHOD_DAC_CONTRACT;
return (m_wFlags3AndTokenRemainder & enum_flag3_HasStableEntryPoint) != 0;
}
inline PCODE GetStableEntryPoint()
{
LIMITED_METHOD_DAC_CONTRACT;
_ASSERTE(HasStableEntryPoint());
_ASSERTE(!IsVersionableWithVtableSlotBackpatch());
return GetMethodEntryPointIfExists();
}
void SetMethodEntryPoint(PCODE addr);
BOOL SetStableEntryPointInterlocked(PCODE addr);
#ifndef DACCESS_COMPILE
PCODE GetTemporaryEntryPoint();
#endif
PCODE GetTemporaryEntryPointIfExists()
{
LIMITED_METHOD_CONTRACT;
BYTE flags4 = VolatileLoad(&m_bFlags4);
if (flags4 & enum_flag4_TemporaryEntryPointAssigned)
{
PTR_MethodDescCodeData codeData = VolatileLoadWithoutBarrier(&m_codeData);
_ASSERTE(codeData != NULL);
PCODE temporaryEntryPoint = codeData->TemporaryEntryPoint;
_ASSERTE(temporaryEntryPoint != (PCODE)NULL);
return temporaryEntryPoint;
}
else
{
return (PCODE)NULL;
}
}
void SetTemporaryEntryPoint(AllocMemTracker *pamTracker);
#ifndef DACCESS_COMPILE
PCODE GetInitialEntryPointForCopiedSlot(MethodTable *pMTBeingCreated, AllocMemTracker* pamTracker)
{
CONTRACTL
{
THROWS;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
if (pMTBeingCreated != GetMethodTable())
{
pamTracker = NULL;
}
// If EnsureTemporaryEntryPointCore is called, then
// both GetTemporaryEntryPointIfExists and GetSlot()
// are guaranteed to return a NON-NULL PCODE.
EnsureTemporaryEntryPointCore(pamTracker);
PCODE result;
if (IsVersionableWithVtableSlotBackpatch())
{
result = GetTemporaryEntryPointIfExists();
}
else
{
_ASSERTE(GetMethodTable()->IsCanonicalMethodTable());
result = GetMethodTable()->GetSlot(GetSlot());
}
_ASSERTE(result != (PCODE)NULL);
return result;
}
#endif
inline BOOL HasPrecode()
{
LIMITED_METHOD_DAC_CONTRACT;
return (m_wFlags3AndTokenRemainder & enum_flag3_HasPrecode) != 0;
}
inline Precode* GetPrecode()
{
LIMITED_METHOD_DAC_CONTRACT;
PRECONDITION(HasPrecode());
Precode* pPrecode = Precode::GetPrecodeFromEntryPoint(GetStableEntryPoint());
PREFIX_ASSUME(pPrecode != NULL);
return pPrecode;
}
inline bool MayHavePrecode()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END
// Ideally, methods that will not have native code (!MayHaveNativeCode() == true) should not be versionable. Currently,
// that is not the case, in some situations it was seen that 1/4 to 1/3 of versionable methods do not have native
// code, though there is no significant overhead from this. MayHaveNativeCode() appears to be an expensive check to do
// for each MethodDesc, even if it's done only once, and when it was attempted, at the time it was showing up noticeably
// in startup performance profiles.
//
// In particular, methods versionable with vtable slot backpatch should not have a precode (in the sense HasPrecode()
// must return false) even if they will not have native code.
bool result = IsVersionable() ? IsVersionableWithPrecode() : !MayHaveNativeCode();
_ASSERTE(!result || !IsVersionableWithVtableSlotBackpatch());
return result;
}
Precode* GetOrCreatePrecode();
void MarkPrecodeAsStableEntrypoint();
// Given a code address return back the MethodDesc whenever possible
//
static MethodDesc * GetMethodDescFromStubAddr(PCODE addr, BOOL fSpeculative = FALSE);
DWORD GetAttrs() const;
DWORD GetImplAttrs();
// This function can lie if a method impl was used to implement
// more than one method on this class. Use GetName(int) to indicate
// which slot you are interested in.
// See the TypeString class for better control over name formatting.
LPCUTF8 GetName();
#ifndef DACCESS_COMPILE
LPCUTF8 GetName(USHORT slot);
#endif // DACCESS_COMPILE
LPCUTF8 GetNameThrowing();
FORCEINLINE LPCUTF8 GetNameOnNonArrayClass()
{
WRAPPER_NO_CONTRACT;
LPCSTR szName;
if (FAILED(GetMDImport()->GetNameOfMethodDef(GetMemberDef(), &szName)))
{
szName = NULL;
}
return szName;
}
COUNT_T GetStableHash();
// Non-zero for InstantiatedMethodDescs
DWORD GetNumGenericMethodArgs();
// Return the number of class type parameters that are in scope for this method
DWORD GetNumGenericClassArgs()
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
return GetMethodTable()->GetNumGenericArgs();
}
// True if this is a method descriptor for an instantiated generic method
// whose method type arguments are the formal type parameters of the generic method
// NOTE: the declaring class may not be the generic type definition e.g. consider C<int>.m<T>
BOOL IsGenericMethodDefinition() const;
// True if the declaring type or instantiation of method (if any) contains formal generic type parameters
BOOL ContainsGenericVariables();
// True if this is a class and method instantiation that on <__Canon,...,__Canon>
BOOL IsTypicalSharedInstantiation();
// True if and only if this is a method descriptor for:
// 1. a non-generic method or a generic method at its typical method instantiation
// 2. in a non-generic class or a typical instantiation of a generic class
// This method can be called on a non-restored method desc
BOOL IsTypicalMethodDefinition() const;
// Force a load of the (typical) constraints on the type parameters of a typical method definition,
// detecting cyclic bounds on class and method type parameters.
void LoadConstraintsForTypicalMethodDefinition(BOOL *pfHasCircularClassConstraints,
BOOL *pfHasCircularMethodConstraints,
ClassLoadLevel level = CLASS_LOADED);
DWORD IsClassConstructor()
{
WRAPPER_NO_CONTRACT;
return IsMdClassConstructor(GetAttrs(), GetName());
}
DWORD IsClassConstructorOrCtor()
{
WRAPPER_NO_CONTRACT;
DWORD dwAttrs = GetAttrs();
if (IsMdRTSpecialName(dwAttrs))
{
LPCUTF8 name = GetName();
return IsMdInstanceInitializer(dwAttrs, name) || IsMdClassConstructor(dwAttrs, name);
}
return FALSE;
}
inline void SetHasMethodImplSlot()
{
m_wFlags |= mdfMethodImpl;
}
inline BOOL HasMethodImplSlot()
{
LIMITED_METHOD_DAC_CONTRACT;
return (mdfMethodImpl & m_wFlags);
}
FORCEINLINE BOOL IsMethodImpl()
{
LIMITED_METHOD_DAC_CONTRACT;
// Once we stop allocating dummy MethodImplSlot in MethodTableBuilder::WriteMethodImplData,
// the check for NULL will become unnecessary.
return HasMethodImplSlot() && (GetMethodImpl()->GetSlots() != NULL);
}
inline DWORD IsStatic()
{
LIMITED_METHOD_DAC_CONTRACT;
// This bit caches the IsMdStatic(GetAttrs()) check. We used to assert it here, but not doing it anymore. GetAttrs()
// accesses metadata that is not compatible with contracts of this method. The metadata access can fail, the metadata
// are not available during shutdown, the metadata access can take locks. It is not worth it to code around all these
// just for the assert.
// _ASSERTE((((m_wFlags & mdfStatic) != 0) == (IsMdStatic(flags) != 0)));
return (m_wFlags & mdfStatic) != 0;
}
inline void SetStatic()
{
LIMITED_METHOD_CONTRACT;
m_wFlags |= mdfStatic;
}
inline void ClearStatic()
{
LIMITED_METHOD_CONTRACT;
m_wFlags &= ~mdfStatic;
}
inline BOOL IsIL()
{
LIMITED_METHOD_DAC_CONTRACT;
return mcIL == GetClassification() || mcInstantiated == GetClassification();
}
//================================================================
// Generics-related predicates etc.
// True if the method descriptor is an instantiation of a generic method.
inline BOOL HasMethodInstantiation() const;
// True if the method descriptor is either an instantiation of
// a generic method or is an instance method in an instantiated class (or both).
BOOL HasClassOrMethodInstantiation()
{
LIMITED_METHOD_DAC_CONTRACT;
return (HasClassInstantiation() || HasMethodInstantiation());
}
inline BOOL HasClassInstantiation() const
{
LIMITED_METHOD_DAC_CONTRACT;
return GetMethodTable()->HasInstantiation();
}
// Return the instantiation for an instantiated generic method
// Return NULL if not an instantiated method
// To get the (representative) instantiation of the declaring class use GetMethodTable()->GetInstantiation()
// NOTE: This will assert if you try to get the instantiation of a generic method def in a non-typical class
// e.g. C<int>.m<U> will fail but C<T>.m<U> will succeed
Instantiation GetMethodInstantiation() const;
// As above, but will succeed on C<int>.m<U>
// To do this it might force a load of the typical parent
Instantiation LoadMethodInstantiation();
// Return a pointer to the method dictionary for an instantiated generic method
// The initial slots in a method dictionary are the type arguments themselves
// Return NULL if not an instantiated method
Dictionary* GetMethodDictionary();
DictionaryLayout* GetDictionaryLayout();
InstantiatedMethodDesc* AsInstantiatedMethodDesc() const;
#ifdef FEATURE_CODE_VERSIONING
CodeVersionManager* GetCodeVersionManager();
#endif
MethodDescBackpatchInfoTracker* GetBackpatchInfoTracker();
PTR_LoaderAllocator GetLoaderAllocator();
Module* GetLoaderModule();
// Strip off method and class instantiation if present and replace by the typical instantiation
// e.g. C<int>.m<string> -> C<T>.m<U>. Does not modify the MethodDesc, but returns
// the appropriate stripped MethodDesc.
// This is the identity function on non-instantiated method descs in non-instantiated classes
MethodDesc* LoadTypicalMethodDefinition();
// Strip off the method instantiation (if present) and replace by the typical instantiation
// e.g. // C<int>.m<string> -> C<int>.m<U>. Does not modify the MethodDesc, but returns
// the appropriate stripped MethodDesc.
// This is the identity function on non-instantiated method descs
MethodDesc* StripMethodInstantiation();
// Return the instantiation of a method's enclosing class
// Return NULL if the enclosing class is not instantiated
// If the method code is shared then this might be a *representative* instantiation
//
// See GetExactClassInstantiation if you need to get the exact
// instantiation of a shared method desc.
Instantiation GetClassInstantiation() const;
// Is the code shared between multiple instantiations of class or method?
// If so, then when compiling the code we might need to look up tokens
// in the class or method dictionary. Also, when debugging the exact generic arguments
// need to be ripped off the stack, either from the this pointer or from one of the
// extra args below.
BOOL IsSharedByGenericInstantiations(); // shared code of any kind
BOOL IsSharedByGenericMethodInstantiations(); // shared due to method instantiation
// How does a method shared between generic instantiations get at
// the extra instantiation information at runtime? Only one of the following three
// will ever hold:
//
// AcquiresInstMethodTableFromThis()
// The method is in a generic class but is not itself a
// generic method (the normal case). Furthermore a "this" pointer
// is available and we can get the exact instantiation from it.
//
// RequiresInstMethodTableArg()
// The method is shared between generic classes but is not
// itself generic. Furthermore no "this" pointer is given
// (e.g. a value type method), so we pass in the exact-instantiation
// method table as an extra argument.
// i.e. per-inst static methods in shared-code instantiated generic
// classes (e.g. static void MyClass<string>::m())
// i.e. shared-code instance methods in instantiated generic
// structs (e.g. void MyValueType<string>::m())
//
// RequiresInstMethodDescArg()
// The method is itself generic and is shared between generic
// instantiations but is not itself generic. Furthermore
// no "this" pointer is given (e.g. a value type method), so we pass in the
// exact-instantiation method table as an extra argument.
// i.e. shared-code instantiated generic methods
//
// These are used for direct calls to instantiated generic methods
// e.g. call void C::m<string>() implemented by calculating dict(m<string>) at compile-time and passing it as an extra parameter
// call void C::m<!0>() implemented by calculating dict(m<!0>) at run-time (if the caller lives in shared-class code)
BOOL AcquiresInstMethodTableFromThis();
BOOL RequiresInstMethodTableArg();
BOOL RequiresInstMethodDescArg();
BOOL RequiresInstArg();
// Can this method handle be given out to reflection for use in a MethodInfo
// object?
BOOL IsRuntimeMethodHandle();
// Given a method table of an object and a method that comes from some
// superclass of the class of that object, find that superclass.
MethodTable * GetExactDeclaringType(MethodTable * ownerOrSubType);
// Given a type handle of an object and a method that comes from some
// superclass of the class of that object, find the instantiation of
// that superclass, i.e. the class instantiation which will be relevant
// to interpreting the signature of the method. The type handle of
// the object does not need to be given in all circumstances, in
// particular it is only needed for MethodDescs pMD that
// return true for pMD->RequiresInstMethodTableArg() or
// pMD->RequiresInstMethodDescArg(). In other cases it is
// allowed to be null.
//
// Will return NULL if the method is not in a generic class.
Instantiation GetExactClassInstantiation(TypeHandle possibleObjType);
BOOL SatisfiesMethodConstraints(TypeHandle thParent, BOOL fThrowIfNotSatisfied = FALSE);
BOOL HasSameMethodDefAs(MethodDesc * pMD);
//================================================================
// Classifications of kinds of MethodDescs.
inline BOOL IsRuntimeSupplied()
{
LIMITED_METHOD_DAC_CONTRACT;
return mcFCall == GetClassification()
|| mcArray == GetClassification();
}
inline DWORD IsArray() const
{
LIMITED_METHOD_DAC_CONTRACT;
return mcArray == GetClassification();
}
inline DWORD IsEEImpl() const
{
LIMITED_METHOD_DAC_CONTRACT;
return mcEEImpl == GetClassification();
}
inline DWORD IsNoMetadata() const
{
LIMITED_METHOD_DAC_CONTRACT;
return (mcDynamic == GetClassification());
}
inline PTR_DynamicMethodDesc AsDynamicMethodDesc();
inline bool IsDynamicMethod();
inline bool IsILStub();
inline bool IsLCGMethod();
inline DWORD IsNDirect()
{
LIMITED_METHOD_DAC_CONTRACT;
return mcPInvoke == GetClassification();
}
inline DWORD IsInterface()
{
WRAPPER_NO_CONTRACT;
return GetMethodTable()->IsInterface();
}
BOOL HasUnmanagedCallersOnlyAttribute();
BOOL ShouldSuppressGCTransition();
#ifdef FEATURE_COMINTEROP
inline DWORD IsCLRToCOMCall()
{
WRAPPER_NO_CONTRACT;
return mcComInterop == GetClassification();
}
#else // !FEATURE_COMINTEROP
// hardcoded to return FALSE to improve code readability
inline DWORD IsCLRToCOMCall()
{
LIMITED_METHOD_CONTRACT;
return FALSE;
}
#endif // !FEATURE_COMINTEROP
// Update flags in a thread safe manner.
#ifndef DACCESS_COMPILE
WORD InterlockedUpdateFlags(WORD wMask, BOOL fSet);
WORD InterlockedUpdateFlags3(WORD wMask, BOOL fSet);
BYTE InterlockedUpdateFlags4(BYTE bMask, BOOL fSet);
#endif
// If the method is in an Edit and Continue (EnC) module, then
// we DON'T want to backpatch this, ever. We MUST always call
// through the precode so that we can update the method.
inline DWORD InEnCEnabledModule()
{
WRAPPER_NO_CONTRACT;
Module *pModule = GetModule();
PREFIX_ASSUME(pModule != NULL);
return pModule->IsEditAndContinueEnabled();
}
inline BOOL IsNotInline()
{
LIMITED_METHOD_CONTRACT;
return (m_wFlags & mdfNotInline);
}
#ifndef DACCESS_COMPILE
inline void SetNotInline(BOOL set)
{
WRAPPER_NO_CONTRACT;
InterlockedUpdateFlags(mdfNotInline, set);
}
#endif // DACCESS_COMPILE
#ifndef DACCESS_COMPILE
VOID EnsureActive();
#endif
CHECK CheckActivated();
//================================================================
// FCalls.
BOOL IsFCall()
{
WRAPPER_NO_CONTRACT;
return mcFCall == GetClassification();
}
BOOL IsQCall();
//================================================================
//
#ifndef DACCESS_COMPILE
inline void ClearFlagsOnUpdate()
{
WRAPPER_NO_CONTRACT;
SetNotInline(FALSE);
}
#endif // DACCESS_COMPILE
// Restore the MethodDesc to it's initial, pristine state, so that
// it can be reused for new code (eg. for EnC, method rental, etc.)
//
// Things to think about before calling this:
//
// Does the caller need to free up the jitted code for the old IL
// (including any other IJitManager datastructures) ?
// Does the caller guarantee thread-safety ?
//
void Reset();
//================================================================
// About the signature.
BOOL IsVarArg();
BOOL IsVoid();
BOOL HasRetBuffArg();
// Returns the # of bytes of stack used by arguments. Does not include
// arguments passed in registers.
UINT SizeOfArgStack();
// Returns the # of bytes of stack used by arguments in a call from native to this function.
// Does not include arguments passed in registers.
UINT SizeOfNativeArgStack();
// Returns the # of bytes to pop after a call. Not necessary the
// same as SizeOfArgStack()!
UINT CbStackPop();
//================================================================
// Unboxing stubs.
//
// Return TRUE if this is this a special stub used to implement delegates to an
// instance method in a value class and/or virtual methods on a value class.
//
// For every BoxedEntryPointStub there is associated unboxed-this-MethodDesc
// which accepts an unboxed "this" pointer.
//
// The action of a typical BoxedEntryPointStub is to
// bump up the this pointer by one word so that it points to the interior of the object
// and then call the underlying unboxed-this-MethodDesc.
//
// Additionally, if the non-BoxedEntryPointStub is RequiresInstMethodTableArg()
// then pass on the MethodTable as an extra argument to the
// underlying unboxed-this-MethodDesc.
BOOL IsUnboxingStub()
{
LIMITED_METHOD_DAC_CONTRACT;
return (m_wFlags3AndTokenRemainder & enum_flag3_IsUnboxingStub) != 0;
}
void SetIsUnboxingStub()
{
LIMITED_METHOD_CONTRACT;
m_wFlags3AndTokenRemainder |= enum_flag3_IsUnboxingStub;
}
//================================================================
// Instantiating Stubs
//
// Return TRUE if this is this a special stub used to implement an
// instantiated generic method or per-instantiation static method.
// The action of an instantiating stub is
// * pass on a MethodTable or InstantiatedMethodDesc extra argument to shared code
BOOL IsInstantiatingStub();
// A wrapper stub is either an unboxing stub or an instantiating stub
BOOL IsWrapperStub();
MethodDesc *GetWrappedMethodDesc();
MethodDesc *GetExistingWrappedMethodDesc();
//==================================================================
// Access the underlying metadata
BOOL HasILHeader()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
return IsIL() && !IsUnboxingStub() && GetRVA();
}
COR_ILMETHOD* GetILHeader();
BOOL HasStoredSig()
{
LIMITED_METHOD_DAC_CONTRACT;
return IsEEImpl() || IsArray() || IsNoMetadata();
}
void GetSig(PCCOR_SIGNATURE *ppSig, DWORD *pcSig);
SigParser GetSigParser();
// Convenience methods for common signature wrapper types.
SigPointer GetSigPointer();
Signature GetSignature();
void GetSigFromMetadata(IMDInternalImport * importer,
PCCOR_SIGNATURE * ppSig,
DWORD * pcSig);
IMDInternalImport* GetMDImport() const
{
WRAPPER_NO_CONTRACT;
Module *pModule = GetModule();
PREFIX_ASSUME(pModule != NULL);
return pModule->GetMDImport();
}
HRESULT GetCustomAttribute(WellKnownAttribute attribute,
const void **ppData,
ULONG *pcbData) const
{
WRAPPER_NO_CONTRACT;
Module *pModule = GetModule();
PREFIX_ASSUME(pModule != NULL);
return pModule->GetCustomAttribute(GetMemberDef(), attribute, ppData, pcbData);
}
#ifndef DACCESS_COMPILE
IMetaDataEmit* GetEmitter()
{
WRAPPER_NO_CONTRACT;
Module *pModule = GetModule();
PREFIX_ASSUME(pModule != NULL);
return pModule->GetEmitter();
}
IMetaDataImport* GetRWImporter()
{
WRAPPER_NO_CONTRACT;
Module *pModule = GetModule();
PREFIX_ASSUME(pModule != NULL);
return pModule->GetRWImporter();
}
#endif // !DACCESS_COMPILE
#ifdef FEATURE_COMINTEROP
WORD GetComSlot();
LONG GetComDispid();
#endif // FEATURE_COMINTEROP
inline DWORD IsCtor()
{
WRAPPER_NO_CONTRACT;
return IsMdInstanceInitializer(GetAttrs(), GetName());
}
inline DWORD IsFinal()
{
WRAPPER_NO_CONTRACT;
return IsMdFinal(GetAttrs());
}
inline DWORD IsPrivate()
{
WRAPPER_NO_CONTRACT;
return IsMdPrivate(GetAttrs());
}
inline DWORD IsPublic() const
{
WRAPPER_NO_CONTRACT;
return IsMdPublic(GetAttrs());
}
inline DWORD IsProtected() const
{
WRAPPER_NO_CONTRACT;
return IsMdFamily(GetAttrs());
}
inline DWORD IsVirtual()
{
WRAPPER_NO_CONTRACT;
return IsMdVirtual(GetAttrs());
}
inline DWORD IsAbstract()
{
WRAPPER_NO_CONTRACT;
return IsMdAbstract(GetAttrs());
}
//==================================================================
// Flags..
inline void SetSynchronized()
{
LIMITED_METHOD_CONTRACT;
m_wFlags |= mdfSynchronized;
}
inline DWORD IsSynchronized()
{
LIMITED_METHOD_DAC_CONTRACT;
return (m_wFlags & mdfSynchronized) != 0;
}
//==================================================================
// The MethodDesc in relation to the VTable it is associated with.
// WARNING: Not all MethodDescs have slots, nor do they all have
// entries in MethodTables. Beware.
// Does the method has virtual slot? Note that methods implementing interfaces
// on value types do not have virtual slots, but they are marked as virtual in metadata.
inline BOOL IsVtableMethod()
{
LIMITED_METHOD_CONTRACT;
MethodTable *pMT = GetMethodTable();
return
!IsEnCAddedMethod()
// The slot numbers are currently meaningless for
// some unboxed-this-generic-method-instantiations
&& !(pMT->IsValueType() && !IsStatic() && !IsUnboxingStub())
&& GetSlot() < pMT->GetNumVirtuals();
}
// Is this a default interface method (virtual non-abstract instance method)
inline BOOL IsDefaultInterfaceMethod()
{
LIMITED_METHOD_CONTRACT;
#ifdef FEATURE_DEFAULT_INTERFACES
return (GetMethodTable()->IsInterface() && !IsStatic() && IsVirtual() && !IsAbstract());
#else
return false;
#endif // FEATURE_DEFAULT_INTERFACES
}
inline BOOL HasNonVtableSlot();
void SetHasNonVtableSlot()
{
LIMITED_METHOD_CONTRACT;
m_wFlags |= mdfHasNonVtableSlot;
}
// duplicate methods
inline BOOL IsDuplicate()
{
LIMITED_METHOD_CONTRACT;
return (m_wFlags & mdfDuplicate) == mdfDuplicate;
}
void SetDuplicate()
{
LIMITED_METHOD_CONTRACT;
// method table is not setup yet
//_ASSERTE(!GetClass()->IsInterface());
m_wFlags |= mdfDuplicate;
}
//==================================================================
//
inline EEClass* GetClass()
{
WRAPPER_NO_CONTRACT;
MethodTable *pMT = GetMethodTable();
EEClass *pClass = pMT->GetClass();
PREFIX_ASSUME(pClass != NULL);
return pClass;
}
inline PTR_MethodTable GetMethodTable() const;
public:
inline MethodDescChunk* GetMethodDescChunk() const;
inline int GetMethodDescChunkIndex() const;
// If this is an method desc. (whether non-generic shared-instantiated or exact-instantiated)
// inside a shared class then get the method table for the representative