Skip to content

Commit

Permalink
Make GCMemoryInfoData blittable (#58738)
Browse files Browse the repository at this point in the history
The runtime side makes assumptions about the layout of this class, but since the class is not blittable, the runtime is free to reorder the fields however it sees fit (`StructLayout(LayoutKind.Sequential)` only affects the *managed* layout of blittable classes - it's not documented to do anything to the managed layout of non-blittable classes).

This prevents improvements to managed layout such as #51416.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
MichalStrehovsky and jkotas committed Sep 18, 2021
1 parent eafc6f1 commit a842e7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
12 changes: 1 addition & 11 deletions src/coreclr/vm/comutilnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ struct GCGenerationInfo
UINT64 fragmentationAfter;
};

#if defined(TARGET_X86) && !defined(TARGET_UNIX)
#include "pshpack4.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4121) // alignment of a member was sensitive to packing
#endif
#endif
class GCMemoryInfoData : public Object
{
public:
Expand All @@ -107,6 +101,7 @@ class GCMemoryInfoData : public Object
UINT32 pauseTimePercent;
UINT8 isCompaction;
UINT8 isConcurrent;
UINT8 padding[6];
GCGenerationInfo generationInfo0;
GCGenerationInfo generationInfo1;
GCGenerationInfo generationInfo2;
Expand All @@ -115,12 +110,7 @@ class GCMemoryInfoData : public Object
UINT64 pauseDuration0;
UINT64 pauseDuration1;
};
#if defined(TARGET_X86) && !defined(TARGET_UNIX)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "poppack.h"
#endif

#ifdef USE_CHECKED_OBJECTREFS
typedef REF<GCMemoryInfoData> GCMEMORYINFODATA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ internal sealed class GCMemoryInfoData
internal long _index;
internal int _generation;
internal int _pauseTimePercentage;
internal bool _compacted;
internal bool _concurrent;
internal byte _compacted;
internal byte _concurrent;

private GCGenerationInfo _generationInfo0;
private GCGenerationInfo _generationInfo1;
Expand Down Expand Up @@ -158,12 +158,12 @@ internal GCMemoryInfo(GCMemoryInfoData data)
/// <summary>
/// Is this a compacting GC or not.
/// </summary>
public bool Compacted => _data._compacted;
public bool Compacted => _data._compacted != 0;

/// <summary>
/// Is this a concurrent GC (BGC) or not.
/// </summary>
public bool Concurrent => _data._concurrent;
public bool Concurrent => _data._concurrent != 0;

/// <summary>
/// Total committed bytes of the managed heap.
Expand Down

0 comments on commit a842e7a

Please sign in to comment.