1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*****************************************************************************\
6* *
7* CorCompile.h - EE / Compiler interface *
8* *
9* Version 1.0 *
10*******************************************************************************
11* *
12* *
13* *
14\*****************************************************************************/
15// See code:CorProfileData for information on Hot Cold splitting using profile data.
16
17
18#ifndef _COR_COMPILE_H_
19#define _COR_COMPILE_H_
20
21#ifndef FEATURE_PREJIT
22#error FEATURE_PREJIT is required for this file
23#endif // FEATURE_PREJIT
24
25#if !defined(_TARGET_X86_) || defined(FEATURE_PAL)
26#ifndef WIN64EXCEPTIONS
27#define WIN64EXCEPTIONS
28#endif
29#endif // !_TARGET_X86_ || FEATURE_PAL
30
31#include <cor.h>
32#include <corhdr.h>
33#include <corinfo.h>
34#include <corjit.h>
35#include <sstring.h>
36#include <shash.h>
37#include <daccess.h>
38#include <corbbtprof.h>
39#include <clrtypes.h>
40#include <fixuppointer.h>
41
42typedef DPTR(struct CORCOMPILE_CODE_MANAGER_ENTRY)
43 PTR_CORCOMPILE_CODE_MANAGER_ENTRY;
44typedef DPTR(struct CORCOMPILE_EE_INFO_TABLE)
45 PTR_CORCOMPILE_EE_INFO_TABLE;
46typedef DPTR(struct CORCOMPILE_HEADER)
47 PTR_CORCOMPILE_HEADER;
48typedef DPTR(struct CORCOMPILE_COLD_METHOD_ENTRY)
49 PTR_CORCOMPILE_COLD_METHOD_ENTRY;
50typedef DPTR(struct CORCOMPILE_EXCEPTION_LOOKUP_TABLE)
51 PTR_CORCOMPILE_EXCEPTION_LOOKUP_TABLE;
52typedef DPTR(struct CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY)
53 PTR_CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY;
54typedef DPTR(struct CORCOMPILE_EXCEPTION_CLAUSE)
55 PTR_CORCOMPILE_EXCEPTION_CLAUSE;
56typedef DPTR(struct CORCOMPILE_VIRTUAL_IMPORT_THUNK)
57 PTR_CORCOMPILE_VIRTUAL_IMPORT_THUNK;
58typedef DPTR(struct CORCOMPILE_EXTERNAL_METHOD_THUNK)
59 PTR_CORCOMPILE_EXTERNAL_METHOD_THUNK;
60typedef DPTR(struct CORCOMPILE_EXTERNAL_METHOD_DATA_ENTRY)
61 PTR_CORCOMPILE_EXTERNAL_METHOD_DATA_ENTRY;
62typedef DPTR(struct CORCOMPILE_VIRTUAL_SECTION_INFO)
63 PTR_CORCOMPILE_VIRTUAL_SECTION_INFO;
64typedef DPTR(struct CORCOMPILE_IMPORT_SECTION)
65 PTR_CORCOMPILE_IMPORT_SECTION;
66
67#ifdef _TARGET_X86_
68
69typedef DPTR(RUNTIME_FUNCTION) PTR_RUNTIME_FUNCTION;
70
71
72// Chained unwind info. Used for cold methods.
73#define RUNTIME_FUNCTION_INDIRECT 0x80000000
74
75#endif // _TARGET_X86_
76
77// The stride is choosen as maximum value that still gives good page locality of RUNTIME_FUNCTION table touches (only one page of
78// RUNTIME_FUNCTION table is going to be touched during most IP2MD lookups).
79//
80// Smaller stride values also improve speed of IP2MD lookups, but this improvement is not significant (5% when going
81// from 8192 to 1024), so the working set / page locality was used as the metric to choose the optimum value.
82//
83#define RUNTIME_FUNCTION_LOOKUP_STRIDE 8192
84
85
86typedef DPTR(struct CORCOMPILE_METHOD_PROFILE_LIST)
87 PTR_CORCOMPILE_METHOD_PROFILE_LIST;
88typedef DPTR(struct CORCOMPILE_RUNTIME_DLL_INFO)
89 PTR_CORCOMPILE_RUNTIME_DLL_INFO;
90typedef DPTR(struct CORCOMPILE_VERSION_INFO) PTR_CORCOMPILE_VERSION_INFO;
91typedef DPTR(struct COR_ILMETHOD) PTR_COR_ILMETHOD;
92
93// This can be used to specify a dll that should be used as the compiler during ngen.
94// If this is not specified, the default compiler dll will be used.
95// If this is specified, it needs to be specified for all the assemblies that are ngenned.
96#define NGEN_COMPILER_OVERRIDE_KEY W("NGen_JitName")
97
98//
99// CORCOMPILE_IMPORT_SECTION describes image range with references to other assemblies or runtime data structures
100//
101// There is number of different types of these ranges: eagerly initialized at image load vs. lazily initialized at method entry
102// vs. lazily initialized on first use; hot vs. cold, handles vs. code pointers, etc.
103//
104struct CORCOMPILE_IMPORT_SECTION
105{
106 IMAGE_DATA_DIRECTORY Section; // Section containing values to be fixed up
107 USHORT Flags; // One or more of CorCompileImportFlags
108 BYTE Type; // One of CorCompileImportType
109 BYTE EntrySize;
110 DWORD Signatures; // RVA of optional signature descriptors
111 DWORD AuxiliaryData; // RVA of optional auxiliary data (typically GC info)
112};
113
114enum CorCompileImportType
115{
116 CORCOMPILE_IMPORT_TYPE_UNKNOWN = 0,
117 CORCOMPILE_IMPORT_TYPE_EXTERNAL_METHOD = 1,
118 CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH = 2,
119 CORCOMPILE_IMPORT_TYPE_STRING_HANDLE = 3,
120 CORCOMPILE_IMPORT_TYPE_TYPE_HANDLE = 4,
121 CORCOMPILE_IMPORT_TYPE_METHOD_HANDLE = 5,
122 CORCOMPILE_IMPORT_TYPE_VIRTUAL_METHOD = 6,
123};
124
125enum CorCompileImportFlags
126{
127 CORCOMPILE_IMPORT_FLAGS_EAGER = 0x0001, // Section at module load time.
128 CORCOMPILE_IMPORT_FLAGS_CODE = 0x0002, // Section contains code.
129 CORCOMPILE_IMPORT_FLAGS_PCODE = 0x0004, // Section contains pointers to code.
130};
131
132// ================================================================================
133// Portable tagged union of a pointer field with a 30 bit scalar value
134// ================================================================================
135
136// The lowest bit of the tag will be set for tagged pointers. We also set the highest bit for convenience.
137// It makes dereferences of tagged pointers to crash under normal circumstances.
138// The highest bit of the tag will be set for tagged indexes (e.g. classid).
139
140#define CORCOMPILE_TOKEN_TAG 0x80000001
141
142// These two macros are mostly used just for debug-only checks to ensure that we have either tagged pointer (lowest bit is set)
143// or tagged index (highest bit is set).
144#define CORCOMPILE_IS_POINTER_TAGGED(token) ((((SIZE_T)(token)) & 0x00000001) != 0)
145#define CORCOMPILE_IS_INDEX_TAGGED(token) ((((SIZE_T)(token)) & 0x80000000) != 0)
146
147// The token (RVA of the fixup in most cases) is stored in the mid 30 bits of DWORD
148#define CORCOMPILE_TAG_TOKEN(token) ((SIZE_T)(((token)<<1)|CORCOMPILE_TOKEN_TAG))
149#define CORCOMPILE_UNTAG_TOKEN(token) ((((SIZE_T)(token))&~CORCOMPILE_TOKEN_TAG)>>1)
150
151#ifdef _TARGET_ARM_
152// Tagging of code pointers on ARM uses inverse logic because of the thumb bit.
153#define CORCOMPILE_IS_PCODE_TAGGED(token) ((((SIZE_T)(token)) & 0x00000001) == 0x00000000)
154#define CORCOMPILE_TAG_PCODE(token) ((SIZE_T)(((token)<<1)|0x80000000))
155#else
156#define CORCOMPILE_IS_PCODE_TAGGED(token) CORCOMPILE_IS_POINTER_TAGGED(token)
157#define CORCOMPILE_TAG_PCODE(token) CORCOMPILE_TAG_TOKEN(token)
158#endif
159
160inline BOOL CORCOMPILE_IS_FIXUP_TAGGED(SIZE_T fixup, PTR_CORCOMPILE_IMPORT_SECTION pSection)
161{
162#ifdef _TARGET_ARM_
163 // Tagging of code pointers on ARM has to use inverse logic because of the thumb bit
164 if (pSection->Flags & CORCOMPILE_IMPORT_FLAGS_PCODE)
165 {
166 return CORCOMPILE_IS_PCODE_TAGGED(fixup);
167 }
168#endif
169
170 return ((((SIZE_T)(fixup)) & CORCOMPILE_TOKEN_TAG) == CORCOMPILE_TOKEN_TAG);
171}
172
173enum CorCompileBuild
174{
175 CORCOMPILE_BUILD_CHECKED,
176 CORCOMPILE_BUILD_FREE
177};
178
179enum CorCompileCodegen
180{
181 CORCOMPILE_CODEGEN_DEBUGGING = 0x0001, // suports debugging (unoptimized code with symbol info)
182
183 CORCOMPILE_CODEGEN_PROFILING = 0x0004, // supports profiling
184 CORCOMPILE_CODEGEN_PROF_INSTRUMENTING = 0x0008, // code is instrumented to collect profile count info
185
186};
187
188
189// Used for INativeImageInstallInfo::GetConfigMask()
190// A bind will ask for the particular bits it needs set; if all bits are set, it is a match. Additional
191// bits are ignored.
192
193enum CorCompileConfigFlags
194{
195 CORCOMPILE_CONFIG_DEBUG_NONE = 0x01, // Assembly has Optimized code
196 CORCOMPILE_CONFIG_DEBUG = 0x02, // Assembly has non-Optimized debuggable code
197 CORCOMPILE_CONFIG_DEBUG_DEFAULT = 0x08, // Additional flag set if this particular setting is the
198 // one indicated by the assembly debug custom attribute.
199
200 CORCOMPILE_CONFIG_PROFILING_NONE = 0x100, // Assembly code has profiling hooks
201 CORCOMPILE_CONFIG_PROFILING = 0x200, // Assembly code has profiling hooks
202
203 CORCOMPILE_CONFIG_INSTRUMENTATION_NONE = 0x1000, // Assembly code has no instrumentation
204 CORCOMPILE_CONFIG_INSTRUMENTATION = 0x2000, // Assembly code has basic block instrumentation
205};
206
207// Values for Flags field of CORCOMPILE_HEADER.
208enum CorCompileHeaderFlags
209{
210 CORCOMPILE_HEADER_HAS_SECURITY_DIRECTORY = 0x00000001, // Original image had a security directory
211 // Note it is useless to cache the actual directory contents
212 // since it must be verified as part of the original image
213 CORCOMPILE_HEADER_IS_IBC_OPTIMIZED = 0x00000002,
214
215 CORCOMPILE_HEADER_IS_READY_TO_RUN = 0x00000004,
216};
217
218//
219// !!! INCREMENT THE MAJOR VERSION ANY TIME THERE IS CHANGE IN CORCOMPILE_HEADER STRUCTURE !!!
220//
221#define CORCOMPILE_SIGNATURE 0x0045474E // 'NGEN'
222#define CORCOMPILE_MAJOR_VERSION 0x0001
223#define CORCOMPILE_MINOR_VERSION 0x0000
224
225// This structure is pointed to by the code:IMAGE_COR20_HEADER (see file:corcompile.h#ManagedHeader)
226// See the file:../../doc/BookOfTheRuntime/NGEN/NGENDesign.doc for more
227struct CORCOMPILE_HEADER
228{
229 // For backward compatibility reasons, VersionInfo field must be at offset 40, ManifestMetaData
230 // must be at 88, PEKind must be at 112/116 bytes, Machine must be at 120/124 bytes, and
231 // size of CORCOMPILE_HEADER must be 164/168 bytes. Be careful when you modify this struct.
232 // See code:PEDecoder::GetMetaDataHelper.
233 DWORD Signature;
234 USHORT MajorVersion;
235 USHORT MinorVersion;
236
237 IMAGE_DATA_DIRECTORY HelperTable; // Table of function pointers to JIT helpers indexed by helper number
238 IMAGE_DATA_DIRECTORY ImportSections; // points to array of code:CORCOMPILE_IMPORT_SECTION
239 IMAGE_DATA_DIRECTORY Dummy0;
240 IMAGE_DATA_DIRECTORY StubsData; // contains the value to register with the stub manager for the delegate stubs & AMD64 tail call stubs
241 IMAGE_DATA_DIRECTORY VersionInfo; // points to a code:CORCOMPILE_VERSION_INFO
242 IMAGE_DATA_DIRECTORY Dependencies; // points to an array of code:CORCOMPILE_DEPENDENCY
243 IMAGE_DATA_DIRECTORY DebugMap; // points to an array of code:CORCOMPILE_DEBUG_RID_ENTRY hashed by method RID
244 IMAGE_DATA_DIRECTORY ModuleImage; // points to the freeze dried Module structure
245 IMAGE_DATA_DIRECTORY CodeManagerTable; // points to a code:CORCOMPILE_CODE_MANAGER_ENTRY
246 IMAGE_DATA_DIRECTORY ProfileDataList;// points to the list of code:CORCOMPILE_METHOD_PROFILE_LIST
247 IMAGE_DATA_DIRECTORY ManifestMetaData; // points to the native manifest metadata
248 IMAGE_DATA_DIRECTORY VirtualSectionsTable;// List of CORCOMPILE_VIRTUAL_SECTION_INFO. Contains a list of Section
249 // ranges for debugging purposes. There is one entry in this table per
250 // ZapVirtualSection in the NGEN image. This data is used to fire ETW
251 // events that describe the various VirtualSection in the NGEN image. These
252 // events are used for diagnostics and performance purposes. Some of the
253 // questions these events help answer are like : how effective is IBC
254 // training data. They can also be used to have better nidump support for
255 // decoding virtual section information ( start - end ranges for each
256 // virtual section )
257
258 TADDR ImageBase; // Actual image base address (ASLR fakes the image base in PE header while applying relocations in kernel)
259 DWORD Flags; // Flags, see CorCompileHeaderFlags above
260
261 DWORD PEKind; // CorPEKind of the original IL image
262
263 ULONG COR20Flags; // Cached value of code:IMAGE_COR20_HEADER.Flags from original IL image
264 WORD Machine; // Cached value of _IMAGE_FILE_HEADER.Machine from original IL image
265 WORD Characteristics;// Cached value of _IMAGE_FILE_HEADER.Characteristics from original IL image
266
267 IMAGE_DATA_DIRECTORY EEInfoTable; // points to a code:CORCOMPILE_EE_INFO_TABLE
268
269 // For backward compatibility (see above)
270 IMAGE_DATA_DIRECTORY Dummy1;
271 IMAGE_DATA_DIRECTORY Dummy2;
272 IMAGE_DATA_DIRECTORY Dummy3;
273 IMAGE_DATA_DIRECTORY Dummy4;
274};
275
276// CORCOMPILE_VIRTUAL_SECTION_INFO describes virtual section ranges. This data is used by nidump
277// and to fire ETW that are used for diagnostics and performance purposes. Some of the questions
278// these events help answer are like : how effective is IBC training data.
279struct CORCOMPILE_VIRTUAL_SECTION_INFO
280{
281 ULONG VirtualAddress;
282 ULONG Size;
283 DWORD SectionType;
284};
285
286#define CORCOMPILE_SECTION_TYPES() \
287 CORCOMPILE_SECTION_TYPE(Module) \
288 CORCOMPILE_SECTION_TYPE(EETable) \
289 CORCOMPILE_SECTION_TYPE(WriteData) \
290 CORCOMPILE_SECTION_TYPE(WriteableData) \
291 CORCOMPILE_SECTION_TYPE(Data) \
292 CORCOMPILE_SECTION_TYPE(RVAStatics) \
293 CORCOMPILE_SECTION_TYPE(EEData) \
294 CORCOMPILE_SECTION_TYPE(DelayLoadInfoTableEager) \
295 CORCOMPILE_SECTION_TYPE(DelayLoadInfoTable) \
296 CORCOMPILE_SECTION_TYPE(EEReadonlyData) \
297 CORCOMPILE_SECTION_TYPE(ReadonlyData) \
298 CORCOMPILE_SECTION_TYPE(Class) \
299 CORCOMPILE_SECTION_TYPE(CrossDomainInfo) \
300 CORCOMPILE_SECTION_TYPE(MethodDesc) \
301 CORCOMPILE_SECTION_TYPE(MethodDescWriteable) \
302 CORCOMPILE_SECTION_TYPE(Exception) \
303 CORCOMPILE_SECTION_TYPE(Instrument) \
304 CORCOMPILE_SECTION_TYPE(VirtualImportThunk) \
305 CORCOMPILE_SECTION_TYPE(ExternalMethodThunk) \
306 CORCOMPILE_SECTION_TYPE(HelperTable) \
307 CORCOMPILE_SECTION_TYPE(MethodPrecodeWriteable) \
308 CORCOMPILE_SECTION_TYPE(MethodPrecodeWrite) \
309 CORCOMPILE_SECTION_TYPE(MethodPrecode) \
310 CORCOMPILE_SECTION_TYPE(Win32Resources) \
311 CORCOMPILE_SECTION_TYPE(Header) \
312 CORCOMPILE_SECTION_TYPE(Metadata) \
313 CORCOMPILE_SECTION_TYPE(DelayLoadInfo) \
314 CORCOMPILE_SECTION_TYPE(ImportTable) \
315 CORCOMPILE_SECTION_TYPE(Code) \
316 CORCOMPILE_SECTION_TYPE(CodeHeader) \
317 CORCOMPILE_SECTION_TYPE(CodeManager) \
318 CORCOMPILE_SECTION_TYPE(UnwindData) \
319 CORCOMPILE_SECTION_TYPE(RuntimeFunction) \
320 CORCOMPILE_SECTION_TYPE(Stubs) \
321 CORCOMPILE_SECTION_TYPE(StubDispatchData) \
322 CORCOMPILE_SECTION_TYPE(ExternalMethodData) \
323 CORCOMPILE_SECTION_TYPE(DelayLoadInfoDelayList) \
324 CORCOMPILE_SECTION_TYPE(ReadonlyShared) \
325 CORCOMPILE_SECTION_TYPE(Readonly) \
326 CORCOMPILE_SECTION_TYPE(IL) \
327 CORCOMPILE_SECTION_TYPE(GCInfo) \
328 CORCOMPILE_SECTION_TYPE(ILMetadata) \
329 CORCOMPILE_SECTION_TYPE(Resources) \
330 CORCOMPILE_SECTION_TYPE(CompressedMaps) \
331 CORCOMPILE_SECTION_TYPE(Debug) \
332 CORCOMPILE_SECTION_TYPE(BaseRelocs) \
333
334// Hot: Items are frequently accessed ( Indicated by either IBC data, or
335// statically known )
336
337// Warm : Items are less frequently accessed, or frequently accessed
338// but were not touched during IBC profiling.
339
340// Cold : Least frequently accessed /shouldn't not be accessed
341// when running a scenario that was used during IBC
342// training ( training scenario )
343
344// HotColdSorted : Sections marked with this category means they contain both
345// Hot items and Cold items. The hot items are placed before
346// the cold items (Sorted)
347
348#define CORCOMPILE_SECTION_RANGE_TYPES() \
349 CORCOMPILE_SECTION_RANGE_TYPE(Hot, 0x00010000) \
350 CORCOMPILE_SECTION_RANGE_TYPE(Warm, 0x00020000) \
351 CORCOMPILE_SECTION_RANGE_TYPE(Cold, 0x00040000) \
352 CORCOMPILE_SECTION_RANGE_TYPE(HotColdSorted, 0x00080000) \
353
354
355// IBCUnProfiled: Items in this VirtualSection are statically determined to be cold.
356// (IBC Profiling wouldn't have helped put these item in a hot section).
357// Items that currently doesn't have IBC probs, or are always put in a specific section
358// regardless of IBC data should fall in this category.
359
360// IBCProfiled: IBC profiling placed items in this section, or
361// items are NOT placed into a hot section they didn't have IBC profiling data
362// ( IBC profiling would have helped put these items in a hot section )
363
364#define CORCOMPILE_SECTION_IBCTYPES() \
365 CORCOMPILE_SECTION_IBCTYPE(IBCUnProfiled, 0x01000000) \
366 CORCOMPILE_SECTION_IBCTYPE(IBCProfiled, 0x02000000) \
367
368
369// Support for VirtualSection Metadata/Categories
370// Please update the VirtualSetionType ETW map in ClrEtwAll.man if you changed this enum.
371// ZapVirtualSectionType is used to describe metadata about VirtualSections.
372// The metadata consists of 3 sub-metadata parts.
373// ---------------------------------------------------
374// 1 byte 1 byte 2 bytes --
375// <IBCType> <RangeType> <VirtualSectionType> --
376// ---------------------------------------------------
377//
378//
379// VirtualSections are a CLR concept to aggregate data
380// items that share common properties together (Hot/Cold/Warm, Writeable/
381// Readonly ...etc.). VirtualSections are tagged with some categories when they
382// are created (code:NewVirtualSection)
383// The VirtualSection categorize are described more in VirtualSectionType enum.
384// The categories describe 2 important aspects for each VirtualSection
385//
386// ***********************************************
387// IBCProfiled v.s NonIBCProfiled Categories.
388// **********************************************
389//
390// IBCProfiled: Distinguish between sections that IBC profiling data has been used
391// to decide the layout of the data items in this section.
392// NonIBCProfiled: We don't have IBC data for all our datastructures.
393// The access pattern/frequency for some data structures
394// are statically determined. Sections that contain these data items
395// are marked as NonIBCProfiled.
396//
397//***************************************************
398// Access Frequency categories
399// **************************************************
400// Hot: Data is frequently accessed
401// Warm: Less frequently accessed than Hot
402// Cold: Should be rarely accessed.
403//
404// The combination of these 2 sub-categories gives us the following valid categories
405// 1-IBCProfiled | Hot: Hot based on IBC profiling data.
406// 2-IBCProfiled | Cold: IBC profiling could have helped make this section hot.
407// 3-NonIBCProfiled | Hot: Statically determined hot.
408// 4-NonIBCProfiled | Warm: Staticaly determined warm.
409// 5-NonIBCProfiled | Cold: Statically determined cold.
410//
411// We should try to place data items into the correct section based on
412// the above categorization, this could mean that we might split
413// a virtual section into 2 sections if it contains multiple heterogeneous items.
414
415enum ZapVirtualSectionType
416{
417 // <IBCType>
418 IBCTypeReservedFlag = 0xFF000000,
419#define CORCOMPILE_SECTION_IBCTYPE(ibcType, flag) ibcType##Section = flag,
420 CORCOMPILE_SECTION_IBCTYPES()
421#undef CORCOMPILE_SECTION_IBCTYPE
422
423 // <RangeType>
424 RangeTypeReservedFlag = 0x00FF0000,
425#define CORCOMPILE_SECTION_RANGE_TYPE(rangeType, flag) rangeType##Range = flag,
426 CORCOMPILE_SECTION_RANGE_TYPES()
427#undef CORCOMPILE_SECTION_RANGE_TYPE
428
429 // <VirtualSectionType>
430 VirtualSectionTypeReservedFlag = 0x0000FFFF,
431 VirtualSectionTypeStartSection = 0x0, // reserved so the first section start at 0x1
432#define CORCOMPILE_SECTION_TYPE(virtualSectionType) virtualSectionType##Section,
433 CORCOMPILE_SECTION_TYPES()
434#undef CORCOMPILE_SECTION_TYPE
435
436 CORCOMPILE_SECTION_TYPE_COUNT
437};
438
439class VirtualSectionData
440{
441
442public :
443 static UINT8 IBCType(DWORD sectionType) { return (UINT8) ((sectionType & IBCTypeReservedFlag) >> 24); }
444 static UINT8 RangeType(DWORD sectionType) { return (UINT8) ((sectionType & RangeTypeReservedFlag) >> 16); }
445 static UINT16 VirtualSectionType(DWORD sectionType) { return (UINT16) ((sectionType & VirtualSectionTypeReservedFlag)); }
446 static BOOL IsIBCProfiledColdSection(DWORD sectionType)
447 {
448 return ((sectionType & ColdRange) == ColdRange) && ((sectionType & IBCProfiledSection) == IBCProfiledSection);
449 }
450};
451
452struct CORCOMPILE_EE_INFO_TABLE
453{
454 TADDR inlinedCallFrameVptr;
455 PTR_LONG addrOfCaptureThreadGlobal;
456 PTR_DWORD addrOfJMCFlag;
457 SIZE_T gsCookie;
458 CORINFO_Object ** emptyString;
459
460 DWORD threadTlsIndex;
461
462 DWORD rvaStaticTlsIndex;
463};
464
465/*********************************************************************************/
466
467// This is the offset to the compressed blob of debug information
468
469typedef ULONG CORCOMPILE_DEBUG_ENTRY;
470
471// A single generic method may be get compiled into multiple copies of code for
472// different instantiations, and can have multiple entries for the same RID.
473
474struct CORCOMPILE_DEBUG_LABELLED_ENTRY
475{
476 DWORD nativeCodeRVA; // the ngen code RVA distinguishes this entry from others with the same RID.
477 CORCOMPILE_DEBUG_ENTRY debugInfoOffset; // offset to the debug information for this native code
478};
479
480// Debug information is accessed using a table of RVAs indexed by the RID token for
481// the method.
482
483typedef CORCOMPILE_DEBUG_ENTRY CORCOMPILE_DEBUG_RID_ENTRY;
484
485// If this bit is not set, the CORCOMPILE_DEBUG_RID_ENTRY RVA points to a compressed
486// debug information blob.
487// If this bit is set, the RVA points to CORCOMPILE_DEBUG_LABELLED_ENTRY.
488// If this bit is set in CORCOMPILE_DEBUG_LABELLED_ENTRY, there is another entry following it.
489
490const CORCOMPILE_DEBUG_RID_ENTRY CORCOMPILE_DEBUG_MULTIPLE_ENTRIES = 0x80000000;
491
492inline bool IsMultipleLabelledEntries(CORCOMPILE_DEBUG_RID_ENTRY rva)
493{
494 SUPPORTS_DAC;
495
496 return (rva & CORCOMPILE_DEBUG_MULTIPLE_ENTRIES) != 0;
497}
498
499inline unsigned GetDebugRidEntryHash(mdToken token)
500{
501 SUPPORTS_DAC;
502
503 unsigned hashCode = token;
504
505 // mix it
506 hashCode -= hashCode >> 17;
507 hashCode -= hashCode >> 11;
508 hashCode -= hashCode >> 5;
509
510 return hashCode;
511}
512
513typedef DPTR(CORCOMPILE_DEBUG_ENTRY) PTR_CORCOMPILE_DEBUG_ENTRY;
514typedef DPTR(struct CORCOMPILE_DEBUG_LABELLED_ENTRY) PTR_CORCOMPILE_DEBUG_LABELLED_ENTRY;
515typedef DPTR(CORCOMPILE_DEBUG_RID_ENTRY) PTR_CORCOMPILE_DEBUG_RID_ENTRY;
516
517/*********************************************************************************/
518
519struct CORCOMPILE_CODE_MANAGER_ENTRY
520{
521 IMAGE_DATA_DIRECTORY HotCode;
522 IMAGE_DATA_DIRECTORY Code;
523 IMAGE_DATA_DIRECTORY ColdCode;
524
525 IMAGE_DATA_DIRECTORY ROData;
526
527 //Layout is
528 //HOT COMMON
529 //HOT IBC
530 //HOT GENERICS
531 //Hot due to procedure splitting
532 ULONG HotIBCMethodOffset;
533 ULONG HotGenericsMethodOffset;
534
535 //Layout is
536 //COLD IBC
537 //Cold due to procedure splitting.
538 ULONG ColdUntrainedMethodOffset;
539};
540
541#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
542
543#define _PRECODE_EXTERNAL_METHOD_THUNK 0x41
544#define _PRECODE_VIRTUAL_IMPORT_THUNK 0x42
545
546 struct CORCOMPILE_VIRTUAL_IMPORT_THUNK
547 {
548 BYTE callJmp[5]; // Call/Jmp Pc-Rel32
549 BYTE precodeType; // 0x42 _PRECODE_VIRTUAL_IMPORT_THUNK
550 WORD slotNum;
551 };
552
553 struct CORCOMPILE_EXTERNAL_METHOD_THUNK
554 {
555 BYTE callJmp[5]; // Call/Jmp Pc-Rel32
556 BYTE precodeType; // 0x41 _PRECODE_EXTERNAL_METHOD_THUNK
557 WORD padding;
558 };
559
560#elif defined(_TARGET_ARM_)
561
562 struct CORCOMPILE_VIRTUAL_IMPORT_THUNK
563 {
564 // Array of words to do the following:
565 //
566 // mov r12, pc ; Save the current address relative to which we will get slot ID and address to patch.
567 // ldr pc, [pc, #4] ; Load the target address. Initially it will point to the helper stub that will patch it
568 // ; to point to the actual target on the first run.
569 WORD m_rgCode[3];
570
571 // WORD to store the slot ID
572 WORD slotNum;
573
574 // The target address - initially, this will point to VirtualMethodFixupStub.
575 // Post patchup by the stub, it will point to the actual method body.
576 PCODE m_pTarget;
577 };
578
579 struct CORCOMPILE_EXTERNAL_METHOD_THUNK
580 {
581 // Array of words to do the following:
582 //
583 // mov r12, pc ; Save the current address relative to which we will get GCRef bitmap and address to patch.
584 // ldr pc, [pc, #4] ; Load the target address. Initially it will point to the helper stub that will patch it
585 // ; to point to the actual target on the first run.
586 WORD m_rgCode[3];
587
588 WORD m_padding;
589
590 // The target address - initially, this will point to ExternalMethodFixupStub.
591 // Post patchup by the stub, it will point to the actual method body.
592 PCODE m_pTarget;
593 };
594
595#elif defined(_TARGET_ARM64_)
596 struct CORCOMPILE_VIRTUAL_IMPORT_THUNK
597 {
598 // Array of words to do the following:
599 //
600 // adr x12, #0 ; Save the current address relative to which we will get slot ID and address to patch.
601 // ldr x10, [x12, #16] ; Load the target address.
602 // br x10 ; Jump to the target
603 DWORD m_rgCode[3];
604
605 // WORD to store the slot ID
606 WORD slotNum;
607
608 // The target address - initially, this will point to VirtualMethodFixupStub.
609 // Post patchup by the stub, it will point to the actual method body.
610 PCODE m_pTarget;
611 };
612
613 struct CORCOMPILE_EXTERNAL_METHOD_THUNK
614 {
615 // Array of words to do the following:
616 // adr x12, #0 ; Save the current address relative to which we will get slot ID and address to patch.
617 // ldr x10, [x12, #16] ; Load the target address.
618 // br x10 ; Jump to the target
619 DWORD m_rgCode[3];
620
621 DWORD m_padding; //aligning stack to 16 bytes
622
623 // The target address - initially, this will point to ExternalMethodFixupStub.
624 // Post patchup by the stub, it will point to the actual method body.
625 PCODE m_pTarget;
626 };
627
628#endif
629
630//
631// GCRefMap blob starts with DWORDs lookup index of relative offsets into the blob. This lookup index is used to limit amount
632// of linear scanning required to find entry in the GCRefMap. The size of this lookup index is
633// <totalNumberOfEntries in the GCRefMap> / GCREFMAP_LOOKUP_STRIDE.
634//
635#define GCREFMAP_LOOKUP_STRIDE 1024
636
637enum CORCOMPILE_GCREFMAP_TOKENS
638{
639 GCREFMAP_SKIP = 0,
640 GCREFMAP_REF = 1,
641 GCREFMAP_INTERIOR = 2,
642 GCREFMAP_METHOD_PARAM = 3,
643 GCREFMAP_TYPE_PARAM = 4,
644 GCREFMAP_VASIG_COOKIE = 5,
645};
646
647// Tags for fixup blobs
648enum CORCOMPILE_FIXUP_BLOB_KIND
649{
650 ENCODE_NONE = 0,
651
652 ENCODE_MODULE_OVERRIDE = 0x80, /* When the high bit is set, override of the module immediately follows */
653
654 ENCODE_DICTIONARY_LOOKUP_THISOBJ = 0x07,
655 ENCODE_DICTIONARY_LOOKUP_TYPE = 0x08,
656 ENCODE_DICTIONARY_LOOKUP_METHOD = 0x09,
657
658 ENCODE_TYPE_HANDLE = 0x10, /* Type handle */
659 ENCODE_METHOD_HANDLE, /* Method handle */
660 ENCODE_FIELD_HANDLE, /* Field handle */
661
662 ENCODE_METHOD_ENTRY, /* For calling a method entry point */
663 ENCODE_METHOD_ENTRY_DEF_TOKEN, /* Smaller version of ENCODE_METHOD_ENTRY - method is def token */
664 ENCODE_METHOD_ENTRY_REF_TOKEN, /* Smaller version of ENCODE_METHOD_ENTRY - method is ref token */
665
666 ENCODE_VIRTUAL_ENTRY, /* For invoking a virtual method */
667 ENCODE_VIRTUAL_ENTRY_DEF_TOKEN, /* Smaller version of ENCODE_VIRTUAL_ENTRY - method is def token */
668 ENCODE_VIRTUAL_ENTRY_REF_TOKEN, /* Smaller version of ENCODE_VIRTUAL_ENTRY - method is ref token */
669 ENCODE_VIRTUAL_ENTRY_SLOT, /* Smaller version of ENCODE_VIRTUAL_ENTRY - type & slot */
670
671 ENCODE_READYTORUN_HELPER, /* ReadyToRun helper */
672 ENCODE_STRING_HANDLE, /* String token */
673
674 ENCODE_NEW_HELPER, /* Dynamically created new helpers */
675 ENCODE_NEW_ARRAY_HELPER,
676
677 ENCODE_ISINSTANCEOF_HELPER, /* Dynamically created casting helper */
678 ENCODE_CHKCAST_HELPER,
679
680 ENCODE_FIELD_ADDRESS, /* For accessing a cross-module static fields */
681 ENCODE_CCTOR_TRIGGER, /* Static constructor trigger */
682
683 ENCODE_STATIC_BASE_NONGC_HELPER, /* Dynamically created static base helpers */
684 ENCODE_STATIC_BASE_GC_HELPER,
685 ENCODE_THREAD_STATIC_BASE_NONGC_HELPER,
686 ENCODE_THREAD_STATIC_BASE_GC_HELPER,
687
688 ENCODE_FIELD_BASE_OFFSET, /* Field base */
689 ENCODE_FIELD_OFFSET,
690
691 ENCODE_TYPE_DICTIONARY,
692 ENCODE_METHOD_DICTIONARY,
693
694 ENCODE_CHECK_TYPE_LAYOUT,
695 ENCODE_CHECK_FIELD_OFFSET,
696
697 ENCODE_DELEGATE_CTOR,
698
699 ENCODE_DECLARINGTYPE_HANDLE,
700
701 ENCODE_MODULE_HANDLE = 0x50, /* Module token */
702 ENCODE_STATIC_FIELD_ADDRESS, /* For accessing a static field */
703 ENCODE_MODULE_ID_FOR_STATICS, /* For accessing static fields */
704 ENCODE_MODULE_ID_FOR_GENERIC_STATICS, /* For accessing static fields */
705 ENCODE_CLASS_ID_FOR_STATICS, /* For accessing static fields */
706 ENCODE_SYNC_LOCK, /* For synchronizing access to a type */
707 ENCODE_INDIRECT_PINVOKE_TARGET, /* For calling a pinvoke method ptr */
708 ENCODE_PROFILING_HANDLE, /* For the method's profiling counter */
709 ENCODE_VARARGS_METHODDEF, /* For calling a varargs method */
710 ENCODE_VARARGS_METHODREF,
711 ENCODE_VARARGS_SIG,
712 ENCODE_ACTIVE_DEPENDENCY, /* Conditional active dependency */
713 ENCODE_METHOD_NATIVE_ENTRY, /* NativeCallable method token */
714};
715
716enum EncodeMethodSigFlags
717{
718 ENCODE_METHOD_SIG_UnboxingStub = 0x01,
719 ENCODE_METHOD_SIG_InstantiatingStub = 0x02,
720 ENCODE_METHOD_SIG_MethodInstantiation = 0x04,
721 ENCODE_METHOD_SIG_SlotInsteadOfToken = 0x08,
722 ENCODE_METHOD_SIG_MemberRefToken = 0x10,
723 ENCODE_METHOD_SIG_Constrained = 0x20,
724 ENCODE_METHOD_SIG_OwnerType = 0x40,
725};
726
727enum EncodeFieldSigFlags
728{
729 ENCODE_FIELD_SIG_IndexInsteadOfToken = 0x08,
730 ENCODE_FIELD_SIG_MemberRefToken = 0x10,
731 ENCODE_FIELD_SIG_OwnerType = 0x40,
732};
733
734class SBuffer;
735class SigBuilder;
736class PEDecoder;
737class GCRefMapBuilder;
738
739//REVIEW: include for ee exception info
740#include "eexcp.h"
741
742struct CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY
743{
744 DWORD MethodStartRVA;
745 DWORD ExceptionInfoRVA;
746};
747
748struct CORCOMPILE_EXCEPTION_LOOKUP_TABLE
749{
750 // pointer to the first element of m_numLookupEntries elements
751 CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY m_Entries[1];
752
753 CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY* ExceptionLookupEntry(unsigned i)
754 {
755 SUPPORTS_DAC_WRAPPER;
756 return &(PTR_CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY(PTR_HOST_MEMBER_TADDR(CORCOMPILE_EXCEPTION_LOOKUP_TABLE,this,m_Entries))[i]);
757 }
758};
759
760struct CORCOMPILE_EXCEPTION_CLAUSE
761{
762 CorExceptionFlag Flags;
763 DWORD TryStartPC;
764 DWORD TryEndPC;
765 DWORD HandlerStartPC;
766 DWORD HandlerEndPC;
767 union {
768 mdToken ClassToken;
769 DWORD FilterOffset;
770 };
771};
772
773//lower order bit (HAS_EXCEPTION_INFO_MASK) used to determine if the method has any exception handling
774#define HAS_EXCEPTION_INFO_MASK 1
775
776struct CORCOMPILE_COLD_METHOD_ENTRY
777{
778#ifdef WIN64EXCEPTIONS
779 DWORD mainFunctionEntryRVA;
780#endif
781 // TODO: hotCodeSize should be encoded in GC info
782 ULONG hotCodeSize;
783};
784
785// MVID used by the metadata of all ngen images
786// {70E9452F-5F0A-4f0e-8E02-203992F4221C}
787EXTERN_GUID(NGEN_IMAGE_MVID, 0x70e9452f, 0x5f0a, 0x4f0e, 0x8e, 0x2, 0x20, 0x39, 0x92, 0xf4, 0x22, 0x1c);
788
789typedef GUID CORCOMPILE_NGEN_SIGNATURE;
790
791// To indicate that the dependency is not hardbound
792// {DB15CD8C-1378-4963-9DF3-14D97E95D1A1}
793EXTERN_GUID(INVALID_NGEN_SIGNATURE, 0xdb15cd8c, 0x1378, 0x4963, 0x9d, 0xf3, 0x14, 0xd9, 0x7e, 0x95, 0xd1, 0xa1);
794
795struct CORCOMPILE_ASSEMBLY_SIGNATURE
796{
797 // Metadata MVID.
798 GUID mvid;
799
800 // timestamp and IL image size for the source IL assembly.
801 // This is used for mini-dump to find matching metadata.
802 DWORD timeStamp;
803 DWORD ilImageSize;
804};
805
806typedef enum
807{
808 CORECLR_INFO,
809 CROSSGEN_COMPILER_INFO,
810 NUM_RUNTIME_DLLS
811} CorCompileRuntimeDlls;
812
813extern LPCWSTR CorCompileGetRuntimeDllName(CorCompileRuntimeDlls id);
814
815// Will always return a valid HMODULE for CLR_INFO, but will return NULL for NGEN_COMPILER_INFO
816// if the DLL has not yet been loaded (it does not try to cause a load).
817extern HMODULE CorCompileGetRuntimeDll(CorCompileRuntimeDlls id);
818
819struct CORCOMPILE_RUNTIME_DLL_INFO
820{
821 // This structure can only contain information not updated by authenticode signing. It is required
822 // for crossgen to work in buildlab. It particular, it cannot contain PE checksum because of it is
823 // update by authenticode signing.
824 DWORD timeStamp;
825 DWORD virtualSize;
826};
827
828
829
830struct CORCOMPILE_VERSION_INFO
831{
832 // OS
833 WORD wOSPlatformID;
834 WORD wOSMajorVersion;
835
836 // For backward compatibility reasons, the following four fields must start at offset 4,
837 // be consequtive, and be 2 bytes each. See code:PEDecoder::GetMetaDataHelper.
838 // EE Version
839 WORD wVersionMajor;
840 WORD wVersionMinor;
841 WORD wVersionBuildNumber;
842 WORD wVersionPrivateBuildNumber;
843
844 // Codegen flags
845 WORD wCodegenFlags;
846 WORD wConfigFlags;
847 WORD wBuild;
848
849 // Processor
850 WORD wMachine;
851 CORINFO_CPU cpuInfo;
852
853 // Signature of source assembly
854 CORCOMPILE_ASSEMBLY_SIGNATURE sourceAssembly;
855
856 // Signature which identifies this ngen image
857 CORCOMPILE_NGEN_SIGNATURE signature;
858
859 // Timestamp info for runtime dlls
860 CORCOMPILE_RUNTIME_DLL_INFO runtimeDllInfo[NUM_RUNTIME_DLLS];
861};
862
863
864
865
866struct CORCOMPILE_DEPENDENCY
867{
868 // Pre-bind Ref
869 mdAssemblyRef dwAssemblyRef;
870
871 // Post-bind Def
872 mdAssemblyRef dwAssemblyDef;
873 CORCOMPILE_ASSEMBLY_SIGNATURE signAssemblyDef;
874
875 CORCOMPILE_NGEN_SIGNATURE signNativeImage; // INVALID_NGEN_SIGNATURE if this a soft-bound dependency
876
877
878};
879
880/*********************************************************************************/
881// Flags used to encode HelperTable
882#if defined(_TARGET_ARM64_)
883#define HELPER_TABLE_ENTRY_LEN 16
884#else
885#define HELPER_TABLE_ENTRY_LEN 8
886#endif //defined(_TARGET_ARM64_)
887
888#define HELPER_TABLE_ALIGN 8
889#define CORCOMPILE_HELPER_PTR 0x80000000 // The entry is pointer to the helper (jump thunk otherwise)
890
891// The layout of this struct is required to be
892// a 'next' pointer followed by a CORBBTPROF_METHOD_HEADER
893//
894struct CORCOMPILE_METHOD_PROFILE_LIST
895{
896 CORCOMPILE_METHOD_PROFILE_LIST * next;
897// CORBBTPROF_METHOD_HEADER info;
898
899 CORBBTPROF_METHOD_HEADER * GetInfo()
900 { return (CORBBTPROF_METHOD_HEADER *) (this+1); }
901};
902
903// see code:CorProfileData.GetHotTokens for how we determine what is in hot meta-data.
904class CorProfileData
905{
906public:
907 CorProfileData(void * rawProfileData); // really of type ZapImage::ProfileDataSection*
908
909 struct CORBBTPROF_TOKEN_INFO * GetTokenFlagsData(SectionFormat section)
910 {
911 if (this == NULL)
912 return NULL;
913 return this->profilingTokenFlagsData[section].data;
914 }
915
916 DWORD GetTokenFlagsCount(SectionFormat section)
917 {
918 if (this == NULL)
919 return 0;
920 return this->profilingTokenFlagsData[section].count;
921 }
922
923 CORBBTPROF_BLOB_ENTRY * GetBlobStream()
924 {
925 if (this == NULL)
926 return NULL;
927 return this->blobStream;
928 }
929
930
931 // see code:MetaData::HotMetaDataHeader for details on reading hot meta-data
932 //
933 // for detail on where we use the API to store the hot meta data
934 // * code:CMiniMdRW.SaveFullTablesToStream#WritingHotMetaData
935 // * code:CMiniMdRW.SaveHotPoolsToStream
936 // * code:CMiniMdRW.SaveHotPoolToStream#CallToGetHotTokens
937 //
938 ULONG GetHotTokens(int table, DWORD mask, DWORD hotValue, mdToken *tokenBuffer, ULONG maxCount)
939 {
940 ULONG count = 0;
941 SectionFormat format = (SectionFormat)(FirstTokenFlagSection + table);
942
943 CORBBTPROF_TOKEN_INFO *profilingData = profilingTokenFlagsData[format].data;
944 DWORD cProfilingData = profilingTokenFlagsData[format].count;
945
946 if (profilingData != NULL)
947 {
948 for (DWORD i = 0; i < cProfilingData; i++)
949 {
950 if ((profilingData[i].flags & mask) == hotValue)
951 {
952 if (tokenBuffer != NULL && count < maxCount)
953 tokenBuffer[count] = profilingData[i].token;
954 count++;
955 }
956 }
957 }
958 return count;
959 }
960
961 //
962 // Token lookup methods
963 //
964 ULONG GetTypeProfilingFlagsOfToken(mdToken token)
965 {
966 _ASSERTE(TypeFromToken(token) == mdtTypeDef);
967 return GetProfilingFlagsOfToken(token);
968 }
969
970 CORBBTPROF_BLOB_PARAM_SIG_ENTRY *GetBlobSigEntry(mdToken token)
971 {
972 _ASSERTE((TypeFromToken(token) == ibcTypeSpec) || (TypeFromToken(token) == ibcMethodSpec));
973
974 CORBBTPROF_BLOB_ENTRY * pBlobEntry = GetBlobEntry(token);
975 if (pBlobEntry == NULL)
976 return NULL;
977
978 _ASSERTE(pBlobEntry->token == token);
979 _ASSERTE((pBlobEntry->type == ParamTypeSpec) || (pBlobEntry->type == ParamMethodSpec));
980
981 return (CORBBTPROF_BLOB_PARAM_SIG_ENTRY *) pBlobEntry;
982 }
983
984 CORBBTPROF_BLOB_NAMESPACE_DEF_ENTRY *GetBlobExternalNamespaceDef(mdToken token)
985 {
986 _ASSERTE(TypeFromToken(token) == ibcExternalNamespace);
987
988 CORBBTPROF_BLOB_ENTRY * pBlobEntry = GetBlobEntry(token);
989 if (pBlobEntry == NULL)
990 return NULL;
991
992 _ASSERTE(pBlobEntry->token == token);
993 _ASSERTE(pBlobEntry->type == ExternalNamespaceDef);
994
995 return (CORBBTPROF_BLOB_NAMESPACE_DEF_ENTRY *) pBlobEntry;
996 }
997
998 CORBBTPROF_BLOB_TYPE_DEF_ENTRY *GetBlobExternalTypeDef(mdToken token)
999 {
1000 _ASSERTE(TypeFromToken(token) == ibcExternalType);
1001
1002 CORBBTPROF_BLOB_ENTRY * pBlobEntry = GetBlobEntry(token);
1003 if (pBlobEntry == NULL)
1004 return NULL;
1005
1006 _ASSERTE(pBlobEntry->token == token);
1007 _ASSERTE(pBlobEntry->type == ExternalTypeDef);
1008
1009 return (CORBBTPROF_BLOB_TYPE_DEF_ENTRY *) pBlobEntry;
1010 }
1011
1012 CORBBTPROF_BLOB_SIGNATURE_DEF_ENTRY *GetBlobExternalSignatureDef(mdToken token)
1013 {
1014 _ASSERTE(TypeFromToken(token) == ibcExternalSignature);
1015
1016 CORBBTPROF_BLOB_ENTRY * pBlobEntry = GetBlobEntry(token);
1017 if (pBlobEntry == NULL)
1018 return NULL;
1019
1020 _ASSERTE(pBlobEntry->token == token);
1021 _ASSERTE(pBlobEntry->type == ExternalSignatureDef);
1022
1023 return (CORBBTPROF_BLOB_SIGNATURE_DEF_ENTRY *) pBlobEntry;
1024 }
1025
1026 CORBBTPROF_BLOB_METHOD_DEF_ENTRY *GetBlobExternalMethodDef(mdToken token)
1027 {
1028 _ASSERTE(TypeFromToken(token) == ibcExternalMethod);
1029
1030 CORBBTPROF_BLOB_ENTRY * pBlobEntry = GetBlobEntry(token);
1031 if (pBlobEntry == NULL)
1032 return NULL;
1033
1034 _ASSERTE(pBlobEntry->token == token);
1035 _ASSERTE(pBlobEntry->type == ExternalMethodDef);
1036
1037 return (CORBBTPROF_BLOB_METHOD_DEF_ENTRY *) pBlobEntry;
1038 }
1039
1040private:
1041 ULONG GetProfilingFlagsOfToken(mdToken token)
1042 {
1043 SectionFormat section = (SectionFormat)((TypeFromToken(token) >> 24) + FirstTokenFlagSection);
1044
1045 CORBBTPROF_TOKEN_INFO *profilingData = this->profilingTokenFlagsData[section].data;
1046 DWORD cProfilingData = this->profilingTokenFlagsData[section].count;
1047
1048 if (profilingData != NULL)
1049 {
1050 for (DWORD i = 0; i < cProfilingData; i++)
1051 {
1052 if (profilingData[i].token == token)
1053 return profilingData[i].flags;
1054 }
1055 }
1056 return 0;
1057 }
1058
1059 CORBBTPROF_BLOB_ENTRY *GetBlobEntry(idTypeSpec token)
1060 {
1061 CORBBTPROF_BLOB_ENTRY * pBlobEntry = this->GetBlobStream();
1062 if (pBlobEntry == NULL)
1063 return NULL;
1064
1065 while (pBlobEntry->TypeIsValid())
1066 {
1067 if (pBlobEntry->token == token)
1068 {
1069 return pBlobEntry;
1070 }
1071 pBlobEntry = pBlobEntry->GetNextEntry();
1072 }
1073
1074 return NULL;
1075 }
1076
1077private:
1078 struct
1079 {
1080 struct CORBBTPROF_TOKEN_INFO *data;
1081 DWORD count;
1082 }
1083 profilingTokenFlagsData[SectionFormatCount];
1084
1085 CORBBTPROF_BLOB_ENTRY* blobStream;
1086};
1087
1088/*********************************************************************************/
1089// IL region is used to group frequently used IL method bodies together
1090
1091enum CorCompileILRegion
1092{
1093 CORCOMPILE_ILREGION_INLINEABLE, // Public inlineable methods
1094 CORCOMPILE_ILREGION_WARM, // Other inlineable methods and methods that failed to NGen
1095 CORCOMPILE_ILREGION_GENERICS, // Generic methods (may be needed to compile non-NGened instantiations)
1096 CORCOMPILE_ILREGION_COLD, // Everything else (should be touched in rare scenarios like reflection or profiling only)
1097 CORCOMPILE_ILREGION_COUNT,
1098};
1099
1100/*********************************************************************************
1101 * ICorCompilePreloader is used to query preloaded EE data structures
1102 *********************************************************************************/
1103
1104class ICorCompilePreloader
1105{
1106 public:
1107 typedef void (__stdcall *CORCOMPILE_CompileStubCallback)(LPVOID pContext, CORINFO_METHOD_HANDLE hStub, CORJIT_FLAGS jitFlags);
1108
1109 //
1110 // Map methods are available after Serialize() is called
1111 // (which will cause it to allocate its data.) Note that returned
1112 // results are RVAs into the image.
1113 //
1114 // If compiling after serializing the preloaded image, these methods can
1115 // be used to avoid making entries in the various info tables.
1116 // Else, use ICorCompileInfo::CanEmbedXXX()
1117 //
1118
1119 virtual DWORD MapMethodEntryPoint(
1120 CORINFO_METHOD_HANDLE handle
1121 ) = 0;
1122
1123 virtual DWORD MapClassHandle(
1124 CORINFO_CLASS_HANDLE handle
1125 ) = 0;
1126
1127 virtual DWORD MapMethodHandle(
1128 CORINFO_METHOD_HANDLE handle
1129 ) = 0;
1130
1131 virtual DWORD MapFieldHandle(
1132 CORINFO_FIELD_HANDLE handle
1133 ) = 0;
1134
1135 virtual DWORD MapAddressOfPInvokeFixup(
1136 CORINFO_METHOD_HANDLE handle
1137 ) = 0;
1138
1139 virtual DWORD MapGenericHandle(
1140 CORINFO_GENERIC_HANDLE handle
1141 ) = 0;
1142
1143 virtual DWORD MapModuleIDHandle(
1144 CORINFO_MODULE_HANDLE handle
1145 ) = 0;
1146
1147 // Load a method for the specified method def
1148 // If the class or method is generic, instantiate all parameters with <object>
1149 virtual CORINFO_METHOD_HANDLE LookupMethodDef(mdMethodDef token) = 0;
1150
1151 // For the given ftnHnd fill in the methInfo structure and return true if successful.
1152 virtual bool GetMethodInfo(mdMethodDef token, CORINFO_METHOD_HANDLE ftnHnd, CORINFO_METHOD_INFO * methInfo) = 0;
1153
1154 // Returns region that the IL should be emitted in
1155 virtual CorCompileILRegion GetILRegion(mdMethodDef token) = 0;
1156
1157 // Find the (parameterized) method for the given blob from the profile data
1158 virtual CORINFO_METHOD_HANDLE FindMethodForProfileEntry(CORBBTPROF_BLOB_PARAM_SIG_ENTRY * profileBlobEntry) = 0;
1159
1160 virtual void ReportInlining(CORINFO_METHOD_HANDLE inliner, CORINFO_METHOD_HANDLE inlinee) = 0;
1161
1162 //
1163 // Call Link when you want all the fixups
1164 // to be applied. You may call this e.g. after
1165 // compiling all the code for the module.
1166 // Return some stats about the types in the ngen image
1167 //
1168 virtual void Link() = 0;
1169
1170 virtual void FixupRVAs() = 0;
1171
1172 virtual void SetRVAsForFields(IMetaDataEmit * pEmit) = 0;
1173
1174 virtual void GetRVAFieldData(mdFieldDef fd, PVOID * ppData, DWORD * pcbSize, DWORD * pcbAlignment) = 0;
1175
1176 // The preloader also maintains a set of uncompiled generic
1177 // methods or methods in generic classes. A single method can be
1178 // registered or all the methods in a class can be registered.
1179 // The method is added to the set only if it should be compiled
1180 // into this ngen image
1181 //
1182 // The zapper registers methods and classes that are resolved by
1183 // findClass and findMethod during compilation
1184 virtual void AddMethodToTransitiveClosureOfInstantiations(CORINFO_METHOD_HANDLE handle) = 0;
1185 virtual void AddTypeToTransitiveClosureOfInstantiations(CORINFO_CLASS_HANDLE handle) = 0;
1186
1187 // Report reference to the given method from compiled code
1188 virtual void MethodReferencedByCompiledCode(CORINFO_METHOD_HANDLE handle) = 0;
1189
1190 virtual BOOL IsUncompiledMethod(CORINFO_METHOD_HANDLE handle) = 0;
1191
1192 // Return a method handle that was previously registered and
1193 // hasn't been compiled already, and remove it from the set
1194 // of uncompiled methods.
1195 // Return NULL if the set is empty
1196 virtual CORINFO_METHOD_HANDLE NextUncompiledMethod() = 0;
1197
1198 // Prepare a method and its statically determinable call graph if
1199 // a hint attribute has been applied. This is called to save
1200 // additional preparation information into the ngen image that
1201 // wouldn't normally be there (since we can't automatically
1202 // determine it's needed).
1203 virtual void PrePrepareMethodIfNecessary(CORINFO_METHOD_HANDLE hMethod) = 0;
1204
1205 // If a method requires stubs, this will call back passing method
1206 // handles for those stubs.
1207 virtual void GenerateMethodStubs(
1208 CORINFO_METHOD_HANDLE hMethod,
1209 bool fNgenProfileImage,
1210 CORCOMPILE_CompileStubCallback pfnCallback,
1211 LPVOID pCallbackContext) = 0;
1212
1213 // Determines whether or not a method is a dynamic method. This is used
1214 // to prevent operations that may require metadata knowledge at times other
1215 // than compile time.
1216 virtual bool IsDynamicMethod(CORINFO_METHOD_HANDLE hMethod) = 0;
1217
1218 // Set method profiling flags for layout of EE datastructures
1219 virtual void SetMethodProfilingFlags(CORINFO_METHOD_HANDLE hMethod, DWORD flags) = 0;
1220
1221 // Returns false if precompiled code must ensure that
1222 // the EE's DoPrestub function gets run before the
1223 // code for the method is used, i.e. if it returns false
1224 // then an indirect call must be made.
1225 //
1226 // Returning true does not guaratee that a direct call can be made:
1227 // there can be other reasons why the entry point cannot be embedded.
1228 //
1229 virtual bool CanSkipMethodPreparation (
1230 CORINFO_METHOD_HANDLE callerHnd, /* IN */
1231 CORINFO_METHOD_HANDLE calleeHnd, /* IN */
1232 CorInfoIndirectCallReason *pReason = NULL,
1233 CORINFO_ACCESS_FLAGS accessFlags = CORINFO_ACCESS_ANY) = 0;
1234
1235 virtual BOOL CanEmbedModuleHandle(
1236 CORINFO_MODULE_HANDLE moduleHandle) = 0;
1237
1238 // These check if we can hardbind to a handle. They guarantee either that
1239 // the structure referred to by the handle is in a referenced zapped image
1240 // or will be saved into the module currently being zapped. That is the
1241 // corresponding GetLoaderModuleForEmeddableXYZ call will return
1242 // either the module currently being zapped or a referenced zapped module.
1243 virtual BOOL CanEmbedClassID(CORINFO_CLASS_HANDLE typeHandle) = 0;
1244 virtual BOOL CanEmbedModuleID(CORINFO_MODULE_HANDLE moduleHandle) = 0;
1245 virtual BOOL CanEmbedClassHandle(CORINFO_CLASS_HANDLE typeHandle) = 0;
1246 virtual BOOL CanEmbedMethodHandle(CORINFO_METHOD_HANDLE methodHandle, CORINFO_METHOD_HANDLE contextHandle = NULL) = 0;
1247 virtual BOOL CanEmbedFieldHandle(CORINFO_FIELD_HANDLE fieldHandle) = 0;
1248
1249 // Return true if we can both embed a direct hardbind to the handle _and_
1250 // no "restore" action is needed on the handle. Equivalent to "CanEmbed + Prerestored".
1251 //
1252 // Typically a handle needs runtime restore it has embedded cross-module references
1253 // or other data that cannot be persisted directly.
1254 virtual BOOL CanPrerestoreEmbedClassHandle(
1255 CORINFO_CLASS_HANDLE classHnd) = 0;
1256
1257 // Return true if a method needs runtime restore
1258 // This is only the case if it is instantiated and any of its type arguments need restoring.
1259 virtual BOOL CanPrerestoreEmbedMethodHandle(
1260 CORINFO_METHOD_HANDLE methodHnd) = 0;
1261
1262 // Can a method entry point be embedded?
1263 virtual BOOL CanEmbedFunctionEntryPoint(
1264 CORINFO_METHOD_HANDLE methodHandle,
1265 CORINFO_METHOD_HANDLE contextHandle = NULL,
1266 CORINFO_ACCESS_FLAGS accessFlags = CORINFO_ACCESS_ANY
1267 ) = 0;
1268
1269 // Prestub is not able to handle method restore in all cases for generics.
1270 // If it is the case the method has to be restored explicitly upfront.
1271 // See the comment inside the implemenation method for more details.
1272 virtual BOOL DoesMethodNeedRestoringBeforePrestubIsRun(
1273 CORINFO_METHOD_HANDLE methodHandle
1274 ) = 0;
1275
1276 // Returns true if the given activation fixup is not necessary
1277 virtual BOOL CanSkipDependencyActivation(
1278 CORINFO_METHOD_HANDLE context,
1279 CORINFO_MODULE_HANDLE moduleFrom,
1280 CORINFO_MODULE_HANDLE moduleTo) = 0;
1281
1282 virtual CORINFO_MODULE_HANDLE GetPreferredZapModuleForClassHandle(
1283 CORINFO_CLASS_HANDLE classHnd
1284 ) = 0;
1285
1286 virtual void NoteDeduplicatedCode(
1287 CORINFO_METHOD_HANDLE method,
1288 CORINFO_METHOD_HANDLE duplicateMethod) = 0;
1289
1290#ifdef FEATURE_READYTORUN_COMPILER
1291 // Returns a compressed encoding of the inline tracking map
1292 // for this compilation
1293 virtual void GetSerializedInlineTrackingMap(
1294 IN OUT SBuffer * pSerializedInlineTrackingMap
1295 ) = 0;
1296#endif
1297
1298 //
1299 // Release frees the preloader
1300 //
1301
1302 virtual ULONG Release() = 0;
1303};
1304
1305//
1306// The DataImage provides several "sections", which can be used
1307// to sort data into different sets for locality control. The Arrange
1308// phase is responsible for placing items into sections.
1309//
1310
1311#define CORCOMPILE_SECTIONS() \
1312 CORCOMPILE_SECTION(MODULE) \
1313 CORCOMPILE_SECTION(WRITE) \
1314 CORCOMPILE_SECTION(METHOD_PRECODE_WRITE) \
1315 CORCOMPILE_SECTION(HOT_WRITEABLE) \
1316 CORCOMPILE_SECTION(WRITEABLE) \
1317 CORCOMPILE_SECTION(HOT) \
1318 CORCOMPILE_SECTION(METHOD_PRECODE_HOT) \
1319 CORCOMPILE_SECTION(RVA_STATICS_HOT) \
1320 CORCOMPILE_SECTION(RVA_STATICS_COLD) \
1321 CORCOMPILE_SECTION(WARM) \
1322 CORCOMPILE_SECTION(READONLY_SHARED_HOT) \
1323 CORCOMPILE_SECTION(READONLY_HOT) \
1324 CORCOMPILE_SECTION(READONLY_WARM) \
1325 CORCOMPILE_SECTION(READONLY_COLD) \
1326 CORCOMPILE_SECTION(READONLY_VCHUNKS) \
1327 CORCOMPILE_SECTION(READONLY_DICTIONARY) \
1328 CORCOMPILE_SECTION(CLASS_COLD) \
1329 CORCOMPILE_SECTION(CROSS_DOMAIN_INFO) \
1330 CORCOMPILE_SECTION(METHOD_PRECODE_COLD) \
1331 CORCOMPILE_SECTION(METHOD_PRECODE_COLD_WRITEABLE) \
1332 CORCOMPILE_SECTION(METHOD_DESC_COLD) \
1333 CORCOMPILE_SECTION(METHOD_DESC_COLD_WRITEABLE) \
1334 CORCOMPILE_SECTION(MODULE_COLD) \
1335 CORCOMPILE_SECTION(DEBUG_COLD) \
1336 CORCOMPILE_SECTION(COMPRESSED_MAPS) \
1337
1338enum CorCompileSection
1339{
1340#define CORCOMPILE_SECTION(section) CORCOMPILE_SECTION_##section,
1341 CORCOMPILE_SECTIONS()
1342#undef CORCOMPILE_SECTION
1343
1344 CORCOMPILE_SECTION_COUNT
1345};
1346
1347enum VerboseLevel
1348{
1349 CORCOMPILE_NO_LOG,
1350 CORCOMPILE_STATS,
1351 CORCOMPILE_VERBOSE
1352};
1353
1354class ZapImage;
1355
1356// When NGEN install /Profile is run, the ZapProfilingHandleImport fixup table contains
1357// these 5 values per MethodDesc
1358enum
1359{
1360 kZapProfilingHandleImportValueIndexFixup = 0,
1361 kZapProfilingHandleImportValueIndexEnterAddr = 1,
1362 kZapProfilingHandleImportValueIndexLeaveAddr = 2,
1363 kZapProfilingHandleImportValueIndexTailcallAddr = 3,
1364 kZapProfilingHandleImportValueIndexClientData = 4,
1365
1366 kZapProfilingHandleImportValueIndexCount
1367};
1368
1369class ICorCompileDataStore
1370{
1371 public:
1372 // Returns ZapImage
1373 virtual ZapImage * GetZapImage() = 0;
1374
1375 // Report an error during preloading:
1376 // 'token' is the metadata token that triggered the error
1377 // hr is the HRESULT from the thrown Exception, or S_OK if we don't have an thrown exception
1378 // resID is the resourceID with additional information from the thrown Exception, or 0
1379 //
1380 virtual void Error(mdToken token, HRESULT hr, UINT _resID, LPCWSTR description) = 0;
1381};
1382
1383
1384class ICorCompilationDomain
1385{
1386 public:
1387
1388 // Sets the application context for fusion
1389 // to use when binding, using a shell exe file path
1390 virtual HRESULT SetContextInfo(
1391 LPCWSTR path,
1392 BOOL isExe
1393 ) = 0;
1394
1395 // Retrieves the dependencies of the code which
1396 // has been compiled
1397 virtual HRESULT GetDependencies(
1398 CORCOMPILE_DEPENDENCY **ppDependencies,
1399 DWORD *cDependencies
1400 ) = 0;
1401
1402
1403#ifdef CROSSGEN_COMPILE
1404 virtual HRESULT SetPlatformWinmdPaths(
1405 LPCWSTR pwzPlatformWinmdPaths
1406 ) = 0;
1407#endif
1408};
1409
1410/*********************************************************************************
1411 * ICorCompileInfo is the interface for a compiler
1412 *********************************************************************************/
1413// Define function pointer ENCODEMODULE_CALLBACK
1414typedef DWORD (*ENCODEMODULE_CALLBACK)(LPVOID pModuleContext, CORINFO_MODULE_HANDLE moduleHandle);
1415
1416// Define function pointer DEFINETOKEN_CALLBACK
1417typedef void (*DEFINETOKEN_CALLBACK)(LPVOID pModuleContext, CORINFO_MODULE_HANDLE moduleHandle, DWORD index, mdTypeRef* token);
1418
1419typedef HRESULT (*CROSS_DOMAIN_CALLBACK)(LPVOID pArgs);
1420
1421class ICorCompileInfo
1422{
1423 public:
1424
1425
1426 //
1427 // Currently no other instance of the EE may be running inside
1428 // a process that is used as an NGEN compilation process.
1429 //
1430 // So, the host must call StartupAsCompilationProcess before compiling
1431 // any code, and Shutdown after finishing.
1432 //
1433 // The arguments control which native image of mscorlib to use.
1434 // This matters for hardbinding.
1435 //
1436
1437 virtual HRESULT Startup(
1438 BOOL fForceDebug,
1439 BOOL fForceProfiling,
1440 BOOL fForceInstrument) = 0;
1441
1442 // Creates a new compilation domain
1443 // The BOOL arguments control what kind of a native image is
1444 // to be generated. Other factors affect what kind of a native image
1445 // will actually be generated. GetAssemblyVersionInfo() ultimately reflects
1446 // the kind of native image that will be generated
1447 //
1448 // pEmitter - sets this as the emitter to use when generating tokens for
1449 // the dependency list. If this is NULL, dependencies won't be computed.
1450
1451 virtual HRESULT CreateDomain(
1452 ICorCompilationDomain **ppDomain, // [OUT]
1453 IMetaDataAssemblyEmit *pEmitter,
1454 BOOL fForceDebug,
1455 BOOL fForceProfiling,
1456 BOOL fForceInstrument
1457 ) = 0;
1458
1459 // calls pfnCallback in the specified domain
1460 virtual HRESULT MakeCrossDomainCallback(
1461 ICorCompilationDomain* pDomain,
1462 CROSS_DOMAIN_CALLBACK pfnCallback,
1463 LPVOID pArgs
1464 ) = 0;
1465
1466 // Destroys a compilation domain
1467 virtual HRESULT DestroyDomain(
1468 ICorCompilationDomain *pDomain
1469 ) = 0;
1470
1471 // Loads an assembly manifest module into the EE
1472 // and returns a handle to it.
1473 virtual HRESULT LoadAssemblyByPath(
1474 LPCWSTR wzPath,
1475 BOOL fExplicitBindToNativeImage,
1476 CORINFO_ASSEMBLY_HANDLE *pHandle
1477 ) = 0;
1478
1479
1480#ifdef FEATURE_COMINTEROP
1481 // Loads a WinRT typeref into the EE and returns
1482 // a handle to it. We have to load all typerefs
1483 // during dependency computation since assemblyrefs
1484 // are meaningless to WinRT.
1485 virtual HRESULT LoadTypeRefWinRT(
1486 IMDInternalImport *pAssemblyImport,
1487 mdTypeRef ref,
1488 CORINFO_ASSEMBLY_HANDLE *pHandle
1489 ) = 0;
1490#endif
1491
1492 virtual BOOL IsInCurrentVersionBubble(CORINFO_MODULE_HANDLE hModule) = 0;
1493
1494 // Loads a module from an assembly into the EE
1495 // and returns a handle to it.
1496 virtual HRESULT LoadAssemblyModule(
1497 CORINFO_ASSEMBLY_HANDLE assembly,
1498 mdFile file,
1499 CORINFO_MODULE_HANDLE *pHandle
1500 ) = 0;
1501
1502
1503 // Checks to see if an up to date zap exists for the
1504 // assembly
1505 virtual BOOL CheckAssemblyZap(
1506 CORINFO_ASSEMBLY_HANDLE assembly,
1507 __out_ecount_opt(*cAssemblyManifestModulePath)
1508 LPWSTR assemblyManifestModulePath,
1509 LPDWORD cAssemblyManifestModulePath
1510 ) = 0;
1511
1512 // Sets up the compilation target in the EE
1513 virtual HRESULT SetCompilationTarget(
1514 CORINFO_ASSEMBLY_HANDLE assembly,
1515 CORINFO_MODULE_HANDLE module
1516 ) = 0;
1517
1518
1519 // Returns the dependency load setting for an assembly ref
1520 virtual HRESULT GetLoadHint(
1521 CORINFO_ASSEMBLY_HANDLE hAssembly,
1522 CORINFO_ASSEMBLY_HANDLE hAssemblyDependency,
1523 LoadHintEnum *loadHint,
1524 LoadHintEnum *defaultLoadHint = NULL
1525 ) = 0;
1526
1527 // Returns information on how the assembly has been loaded
1528 virtual HRESULT GetAssemblyVersionInfo(
1529 CORINFO_ASSEMBLY_HANDLE hAssembly,
1530 CORCOMPILE_VERSION_INFO *pInfo
1531 ) = 0;
1532
1533 // Returns the manifest metadata for an assembly
1534 // Use the internal IMDInternalImport for performance.
1535 // Creation of the public IMetaDataImport * triggers
1536 // conversion to R/W metadata that slows down all subsequent accesses.
1537 virtual IMDInternalImport * GetAssemblyMetaDataImport(
1538 CORINFO_ASSEMBLY_HANDLE assembly
1539 ) = 0;
1540
1541 // Returns an interface to query the metadata for a loaded module
1542 // Use the internal IMDInternalImport for performance.
1543 // Creation of the public IMetaDataAssemblyImport * triggers
1544 // conversion to R/W metadata that slows down all subsequent accesses.
1545 virtual IMDInternalImport * GetModuleMetaDataImport(
1546 CORINFO_MODULE_HANDLE module
1547 ) = 0;
1548
1549 // Returns the module of the assembly which contains the manifest,
1550 // or NULL if the manifest is standalone.
1551 virtual CORINFO_MODULE_HANDLE GetAssemblyModule(
1552 CORINFO_ASSEMBLY_HANDLE assembly
1553 ) = 0;
1554
1555 // Returns the assembly of a loaded module
1556 virtual CORINFO_ASSEMBLY_HANDLE GetModuleAssembly(
1557 CORINFO_MODULE_HANDLE module
1558 ) = 0;
1559
1560 // Returns the current PEDecoder of a loaded module.
1561 virtual PEDecoder * GetModuleDecoder(
1562 CORINFO_MODULE_HANDLE module
1563 ) = 0;
1564
1565 // Gets the full file name, including path, of a loaded module
1566 virtual void GetModuleFileName(
1567 CORINFO_MODULE_HANDLE module,
1568 SString &result
1569 ) = 0;
1570
1571 // Get a class def token
1572 virtual HRESULT GetTypeDef(
1573 CORINFO_CLASS_HANDLE classHandle,
1574 mdTypeDef *token
1575 ) = 0;
1576
1577 // Get a method def token
1578 virtual HRESULT GetMethodDef(
1579 CORINFO_METHOD_HANDLE methodHandle,
1580 mdMethodDef *token
1581 ) = 0;
1582
1583 // Get a field def token
1584 virtual HRESULT GetFieldDef(
1585 CORINFO_FIELD_HANDLE fieldHandle,
1586 mdFieldDef *token
1587 ) = 0;
1588
1589 // Get the loader module for mscorlib
1590 virtual CORINFO_MODULE_HANDLE GetLoaderModuleForMscorlib() = 0;
1591
1592 // Get the loader module for a type (where the type is regarded as
1593 // living for the purposes of loading, unloading, and ngen).
1594 //
1595 // classHandle must have passed CanEmbedClassHandle, since the zapper
1596 // should only care about the module where a type
1597 // prefers to be saved if it knows that that module is either
1598 // an zapped module or is the module currently being compiled.
1599 // See vm\ceeload.h for more information
1600 virtual CORINFO_MODULE_HANDLE GetLoaderModuleForEmbeddableType(
1601 CORINFO_CLASS_HANDLE classHandle
1602 ) = 0;
1603
1604 // Get the loader module for a method (where the method is regarded as
1605 // living for the purposes of loading, unloading, and ngen)
1606 //
1607 // methodHandle must have passed CanEmbedMethodHandle, since the zapper
1608 // should only care about the module where a type
1609 // prefers to be saved if it knows that that module is either
1610 // an zapped module or is the module currently being compiled.
1611 // See vm\ceeload.h for more information
1612 virtual CORINFO_MODULE_HANDLE GetLoaderModuleForEmbeddableMethod(
1613 CORINFO_METHOD_HANDLE methodHandle
1614 ) = 0;
1615
1616 // Get the loader module for a method (where the method is regarded as
1617 // living for the purposes of loading, unloading, and ngen)
1618 // See vm\ceeload.h for more information
1619 virtual CORINFO_MODULE_HANDLE GetLoaderModuleForEmbeddableField(
1620 CORINFO_FIELD_HANDLE fieldHandle
1621 ) = 0;
1622
1623 // Set the list of assemblies we can hard bind to
1624 virtual void SetAssemblyHardBindList(
1625 __in_ecount(cHardBindList)
1626 LPWSTR * pHardBindList,
1627 DWORD cHardBindList
1628 ) = 0;
1629
1630 // Encode a module for the imports table
1631 virtual void EncodeModuleAsIndex(
1632 CORINFO_MODULE_HANDLE fromHandle,
1633 CORINFO_MODULE_HANDLE handle,
1634 DWORD *pIndex,
1635 IMetaDataAssemblyEmit *pAssemblyEmit) = 0;
1636
1637
1638 // Encode a class into the given SigBuilder.
1639 virtual void EncodeClass(
1640 CORINFO_MODULE_HANDLE referencingModule,
1641 CORINFO_CLASS_HANDLE classHandle,
1642 SigBuilder * pSigBuilder,
1643 LPVOID encodeContext,
1644 ENCODEMODULE_CALLBACK pfnEncodeModule) = 0;
1645
1646 // Encode a method into the given SigBuilder.
1647 virtual void EncodeMethod(
1648 CORINFO_MODULE_HANDLE referencingModule,
1649 CORINFO_METHOD_HANDLE handle,
1650 SigBuilder * pSigBuilder,
1651 LPVOID encodeContext,
1652 ENCODEMODULE_CALLBACK pfnEncodeModule,
1653 CORINFO_RESOLVED_TOKEN * pResolvedToken = NULL,
1654 CORINFO_RESOLVED_TOKEN * pConstrainedResolvedToken = NULL,
1655 BOOL fEncodeUsingResolvedTokenSpecStreams = FALSE) = 0;
1656
1657 // Returns non-null methoddef or memberref token if it is sufficient to encode the method (no generic instantiations, etc.)
1658 virtual mdToken TryEncodeMethodAsToken(
1659 CORINFO_METHOD_HANDLE handle,
1660 CORINFO_RESOLVED_TOKEN * pResolvedToken,
1661 CORINFO_MODULE_HANDLE * referencingModule) = 0;
1662
1663 // Returns method slot (for encoding virtual stub dispatch)
1664 virtual DWORD TryEncodeMethodSlot(
1665 CORINFO_METHOD_HANDLE handle) = 0;
1666
1667 // Encode a field into the given SigBuilder.
1668 virtual void EncodeField(
1669 CORINFO_MODULE_HANDLE referencingModule,
1670 CORINFO_FIELD_HANDLE handle,
1671 SigBuilder * pSigBuilder,
1672 LPVOID encodeContext,
1673 ENCODEMODULE_CALLBACK pfnEncodeModule,
1674 CORINFO_RESOLVED_TOKEN * pResolvedToken = NULL,
1675 BOOL fEncodeUsingResolvedTokenSpecStreams = FALSE) = 0;
1676
1677
1678 // Encode generic dictionary signature
1679 virtual void EncodeGenericSignature(
1680 LPVOID signature,
1681 BOOL fMethod,
1682 SigBuilder * pSigBuilder,
1683 LPVOID encodeContext,
1684 ENCODEMODULE_CALLBACK pfnEncodeModule) = 0;
1685
1686
1687 virtual BOOL IsEmptyString(
1688 mdString token,
1689 CORINFO_MODULE_HANDLE module) = 0;
1690
1691
1692 // Preload a modules' EE data structures
1693 // directly into an executable image
1694
1695 virtual ICorCompilePreloader * PreloadModule(
1696 CORINFO_MODULE_HANDLE moduleHandle,
1697 ICorCompileDataStore *pData,
1698 CorProfileData *profileData
1699 ) = 0;
1700
1701 // Gets the codebase URL for the assembly
1702 virtual void GetAssemblyCodeBase(
1703 CORINFO_ASSEMBLY_HANDLE hAssembly,
1704 SString &result) = 0;
1705
1706 // Returns the GC-information for a method. This is the simple representation
1707 // and can be used when a code that can trigger a GC does not have access
1708 // to the CORINFO_METHOD_HANDLE (which is normally used to access the GC information)
1709 //
1710 // Returns S_FALSE if there is no simple representation for the method's GC info
1711 //
1712 virtual void GetCallRefMap(
1713 CORINFO_METHOD_HANDLE hMethod,
1714 GCRefMapBuilder * pBuilder,
1715 bool isDispatchCell) = 0;
1716
1717 // Returns a compressed block of debug information
1718 //
1719 // Uncompressed debug maps are passed in.
1720 // Writes to outgoing SBuffer.
1721 // Throws on failure.
1722 virtual void CompressDebugInfo(
1723 IN ICorDebugInfo::OffsetMapping * pOffsetMapping,
1724 IN ULONG iOffsetMapping,
1725 IN ICorDebugInfo::NativeVarInfo * pNativeVarInfo,
1726 IN ULONG iNativeVarInfo,
1727 IN OUT SBuffer * pDebugInfoBuffer
1728 ) = 0;
1729
1730
1731
1732 // Allows to set verbose level for log messages, enabled in retail build too for stats
1733 virtual HRESULT SetVerboseLevel(
1734 IN VerboseLevel level) = 0;
1735
1736 // Get the compilation flags that are shared between JIT and NGen
1737 virtual HRESULT GetBaseJitFlags(
1738 IN CORINFO_METHOD_HANDLE hMethod,
1739 OUT CORJIT_FLAGS *pFlags) = 0;
1740
1741 virtual ICorJitHost* GetJitHost() = 0;
1742
1743 // needed for stubs to obtain the number of bytes to copy into the native image
1744 // return the beginning of the stub and the size to copy (in bytes)
1745 virtual void* GetStubSize(void *pStubAddress, DWORD *pSizeToCopy) = 0;
1746
1747 // Takes a stub and blits it into the buffer, resetting the reference count
1748 // to 1 on the clone. The buffer has to be large enough to hold the stub object and the code
1749 virtual HRESULT GetStubClone(void *pStub, BYTE *pBuffer, DWORD dwBufferSize) = 0;
1750
1751 // true if the method has [NativeCallableAttribute]
1752 virtual BOOL IsNativeCallableMethod(CORINFO_METHOD_HANDLE handle) = 0;
1753
1754 virtual BOOL GetIsGeneratingNgenPDB() = 0;
1755 virtual void SetIsGeneratingNgenPDB(BOOL fGeneratingNgenPDB) = 0;
1756
1757#ifdef FEATURE_READYTORUN_COMPILER
1758 virtual CORCOMPILE_FIXUP_BLOB_KIND GetFieldBaseOffset(
1759 CORINFO_CLASS_HANDLE classHnd,
1760 DWORD * pBaseOffset
1761 ) = 0;
1762
1763 virtual BOOL NeedsTypeLayoutCheck(CORINFO_CLASS_HANDLE classHnd) = 0;
1764 virtual void EncodeTypeLayout(CORINFO_CLASS_HANDLE classHandle, SigBuilder * pSigBuilder) = 0;
1765
1766 virtual BOOL AreAllClassesFullyLoaded(CORINFO_MODULE_HANDLE moduleHandle) = 0;
1767
1768 virtual int GetVersionResilientTypeHashCode(CORINFO_MODULE_HANDLE moduleHandle, mdToken token) = 0;
1769
1770 virtual int GetVersionResilientMethodHashCode(CORINFO_METHOD_HANDLE methodHandle) = 0;
1771#endif
1772
1773 virtual BOOL HasCustomAttribute(CORINFO_METHOD_HANDLE method, LPCSTR customAttributeName) = 0;
1774};
1775
1776/*****************************************************************************/
1777// This function determines the compile flags to use for a generic intatiation
1778// since only the open instantiation can be verified.
1779// See the comment associated with CORJIT_FLAG_SKIP_VERIFICATION for details.
1780//
1781// On return:
1782// if *raiseVerificationException=TRUE, the caller should raise a VerificationException.
1783// if *unverifiableGenericCode=TRUE, the method is a generic instantiation with
1784// unverifiable code
1785
1786CORJIT_FLAGS GetCompileFlagsIfGenericInstantiation(
1787 CORINFO_METHOD_HANDLE method,
1788 CORJIT_FLAGS compileFlags,
1789 ICorJitInfo * pCorJitInfo,
1790 BOOL * raiseVerificationException,
1791 BOOL * unverifiableGenericCode);
1792
1793// Returns the global instance of JIT->EE interface for NGen
1794
1795extern "C" ICorDynamicInfo * __stdcall GetZapJitInfo();
1796
1797// Returns the global instance of Zapper->EE interface
1798
1799extern "C" ICorCompileInfo * __stdcall GetCompileInfo();
1800
1801// Stress mode to leave some methods/types uncompiled in the ngen image.
1802// Those methods will be JIT-compiled at runtime as needed.
1803
1804extern "C" unsigned __stdcall PartialNGenStressPercentage();
1805
1806// create a PDB dumping all functions in hAssembly into pdbPath
1807extern "C" HRESULT __stdcall CreatePdb(CORINFO_ASSEMBLY_HANDLE hAssembly, BSTR pNativeImagePath, BSTR pPdbPath, BOOL pdbLines, BSTR pManagedPdbSearchPath, LPCWSTR pDiasymreaderPath);
1808
1809extern bool g_fNGenMissingDependenciesOk;
1810
1811extern bool g_fNGenWinMDResilient;
1812
1813#ifdef FEATURE_READYTORUN_COMPILER
1814extern bool g_fReadyToRunCompilation;
1815#endif
1816
1817inline bool IsReadyToRunCompilation()
1818{
1819#ifdef FEATURE_READYTORUN_COMPILER
1820 return g_fReadyToRunCompilation;
1821#else
1822 return false;
1823#endif
1824}
1825
1826#endif /* COR_COMPILE_H_ */
1827