Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
566b15e
Implement IsSimpleCopy and CanAssignArrayType in managed code
huoyaoyuan May 27, 2024
8a592b9
Fold IsSimpleCopy back to CanAssignArrayType
huoyaoyuan May 27, 2024
0dce3d4
Delete FCall and QCall definitions for copy
huoyaoyuan May 27, 2024
d29e5d8
Convert InternalSetValue to managed
huoyaoyuan May 28, 2024
5dd0e3c
Setup FCalls
huoyaoyuan May 28, 2024
527021c
Remove FCall for GetCorElementTypeOfElementType
huoyaoyuan May 28, 2024
e7d843a
Complete TryUnBox
huoyaoyuan May 28, 2024
2bb5fe7
Fix FCall definition
huoyaoyuan May 28, 2024
f7da172
Implement InitializeArray in managed
huoyaoyuan May 28, 2024
0924555
Implement GetSpanDataFrom in managed
huoyaoyuan May 28, 2024
dc85381
Remove FCall definition
huoyaoyuan May 28, 2024
f99c553
Fix RVA field address
huoyaoyuan May 28, 2024
c5e6cc4
Fix RVA assert
huoyaoyuan May 28, 2024
470b86f
Do not use hydrated RtFieldInfo
huoyaoyuan May 28, 2024
c7821e6
Use QCall for LoadSize
huoyaoyuan May 29, 2024
5225203
Fix CanAssignArrayType condition
huoyaoyuan May 29, 2024
07293e3
Fix compilation
huoyaoyuan May 29, 2024
5da88c3
Simplify AssignType enum
huoyaoyuan May 29, 2024
5222bca
Fix I and U in CanPrimitiveWiden
huoyaoyuan May 29, 2024
335b2fb
CanCastTo should be QCall
huoyaoyuan May 30, 2024
93ec9d8
Remove ThrowHelper usages that not in hot path
huoyaoyuan May 31, 2024
c3f5097
Merge branch 'main' into array-fcall
huoyaoyuan Jun 6, 2024
481e4d4
Revert the known broken InternalSetValue
huoyaoyuan Jun 6, 2024
a266a30
Revert "Revert the known broken InternalSetValue"
huoyaoyuan Jun 6, 2024
b8e4584
Fix heap overwrite
huoyaoyuan Jun 7, 2024
5465a97
Add disabled test for RVA field reflection
huoyaoyuan Jun 9, 2024
4ce4f51
Push back changes around IsSimpleCopy and CanAssignArrayType
huoyaoyuan Jun 10, 2024
30b7d8f
Move PrimitiveWiden to InvokeUtils
huoyaoyuan Jun 12, 2024
8a9c5bc
Merge coreclr specific InvokeUtils
huoyaoyuan Jun 12, 2024
f95fa34
Revert "Merge coreclr specific InvokeUtils"
huoyaoyuan Jun 13, 2024
ebfd224
Move InvokeUtils to shared
huoyaoyuan Jun 13, 2024
d9205c6
Apply suggestions from code review
huoyaoyuan Jun 18, 2024
7eef724
Merge branch 'main' into array-fcall
huoyaoyuan Jun 18, 2024
8cfb58f
Fix trailing whitespace
huoyaoyuan Jun 18, 2024
fbb9d71
Reduce QCalls
huoyaoyuan Jun 18, 2024
324df76
Reduce CorElementType overhead
huoyaoyuan Jun 18, 2024
089ae12
Separate RVA reflection change out
huoyaoyuan Jun 19, 2024
a5e7441
Revert GetCorElementTypeOfElementType
huoyaoyuan Jun 19, 2024
5552d63
Change the MethodTable FCall to be optimal for primitive and share wi…
huoyaoyuan Jun 19, 2024
133cd8a
Return ref from GetSpanDataFrom
huoyaoyuan Jun 19, 2024
e17bf0e
Handle enum conversion to underlying type
huoyaoyuan Jun 19, 2024
dd1e2dd
Update exception message
huoyaoyuan Jun 19, 2024
32b8789
Add KeepAlive
huoyaoyuan Jun 20, 2024
582eaf1
Remove unnecessary qcall handle
huoyaoyuan Jun 20, 2024
1836ae5
Fix ref src
huoyaoyuan Jun 20, 2024
cb6aa00
Update FCall name and assert
huoyaoyuan Jun 24, 2024
49cf866
Remove unused changes
huoyaoyuan Jun 24, 2024
7a0c398
Use void* for address
huoyaoyuan Jun 24, 2024
db677ad
Apply suggestions from code review
huoyaoyuan Jun 25, 2024
353715e
Remove unused enum FCall
huoyaoyuan Jun 24, 2024
8fb1c96
Use sizeof
huoyaoyuan Jun 25, 2024
26d4c80
Add some comment
huoyaoyuan Jun 25, 2024
5f7263f
Add comment to lifetime
huoyaoyuan Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Jan Kotas <[email protected]>
  • Loading branch information
huoyaoyuan and jkotas authored Jun 18, 2024
commit d9205c6ffae6c66c9f3987d7cc2f9058abbbc901
44 changes: 20 additions & 24 deletions src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,33 +437,24 @@ private unsafe void InternalSetValue(object? value, nint flattenedIndex)
if (pElementMethodTable->IsValueType)
{
ref byte offsetDataRef = ref Unsafe.Add(ref arrayDataRef, flattenedIndex * pMethodTable->ComponentSize);
nuint elementSize = pElementMethodTable->GetNumInstanceFieldBytes();
if (pElementMethodTable->ContainsGCPointers)
SpanHelpers.ClearWithReferences(ref Unsafe.As<byte, nint>(ref offsetDataRef), pElementMethodTable->GetNumInstanceFieldBytes() / (nuint)sizeof(IntPtr));
SpanHelpers.ClearWithReferences(ref Unsafe.As<byte, nint>(ref offsetDataRef), elementSize / (nuint)sizeof(IntPtr));
else
SpanHelpers.ClearWithoutReferences(ref offsetDataRef, pElementMethodTable->GetNumInstanceFieldBytes());
SpanHelpers.ClearWithoutReferences(ref offsetDataRef, elementSize);
}
else
{
ref object? elementRef = ref Unsafe.As<byte, object?>(ref arrayDataRef);
ref object? offsetElementRef = ref Unsafe.Add(ref elementRef, (nuint)flattenedIndex);
offsetElementRef = null;
Unsafe.Add(ref Unsafe.As<byte, object?>(ref arrayDataRef), (nuint)flattenedIndex) = null;
}
}
else if (TypeHandle.AreSameType(arrayElementTypeHandle, TypeHandle.TypeHandleOf<object>()))
{
// Everything is compatible with Object
ref object? elementRef = ref Unsafe.As<byte, object?>(ref arrayDataRef);
ref object? offsetElementRef = ref Unsafe.Add(ref elementRef, (nuint)flattenedIndex);
offsetElementRef = value;
}
else if (!pElementMethodTable->IsValueType)
{
if (CastHelpers.IsInstanceOfAny(pElementMethodTable, value) == null)
if (pElementMethodTable != TypeHandle.TypeHandleOf<object>().AsMethodTable() // Everything is compatible with Object
&& CastHelpers.IsInstanceOfAny(pElementMethodTable, value) == null)
throw new InvalidCastException(SR.InvalidCast_StoreArrayElement);

ref object? elementRef = ref Unsafe.As<byte, object?>(ref arrayDataRef);
ref object? offsetElementRef = ref Unsafe.Add(ref elementRef, (nuint)flattenedIndex);
offsetElementRef = value;
Unsafe.Add(ref Unsafe.As<byte, object?>(ref arrayDataRef), (nuint)flattenedIndex) = value;
}
else
{
Expand All @@ -476,23 +467,28 @@ private unsafe void InternalSetValue(object? value, nint flattenedIndex)
{
RuntimeHelpers.Unbox_Nullable(ref offsetDataRef, pElementMethodTable, value);
}
else if (pElementMethodTable->ContainsGCPointers)
{
Buffer.BulkMoveWithWriteBarrier(ref offsetDataRef, ref value.GetRawData(), pElementMethodTable->GetNumInstanceFieldBytes());
}
else
{
SpanHelpers.Memmove(ref offsetDataRef, ref value.GetRawData(), pElementMethodTable->GetNumInstanceFieldBytes());
nuint elementSize = pElementMethodTable->GetNumInstanceFieldBytes();
if (pElementMethodTable->ContainsGCPointers)
{
Buffer.BulkMoveWithWriteBarrier(ref offsetDataRef, ref value.GetRawData(), elementSize);
}
else
{
SpanHelpers.Memmove(ref offsetDataRef, ref value.GetRawData(), elementSize);
}
}
}
else
{
// Allow enum -> primitive conversion, disallow primitive -> enum conversion
MethodTable* thSrc = RuntimeHelpers.GetMethodTable(value);
CorElementType srcType = thSrc->GetVerifierCorElementType();
MethodTable* pValueMethodTable = RuntimeHelpers.GetMethodTable(value);
CorElementType srcType = pValueMethodTable->GetVerifierCorElementType();
CorElementType targetType = pElementMethodTable->GetVerifierCorElementType();

if (!srcType.IsPrimitiveType() || !targetType.IsPrimitiveType() || !pElementMethodTable->IsTruePrimitive)
// Array.SetValue() does *not* permit conversion from a primitive to an Enum.
if (!pValueMethodTable->IsPrimitive || !pElementMethodTable->IsTruePrimitive)
throw new InvalidCastException(SR.InvalidCast_StoreArrayElement);

// Get a properly widened type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static unsafe void InitializeArray(Array array, RuntimeFieldHandle fldHan
throw new ArgumentException(SR.Argument_BadFieldForInitializeArray);

// Note that we do not check that the field is actually in the PE file that is initializing
// the array. Basically the data being published is can be accessed by anyone with the proper
// the array. Basically, the data being published can be accessed by anyone with the proper
// permissions (C# marks these as assembly visibility, and thus are protected from outside
// snooping)

Expand Down