-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathmethodcontext.cpp
7150 lines (6204 loc) · 282 KB
/
methodcontext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
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.
//----------------------------------------------------------
// MethodContext.cpp - Primary structure to store all the EE-JIT details required to replay creation of a method
// CompileResult contains the stuff generated by a compilation
//----------------------------------------------------------
#include "standardpch.h"
#include "methodcontext.h"
#include "compileresult.h"
#include "lightweightmap.h"
#include "callutils.h"
#include "spmirecordhelper.h"
#include "spmidumphelper.h"
#include "spmiutil.h"
#define sparseMC // Support filling in details where guesses are okay and will still generate good code. (i.e. helper
// function addresses)
// static variable initialization
Hash MethodContext::m_hash;
MethodContext::MethodContext()
{
methodSize = 0;
#define LWM(map, key, value) map = nullptr;
#include "lwmlist.h"
cr = new CompileResult();
index = -1;
isReadyToRunCompilation = ReadyToRunCompilation::Uninitialized;
}
MethodContext::~MethodContext()
{
Destroy();
}
void MethodContext::Destroy()
{
#define LWM(map, key, value) \
if (map != nullptr) \
delete map;
#include "lwmlist.h"
delete cr;
FreeTempAllocations();
}
#define sparseAddLen(target) \
if (target != nullptr) \
{ \
if (target->GetCount() != 0) \
totalLen += target->CalculateArraySize() + 6; /* packet canary from lightweightmap + packet marker */ \
}
#define sparseWriteFile(target) \
if (target != nullptr) \
{ \
if (target->GetCount() != 0) \
{ \
buff2[buffIndex++] = (unsigned char)Packet_##target; \
unsigned int loc = target->DumpToArray(&buff2[buffIndex + 4]); \
memcpy(&buff2[buffIndex], &loc, sizeof(unsigned int)); \
buffIndex += 4 + loc; \
buff2[buffIndex++] = 0x42; \
} \
}
#define sparseWriteFileCR(target) \
if (cr != nullptr) \
{ \
if (cr->target != nullptr) \
{ \
if (cr->target->GetCount() != 0) \
{ \
buff2[buffIndex++] = (unsigned char)PacketCR_##target; \
unsigned int loc = cr->target->DumpToArray(&buff2[buffIndex + 4]); \
memcpy(&buff2[buffIndex], &loc, sizeof(unsigned int)); \
buffIndex += 4 + loc; \
buff2[buffIndex++] = 0x42; \
} \
} \
}
#define sparseReadFile(target, key, value) \
case Packet_##target: \
{ \
target = new LightWeightMap<key, value>(); \
target->ReadFromArray(&buff2[buffIndex], localsize); \
break; \
}
#define sparseReadFileCR(target, key, value) \
case PacketCR_##target: \
{ \
cr->target = new LightWeightMap<key, value>(); \
cr->target->ReadFromArray(&buff2[buffIndex], localsize); \
break; \
}
#define sparseReadFileDense(target, value) \
case Packet_##target: \
{ \
target = new DenseLightWeightMap<value>(); \
target->ReadFromArray(&buff2[buffIndex], localsize); \
break; \
}
#define sparseReadFileCRDense(target, value) \
case PacketCR_##target: \
{ \
cr->target = new DenseLightWeightMap<value>(); \
cr->target->ReadFromArray(&buff2[buffIndex], localsize); \
break; \
}
unsigned int MethodContext::calculateFileSize()
{
// Calculate file size
unsigned int totalLen = 0;
#define LWM(map, key, value) sparseAddLen(map)
#include "lwmlist.h"
// Compile Result members
if (cr != nullptr)
{
#define LWM(map, key, value) sparseAddLen(cr->map);
#include "crlwmlist.h"
}
return totalLen;
}
unsigned int MethodContext::calculateRawFileSize()
{
return 2 /* leading magic cookie 'm', 'c' */ + 4 /* 4-byte data length */ + calculateFileSize() +
2 /* end canary '4', '2' */;
}
unsigned int MethodContext::saveToFile(HANDLE hFile)
{
unsigned int totalLen = calculateFileSize();
unsigned int totalFileSize =
2 /* leading magic cookie 'm', 'c' */ + 4 /* 4-byte data length */ + totalLen + 2 /* end canary '4', '2' */;
DWORD bytesWritten = 0;
unsigned int buffIndex = 0;
unsigned char* buff2 = new unsigned char[totalFileSize];
buff2[buffIndex++] = 'm';
buff2[buffIndex++] = 'c';
memcpy(&buff2[buffIndex], &totalLen, sizeof(unsigned int));
buffIndex += 4;
#define LWM(map, key, value) sparseWriteFile(map)
#include "lwmlist.h"
// Compile Result members
#define LWM(map, key, value) sparseWriteFileCR(map);
#include "crlwmlist.h"
// Write the end canary
buff2[buffIndex++] = '4';
buff2[buffIndex++] = '2';
Assert(buffIndex == totalFileSize);
WriteFile(hFile, buff2, totalFileSize, &bytesWritten, NULL);
delete[] buff2;
return bytesWritten;
}
// This code can't exist in a function with C++ objects needing destruction. Returns true on success
// (and sets *ppmc with new MethodContext), false on failure.
//
// static
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc)
{
MethodContext* mc = new MethodContext();
mc->index = mcIndex;
*ppmc = mc;
return mc->Initialize(mcIndex, buff, size);
}
// static
bool MethodContext::Initialize(int mcIndex, HANDLE hFile, /* OUT */ MethodContext** ppmc)
{
MethodContext* mc = new MethodContext();
mc->index = mcIndex;
*ppmc = mc;
return mc->Initialize(mcIndex, hFile);
}
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size)
{
bool result = true;
struct Param
{
unsigned char* buff;
DWORD size;
MethodContext* pThis;
} param;
param.buff = buff;
param.size = size;
param.pThis = this;
PAL_TRY(Param*, pParam, ¶m)
{
pParam->pThis->MethodInitHelper(pParam->buff, pParam->size);
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CatchMC)
{
LogError("Method %d is of low integrity.", mcIndex);
result = false;
}
PAL_ENDTRY
return result;
}
bool MethodContext::Initialize(int mcIndex, HANDLE hFile)
{
bool result = true;
struct Param
{
HANDLE hFile;
MethodContext* pThis;
} param;
param.hFile = hFile;
param.pThis = this;
PAL_TRY(Param*, pParam, ¶m)
{
pParam->pThis->MethodInitHelperFile(pParam->hFile);
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CatchMC)
{
LogError("Method %d is of low integrity.", mcIndex);
result = false;
}
PAL_ENDTRY
return result;
}
void MethodContext::MethodInitHelperFile(HANDLE hFile)
{
DWORD bytesRead;
char buff[512];
unsigned int totalLen = 0;
AssertCode(ReadFile(hFile, buff, 2 + sizeof(unsigned int), &bytesRead, NULL) == TRUE,
EXCEPTIONCODE_MC); // Read Magic number and totalLen
AssertCodeMsg((buff[0] == 'm') && (buff[1] == 'c'), EXCEPTIONCODE_MC, "Didn't find magic number");
memcpy(&totalLen, &buff[2], sizeof(unsigned int));
unsigned char* buff2 = new unsigned char[totalLen + 2]; // total + End Canary
AssertCode(ReadFile(hFile, buff2, totalLen + 2, &bytesRead, NULL) == TRUE, EXCEPTIONCODE_MC);
AssertCodeMsg((buff2[totalLen] == '4') && (buff2[totalLen + 1] == '2'), EXCEPTIONCODE_MC, "Didn't find end canary");
MethodInitHelper(buff2, totalLen);
}
void MethodContext::MethodInitHelper(unsigned char* buff2, unsigned int totalLen)
{
unsigned int buffIndex = 0;
unsigned int localsize = 0;
unsigned char canary = 0xff;
unsigned char* buff3 = nullptr;
FreeTempAllocations();
while (buffIndex < totalLen)
{
mcPackets packetType = (mcPackets)buff2[buffIndex++];
memcpy(&localsize, &buff2[buffIndex], sizeof(unsigned int));
buffIndex += sizeof(unsigned int);
switch (packetType)
{
#define LWM(map, key, value) sparseReadFile(map, key, value)
#define DENSELWM(map, value) sparseReadFileDense(map, value)
#include "lwmlist.h"
#define LWM(map, key, value) sparseReadFileCR(map, key, value)
#define DENSELWM(map, value) sparseReadFileCRDense(map, value)
#include "crlwmlist.h"
default:
LogException(EXCEPTIONCODE_MC, "Read ran into unknown packet type %u. Are you using a newer recorder?",
packetType);
// break;
}
buffIndex += localsize;
canary = buff2[buffIndex++];
AssertCodeMsg(canary == 0x42, EXCEPTIONCODE_MC, "Didn't find trailing canary for map");
}
AssertCodeMsg((buff2[buffIndex++] == '4') && (buff2[buffIndex++] == '2'), EXCEPTIONCODE_MC,
"Didn't find trailing canary for map");
delete[] buff2;
}
#define dumpStat(target) \
if (target != nullptr) \
{ \
if (target->GetCount() > 0) \
{ \
int t = sprintf_s(buff, len, "%u", target->GetCount()); \
buff += t; \
len -= t; \
} \
} \
{ \
*buff++ = ','; \
len--; \
} \
if (target != nullptr) \
{ \
int t = sprintf_s(buff, len, "%u", target->CalculateArraySize()); \
buff += t; \
len -= t; \
} \
{ \
*buff++ = ','; \
len--; \
}
// Dump statistics about each LightWeightMap to the buffer: count of elements, and total size in bytes of map.
int MethodContext::dumpStatToBuffer(char* buff, int len)
{
char* obuff = buff;
// assumption of enough buffer.. :-|
#define LWM(map, key, value) dumpStat(map)
#include "lwmlist.h"
// Compile Result members
#define LWM(map, key, value) dumpStat(cr->map);
#include "crlwmlist.h"
return (int)(buff - obuff);
}
int MethodContext::dumpStatTitleToBuffer(char* buff, int len)
{
const char* title =
#define LWM(map, key, value) #map "," #map " SZ,"
#include "lwmlist.h"
#define LWM(map, key, value) "CR_" #map ",CR_" #map " SZ,"
#include "crlwmlist.h"
;
int titleLen = (int)strlen(title);
if ((titleLen + 1) > len)
{
LogError("titleLen is larger than given len");
return 0;
}
strcpy_s(buff, len, title);
return titleLen;
}
#define softMapEqual(a) \
if (a != nullptr) \
{ \
if (other->a == nullptr) \
return false; \
if (a->GetCount() != other->a->GetCount()) \
return false; \
} \
else if (other->a != nullptr) \
return false;
bool MethodContext::Equal(MethodContext* other)
{
// returns true if equal. Note this is permissive, that is to say that we may reason that too many things are
// equal. Adding more detailed checks would cause us to reason more things as unique;
// Compare MethodInfo's first.
CORINFO_METHOD_INFO otherInfo;
unsigned otherFlags = 0;
other->repCompileMethod(&otherInfo, &otherFlags);
CORINFO_METHOD_INFO ourInfo;
unsigned ourFlags = 0;
repCompileMethod(&ourInfo, &ourFlags);
if (otherInfo.ILCodeSize != ourInfo.ILCodeSize)
return false;
if (otherInfo.args.numArgs != ourInfo.args.numArgs)
return false;
if (otherInfo.args.retType != ourInfo.args.retType)
return false;
if (otherInfo.locals.numArgs != ourInfo.locals.numArgs)
return false;
if (otherInfo.EHcount != ourInfo.EHcount)
return false;
if (otherInfo.options != ourInfo.options)
return false;
for (unsigned int j = 0; j < otherInfo.ILCodeSize; j++)
if (otherInfo.ILCode[j] != ourInfo.ILCode[j])
return false;
if (otherInfo.maxStack != ourInfo.maxStack)
return false;
if (otherInfo.regionKind != ourInfo.regionKind)
return false;
if (otherInfo.args.callConv != ourInfo.args.callConv)
return false;
if (otherInfo.args.cbSig != ourInfo.args.cbSig)
return false;
if (otherInfo.args.flags != ourInfo.args.flags)
return false;
if (otherInfo.locals.cbSig != ourInfo.locals.cbSig)
return false;
if (otherFlags != ourFlags)
return false;
// Now compare the other maps to "estimate" equality.
#define LWM(map, key, value) softMapEqual(map)
#include "lwmlist.h"
// Compile Result members
#define LWM(map, key, value) softMapEqual(cr->map)
#include "crlwmlist.h"
// Base case is we "match"
return true;
}
//------------------------------------------------------------------------------
// MethodContext::recGlobalContext
// This method copies any relevant global (i.e. per-JIT-instance) data from
// the given method context. Currently this is limited to configuration
// values, but may grow to encompass other information in the future (e.g.
// any information that is exposed by the ICorJitHost interface and is
// therefore accessible outside the context of a call to
// `ICJI::compileMethod`).
//
// This method is intended to be called as part of initializing a method
// during collection.
void MethodContext::recGlobalContext(const MethodContext& other)
{
Assert(GetIntConfigValue == nullptr);
Assert(GetStringConfigValue == nullptr);
if (other.GetIntConfigValue != nullptr)
{
GetIntConfigValue = new LightWeightMap<Agnostic_ConfigIntInfo, DWORD>(*other.GetIntConfigValue);
}
if (other.GetStringConfigValue != nullptr)
{
GetStringConfigValue = new LightWeightMap<DWORD, DWORD>(*other.GetStringConfigValue);
}
}
// dumpToConsole: Display the method context numbered `mcNumber` to the console. If `simple` is true,
// dump without function name information. This is useful to debug problems with the creation of that
// information, which requires looking at the dumped info.
void MethodContext::dumpToConsole(int mcNumber, bool simple)
{
printf("*****************************************");
if (mcNumber != -1)
{
printf(" method context #%d", mcNumber);
}
if (!simple)
{
// Dump method name, etc., to output.
char bufferIdentityInfo[METHOD_IDENTITY_INFO_SIZE];
int cbLen = dumpMethodIdentityInfoToBuffer(bufferIdentityInfo, METHOD_IDENTITY_INFO_SIZE);
if (cbLen >= 0)
{
printf(" %s", bufferIdentityInfo);
}
}
printf("\n");
#define LWM(map, key, value) dumpLWM(this, map)
#define DENSELWM(map, value) dumpLWMDense(this, map)
#include "lwmlist.h"
// Compile Result members
#define LWM(map, key, value) dumpLWM(this->cr, map)
#define DENSELWM(map, value) dumpLWMDense(this->cr, map)
#include "crlwmlist.h"
}
const char* toString(InfoAccessType iat)
{
switch (iat)
{
case IAT_VALUE:
return "VALUE";
case IAT_PVALUE:
return "PVALUE";
case IAT_PPVALUE:
return "PPVALUE";
case IAT_RELPVALUE:
return "RELPVALUE";
default:
return "UNKNOWN";
}
};
const char* toString(CORINFO_CALL_KIND cick)
{
switch (cick)
{
case CORINFO_CALL:
return "CALL";
case CORINFO_CALL_CODE_POINTER:
return "CALL_CODE_POINTER";
case CORINFO_VIRTUALCALL_STUB:
return "VIRTUALCALL_STUB";
case CORINFO_VIRTUALCALL_LDVIRTFTN:
return "VIRTUALCALL_LDVIRTFTN";
case CORINFO_VIRTUALCALL_VTABLE:
return "VIRTUALCALL_VTABLE";
default:
return "UNKNOWN";
}
};
const char* toString(CorInfoType cit)
{
switch (cit)
{
case CORINFO_TYPE_UNDEF:
return "undef";
case CORINFO_TYPE_VOID:
return "void";
case CORINFO_TYPE_BOOL:
return "bool";
case CORINFO_TYPE_CHAR:
return "char";
case CORINFO_TYPE_BYTE:
return "byte";
case CORINFO_TYPE_UBYTE:
return "ubyte";
case CORINFO_TYPE_SHORT:
return "short";
case CORINFO_TYPE_USHORT:
return "ushort";
case CORINFO_TYPE_INT:
return "int";
case CORINFO_TYPE_UINT:
return "uint";
case CORINFO_TYPE_LONG:
return "long";
case CORINFO_TYPE_ULONG:
return "ulong";
case CORINFO_TYPE_NATIVEINT:
return "nativeint";
case CORINFO_TYPE_NATIVEUINT:
return "nativeuint";
case CORINFO_TYPE_FLOAT:
return "float";
case CORINFO_TYPE_DOUBLE:
return "double";
case CORINFO_TYPE_STRING:
return "string";
case CORINFO_TYPE_PTR:
return "ptr";
case CORINFO_TYPE_BYREF:
return "byref";
case CORINFO_TYPE_VALUECLASS:
return "valueclass";
case CORINFO_TYPE_CLASS:
return "class";
case CORINFO_TYPE_REFANY:
return "refany";
case CORINFO_TYPE_VAR:
return "var";
default:
return "UNKNOWN";
}
}
const char* toString(CorInfoTypeWithMod cit)
{
// Need to cast `cit` to numeric type to avoid clang compiler warnings
// "case value not in enumerated type 'CorInfoTypeWithMod'".
switch ((unsigned)cit)
{
case (unsigned)(CORINFO_TYPE_BYREF | CORINFO_TYPE_MOD_PINNED):
return "pinned byref";
case (unsigned)(CORINFO_TYPE_CLASS | CORINFO_TYPE_MOD_PINNED):
return "pinned class";
default:
return toString((CorInfoType)(cit & CORINFO_TYPE_MASK));
}
}
unsigned int toCorInfoSize(CorInfoType cit)
{
switch (cit)
{
case CORINFO_TYPE_BOOL:
case CORINFO_TYPE_BYTE:
case CORINFO_TYPE_UBYTE:
return 1;
case CORINFO_TYPE_CHAR:
case CORINFO_TYPE_SHORT:
case CORINFO_TYPE_USHORT:
return 2;
case CORINFO_TYPE_FLOAT:
case CORINFO_TYPE_INT:
case CORINFO_TYPE_UINT:
return 4;
case CORINFO_TYPE_DOUBLE:
case CORINFO_TYPE_LONG:
case CORINFO_TYPE_ULONG:
return 8;
case CORINFO_TYPE_NATIVEINT:
case CORINFO_TYPE_NATIVEUINT:
case CORINFO_TYPE_PTR:
case CORINFO_TYPE_BYREF:
case CORINFO_TYPE_CLASS:
return (int)SpmiTargetPointerSize();
case CORINFO_TYPE_STRING:
case CORINFO_TYPE_VALUECLASS:
case CORINFO_TYPE_REFANY:
case CORINFO_TYPE_UNDEF:
case CORINFO_TYPE_VOID:
default:
__debugbreak();
return 0;
}
return -1;
}
void MethodContext::recCompileMethod(CORINFO_METHOD_INFO* info, unsigned flags)
{
if (CompileMethod == nullptr)
CompileMethod = new LightWeightMap<DWORD, Agnostic_CompileMethod>();
Agnostic_CompileMethod value;
value.info.ftn = CastHandle(info->ftn);
value.info.scope = CastHandle(info->scope);
value.info.ILCode_offset = (DWORD)CompileMethod->AddBuffer(info->ILCode, info->ILCodeSize);
value.info.ILCodeSize = (DWORD)info->ILCodeSize;
value.info.maxStack = (DWORD)info->maxStack;
value.info.EHcount = (DWORD)info->EHcount;
value.info.options = (DWORD)info->options;
value.info.regionKind = (DWORD)info->regionKind;
value.info.args = SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INFO(info->args, CompileMethod, SigInstHandleMap);
value.info.locals = SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INFO(info->locals, CompileMethod, SigInstHandleMap);
value.flags = (DWORD)flags;
CompileMethod->Add(0, value);
DEBUG_REC(dmpCompileMethod(0, value));
}
void MethodContext::dmpCompileMethod(DWORD key, const Agnostic_CompileMethod& value)
{
printf("CompileMethod key %u, value ftn-%016llX scp-%016llX ilo-%u ils-%u ms-%u ehc-%u opt-%u rk-%u args-%s locals-%s flg-%08X",
key, value.info.ftn, value.info.scope, value.info.ILCode_offset, value.info.ILCodeSize, value.info.maxStack,
value.info.EHcount, value.info.options, value.info.regionKind,
SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO(value.info.args, CompileMethod, SigInstHandleMap).c_str(),
SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO(value.info.locals, CompileMethod, SigInstHandleMap).c_str(),
value.flags);
}
void MethodContext::repCompileMethod(CORINFO_METHOD_INFO* info, unsigned* flags)
{
AssertMapAndKeyExistNoMessage(CompileMethod, 0);
Agnostic_CompileMethod value;
value = CompileMethod->Get((DWORD)0); // The only item in this set is a single group of inputs to CompileMethod
DEBUG_REP(dmpCompileMethod(0, value));
info->ftn = (CORINFO_METHOD_HANDLE)value.info.ftn;
info->scope = (CORINFO_MODULE_HANDLE)value.info.scope;
info->ILCode = CompileMethod->GetBuffer(value.info.ILCode_offset);
info->ILCodeSize = (unsigned)value.info.ILCodeSize;
methodSize = info->ILCodeSize;
info->maxStack = (unsigned)value.info.maxStack;
info->EHcount = (unsigned)value.info.EHcount;
info->options = (CorInfoOptions)value.info.options;
info->regionKind = (CorInfoRegionKind)value.info.regionKind;
info->args = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.args, CompileMethod, SigInstHandleMap);
info->locals = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.locals, CompileMethod, SigInstHandleMap);
*flags = (unsigned)value.flags;
}
void MethodContext::recGetMethodClass(CORINFO_METHOD_HANDLE methodHandle, CORINFO_CLASS_HANDLE classHandle)
{
if (GetMethodClass == nullptr)
GetMethodClass = new LightWeightMap<DWORDLONG, DWORDLONG>();
DWORDLONG key = CastHandle(methodHandle);
DWORDLONG value = CastHandle(classHandle);
GetMethodClass->Add(key, value);
DEBUG_REC(dmpGetMethodClass(key, value));
}
void MethodContext::dmpGetMethodClass(DWORDLONG key, DWORDLONG value)
{
printf("GetMethodClass key %016llX, value %016llX", key, value);
}
CORINFO_CLASS_HANDLE MethodContext::repGetMethodClass(CORINFO_METHOD_HANDLE methodHandle)
{
DWORDLONG key = CastHandle(methodHandle);
AssertMapAndKeyExist(GetMethodClass, key, ": key %016llX", key);
DWORDLONG value = GetMethodClass->Get(key);
DEBUG_REP(dmpGetMethodClass(key, value));
CORINFO_CLASS_HANDLE result = (CORINFO_CLASS_HANDLE)value;
return result;
}
void MethodContext::recGetMethodModule(CORINFO_METHOD_HANDLE methodHandle, CORINFO_MODULE_HANDLE moduleHandle)
{
if (GetMethodModule == nullptr)
GetMethodModule = new LightWeightMap<DWORDLONG, DWORDLONG>();
DWORDLONG key = CastHandle(methodHandle);
DWORDLONG value = CastHandle(moduleHandle);
GetMethodModule->Add(key, value);
DEBUG_REC(dmpGetMethodModule(key, value));
}
void MethodContext::dmpGetMethodModule(DWORDLONG key, DWORDLONG value)
{
printf("GetMethodModule key %016llX, value %016llX", key, value);
}
CORINFO_MODULE_HANDLE MethodContext::repGetMethodModule(CORINFO_METHOD_HANDLE methodHandle)
{
DWORDLONG key = CastHandle(methodHandle);
AssertMapAndKeyExist(GetMethodModule, key, ": key %016llX", key);
DWORDLONG value = GetMethodModule->Get(key);
DEBUG_REP(dmpGetMethodModule(key, value));
CORINFO_MODULE_HANDLE result = (CORINFO_MODULE_HANDLE)value;
return result;
}
void MethodContext::recGetClassAttribs(CORINFO_CLASS_HANDLE classHandle, DWORD attribs)
{
if (GetClassAttribs == nullptr)
GetClassAttribs = new LightWeightMap<DWORDLONG, DWORD>();
DWORDLONG key = CastHandle(classHandle);
GetClassAttribs->Add(key, attribs);
DEBUG_REC(dmpGetClassAttribs(key, attribs));
}
void MethodContext::dmpGetClassAttribs(DWORDLONG key, DWORD value)
{
printf("GetClassAttribs key %016llX, value %08X (%s)", key, value, SpmiDumpHelper::DumpCorInfoFlag((CorInfoFlag)value).c_str());
}
DWORD MethodContext::repGetClassAttribs(CORINFO_CLASS_HANDLE classHandle)
{
DWORDLONG key = CastHandle(classHandle);
AssertMapAndKeyExist(GetClassAttribs, key, ": key %016llX", key);
DWORD value = GetClassAttribs->Get(key);
DEBUG_REP(dmpGetClassAttribs(key, value));
return value;
}
void MethodContext::recIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn, bool result)
{
if (IsJitIntrinsic == nullptr)
IsJitIntrinsic = new LightWeightMap<DWORDLONG, DWORD>();
DWORDLONG key = CastHandle(ftn);
DWORD value = result ? 1 : 0;
IsJitIntrinsic->Add(key, value);
DEBUG_REC(dmpIsJitIntrinsic(key, value));
}
void MethodContext::dmpIsJitIntrinsic(DWORDLONG key, DWORD value)
{
printf("IsJitIntrinsic key ftn-%016llX, value res-%u", key, value);
}
bool MethodContext::repIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn)
{
DWORDLONG key = CastHandle(ftn);
AssertMapAndKeyExist(IsJitIntrinsic, key, ": key %016llX", key);
DWORD value = IsJitIntrinsic->Get(key);
DEBUG_REP(dmpIsJitIntrinsic(key, value));
return value != 0;
}
void MethodContext::recGetMethodAttribs(CORINFO_METHOD_HANDLE methodHandle, DWORD attribs)
{
if (GetMethodAttribs == nullptr)
GetMethodAttribs = new LightWeightMap<DWORDLONG, DWORD>();
DWORDLONG key = CastHandle(methodHandle);
GetMethodAttribs->Add(key, attribs);
DEBUG_REC(dmpGetMethodAttribs(key, attribs));
}
void MethodContext::dmpGetMethodAttribs(DWORDLONG key, DWORD value)
{
printf("GetMethodAttribs key %016llX, value %08X (%s)", key, value, SpmiDumpHelper::DumpCorInfoFlag((CorInfoFlag)value).c_str());
}
DWORD MethodContext::repGetMethodAttribs(CORINFO_METHOD_HANDLE methodHandle)
{
DWORDLONG key = CastHandle(methodHandle);
AssertMapAndKeyExist(GetMethodAttribs, key, ": key %016llX", key);
DWORD value = GetMethodAttribs->Get(key);
DEBUG_REP(dmpGetMethodAttribs(key, value));
if (cr->repSetMethodAttribs(methodHandle) == CORINFO_FLG_BAD_INLINEE)
value ^= CORINFO_FLG_DONT_INLINE;
return value;
}
void MethodContext::recGetClassModule(CORINFO_CLASS_HANDLE cls, CORINFO_MODULE_HANDLE mod)
{
if (GetClassModule == nullptr)
GetClassModule = new LightWeightMap<DWORDLONG, DWORDLONG>();
DWORDLONG key = CastHandle(cls);
DWORDLONG value = CastHandle(mod);
GetClassModule->Add(key, value);
DEBUG_REC(dmpGetClassModule(key, value));
}
void MethodContext::dmpGetClassModule(DWORDLONG key, DWORDLONG value)
{
printf("GetClassModule cls-%016llX, mod-%016llX", key, value);
}
CORINFO_MODULE_HANDLE MethodContext::repGetClassModule(CORINFO_CLASS_HANDLE cls)
{
DWORDLONG key = CastHandle(cls);
AssertMapAndKeyExist(GetClassModule, key, ": key %016llX", key);
DWORDLONG value = GetClassModule->Get(key);
DEBUG_REP(dmpGetClassModule(key, value));
CORINFO_MODULE_HANDLE result = (CORINFO_MODULE_HANDLE)value;
return result;
}
void MethodContext::recGetModuleAssembly(CORINFO_MODULE_HANDLE mod, CORINFO_ASSEMBLY_HANDLE assem)
{
if (GetModuleAssembly == nullptr)
GetModuleAssembly = new LightWeightMap<DWORDLONG, DWORDLONG>();
DWORDLONG key = CastHandle(mod);
DWORDLONG value = CastHandle(assem);
GetModuleAssembly->Add(key, value);
DEBUG_REC(dmpGetModuleAssembly(key, value));
}
void MethodContext::dmpGetModuleAssembly(DWORDLONG key, DWORDLONG value)
{
printf("GetModuleAssembly mod-%016llX, assem-%016llX", key, value);
}
CORINFO_ASSEMBLY_HANDLE MethodContext::repGetModuleAssembly(CORINFO_MODULE_HANDLE mod)
{
DWORDLONG key = CastHandle(mod);
AssertMapAndKeyExist(GetModuleAssembly, key, ": key %016llX", key);
DWORDLONG value = GetModuleAssembly->Get(key);
DEBUG_REP(dmpGetModuleAssembly(key, value));
CORINFO_ASSEMBLY_HANDLE result = (CORINFO_ASSEMBLY_HANDLE)value;
return result;
}
void MethodContext::recGetAssemblyName(CORINFO_ASSEMBLY_HANDLE assem, const char* assemblyName)
{
if (GetAssemblyName == nullptr)
GetAssemblyName = new LightWeightMap<DWORDLONG, DWORD>();
DWORD value;
if (assemblyName != nullptr)
{
value = GetAssemblyName->AddBuffer((const unsigned char*)assemblyName, (DWORD)strlen(assemblyName) + 1);
}
else
{
value = (DWORD)-1;
}
DWORDLONG key = CastHandle(assem);
GetAssemblyName->Add(key, value);
DEBUG_REC(dmpGetAssemblyName(key, value));
}
void MethodContext::dmpGetAssemblyName(DWORDLONG key, DWORD value)
{
const char* assemblyName = (const char*)GetAssemblyName->GetBuffer(value);
printf("GetAssemblyName assem-%016llX, value-%u '%s'", key, value, assemblyName);
GetAssemblyName->Unlock();
}
const char* MethodContext::repGetAssemblyName(CORINFO_ASSEMBLY_HANDLE assem)
{
DWORDLONG key = CastHandle(assem);
const char* result = "hackishAssemblyName";
DWORD value = (DWORD)-1;
int itemIndex = -1;
if (GetAssemblyName != nullptr)
{
itemIndex = GetAssemblyName->GetIndex(key);
}
if (itemIndex >= 0)
{
value = GetAssemblyName->Get(key);
result = (const char*)GetAssemblyName->GetBuffer(value);
}
DEBUG_REP(dmpGetAssemblyName(key, value));
return result;
}
// Note - the jit will call freearray on the array we give back....
void MethodContext::recGetVars(CORINFO_METHOD_HANDLE ftn,
ULONG32* cVars,
ICorDebugInfo::ILVarInfo** vars_in,
bool* extendOthers)
{
if (GetVars == nullptr)
GetVars = new LightWeightMap<DWORDLONG, Agnostic_GetVars>();
Agnostic_GetVars value;
value.cVars = (DWORD)*cVars;
value.vars_offset =
(DWORD)GetVars->AddBuffer((unsigned char*)*vars_in, sizeof(ICorDebugInfo::ILVarInfo) * (*cVars));
value.extendOthers = (DWORD)*extendOthers;
DWORDLONG key = CastHandle(ftn);
GetVars->Add(key, value);
DEBUG_REC(dmpGetVars(key, value));
}
void MethodContext::dmpGetVars(DWORDLONG key, const Agnostic_GetVars& value)
{
ICorDebugInfo::ILVarInfo* vars = (ICorDebugInfo::ILVarInfo*)GetVars->GetBuffer(value.vars_offset);
printf("GetVars key ftn-%016llX, value cVars-%u extendOthers-%u (", key, value.cVars, value.extendOthers);
for (unsigned int i = 0; i < value.cVars; i++)
printf("(%u %u %u %u)", i, vars[i].startOffset, vars[i].endOffset, vars[i].varNumber);
printf(")");
GetVars->Unlock();
}
void MethodContext::repGetVars(CORINFO_METHOD_HANDLE ftn,
ULONG32* cVars,
ICorDebugInfo::ILVarInfo** vars_in,
bool* extendOthers)
{
if (GetVars == nullptr)
{
*cVars = 0;
return;
}
DWORDLONG key = CastHandle(ftn);
Agnostic_GetVars value = GetVars->Get(key);
DEBUG_REP(dmpGetVars(key, value));
*cVars = (ULONG32)value.cVars;
if (*cVars > 0)
*vars_in = (ICorDebugInfo::ILVarInfo*)GetVars->GetBuffer(value.vars_offset);
*extendOthers = value.extendOthers != 0;
}
// Note - the jit will call freearray on the array we give back....
void MethodContext::recGetBoundaries(CORINFO_METHOD_HANDLE ftn,
unsigned int* cILOffsets,
uint32_t** pILOffsets,
ICorDebugInfo::BoundaryTypes* implicitBoundaries)
{
if (GetBoundaries == nullptr)
GetBoundaries = new LightWeightMap<DWORDLONG, Agnostic_GetBoundaries>();
Agnostic_GetBoundaries value;
value.cILOffsets = (DWORD)*cILOffsets;
value.pILOffset_offset =
(DWORD)GetBoundaries->AddBuffer((unsigned char*)*pILOffsets, sizeof(DWORD) * (*cILOffsets));
value.implicitBoundaries = *implicitBoundaries;
DWORDLONG key = CastHandle(ftn);
GetBoundaries->Add(key, value);
DEBUG_REC(dmpGetBoundaries(key, value));
}
void MethodContext::dmpGetBoundaries(DWORDLONG key, const Agnostic_GetBoundaries& value)
{
printf("GetBoundaries key ftn-%016llX, value cnt-%u imp-%u{", key, value.cILOffsets, value.implicitBoundaries);
DWORD* bnd = (DWORD*)GetBoundaries->GetBuffer(value.pILOffset_offset);
for (unsigned int i = 0; i < value.cILOffsets; i++)
{
printf("%u", bnd[i]);
if (i < (value.cILOffsets + 1))
printf(",");
}
GetBoundaries->Unlock();
printf("}");
}
void MethodContext::repGetBoundaries(CORINFO_METHOD_HANDLE ftn,
unsigned int* cILOffsets,
uint32_t** pILOffsets,
ICorDebugInfo::BoundaryTypes* implicitBoundaries)