-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uptake GC Registration for core (not mono)
- Loading branch information
1 parent
8e7ace7
commit bf9fab2
Showing
21 changed files
with
1,138 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace System.Reflection | ||
{ | ||
internal partial class ConstructorInvoker | ||
{ | ||
[DebuggerStepThrough] | ||
[DebuggerHidden] | ||
public unsafe object? InvokeUnsafe(object? obj, IntPtr* args, BindingFlags invokeAttr) | ||
{ | ||
// Todo: add strategy for calling IL Emit-based version | ||
return InvokeNonEmitUnsafe(obj, args, invokeAttr); | ||
} | ||
|
||
[DebuggerStepThrough] | ||
[DebuggerHidden] | ||
private unsafe object InvokeNonEmitUnsafe(object? obj, IntPtr* args, BindingFlags invokeAttr) | ||
{ | ||
if ((invokeAttr & BindingFlags.DoNotWrapExceptions) == 0) | ||
{ | ||
bool rethrow = false; | ||
|
||
try | ||
{ | ||
return RuntimeMethodHandle.InvokeMethod(obj, (void**)args, _constructorInfo.Signature, isConstructor: obj is null, out rethrow)!; | ||
} | ||
catch (OutOfMemoryException) | ||
{ | ||
throw; // Re-throw for backward compatibility. | ||
} | ||
catch (Exception ex) when (!rethrow) | ||
{ | ||
throw new TargetInvocationException(ex); | ||
} | ||
} | ||
else | ||
{ | ||
return RuntimeMethodHandle.InvokeMethod(obj, (void**)args, _constructorInfo.Signature, isConstructor: obj is null, out _)!; | ||
} | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/coreclr/System.Private.CoreLib/src/System/Reflection/DynamicMethodInvoker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Reflection | ||
{ | ||
internal sealed partial class DynamicMethodInvoker | ||
{ | ||
private readonly bool _hasRefs; | ||
|
||
public Signature Signature { get; } | ||
|
||
public DynamicMethodInvoker(Signature signature) | ||
{ | ||
Signature = signature; | ||
|
||
RuntimeType[] sigTypes = signature.Arguments; | ||
for (int i = 0; i < sigTypes.Length; i++) | ||
{ | ||
if (sigTypes[i].IsByRef) | ||
{ | ||
_hasRefs = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public bool HasRefs => _hasRefs; | ||
|
||
public unsafe object? InvokeUnsafe(object? obj, IntPtr* args, BindingFlags invokeAttr) | ||
{ | ||
// Todo: add strategy for calling IL Emit-based version | ||
return InvokeNonEmitUnsafe(obj, args, invokeAttr); | ||
} | ||
|
||
private unsafe object? InvokeNonEmitUnsafe(object? obj, IntPtr* arguments, BindingFlags invokeAttr) | ||
{ | ||
if ((invokeAttr & BindingFlags.DoNotWrapExceptions) == 0) | ||
{ | ||
bool rethrow = false; | ||
|
||
try | ||
{ | ||
return RuntimeMethodHandle.InvokeMethod(obj, (void**)arguments, Signature, isConstructor: false, out rethrow); | ||
} | ||
catch (Exception e) when (!rethrow) | ||
{ | ||
throw new TargetInvocationException(e); | ||
} | ||
} | ||
else | ||
{ | ||
return RuntimeMethodHandle.InvokeMethod(obj, (void**)arguments, Signature, isConstructor: false, out _); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/coreclr/System.Private.CoreLib/src/System/Reflection/FieldAccessor.CoreCLR.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Reflection | ||
{ | ||
internal partial class FieldAccessor | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public object? InvokeGetter(object? obj) | ||
{ | ||
// Todo: add strategy for calling IL Emit-based version | ||
return InvokeGetterNonEmit(obj); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void InvokeSetter(object? obj, object? value) | ||
{ | ||
// Todo: add strategy for calling IL Emit-based version | ||
InvokeSetterNonEmit(obj, value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal object? InvokeGetterNonEmit(object? obj) | ||
{ | ||
RuntimeType? declaringType = _fieldInfo.DeclaringType as RuntimeType; | ||
RuntimeType fieldType = (RuntimeType)_fieldInfo.FieldType; | ||
bool domainInitialized = false; | ||
|
||
if (declaringType == null) | ||
{ | ||
return RuntimeFieldHandle.GetValue(_fieldInfo, obj, fieldType, null, ref domainInitialized); | ||
} | ||
else | ||
{ | ||
domainInitialized = declaringType.DomainInitialized; | ||
object? retVal = RuntimeFieldHandle.GetValue(_fieldInfo, obj, fieldType, declaringType, ref domainInitialized); | ||
declaringType.DomainInitialized = domainInitialized; | ||
return retVal; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal void InvokeSetterNonEmit(object? obj, object? value) | ||
{ | ||
RuntimeType? declaringType = _fieldInfo.DeclaringType as RuntimeType; | ||
RuntimeType fieldType = (RuntimeType)_fieldInfo.FieldType; | ||
bool domainInitialized = false; | ||
|
||
if (declaringType == null) | ||
{ | ||
RuntimeFieldHandle.SetValue( | ||
_fieldInfo, | ||
obj, | ||
value, | ||
fieldType, | ||
_fieldInfo.Attributes, | ||
declaringType: null, | ||
ref domainInitialized); | ||
} | ||
else | ||
{ | ||
domainInitialized = declaringType.DomainInitialized; | ||
|
||
RuntimeFieldHandle.SetValue( | ||
_fieldInfo, | ||
obj, | ||
value, | ||
fieldType, | ||
_fieldInfo.Attributes, | ||
declaringType, | ||
ref domainInitialized); | ||
|
||
declaringType.DomainInitialized = domainInitialized; | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.