Commit b22aa17
Allow reference types for pinned GC.AllocateArray() (#89293)
* Relaxing constraints of System.GC.AllocateArray<T>.
It's now possible to allocate pinned and default-initialized arrays that contain references.
Fix #48703
* Adding coverage of GC.AllocateArray with ref types.
Added a test that pins a reference type array and resolves references to indices with pointer arithmetic, checking that modifications are visible back in the original array.
Test #48703
* Mono/NativeAOT relaxing of System.GC.AllocateArray<T>.
* Relaxed GC.AllocateUninitializedArray for ref types as well.
This was done by deferring reference types to GC.AllocateArray to avoid potential memory issues with the GC + uninitialized memory. The API only promises to avoid initialization if possible, anyway.
Refactored tests to parametrically exercise these new relaxed constraints.
* Simplifiy conditionals in AllocateUninitializedArray.
Relying on internal implementation zeroing refs if necessary.
* Also simplify path for NativeOAT.
Mono already piggybacks on the AllocateArray path anyway.
* Simplify pinning paths.
All conditional paths in GC.Allocate*Array now handle pinning unconditionally out of the main branch.
* Don't use `var` if type name doesn't exist explicitly on right-hand side
* PR feedback for using terse method tables and JIT intrinsics for GC array allocation that should be slightly faster.
* Changed EmbeddedValueType and added comment.
After a longer discussion, settled on a slightly augmented suggestion that isn't as controversial as the prior one.
* Fixing signature for `RhAllocateNewArray` in NativeAOT to directly use a `MethodTable*`
* Adding explicit structlayout to silence warning for EmbeddedValueType in GCTests, and improved the comment.
---------
Co-authored-by: Jan Kotas <jkotas@microsoft.com>1 parent 1c4e4c1 commit b22aa17
5 files changed
Lines changed: 58 additions & 36 deletions
File tree
- src
- coreclr
- System.Private.CoreLib/src/System
- nativeaot/System.Private.CoreLib/src/System
- Runtime
- libraries/System.Runtime/tests/System
- mono/System.Private.CoreLib/src/System
Lines changed: 2 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
741 | 741 | | |
742 | 742 | | |
743 | 743 | | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | 744 | | |
748 | 745 | | |
749 | 746 | | |
| |||
766 | 763 | | |
767 | 764 | | |
768 | 765 | | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | 766 | | |
| 767 | + | |
774 | 768 | | |
775 | 769 | | |
776 | 770 | | |
| |||
784 | 778 | | |
785 | 779 | | |
786 | 780 | | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | 781 | | |
791 | 782 | | |
792 | 783 | | |
793 | 784 | | |
794 | 785 | | |
795 | 786 | | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | 787 | | |
800 | 788 | | |
801 | 789 | | |
802 | | - | |
| 790 | + | |
803 | 791 | | |
804 | 792 | | |
805 | 793 | | |
| |||
Lines changed: 2 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
795 | 795 | | |
796 | 796 | | |
797 | 797 | | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | 798 | | |
802 | 799 | | |
803 | 800 | | |
| |||
819 | 816 | | |
820 | 817 | | |
821 | 818 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | 819 | | |
827 | 820 | | |
828 | 821 | | |
| |||
837 | 830 | | |
838 | 831 | | |
839 | 832 | | |
840 | | - | |
| 833 | + | |
841 | 834 | | |
842 | 835 | | |
843 | 836 | | |
| |||
851 | 844 | | |
852 | 845 | | |
853 | 846 | | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | 847 | | |
858 | 848 | | |
859 | 849 | | |
860 | 850 | | |
861 | 851 | | |
862 | 852 | | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | 853 | | |
867 | 854 | | |
868 | 855 | | |
869 | 856 | | |
870 | 857 | | |
871 | 858 | | |
872 | 859 | | |
873 | | - | |
| 860 | + | |
874 | 861 | | |
875 | 862 | | |
876 | 863 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1058 | 1058 | | |
1059 | 1059 | | |
1060 | 1060 | | |
1061 | | - | |
1062 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1063 | 1095 | | |
1064 | | - | |
1065 | | - | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
1066 | 1115 | | |
1067 | 1116 | | |
1068 | 1117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
285 | | - | |
286 | 284 | | |
287 | 285 | | |
288 | 286 | | |
| |||
0 commit comments