Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(); }
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,6 @@ class ReflectFieldObject : public BaseObjectWithCachedData
INT32 m_empty2;
OBJECTREF m_empty3;
OBJECTREF m_empty4;
OBJECTREF m_empty5;
FieldDesc * m_pFD;

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ExceptionHandlingClause.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ExceptionHandlingClauseOptions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldAccessor.cs" Condition="'$(FeatureNativeAot)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\GenericParameterAttributes.cs" />
Expand Down Expand Up @@ -2456,4 +2455,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
</ItemGroup>
</Project>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down