From 5e88eaaa8ed75ee4e6653ce333da5747c4c54394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 7 Sep 2021 09:25:00 +0900 Subject: [PATCH 1/3] Make GCMemoryInfo blittable 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. --- .../System.Private.CoreLib/src/System/GCMemoryInfo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs b/src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs index 9754b21ef79f3..4a75f254eaab8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs @@ -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; @@ -158,12 +158,12 @@ internal GCMemoryInfo(GCMemoryInfoData data) /// /// Is this a compacting GC or not. /// - public bool Compacted => _data._compacted; + public bool Compacted => _data._compacted != 0; /// /// Is this a concurrent GC (BGC) or not. /// - public bool Concurrent => _data._concurrent; + public bool Concurrent => _data._concurrent != 0; /// /// Total committed bytes of the managed heap. From 15805f1be0d1e5a8d4b6aa57bcea6a880a9f89d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 7 Sep 2021 10:58:33 +0900 Subject: [PATCH 2/3] Maybe fix x86? --- src/coreclr/vm/comutilnative.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/coreclr/vm/comutilnative.h b/src/coreclr/vm/comutilnative.h index f59bbe7f66c11..b4c89bbc71df6 100644 --- a/src/coreclr/vm/comutilnative.h +++ b/src/coreclr/vm/comutilnative.h @@ -83,13 +83,6 @@ 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: @@ -115,12 +108,6 @@ 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; From f6119a2f1ae5c26222ab79620e6fba87cd28f7ca Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 17 Sep 2021 17:28:42 -0700 Subject: [PATCH 3/3] Fix? --- src/coreclr/vm/comutilnative.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/vm/comutilnative.h b/src/coreclr/vm/comutilnative.h index b4c89bbc71df6..11f805e4b66fc 100644 --- a/src/coreclr/vm/comutilnative.h +++ b/src/coreclr/vm/comutilnative.h @@ -83,6 +83,7 @@ struct GCGenerationInfo UINT64 fragmentationAfter; }; +#include "pshpack4.h" class GCMemoryInfoData : public Object { public: @@ -100,6 +101,7 @@ class GCMemoryInfoData : public Object UINT32 pauseTimePercent; UINT8 isCompaction; UINT8 isConcurrent; + UINT8 padding[6]; GCGenerationInfo generationInfo0; GCGenerationInfo generationInfo1; GCGenerationInfo generationInfo2; @@ -108,6 +110,7 @@ class GCMemoryInfoData : public Object UINT64 pauseDuration0; UINT64 pauseDuration1; }; +#include "poppack.h" #ifdef USE_CHECKED_OBJECTREFS typedef REF GCMEMORYINFODATA;