Skip to content

Commit

Permalink
Use named nested anonymous types (dotnet/coreclr#27485)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@b46c857
  • Loading branch information
am11 authored and jkotas committed Oct 27, 2019
1 parent 0c557e5 commit 8abf9cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
42 changes: 21 additions & 21 deletions src/coreclr/src/vm/fieldmarshaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,22 @@ BOOL IsStructMarshalable(TypeHandle th)
}

NativeFieldDescriptor::NativeFieldDescriptor()
:m_nativeSize(1),
m_alignmentRequirement(1),
m_offset(0),
:m_offset(0),
m_flags(NATIVE_FIELD_CATEGORY_ILLEGAL),
m_isNestedType(false)
{
nativeSizeAndAlignment.m_nativeSize = 1;
nativeSizeAndAlignment.m_alignmentRequirement = 1;
m_pFD.SetValueMaybeNull(nullptr);
}

NativeFieldDescriptor::NativeFieldDescriptor(NativeFieldFlags flags, ULONG nativeSize, ULONG alignment)
:m_nativeSize(nativeSize),
m_alignmentRequirement(alignment),
m_offset(0),
:m_offset(0),
m_flags(flags),
m_isNestedType(false)
{
nativeSizeAndAlignment.m_nativeSize = nativeSize;
nativeSizeAndAlignment.m_alignmentRequirement = alignment;
m_pFD.SetValueMaybeNull(nullptr);
}

Expand All @@ -320,8 +320,8 @@ NativeFieldDescriptor::NativeFieldDescriptor(PTR_MethodTable pMT, int numElement
CONTRACTL_END;

m_pFD.SetValueMaybeNull(nullptr);
m_pNestedType.SetValue(pMT);
m_numElements = numElements;
nestedTypeAndCount.m_pNestedType.SetValue(pMT);
nestedTypeAndCount.m_numElements = numElements;
m_flags = isBlittable ? NATIVE_FIELD_CATEGORY_NESTED_BLITTABLE : NATIVE_FIELD_CATEGORY_NESTED;
m_isNestedType = true;
}
Expand All @@ -334,13 +334,13 @@ NativeFieldDescriptor::NativeFieldDescriptor(const NativeFieldDescriptor& other)
m_pFD.SetValueMaybeNull(other.m_pFD.GetValueMaybeNull());
if (m_isNestedType)
{
m_pNestedType.SetValueMaybeNull(other.m_pNestedType.GetValueMaybeNull());
m_numElements = other.m_numElements;
nestedTypeAndCount.m_pNestedType.SetValueMaybeNull(other.nestedTypeAndCount.m_pNestedType.GetValueMaybeNull());
nestedTypeAndCount.m_numElements = other.nestedTypeAndCount.m_numElements;
}
else
{
m_nativeSize = other.m_nativeSize;
m_alignmentRequirement = other.m_alignmentRequirement;
nativeSizeAndAlignment.m_nativeSize = other.nativeSizeAndAlignment.m_nativeSize;
nativeSizeAndAlignment.m_alignmentRequirement = other.nativeSizeAndAlignment.m_alignmentRequirement;
}
}

Expand All @@ -353,13 +353,13 @@ NativeFieldDescriptor& NativeFieldDescriptor::operator=(const NativeFieldDescrip

if (m_isNestedType)
{
m_pNestedType.SetValueMaybeNull(other.m_pNestedType.GetValueMaybeNull());
m_numElements = other.m_numElements;
nestedTypeAndCount.m_pNestedType.SetValueMaybeNull(other.nestedTypeAndCount.m_pNestedType.GetValueMaybeNull());
nestedTypeAndCount.m_numElements = other.nestedTypeAndCount.m_numElements;
}
else
{
m_nativeSize = other.m_nativeSize;
m_alignmentRequirement = other.m_alignmentRequirement;
nativeSizeAndAlignment.m_nativeSize = other.nativeSizeAndAlignment.m_nativeSize;
nativeSizeAndAlignment.m_alignmentRequirement = other.nativeSizeAndAlignment.m_alignmentRequirement;
}

return *this;
Expand All @@ -378,7 +378,7 @@ PTR_MethodTable NativeFieldDescriptor::GetNestedNativeMethodTable() const
}
CONTRACT_END;

RETURN m_pNestedType.GetValue();
RETURN nestedTypeAndCount.m_pNestedType.GetValue();
}

PTR_FieldDesc NativeFieldDescriptor::GetFieldDesc() const
Expand All @@ -401,7 +401,7 @@ BOOL NativeFieldDescriptor::IsRestored() const
WRAPPER_NO_CONTRACT;

#ifdef FEATURE_PREJIT
return m_pNestedType.IsNull() || (!m_pNestedType.IsTagged() && m_pNestedType.GetValue()->IsRestored());
return nestedTypeAndCount.m_pNestedType.IsNull() || (!nestedTypeAndCount.m_pNestedType.IsTagged() && nestedTypeAndCount.m_pNestedType.GetValue()->IsRestored());
#else // FEATURE_PREJIT
// putting the IsFullyLoaded check here is tempting but incorrect
return TRUE;
Expand All @@ -416,7 +416,7 @@ void NativeFieldDescriptor::Restore()
THROWS;
GC_TRIGGERS;
MODE_ANY;
PRECONDITION(!m_isNestedType || CheckPointer(m_pNestedType.GetValue()));
PRECONDITION(!m_isNestedType || CheckPointer(nestedTypeAndCount.m_pNestedType.GetValue()));
}
CONTRACTL_END;

Expand All @@ -429,10 +429,10 @@ void NativeFieldDescriptor::Restore()
{

#ifdef FEATURE_PREJIT
Module::RestoreMethodTablePointer(&m_pNestedType);
Module::RestoreMethodTablePointer(&nestedTypeAndCount.m_pNestedType);
#else // FEATURE_PREJIT
// without NGEN we only have to make sure that the type is fully loaded
PTR_MethodTable pMT = m_pNestedType.GetValue();
PTR_MethodTable pMT = nestedTypeAndCount.m_pNestedType.GetValue();
if (pMT != NULL)
ClassLoader::EnsureLoaded(pMT);
#endif // FEATURE_PREJIT
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/src/vm/fieldmarshaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class NativeFieldDescriptor

if (m_isNestedType)
{
image->FixupMethodTablePointer(this, &m_pNestedType);
image->FixupMethodTablePointer(this, &nestedTypeAndCount.m_pNestedType);
}
}
#endif // defined(FEATURE_PREJIT) && !defined(DACCESS_COMPILE)
Expand All @@ -127,7 +127,7 @@ class NativeFieldDescriptor
}
CONTRACTL_END;

return m_numElements;
return nestedTypeAndCount.m_numElements;
}

UINT32 NativeSize() const
Expand All @@ -138,7 +138,7 @@ class NativeFieldDescriptor
}
else
{
return m_nativeSize;
return nativeSizeAndAlignment.m_nativeSize;
}
}

Expand All @@ -150,7 +150,7 @@ class NativeFieldDescriptor
}
else
{
return m_alignmentRequirement;
return nativeSizeAndAlignment.m_alignmentRequirement;
}
}

Expand Down Expand Up @@ -186,12 +186,12 @@ class NativeFieldDescriptor
{
RelativeFixupPointer<PTR_MethodTable> m_pNestedType;
ULONG m_numElements;
};
} nestedTypeAndCount;
struct
{
UINT32 m_nativeSize;
UINT32 m_alignmentRequirement;
};
} nativeSizeAndAlignment;
};
UINT32 m_offset;
NativeFieldFlags m_flags;
Expand Down

0 comments on commit 8abf9cb

Please sign in to comment.