Skip to content

Commit

Permalink
Allocate memory for non gc statics (dotnet#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Oct 4, 2020
1 parent 30e6731 commit d77a0eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2840,9 +2840,9 @@ private void InterpretLoadStaticField(FieldDesc field)
var fieldOffset = field.Offset.AsInt;
var staticsBase = field switch
{
{ HasGCStaticBase: false, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetNonGcStaticFieldData(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: false, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetNonGcStaticFieldDataDirect(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: false, IsThreadStatic: true } => IntPtr.Zero,
{ HasGCStaticBase: true, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetGcStaticFieldData(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: true, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetGcStaticFieldDataDirect(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: true, IsThreadStatic: true } => IntPtr.Zero,
};

Expand Down Expand Up @@ -3015,9 +3015,9 @@ private void InterpretStoreStaticField(FieldDesc field)
var fieldOffset = field.Offset.AsInt;
var staticsBase = field switch
{
{ HasGCStaticBase: false, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetNonGcStaticFieldData(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: false, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetNonGcStaticFieldDataDirect(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: false, IsThreadStatic: true } => IntPtr.Zero,
{ HasGCStaticBase: true, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetGcStaticFieldData(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: true, IsThreadStatic: false } => TypeLoaderEnvironment.Instance.TryGetNonGcStaticFieldDataDirect(field.OwningType.GetRuntimeTypeHandle()),
{ HasGCStaticBase: true, IsThreadStatic: true } => IntPtr.Zero,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,15 @@ private static void CreateEETypeWorker(EEType* pTemplateEEType, UInt32 hashCodeO
if (isGeneric)
{
genericComposition = MemoryHelpers.AllocateMemory(EEType.GetGenericCompositionSize(arity, pEEType->HasGenericVariance));
pEEType->SetGenericComposition(genericComposition);
pEEType->SetGenericComposition(genericComposition);
}

if (state.NonGcDataSize > 0)
{
nonGcStaticData = MemoryHelpers.AllocateMemory(state.NonGcDataSize);
MemoryHelpers.Memset(nonGcStaticData, state.NonGcDataSize, 0);
Debug.Assert(nonGCStaticDataOffset <= state.NonGcDataSize);
pEEType->DynamicNonGcStaticsData = (IntPtr)((byte*)nonGcStaticData + nonGCStaticDataOffset);
}
if (state.NonGcDataSize > 0)
{
nonGcStaticData = MemoryHelpers.AllocateMemory(state.NonGcDataSize);
MemoryHelpers.Memset(nonGcStaticData, state.NonGcDataSize, 0);
Debug.Assert(nonGCStaticDataOffset <= state.NonGcDataSize);
pEEType->DynamicNonGcStaticsData = (IntPtr)((byte*)nonGcStaticData + nonGCStaticDataOffset);
}

if (!isGenericEETypeDef && state.ThreadDataSize != 0)
Expand Down

0 comments on commit d77a0eb

Please sign in to comment.