This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
jithelpers.cpp
6294 lines (4995 loc) · 192 KB
/
jithelpers.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.
// See the LICENSE file in the project root for more information.
#include "common.h"
#include "jitinterface.h"
#include "codeman.h"
#include "method.hpp"
#include "class.h"
#include "object.h"
#include "field.h"
#include "stublink.h"
#include "virtualcallstub.h"
#include "corjit.h"
#include "eeconfig.h"
#include "excep.h"
#include "log.h"
#include "excep.h"
#include "float.h" // for isnan
#include "dbginterface.h"
#include "dllimport.h"
#include "gcheaputilities.h"
#include "comdelegate.h"
#include "jitperf.h" // to track jit perf
#include "corprof.h"
#include "eeprofinterfaces.h"
#ifndef FEATURE_PAL
// Included for referencing __report_gsfailure
#include "process.h"
#endif // !FEATURE_PAL
#ifdef PROFILING_SUPPORTED
#include "proftoeeinterfaceimpl.h"
#endif
#include "ecall.h"
#include "generics.h"
#include "typestring.h"
#include "typedesc.h"
#include "genericdict.h"
#include "array.h"
#include "debuginfostore.h"
#include "safemath.h"
#include "threadstatics.h"
#ifdef FEATURE_PREJIT
#include "compile.h"
#endif
#ifdef HAVE_GCCOVER
#include "gccover.h"
#endif // HAVE_GCCOVER
#include "runtimehandles.h"
//========================================================================
//
// This file contains implementation of all JIT helpers. The helpers are
// divided into following categories:
//
// INTEGER ARITHMETIC HELPERS
// FLOATING POINT HELPERS
// INSTANCE FIELD HELPERS
// STATIC FIELD HELPERS
// SHARED STATIC FIELD HELPERS
// CASTING HELPERS
// ALLOCATION HELPERS
// STRING HELPERS
// ARRAY HELPERS
// VALUETYPE/BYREF HELPERS
// GENERICS HELPERS
// EXCEPTION HELPERS
// SECURITY HELPERS
// DEBUGGER/PROFILER HELPERS
// GC HELPERS
// INTEROP HELPERS
//
//========================================================================
//========================================================================
//
// INTEGER ARITHMETIC HELPERS
//
//========================================================================
#include <optsmallperfcritical.h>
//
// helper macro to multiply two 32-bit uints
//
#define Mul32x32To64(a, b) ((UINT64)((UINT32)(a)) * (UINT64)((UINT32)(b)))
//
// helper macro to get high 32-bit of 64-bit int
//
#define Hi32Bits(a) ((UINT32)((UINT64)(a) >> 32))
//
// helper macro to check whether 64-bit signed int fits into 32-bit signed (compiles into one 32-bit compare)
//
#define Is32BitSigned(a) (Hi32Bits(a) == Hi32Bits((INT64)(INT32)(a)))
//
// helper function to shift the result by 32-bits
//
inline UINT64 ShiftToHi32Bits(UINT32 x)
{
// The shift compiles into slow multiplication by 2^32! VSWhidbey 360736
// return ((UINT64)x) << 32;
ULARGE_INTEGER ret;
ret.u.HighPart = x;
ret.u.LowPart = 0;
return ret.QuadPart;
}
#if !defined(_TARGET_X86_) || defined(FEATURE_PAL)
/*********************************************************************/
HCIMPL2_VV(INT64, JIT_LMul, INT64 val1, INT64 val2)
{
FCALL_CONTRACT;
UINT32 val1High = Hi32Bits(val1);
UINT32 val2High = Hi32Bits(val2);
if ((val1High == 0) && (val2High == 0))
return Mul32x32To64(val1, val2);
return (val1 * val2);
}
HCIMPLEND
#endif // !_TARGET_X86_ || FEATURE_PAL
/*********************************************************************/
HCIMPL2_VV(INT64, JIT_LMulOvf, INT64 val1, INT64 val2)
{
FCALL_CONTRACT;
// This short-cut does not actually help since the multiplication
// of two 32-bit signed ints compiles into the call to a slow helper
// if (Is32BitSigned(val1) && Is32BitSigned(val2))
// return (INT64)(INT32)val1 * (INT64)(INT32)val2;
INDEBUG(INT64 expected = val1 * val2;)
INT64 ret;
// Remember the sign of the result
INT32 sign = Hi32Bits(val1) ^ Hi32Bits(val2);
// Convert to unsigned multiplication
if (val1 < 0) val1 = -val1;
if (val2 < 0) val2 = -val2;
// Get the upper 32 bits of the numbers
UINT32 val1High = Hi32Bits(val1);
UINT32 val2High = Hi32Bits(val2);
UINT64 valMid;
if (val1High == 0) {
// Compute the 'middle' bits of the long multiplication
valMid = Mul32x32To64(val2High, val1);
}
else {
if (val2High != 0)
goto ThrowExcep;
// Compute the 'middle' bits of the long multiplication
valMid = Mul32x32To64(val1High, val2);
}
// See if any bits after bit 32 are set
if (Hi32Bits(valMid) != 0)
goto ThrowExcep;
ret = Mul32x32To64(val1, val2) + ShiftToHi32Bits((UINT32)(valMid));
// check for overflow
if (Hi32Bits(ret) < (UINT32)valMid)
goto ThrowExcep;
if (sign >= 0) {
// have we spilled into the sign bit?
if (ret < 0)
goto ThrowExcep;
}
else {
ret = -ret;
// have we spilled into the sign bit?
if (ret > 0)
goto ThrowExcep;
}
_ASSERTE(ret == expected);
return ret;
ThrowExcep:
FCThrow(kOverflowException);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(UINT64, JIT_ULMulOvf, UINT64 val1, UINT64 val2)
{
FCALL_CONTRACT;
INDEBUG(UINT64 expected = val1 * val2;)
UINT64 ret;
// Get the upper 32 bits of the numbers
UINT32 val1High = Hi32Bits(val1);
UINT32 val2High = Hi32Bits(val2);
UINT64 valMid;
if (val1High == 0) {
if (val2High == 0)
return Mul32x32To64(val1, val2);
// Compute the 'middle' bits of the long multiplication
valMid = Mul32x32To64(val2High, val1);
}
else {
if (val2High != 0)
goto ThrowExcep;
// Compute the 'middle' bits of the long multiplication
valMid = Mul32x32To64(val1High, val2);
}
// See if any bits after bit 32 are set
if (Hi32Bits(valMid) != 0)
goto ThrowExcep;
ret = Mul32x32To64(val1, val2) + ShiftToHi32Bits((UINT32)(valMid));
// check for overflow
if (Hi32Bits(ret) < (UINT32)valMid)
goto ThrowExcep;
_ASSERTE(ret == expected);
return ret;
ThrowExcep:
FCThrow(kOverflowException);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2(INT32, JIT_Div, INT32 dividend, INT32 divisor)
{
FCALL_CONTRACT;
RuntimeExceptionKind ehKind;
if (((UINT32) (divisor + 1)) <= 1) // Unsigned test for divisor in [-1 .. 0]
{
if (divisor == 0)
{
ehKind = kDivideByZeroException;
goto ThrowExcep;
}
else if (divisor == -1)
{
if (dividend == _I32_MIN)
{
ehKind = kOverflowException;
goto ThrowExcep;
}
return -dividend;
}
}
return(dividend / divisor);
ThrowExcep:
FCThrow(ehKind);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2(INT32, JIT_Mod, INT32 dividend, INT32 divisor)
{
FCALL_CONTRACT;
RuntimeExceptionKind ehKind;
if (((UINT32) (divisor + 1)) <= 1) // Unsigned test for divisor in [-1 .. 0]
{
if (divisor == 0)
{
ehKind = kDivideByZeroException;
goto ThrowExcep;
}
else if (divisor == -1)
{
if (dividend == _I32_MIN)
{
ehKind = kOverflowException;
goto ThrowExcep;
}
return 0;
}
}
return(dividend % divisor);
ThrowExcep:
FCThrow(ehKind);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2(UINT32, JIT_UDiv, UINT32 dividend, UINT32 divisor)
{
FCALL_CONTRACT;
if (divisor == 0)
FCThrow(kDivideByZeroException);
return(dividend / divisor);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2(UINT32, JIT_UMod, UINT32 dividend, UINT32 divisor)
{
FCALL_CONTRACT;
if (divisor == 0)
FCThrow(kDivideByZeroException);
return(dividend % divisor);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(INT64, JIT_LDiv, INT64 dividend, INT64 divisor)
{
FCALL_CONTRACT;
RuntimeExceptionKind ehKind;
if (Is32BitSigned(divisor))
{
if ((INT32)divisor == 0)
{
ehKind = kDivideByZeroException;
goto ThrowExcep;
}
if ((INT32)divisor == -1)
{
if ((UINT64) dividend == UI64(0x8000000000000000))
{
ehKind = kOverflowException;
goto ThrowExcep;
}
return -dividend;
}
// Check for -ive or +ive numbers in the range -2**31 to 2**31
if (Is32BitSigned(dividend))
return((INT32)dividend / (INT32)divisor);
}
// For all other combinations fallback to int64 div.
return(dividend / divisor);
ThrowExcep:
FCThrow(ehKind);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(INT64, JIT_LMod, INT64 dividend, INT64 divisor)
{
FCALL_CONTRACT;
RuntimeExceptionKind ehKind;
if (Is32BitSigned(divisor))
{
if ((INT32)divisor == 0)
{
ehKind = kDivideByZeroException;
goto ThrowExcep;
}
if ((INT32)divisor == -1)
{
// <TODO>TODO, we really should remove this as it lengthens the code path
// and the spec really says that it should not throw an exception. </TODO>
if ((UINT64) dividend == UI64(0x8000000000000000))
{
ehKind = kOverflowException;
goto ThrowExcep;
}
return 0;
}
// Check for -ive or +ive numbers in the range -2**31 to 2**31
if (Is32BitSigned(dividend))
return((INT32)dividend % (INT32)divisor);
}
// For all other combinations fallback to int64 div.
return(dividend % divisor);
ThrowExcep:
FCThrow(ehKind);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(UINT64, JIT_ULDiv, UINT64 dividend, UINT64 divisor)
{
FCALL_CONTRACT;
if (Hi32Bits(divisor) == 0)
{
if ((UINT32)(divisor) == 0)
FCThrow(kDivideByZeroException);
if (Hi32Bits(dividend) == 0)
return((UINT32)dividend / (UINT32)divisor);
}
return(dividend / divisor);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(UINT64, JIT_ULMod, UINT64 dividend, UINT64 divisor)
{
FCALL_CONTRACT;
if (Hi32Bits(divisor) == 0)
{
if ((UINT32)(divisor) == 0)
FCThrow(kDivideByZeroException);
if (Hi32Bits(dividend) == 0)
return((UINT32)dividend % (UINT32)divisor);
}
return(dividend % divisor);
}
HCIMPLEND
#if !defined(BIT64) && !defined(_TARGET_X86_)
/*********************************************************************/
HCIMPL2_VV(UINT64, JIT_LLsh, UINT64 num, int shift)
{
FCALL_CONTRACT;
return num << (shift & 0x3F);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(INT64, JIT_LRsh, INT64 num, int shift)
{
FCALL_CONTRACT;
return num >> (shift & 0x3F);
}
HCIMPLEND
/*********************************************************************/
HCIMPL2_VV(UINT64, JIT_LRsz, UINT64 num, int shift)
{
FCALL_CONTRACT;
return num >> (shift & 0x3F);
}
HCIMPLEND
#endif // !BIT64 && !_TARGET_X86_
#include <optdefault.h>
//========================================================================
//
// FLOATING POINT HELPERS
//
//========================================================================
#include <optsmallperfcritical.h>
/*********************************************************************/
//
HCIMPL1_V(double, JIT_ULng2Dbl, UINT64 val)
{
FCALL_CONTRACT;
double conv = (double) ((INT64) val);
if (conv < 0)
conv += (4294967296.0 * 4294967296.0); // add 2^64
_ASSERTE(conv >= 0);
return(conv);
}
HCIMPLEND
/*********************************************************************/
// needed for ARM and RyuJIT-x86
HCIMPL1_V(double, JIT_Lng2Dbl, INT64 val)
{
FCALL_CONTRACT;
return double(val);
}
HCIMPLEND
//--------------------------------------------------------------------------
template <class ftype>
ftype modftype(ftype value, ftype *iptr);
template <> float modftype(float value, float *iptr) { return modff(value, iptr); }
template <> double modftype(double value, double *iptr) { return modf(value, iptr); }
// round to nearest, round to even if tied
template <class ftype>
ftype BankersRound(ftype value)
{
if (value < 0.0) return -BankersRound <ftype> (-value);
ftype integerPart;
modftype( value, &integerPart );
// if decimal part is exactly .5
if ((value -(integerPart +0.5)) == 0.0)
{
// round to even
#if defined(_TARGET_ARM_) && defined(FEATURE_CORESYSTEM)
// @ARMTODO: On ARM when building on CoreSystem (where we link against the system CRT) an attempt to
// use fmod(float, float) fails to link (apparently this is converted to a reference to fmodf, which
// is not included in the system CRT). Use the double version instead.
if (fmod(double(integerPart), double(2.0)) == 0.0)
return integerPart;
#else
if (fmod(ftype(integerPart), ftype(2.0)) == 0.0)
return integerPart;
#endif
// Else return the nearest even integer
return (ftype)_copysign(ceil(fabs(value+0.5)),
value);
}
// Otherwise round to closest
return (ftype)_copysign(floor(fabs(value)+0.5),
value);
}
/*********************************************************************/
// round double to nearest int (as double)
HCIMPL1_V(double, JIT_DoubleRound, double val)
{
FCALL_CONTRACT;
return BankersRound(val);
}
HCIMPLEND
/*********************************************************************/
// round float to nearest int (as float)
HCIMPL1_V(float, JIT_FloatRound, float val)
{
FCALL_CONTRACT;
return BankersRound(val);
}
HCIMPLEND
/*********************************************************************/
// Call fast Dbl2Lng conversion - used by functions below
FORCEINLINE INT64 FastDbl2Lng(double val)
{
#ifdef _TARGET_X86_
FCALL_CONTRACT;
return HCCALL1_V(JIT_Dbl2Lng, val);
#else
FCALL_CONTRACT;
return((__int64) val);
#endif
}
/*********************************************************************/
HCIMPL1_V(UINT32, JIT_Dbl2UIntOvf, double val)
{
FCALL_CONTRACT;
// Note that this expression also works properly for val = NaN case
if (val > -1.0 && val < 4294967296.0)
return((UINT32)FastDbl2Lng(val));
FCThrow(kOverflowException);
}
HCIMPLEND
/*********************************************************************/
HCIMPL1_V(UINT64, JIT_Dbl2ULng, double val)
{
FCALL_CONTRACT;
const double two63 = 2147483648.0 * 4294967296.0;
UINT64 ret;
if (val < two63) {
ret = FastDbl2Lng(val);
}
else {
// subtract 0x8000000000000000, do the convert then add it back again
ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000);
}
return ret;
}
HCIMPLEND
/*********************************************************************/
HCIMPL1_V(UINT64, JIT_Dbl2ULngOvf, double val)
{
FCALL_CONTRACT;
const double two64 = 4294967296.0 * 4294967296.0;
// Note that this expression also works properly for val = NaN case
if (val > -1.0 && val < two64) {
const double two63 = 2147483648.0 * 4294967296.0;
UINT64 ret;
if (val < two63) {
ret = FastDbl2Lng(val);
}
else {
// subtract 0x8000000000000000, do the convert then add it back again
ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000);
}
#ifdef _DEBUG
// since no overflow can occur, the value always has to be within 1
double roundTripVal = HCCALL1_V(JIT_ULng2Dbl, ret);
_ASSERTE(val - 1.0 <= roundTripVal && roundTripVal <= val + 1.0);
#endif // _DEBUG
return ret;
}
FCThrow(kOverflowException);
}
HCIMPLEND
#if !defined(_TARGET_X86_) || defined(FEATURE_PAL)
HCIMPL1_V(INT64, JIT_Dbl2Lng, double val)
{
FCALL_CONTRACT;
return((INT64)val);
}
HCIMPLEND
HCIMPL1_V(int, JIT_Dbl2IntOvf, double val)
{
FCALL_CONTRACT;
const double two31 = 2147483648.0;
// Note that this expression also works properly for val = NaN case
if (val > -two31 - 1 && val < two31)
return((INT32)val);
FCThrow(kOverflowException);
}
HCIMPLEND
HCIMPL1_V(INT64, JIT_Dbl2LngOvf, double val)
{
FCALL_CONTRACT;
const double two63 = 2147483648.0 * 4294967296.0;
// Note that this expression also works properly for val = NaN case
// We need to compare with the very next double to two63. 0x402 is epsilon to get us there.
if (val > -two63 - 0x402 && val < two63)
return((INT64)val);
FCThrow(kOverflowException);
}
HCIMPLEND
HCIMPL2_VV(float, JIT_FltRem, float dividend, float divisor)
{
FCALL_CONTRACT;
//
// From the ECMA standard:
//
// If [divisor] is zero or [dividend] is infinity
// the result is NaN.
// If [divisor] is infinity,
// the result is [dividend] (negated for -infinity***).
//
// ***"negated for -infinity" has been removed from the spec
//
if (divisor==0 || !_finite(dividend))
{
UINT32 NaN = CLR_NAN_32;
return *(float *)(&NaN);
}
else if (!_finite(divisor) && !_isnan(divisor))
{
return dividend;
}
// else...
#if 0
// COMPILER BUG WITH FMODF() + /Oi, USE FMOD() INSTEAD
return fmodf(dividend,divisor);
#else
return (float)fmod((double)dividend,(double)divisor);
#endif
}
HCIMPLEND
HCIMPL2_VV(double, JIT_DblRem, double dividend, double divisor)
{
FCALL_CONTRACT;
//
// From the ECMA standard:
//
// If [divisor] is zero or [dividend] is infinity
// the result is NaN.
// If [divisor] is infinity,
// the result is [dividend] (negated for -infinity***).
//
// ***"negated for -infinity" has been removed from the spec
//
if (divisor==0 || !_finite(dividend))
{
UINT64 NaN = CLR_NAN_64;
return *(double *)(&NaN);
}
else if (!_finite(divisor) && !_isnan(divisor))
{
return dividend;
}
// else...
return(fmod(dividend,divisor));
}
HCIMPLEND
#endif // !_TARGET_X86_ || FEATURE_PAL
#include <optdefault.h>
//========================================================================
//
// INSTANCE FIELD HELPERS
//
//========================================================================
/*********************************************************************/
// Returns the address of the field in the object (This is an interior
// pointer and the caller has to use it appropriately). obj can be
// either a reference or a byref
HCIMPL2(void*, JIT_GetFieldAddr_Framed, Object *obj, FieldDesc* pFD)
{
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(pFD));
} CONTRACTL_END;
void * fldAddr = NULL;
OBJECTREF objRef = ObjectToOBJECTREF(obj);
HELPER_METHOD_FRAME_BEGIN_RET_1(objRef);
if (objRef == NULL)
COMPlusThrow(kNullReferenceException);
fldAddr = pFD->GetAddress(OBJECTREFToObject(objRef));
HELPER_METHOD_FRAME_END();
return fldAddr;
}
HCIMPLEND
#include <optsmallperfcritical.h>
HCIMPL2(void*, JIT_GetFieldAddr, Object *obj, FieldDesc* pFD)
{
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(pFD));
} CONTRACTL_END;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetFieldAddr_Framed, obj, pFD);
}
return pFD->GetAddressGuaranteedInHeap(obj);
}
HCIMPLEND
#include <optdefault.h>
/*********************************************************************/
#define HCallAssert(cache, target) // suppressed to avoid ambiguous cast errors caused by use of template
template <typename FIELDTYPE>
NOINLINE HCIMPL2(FIELDTYPE, JIT_GetField_Framed, Object *obj, FieldDesc *pFD)
#undef HCallAssert
{
FCALL_CONTRACT;
FIELDTYPE value = 0;
// This is an instance field helper
_ASSERTE(!pFD->IsStatic());
OBJECTREF objRef = ObjectToOBJECTREF(obj);
HELPER_METHOD_FRAME_BEGIN_RET_1(objRef);
if (objRef == NULL)
COMPlusThrow(kNullReferenceException);
pFD->GetInstanceField(objRef, &value);
HELPER_METHOD_POLL();
HELPER_METHOD_FRAME_END();
return value;
}
HCIMPLEND
/*********************************************************************/
#include <optsmallperfcritical.h>
HCIMPL2(INT8, JIT_GetField8, Object *obj, FieldDesc *pFD)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetField_Framed<INT8>, obj, pFD);
}
INT8 val = VolatileLoad<INT8>((INT8*)pFD->GetAddressGuaranteedInHeap(obj));
FC_GC_POLL_RET();
return val;
}
HCIMPLEND
HCIMPL2(INT16, JIT_GetField16, Object *obj, FieldDesc *pFD)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetField_Framed<INT16>, obj, pFD);
}
INT16 val = VolatileLoad<INT16>((INT16*)pFD->GetAddressGuaranteedInHeap(obj));
FC_GC_POLL_RET();
return val;
}
HCIMPLEND
HCIMPL2(INT32, JIT_GetField32, Object *obj, FieldDesc *pFD)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetField_Framed<INT32>, obj, pFD);
}
INT32 val = VolatileLoad<INT32>((INT32*)pFD->GetAddressGuaranteedInHeap(obj));
FC_GC_POLL_RET();
return val;
}
HCIMPLEND
HCIMPL2(INT64, JIT_GetField64, Object *obj, FieldDesc *pFD)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetField_Framed<INT64>, obj, pFD);
}
INT64 val = VolatileLoad<INT64>((INT64*)pFD->GetAddressGuaranteedInHeap(obj));
FC_GC_POLL_RET();
return val;
}
HCIMPLEND
HCIMPL2(FLOAT, JIT_GetFieldFloat, Object *obj, FieldDesc *pFD)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetField_Framed<FLOAT>, obj, pFD);
}
FLOAT val;
(INT32&)val = VolatileLoad<INT32>((INT32*)pFD->GetAddressGuaranteedInHeap(obj));
FC_GC_POLL_RET();
return val;
}
HCIMPLEND
HCIMPL2(DOUBLE, JIT_GetFieldDouble, Object *obj, FieldDesc *pFD)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetField_Framed<DOUBLE>, obj, pFD);
}
DOUBLE val;
(INT64&)val = VolatileLoad<INT64>((INT64*)pFD->GetAddressGuaranteedInHeap(obj));
FC_GC_POLL_RET();
return val;
}
HCIMPLEND
#include <optdefault.h>
/*********************************************************************/
#define HCallAssert(cache, target) // suppressed to avoid ambiguous cast errors caused by use of template
template <typename FIELDTYPE>
NOINLINE HCIMPL3(VOID, JIT_SetField_Framed, Object *obj, FieldDesc* pFD, FIELDTYPE val)
#undef HCallAssert
{
FCALL_CONTRACT;
// This is an instance field helper
_ASSERTE(!pFD->IsStatic());
OBJECTREF objRef = ObjectToOBJECTREF(obj);
HELPER_METHOD_FRAME_BEGIN_1(objRef);
if (objRef == NULL)
COMPlusThrow(kNullReferenceException);
pFD->SetInstanceField(objRef, &val);
HELPER_METHOD_POLL();
HELPER_METHOD_FRAME_END();
}
HCIMPLEND
/*********************************************************************/
#include <optsmallperfcritical.h>
HCIMPL3(VOID, JIT_SetField8, Object *obj, FieldDesc *pFD, INT8 val)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL3(JIT_SetField_Framed<INT8>, obj, pFD, val);
}
VolatileStore<INT8>((INT8*)pFD->GetAddressGuaranteedInHeap(obj), val);
FC_GC_POLL();
}
HCIMPLEND
HCIMPL3(VOID, JIT_SetField16, Object *obj, FieldDesc *pFD, INT16 val)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL3(JIT_SetField_Framed<INT16>, obj, pFD, val);
}
VolatileStore<INT16>((INT16*)pFD->GetAddressGuaranteedInHeap(obj), val);
FC_GC_POLL();
}
HCIMPLEND
HCIMPL3(VOID, JIT_SetField32, Object *obj, FieldDesc *pFD, INT32 val)
{
FCALL_CONTRACT;
if (obj == NULL || g_IBCLogger.InstrEnabled() || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL3(JIT_SetField_Framed<INT32>, obj, pFD, val);
}
VolatileStore<INT32>((INT32*)pFD->GetAddressGuaranteedInHeap(obj), val);
FC_GC_POLL();
}
HCIMPLEND