diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
index ac322bdf20c002..8ff2878596daf6 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
@@ -18,23 +18,12 @@ internal sealed unsafe class RtFieldInfo : RuntimeFieldInfo, IRuntimeFieldInfo
// lazy caching
private string? m_name;
private RuntimeType? m_fieldType;
- internal FieldAccessor? m_invoker;
-
+ private InvocationFlags m_invocationFlags;
internal InvocationFlags InvocationFlags
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => (Invoker._invocationFlags & InvocationFlags.Initialized) != 0 ?
- Invoker._invocationFlags : InitializeInvocationFlags();
- }
-
- private FieldAccessor Invoker
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- m_invoker ??= new FieldAccessor(this);
- return m_invoker;
- }
+ get => (m_invocationFlags & InvocationFlags.Initialized) != 0 ?
+ m_invocationFlags : InitializeInvocationFlags();
}
[MethodImpl(MethodImplOptions.NoInlining)]
@@ -67,7 +56,7 @@ private InvocationFlags InitializeInvocationFlags()
}
// must be last to avoid threading problems
- return Invoker._invocationFlags = invocationFlags | InvocationFlags.Initialized;
+ return m_invocationFlags = invocationFlags | InvocationFlags.Initialized;
}
#endregion
@@ -113,63 +102,6 @@ internal override bool CacheEquals(object? o)
return o is RtFieldInfo m && m.m_fieldHandle == m_fieldHandle;
}
- [DebuggerStepThrough]
- [DebuggerHidden]
- internal object? GetValueNonEmit(object? obj)
- {
- RuntimeType? declaringType = DeclaringType as RuntimeType;
- RuntimeType fieldType = (RuntimeType)FieldType;
- bool domainInitialized = false;
-
- if (declaringType == null)
- {
- return RuntimeFieldHandle.GetValue(this, obj, fieldType, null, ref domainInitialized);
- }
- else
- {
- domainInitialized = declaringType.DomainInitialized;
- object? retVal = RuntimeFieldHandle.GetValue(this, obj, fieldType, declaringType, ref domainInitialized);
- declaringType.DomainInitialized = domainInitialized;
- return retVal;
- }
- }
-
- [DebuggerStepThrough]
- [DebuggerHidden]
- internal void SetValueNonEmit(object? obj, object? value)
- {
- RuntimeType? declaringType = DeclaringType as RuntimeType;
- RuntimeType fieldType = (RuntimeType)FieldType;
- bool domainInitialized = false;
-
- if (declaringType == null)
- {
- RuntimeFieldHandle.SetValue(
- this,
- obj,
- value,
- fieldType,
- Attributes,
- declaringType: null,
- ref domainInitialized);
- }
- else
- {
- domainInitialized = declaringType.DomainInitialized;
-
- RuntimeFieldHandle.SetValue(
- this,
- obj,
- value,
- fieldType,
- Attributes,
- declaringType,
- ref domainInitialized);
-
- declaringType.DomainInitialized = domainInitialized;
- }
- }
-
#endregion
#region MemberInfo Overrides
@@ -211,7 +143,20 @@ public override int GetHashCode() =>
CheckConsistency(obj);
- return Invoker.GetValue(obj);
+ RuntimeType fieldType = (RuntimeType)FieldType;
+
+ bool domainInitialized = false;
+ if (declaringType == null)
+ {
+ return RuntimeFieldHandle.GetValue(this, obj, fieldType, null, ref domainInitialized);
+ }
+ else
+ {
+ domainInitialized = declaringType.DomainInitialized;
+ object? retVal = RuntimeFieldHandle.GetValue(this, obj, fieldType, declaringType, ref domainInitialized);
+ declaringType.DomainInitialized = domainInitialized;
+ return retVal;
+ }
}
public override object GetRawConstantValue() { throw new InvalidOperationException(); }
@@ -258,7 +203,17 @@ public override void SetValue(object? obj, object? value, BindingFlags invokeAtt
fieldType.CheckValue(ref value, copyBack: ref _ref, binder, culture, invokeAttr);
}
- Invoker.SetValue(obj, value);
+ bool domainInitialized = false;
+ if (declaringType is null)
+ {
+ RuntimeFieldHandle.SetValue(this, obj, value, fieldType, m_fieldAttributes, null, ref domainInitialized);
+ }
+ else
+ {
+ domainInitialized = declaringType.DomainInitialized;
+ RuntimeFieldHandle.SetValue(this, obj, value, fieldType, m_fieldAttributes, declaringType, ref domainInitialized);
+ declaringType.DomainInitialized = domainInitialized;
+ }
}
[DebuggerStepThrough]
diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
index 6b7d2425135cc0..4b8846c4ad34f5 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
@@ -1185,7 +1185,6 @@ public RuntimeFieldInfoStub(RuntimeFieldHandleInternal fieldHandle, object keepa
private object? m_d;
private int m_b;
private object? m_e;
- private object? m_f;
private RuntimeFieldHandleInternal m_fieldHandle;
#pragma warning restore 414, 169
diff --git a/src/coreclr/vm/object.h b/src/coreclr/vm/object.h
index 5a8f1624ac5971..4c731c4a240f4b 100644
--- a/src/coreclr/vm/object.h
+++ b/src/coreclr/vm/object.h
@@ -1153,7 +1153,6 @@ class ReflectFieldObject : public BaseObjectWithCachedData
INT32 m_empty2;
OBJECTREF m_empty3;
OBJECTREF m_empty4;
- OBJECTREF m_empty5;
FieldDesc * m_pFD;
public:
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 6f3a16e6136363..a908b752f45f48 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -617,7 +617,6 @@
-
@@ -2456,4 +2455,4 @@
-
\ No newline at end of file
+
diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs
deleted file mode 100644
index 530c5e767f7745..00000000000000
--- a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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 sealed partial class FieldAccessor
- {
- private readonly RtFieldInfo _fieldInfo;
- public InvocationFlags _invocationFlags;
-
- public FieldAccessor(RtFieldInfo fieldInfo)
- {
- _fieldInfo = fieldInfo;
- }
-
- [DebuggerStepThrough]
- [DebuggerHidden]
- public object? GetValue(object? obj)
- {
- // Todo: add strategy for calling IL Emit-based version
- return _fieldInfo.GetValueNonEmit(obj);
- }
-
- [DebuggerStepThrough]
- [DebuggerHidden]
- public void SetValue(object? obj, object? value)
- {
- // Todo: add strategy for calling IL Emit-based version
- _fieldInfo.SetValueNonEmit(obj, value);
- }
- }
-}
diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
index 1fcb29907ae2aa..40265d7b9a2702 100644
--- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
+++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
@@ -38,8 +38,6 @@ internal abstract class RtFieldInfo : FieldInfo
internal abstract object UnsafeGetValue(object obj);
internal abstract void UnsafeSetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
internal abstract void CheckConsistency(object target);
- internal abstract object? GetValueNonEmit(object? obj);
- internal abstract void SetValueNonEmit(object? obj, object? value);
}
[StructLayout(LayoutKind.Sequential)]
@@ -51,19 +49,8 @@ internal sealed class RuntimeFieldInfo : RtFieldInfo
private string? name;
private Type? type;
private FieldAttributes attrs;
- private FieldAccessor? invoker;
#pragma warning restore 649
- private FieldAccessor Invoker
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- invoker ??= new FieldAccessor(this);
- return invoker;
- }
- }
-
public override Module Module
{
get
@@ -128,13 +115,6 @@ public override void SetValueDirect(TypedReference obj, object value)
}
}
- [DebuggerStepThrough]
- [DebuggerHidden]
- internal override void SetValueNonEmit(object? obj, object? value)
- {
- SetValueInternal(this, obj, value);
- }
-
[DebuggerStepThrough]
[DebuggerHidden]
public override object GetValueDirect(TypedReference obj)
@@ -149,13 +129,6 @@ public override object GetValueDirect(TypedReference obj)
}
}
- [DebuggerStepThrough]
- [DebuggerHidden]
- internal override object? GetValueNonEmit(object? obj)
- {
- return GetValueInternal(obj);
- }
-
public override FieldAttributes Attributes
{
get
@@ -239,7 +212,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit)
if (!IsLiteral)
CheckGeneric();
- return Invoker.GetValue(obj);
+ return GetValueInternal(obj);
}
public override string ToString()
@@ -278,7 +251,7 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr,
}
}
- Invoker.SetValue(obj, val);
+ SetValueInternal(this, obj, val);
}
internal RuntimeFieldInfo Clone(string newName)