From 000b528e638ad8d7c73816b23e4ab7a0e21e2089 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 4 Jul 2024 02:37:26 +0200 Subject: [PATCH 01/16] Enable "Allocate on stack" for NAOT/R2R --- .../System.Private.CoreLib.csproj | 1 - src/coreclr/jit/objectalloc.h | 9 --------- .../tools/Common/JitInterface/CorInfoImpl.cs | 18 +++++++++++++++--- .../System.Private.CoreLib.Shared.projitems | 1 + .../CompilerServices/StackAllocatedBox.cs | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) rename src/{coreclr => libraries}/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs (90%) diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj index f1282ff6768c4..1586ba4132120 100644 --- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -197,7 +197,6 @@ - diff --git a/src/coreclr/jit/objectalloc.h b/src/coreclr/jit/objectalloc.h index 283216d79482b..8a873be8b34ad 100644 --- a/src/coreclr/jit/objectalloc.h +++ b/src/coreclr/jit/objectalloc.h @@ -164,15 +164,6 @@ inline bool ObjectAllocator::CanAllocateLclVarOnStack(unsigned int lclNu return false; } -#ifdef FEATURE_READYTORUN - if (comp->opts.IsReadyToRun()) - { - // Need to fix getClassGClayout and maybe more - *reason = "[R2R/NAOT support NYI]"; - return false; - } -#endif - classSize = comp->info.compCompHnd->getHeapClassSize(clsHnd); } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index c97828d4f01d5..76e400164a6c9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2606,9 +2606,21 @@ private CorInfoHelpFunc getSharedCCtorHelper(CORINFO_CLASS_STRUCT_* clsHnd) private CORINFO_CLASS_STRUCT_* getTypeForBoxOnStack(CORINFO_CLASS_STRUCT_* cls) { - // Todo: implement... - _ = HandleToObject(cls); - return null; + TypeDesc clsTypeDesc = HandleToObject(cls); + if (clsTypeDesc.IsNullable) + { + clsTypeDesc = clsTypeDesc.Instantiation[0]; + } + + if (clsTypeDesc.RequiresAlign8()) + { + // Conservatively give up on such types (32bit) + return null; + } + + // Instantiate StackAllocatedBox helper type with the type we're boxing + MetadataType placeholderType = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.CompilerServices", "StackAllocatedBox`1"); + return ObjectToHandle(placeholderType.MakeInstantiatedType(clsTypeDesc)); } private CorInfoHelpFunc getBoxHelper(CORINFO_CLASS_STRUCT_* cls) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 233d19f0d5b5f..9045c03a920b9 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -896,6 +896,7 @@ + diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs similarity index 90% rename from src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs index 885a2d93c6242..a47a888a78ecf 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs @@ -9,7 +9,7 @@ namespace System.Runtime.CompilerServices internal unsafe struct StackAllocatedBox { // These fields are only accessed from jitted code - private MethodTable* _pMethodTable; + private IntPtr _pMethodTable; private T _value; } } From 67b495dfecdb9fb9345936b68f540b76456c05fd Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 4 Jul 2024 19:17:11 +0200 Subject: [PATCH 02/16] Fix getClassGClayout on NAOT --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 76e400164a6c9..c7129bd873af5 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2352,14 +2352,8 @@ private uint getClassGClayout(CORINFO_CLASS_STRUCT_* cls, byte* gcPtrs) uint result = 0; MetadataType type = (MetadataType)HandleToObject(cls); - - int pointerSize = PointerSize; - - int ptrsCount = AlignmentHelper.AlignUp(type.InstanceFieldSize.AsInt, pointerSize) / pointerSize; - - // Assume no GC pointers at first - for (int i = 0; i < ptrsCount; i++) - gcPtrs[i] = (byte)CorInfoGCType.TYPE_GC_NONE; + uint size = type.IsValueType ? getClassSize(cls) : getHeapClassSize(cls); + new Span(gcPtrs, (int)((size + PointerSize - 1) / PointerSize)).Clear(); if (type.ContainsGCPointers || type.IsByRefLike) { From 8e0e9eb28d3baca93e5aaf083bfacb112b00965d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 4 Jul 2024 22:30:31 +0200 Subject: [PATCH 03/16] Handle CORINFO_HELP_UNBOX_TYPETEST on NAOT/R2R --- src/coreclr/inc/corinfoinstructionset.h | 24 +++++----- src/coreclr/inc/jiteeversionguid.h | 10 ++-- src/coreclr/inc/readytorun.h | 4 +- src/coreclr/inc/readytorunhelpers.h | 1 + .../src/System/Runtime/RuntimeExports.cs | 24 ++++++++++ .../nativeaot/Runtime/inc/ModuleHeaders.h | 2 +- .../Common/Internal/Runtime/ModuleHeaders.cs | 2 +- .../Internal/Runtime/ReadyToRunConstants.cs | 1 + .../JitInterface/CorInfoInstructionSet.cs | 48 +++++++++---------- .../ILCompiler.Compiler/Compiler/JitHelper.cs | 3 ++ .../JitInterface/CorInfoImpl.ReadyToRun.cs | 3 ++ .../ReadyToRunSignature.cs | 4 ++ .../ILCompiler.RyuJit.csproj | 6 +++ .../JitInterface/CorInfoImpl.RyuJit.cs | 3 ++ 14 files changed, 91 insertions(+), 44 deletions(-) diff --git a/src/coreclr/inc/corinfoinstructionset.h b/src/coreclr/inc/corinfoinstructionset.h index 9a3c0efc70927..43f2be795314f 100644 --- a/src/coreclr/inc/corinfoinstructionset.h +++ b/src/coreclr/inc/corinfoinstructionset.h @@ -608,18 +608,18 @@ inline CORINFO_InstructionSetFlags EnsureInstructionSetFlagsAreValid(CORINFO_Ins resultflags.RemoveInstructionSet(InstructionSet_AVX512F); if (resultflags.HasInstructionSet(InstructionSet_AVX512F_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) resultflags.RemoveInstructionSet(InstructionSet_AVX512F_VL); - if (resultflags.HasInstructionSet(InstructionSet_AVX512CD) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) - resultflags.RemoveInstructionSet(InstructionSet_AVX512CD); - if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512CD)) - resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); - if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F_VL)) - resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet_AVX512BW) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) resultflags.RemoveInstructionSet(InstructionSet_AVX512BW); if (resultflags.HasInstructionSet(InstructionSet_AVX512BW_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512BW)) resultflags.RemoveInstructionSet(InstructionSet_AVX512BW_VL); if (resultflags.HasInstructionSet(InstructionSet_AVX512BW_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F_VL)) resultflags.RemoveInstructionSet(InstructionSet_AVX512BW_VL); + if (resultflags.HasInstructionSet(InstructionSet_AVX512CD) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) + resultflags.RemoveInstructionSet(InstructionSet_AVX512CD); + if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512CD)) + resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); + if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F_VL)) + resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet_AVX512DQ) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) resultflags.RemoveInstructionSet(InstructionSet_AVX512DQ); if (resultflags.HasInstructionSet(InstructionSet_AVX512DQ_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512DQ)) @@ -714,18 +714,18 @@ inline CORINFO_InstructionSetFlags EnsureInstructionSetFlagsAreValid(CORINFO_Ins resultflags.RemoveInstructionSet(InstructionSet_AVX512F); if (resultflags.HasInstructionSet(InstructionSet_AVX512F_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) resultflags.RemoveInstructionSet(InstructionSet_AVX512F_VL); - if (resultflags.HasInstructionSet(InstructionSet_AVX512CD) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) - resultflags.RemoveInstructionSet(InstructionSet_AVX512CD); - if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512CD)) - resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); - if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F_VL)) - resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet_AVX512BW) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) resultflags.RemoveInstructionSet(InstructionSet_AVX512BW); if (resultflags.HasInstructionSet(InstructionSet_AVX512BW_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512BW)) resultflags.RemoveInstructionSet(InstructionSet_AVX512BW_VL); if (resultflags.HasInstructionSet(InstructionSet_AVX512BW_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F_VL)) resultflags.RemoveInstructionSet(InstructionSet_AVX512BW_VL); + if (resultflags.HasInstructionSet(InstructionSet_AVX512CD) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) + resultflags.RemoveInstructionSet(InstructionSet_AVX512CD); + if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512CD)) + resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); + if (resultflags.HasInstructionSet(InstructionSet_AVX512CD_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512F_VL)) + resultflags.RemoveInstructionSet(InstructionSet_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet_AVX512DQ) && !resultflags.HasInstructionSet(InstructionSet_AVX512F)) resultflags.RemoveInstructionSet(InstructionSet_AVX512DQ); if (resultflags.HasInstructionSet(InstructionSet_AVX512DQ_VL) && !resultflags.HasInstructionSet(InstructionSet_AVX512DQ)) diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 84284fd2c34a7..f5083f8fd416f 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* e6c7a441-8d3c-4135-abc2-bc4dd7c6a4d7 */ - 0xe6c7a441, - 0x8d3c, - 0x4135, - {0xab, 0xc2, 0xbc, 0x4d, 0xd7, 0xc6, 0xa4, 0xd7} +constexpr GUID JITEEVersionIdentifier = { /* 09a675fa-5035-4437-ae49-824fa63aa69a */ + 0x09a675fa, + 0x5035, + 0x4437, + {0xae, 0x49, 0x82, 0x4f, 0xa6, 0x3a, 0xa6, 0x9a} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/inc/readytorun.h b/src/coreclr/inc/readytorun.h index 521ad7e2ca54e..4423363fb5b36 100644 --- a/src/coreclr/inc/readytorun.h +++ b/src/coreclr/inc/readytorun.h @@ -20,7 +20,7 @@ // If you update this, ensure you run `git grep MINIMUM_READYTORUN_MAJOR_VERSION` // and handle pending work. #define READYTORUN_MAJOR_VERSION 10 -#define READYTORUN_MINOR_VERSION 0x0000 +#define READYTORUN_MINOR_VERSION 0x0001 #define MINIMUM_READYTORUN_MAJOR_VERSION 10 @@ -37,6 +37,7 @@ // R2R Version 9.3 adds BulkWriteBarrier helper // uses GCInfo v3, which makes safe points in partially interruptible code interruptible. // R2R Version 10.0 adds support for the statics being allocated on a per type basis instead of on a per module basis +// R2R Version 10.1 adds Unbox_TypeTest helper struct READYTORUN_CORE_HEADER { @@ -357,6 +358,7 @@ enum ReadyToRunHelper READYTORUN_HELPER_Unbox = 0x5A, READYTORUN_HELPER_Unbox_Nullable = 0x5B, READYTORUN_HELPER_NewMultiDimArr = 0x5C, + READYTORUN_HELPER_Unbox_TypeTest = 0x5D, // Helpers used with generic handle lookup cases READYTORUN_HELPER_NewObject = 0x60, diff --git a/src/coreclr/inc/readytorunhelpers.h b/src/coreclr/inc/readytorunhelpers.h index ec9734691ed47..40567be02aa3c 100644 --- a/src/coreclr/inc/readytorunhelpers.h +++ b/src/coreclr/inc/readytorunhelpers.h @@ -45,6 +45,7 @@ HELPER(READYTORUN_HELPER_Box_Nullable, CORINFO_HELP_BOX_NULLABLE, HELPER(READYTORUN_HELPER_Unbox, CORINFO_HELP_UNBOX, ) HELPER(READYTORUN_HELPER_Unbox_Nullable, CORINFO_HELP_UNBOX_NULLABLE, ) HELPER(READYTORUN_HELPER_NewMultiDimArr, CORINFO_HELP_NEW_MDARR, ) +HELPER(READYTORUN_HELPER_Unbox_TypeTest, CORINFO_HELP_UNBOX_TYPETEST, ) HELPER(READYTORUN_HELPER_NewObject, CORINFO_HELP_NEWFAST, ) HELPER(READYTORUN_HELPER_NewArray, CORINFO_HELP_NEWARR_1_DIRECT, ) diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs index 6fa6c5460dbb8..5867d8aeb6dc7 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs @@ -11,6 +11,8 @@ using Internal.Runtime; +using static Interop; + namespace System.Runtime { internal static partial class RuntimeExports @@ -227,6 +229,28 @@ public static unsafe void RhUnboxNullable(ref byte data, MethodTable* pUnboxToEE RhUnbox(obj, ref data, pUnboxToEEType); } + [RuntimeExport("RhUnboxTypeTest")] + public static unsafe void RhUnboxTypeTest(MethodTable* pMT1, MethodTable* pMT2) + { + var eeType1 = new EETypePtr(pMT1); + var eeType2 = new EETypePtr(pMT2); + + if (eeType1.CorElementType == eeType2.CorElementType && + (pMT1->IsEnum || pMT1->IsActualPrimitive) && + (pMT2->IsEnum || pMT2->IsActualPrimitive)) + { + // type test test passes + } + ////else if (pMT1->IsEquivalentTo(pMT2)) + ////{ + //// // the structures are equivalent + ////} + else + { + throw pMT2->GetClasslibException(ExceptionIDs.InvalidCast); + } + } + [RuntimeExport("RhUnbox")] public static unsafe void RhUnbox(object? obj, ref byte data, MethodTable* pUnboxToEEType) { diff --git a/src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h b/src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h index f3f60f6900924..37e5883b4059b 100644 --- a/src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h +++ b/src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h @@ -12,7 +12,7 @@ struct ReadyToRunHeaderConstants static const uint32_t Signature = 0x00525452; // 'RTR' static const uint32_t CurrentMajorVersion = 10; - static const uint32_t CurrentMinorVersion = 0; + static const uint32_t CurrentMinorVersion = 1; }; struct ReadyToRunHeader diff --git a/src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs b/src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs index 8aa1080913076..51860d1341c7b 100644 --- a/src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs +++ b/src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs @@ -16,7 +16,7 @@ internal struct ReadyToRunHeaderConstants public const uint Signature = 0x00525452; // 'RTR' public const ushort CurrentMajorVersion = 10; - public const ushort CurrentMinorVersion = 0; + public const ushort CurrentMinorVersion = 1; } #if READYTORUN #pragma warning disable 0169 diff --git a/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs b/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs index af86b107e5b31..a4c945baae988 100644 --- a/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs +++ b/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs @@ -267,6 +267,7 @@ public enum ReadyToRunHelper Unbox = 0x5A, Unbox_Nullable = 0x5B, NewMultiDimArr = 0x5C, + Unbox_TypeTest = 0x5D, // Helpers used with generic handle lookup cases NewObject = 0x60, diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs b/src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs index 9971accb07818..42807bfcec1d9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs @@ -746,18 +746,18 @@ public static InstructionSetFlags ExpandInstructionSetByImplicationHelper(Target resultflags.AddInstructionSet(InstructionSet.X64_EVEX); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F_VL)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512F); - if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD)) - resultflags.AddInstructionSet(InstructionSet.X64_AVX512F); - if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD_VL)) - resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD); - if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD_VL)) - resultflags.AddInstructionSet(InstructionSet.X64_AVX512F_VL); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512BW)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512F); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512BW_VL)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512BW); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512BW_VL)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512F_VL); + if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD)) + resultflags.AddInstructionSet(InstructionSet.X64_AVX512F); + if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD_VL)) + resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD); + if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD_VL)) + resultflags.AddInstructionSet(InstructionSet.X64_AVX512F_VL); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512DQ)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512F); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512DQ_VL)) @@ -853,18 +853,18 @@ public static InstructionSetFlags ExpandInstructionSetByImplicationHelper(Target resultflags.AddInstructionSet(InstructionSet.X86_EVEX); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F_VL)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512F); - if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD)) - resultflags.AddInstructionSet(InstructionSet.X86_AVX512F); - if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD_VL)) - resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD); - if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD_VL)) - resultflags.AddInstructionSet(InstructionSet.X86_AVX512F_VL); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512BW)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512F); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512BW_VL)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512BW); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512BW_VL)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512F_VL); + if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD)) + resultflags.AddInstructionSet(InstructionSet.X86_AVX512F); + if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD_VL)) + resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD); + if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD_VL)) + resultflags.AddInstructionSet(InstructionSet.X86_AVX512F_VL); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512DQ)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512F); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512DQ_VL)) @@ -1087,18 +1087,18 @@ private static InstructionSetFlags ExpandInstructionSetByReverseImplicationHelpe resultflags.AddInstructionSet(InstructionSet.X64_AVX512F); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512F_VL); - if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F)) - resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD); - if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD)) - resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD_VL); - if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F_VL)) - resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512BW); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512BW)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512BW_VL); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F_VL)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512BW_VL); + if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F)) + resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD); + if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512CD)) + resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD_VL); + if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F_VL)) + resultflags.AddInstructionSet(InstructionSet.X64_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512F)) resultflags.AddInstructionSet(InstructionSet.X64_AVX512DQ); if (resultflags.HasInstructionSet(InstructionSet.X64_AVX512DQ)) @@ -1194,18 +1194,18 @@ private static InstructionSetFlags ExpandInstructionSetByReverseImplicationHelpe resultflags.AddInstructionSet(InstructionSet.X86_AVX512F); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512F_VL); - if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F)) - resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD); - if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD)) - resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD_VL); - if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F_VL)) - resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512BW); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512BW)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512BW_VL); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F_VL)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512BW_VL); + if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F)) + resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD); + if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512CD)) + resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD_VL); + if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F_VL)) + resultflags.AddInstructionSet(InstructionSet.X86_AVX512CD_VL); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512F)) resultflags.AddInstructionSet(InstructionSet.X86_AVX512DQ); if (resultflags.HasInstructionSet(InstructionSet.X86_AVX512DQ)) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs index c04658df379f7..ad06db49ecc23 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs @@ -119,6 +119,9 @@ public static void GetEntryPoint(TypeSystemContext context, ReadyToRunHelper id, case ReadyToRunHelper.Unbox_Nullable: mangledName = "RhUnboxNullable"; break; + case ReadyToRunHelper.Unbox_TypeTest: + mangledName = "RhUnboxTypeTest"; + break; case ReadyToRunHelper.NewMultiDimArr: methodDesc = context.GetHelperEntryPoint("ArrayHelpers", "NewObjArray"); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 4b5a5910988b3..69727ff369e38 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -1065,6 +1065,9 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum) case CorInfoHelpFunc.CORINFO_HELP_UNBOX: id = ReadyToRunHelper.Unbox; break; + case CorInfoHelpFunc.CORINFO_HELP_UNBOX_TYPETEST: + id = ReadyToRunHelper.Unbox_TypeTest; + break; case CorInfoHelpFunc.CORINFO_HELP_UNBOX_NULLABLE: id = ReadyToRunHelper.Unbox_Nullable; break; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs index 329b95f5d3c4e..4a62123d694af 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs @@ -1765,6 +1765,10 @@ private void ParseHelper(StringBuilder builder) builder.Append("UNBOX_NULLABLE"); break; + case ReadyToRunHelper.Unbox_TypeTest: + builder.Append("UNBOX_TYPETEST"); + break; + case ReadyToRunHelper.NewMultiDimArr: builder.Append("NEW_MULTI_DIM_ARR"); break; diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj b/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj index 3ddf3e46a13cb..bb224ee8af366 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj @@ -16,6 +16,12 @@ false Debug;Release;Checked + + False + + + False + diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 3ce82beeac667..db9786e2646ef 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -586,6 +586,9 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum) case CorInfoHelpFunc.CORINFO_HELP_UNBOX: id = ReadyToRunHelper.Unbox; break; + case CorInfoHelpFunc.CORINFO_HELP_UNBOX_TYPETEST: + id = ReadyToRunHelper.Unbox_TypeTest; + break; case CorInfoHelpFunc.CORINFO_HELP_UNBOX_NULLABLE: id = ReadyToRunHelper.Unbox_Nullable; break; From 2a62eeb1e3f6669688256baa474f2c87fbb25ed2 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 4 Jul 2024 22:38:32 +0200 Subject: [PATCH 04/16] fix build --- .../src/System/Runtime/RuntimeExports.cs | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs index 5867d8aeb6dc7..0acf86a0106fe 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs @@ -229,27 +229,29 @@ public static unsafe void RhUnboxNullable(ref byte data, MethodTable* pUnboxToEE RhUnbox(obj, ref data, pUnboxToEEType); } +#pragma warning disable IDE0060 [RuntimeExport("RhUnboxTypeTest")] public static unsafe void RhUnboxTypeTest(MethodTable* pMT1, MethodTable* pMT2) { - var eeType1 = new EETypePtr(pMT1); - var eeType2 = new EETypePtr(pMT2); - - if (eeType1.CorElementType == eeType2.CorElementType && - (pMT1->IsEnum || pMT1->IsActualPrimitive) && - (pMT2->IsEnum || pMT2->IsActualPrimitive)) - { - // type test test passes - } - ////else if (pMT1->IsEquivalentTo(pMT2)) - ////{ - //// // the structures are equivalent - ////} - else - { - throw pMT2->GetClasslibException(ExceptionIDs.InvalidCast); - } + //var eeType1 = new EETypePtr(pMT1); + //var eeType2 = new EETypePtr(pMT2); + // + //if (eeType1.CorElementType == eeType2.CorElementType && + // (pMT1->IsEnum || pMT1->IsActualPrimitive) && + // (pMT2->IsEnum || pMT2->IsActualPrimitive)) + //{ + // // type test test passes + //} + //else if (pMT1->IsEquivalentTo(pMT2)) + //{ + // // the structures are equivalent + //} + //else + //{ + // throw pMT2->GetClasslibException(ExceptionIDs.InvalidCast); + //} } +#pragma warning restore IDE0060 [RuntimeExport("RhUnbox")] public static unsafe void RhUnbox(object? obj, ref byte data, MethodTable* pUnboxToEEType) From 741e4fae12169afe0f8e01830bc1bfad21ab9990 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 5 Jul 2024 11:24:28 +0200 Subject: [PATCH 05/16] implement RhUnboxTypeTest --- .../src/System/Runtime/RuntimeExports.cs | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs index 0acf86a0106fe..76f16fe96cf5f 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs @@ -229,29 +229,14 @@ public static unsafe void RhUnboxNullable(ref byte data, MethodTable* pUnboxToEE RhUnbox(obj, ref data, pUnboxToEEType); } -#pragma warning disable IDE0060 [RuntimeExport("RhUnboxTypeTest")] public static unsafe void RhUnboxTypeTest(MethodTable* pMT1, MethodTable* pMT2) { - //var eeType1 = new EETypePtr(pMT1); - //var eeType2 = new EETypePtr(pMT2); - // - //if (eeType1.CorElementType == eeType2.CorElementType && - // (pMT1->IsEnum || pMT1->IsActualPrimitive) && - // (pMT2->IsEnum || pMT2->IsActualPrimitive)) - //{ - // // type test test passes - //} - //else if (pMT1->IsEquivalentTo(pMT2)) - //{ - // // the structures are equivalent - //} - //else - //{ - // throw pMT2->GetClasslibException(ExceptionIDs.InvalidCast); - //} + if (!UnboxAnyTypeCompare(pMT1, pMT2)) + { + throw pMT2->GetClasslibException(ExceptionIDs.InvalidCast); + } } -#pragma warning restore IDE0060 [RuntimeExport("RhUnbox")] public static unsafe void RhUnbox(object? obj, ref byte data, MethodTable* pUnboxToEEType) From 396677b0478827657ceef50c1e9a4da17c77615b Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 5 Jul 2024 11:29:46 +0200 Subject: [PATCH 06/16] Update ILCompiler.RyuJit.csproj --- .../tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj b/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj index bb224ee8af366..3ddf3e46a13cb 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj @@ -16,12 +16,6 @@ false Debug;Release;Checked - - False - - - False - From 19936e7306e46e5831487c2fef363b892ff96367 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 5 Jul 2024 12:06:52 +0200 Subject: [PATCH 07/16] Update StackAllocatedBox.cs --- .../src/System/Runtime/CompilerServices/StackAllocatedBox.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs index a47a888a78ecf..868edb18c1594 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/StackAllocatedBox.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Runtime.CompilerServices { + [NonVersionable] [StructLayout(LayoutKind.Sequential)] internal unsafe struct StackAllocatedBox { From b07c1a0559735d1a7e89cc9775ce4046a0b7f634 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 5 Jul 2024 15:35:16 +0200 Subject: [PATCH 08/16] clean up --- .../Runtime.Base/src/System/Runtime/RuntimeExports.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs index 76f16fe96cf5f..8a552a86cd48d 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs @@ -11,8 +11,6 @@ using Internal.Runtime; -using static Interop; - namespace System.Runtime { internal static partial class RuntimeExports @@ -230,11 +228,13 @@ public static unsafe void RhUnboxNullable(ref byte data, MethodTable* pUnboxToEE } [RuntimeExport("RhUnboxTypeTest")] - public static unsafe void RhUnboxTypeTest(MethodTable* pMT1, MethodTable* pMT2) + public static unsafe void RhUnboxTypeTest(MethodTable* pType, MethodTable* pBoxType) { - if (!UnboxAnyTypeCompare(pMT1, pMT2)) + Debug.Assert(pType->IsValueType); + + if (!UnboxAnyTypeCompare(pType, pBoxType)) { - throw pMT2->GetClasslibException(ExceptionIDs.InvalidCast); + throw pType->GetClasslibException(ExceptionIDs.InvalidCast); } } From ea65a01049dbe355f6373f7214ed531b7ec87d75 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Wed, 10 Jul 2024 21:22:28 +0200 Subject: [PATCH 09/16] Update src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Co-authored-by: Jan Kotas --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index c7129bd873af5..974f5b5a87d76 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2613,7 +2613,12 @@ private CorInfoHelpFunc getSharedCCtorHelper(CORINFO_CLASS_STRUCT_* clsHnd) } // Instantiate StackAllocatedBox helper type with the type we're boxing - MetadataType placeholderType = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.CompilerServices", "StackAllocatedBox`1"); + MetadataType placeholderType = _compilation.TypeSystemContext.SystemModule.GetType("System.Runtime.CompilerServices", "StackAllocatedBox`1", throwIfNotFound: false); + if (placeholderType == null) + { + // Give up if corelib does not have support for stackallocation + return null; + } return ObjectToHandle(placeholderType.MakeInstantiatedType(clsTypeDesc)); } From ebd8f9af7590d6f59c734b87abe72f33fb056532 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 10 Jul 2024 22:09:08 +0200 Subject: [PATCH 10/16] Add tests --- .../ObjectStackAllocationTests.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs index 5a45f43dcc7ca..fb0aaeaef9c0e 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs @@ -117,6 +117,11 @@ public static int TestEntryPoint() expectedAllocationKind = AllocationKind.Heap; } + if (expectedAllocationKind == AllocationKind.Stack) + { + ZeroAllocTest(); + } + classA = new SimpleClassA(f1, f2); classWithGCField = new SimpleClassWithGCField(f1, f2, null); @@ -352,5 +357,66 @@ static int AllocateClassWithGcFieldAndInt() GC.Collect(); return c.i; } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ZeroAllocTest() + { + long before = GC.GetAllocatedBytesForCurrentThread(); + Case1(); + EnsureZeroAllocated(before); + Case2(); + EnsureZeroAllocated(before); + Case3(null); + EnsureZeroAllocated(before); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void EnsureZeroAllocated(long before) + { + long after = GC.GetAllocatedBytesForCurrentThread(); + if (after - before != 0) + throw new InvalidOperationException($"Unexpected allocation: {after - before} bytes"); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static long Case1() + { + // Explicit object allocation, but the object + // never escapes the method. + MyRecord obj = new MyRecord(1, 2, default); + return obj.A + obj.B; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Case2() + { + // Box it + object o = new Guid(); + Consume(42); + // Unbox it (multi-use) + Consume((Guid)o); + Consume((Guid)o); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Case3(object? o) + { + // A condition to make it more complicated + // (and trigger CORINFO_HELP_UNBOX_TYPETEST) + if (o == null) + { + // Box it + o = new Guid(); + } + // Unbox it + Consume((Guid)o); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Consume(T _) + { + } + + private record class MyRecord(int A, long B, Guid C); } } From b5985a52e794fe9e34334772b00b837896914cd4 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 10 Jul 2024 22:11:00 +0200 Subject: [PATCH 11/16] Address feedback --- src/coreclr/inc/jiteeversionguid.h | 10 +++++----- src/tests/issues.targets | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index f5083f8fd416f..84284fd2c34a7 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 09a675fa-5035-4437-ae49-824fa63aa69a */ - 0x09a675fa, - 0x5035, - 0x4437, - {0xae, 0x49, 0x82, 0x4f, 0xa6, 0x3a, 0xa6, 0x9a} +constexpr GUID JITEEVersionIdentifier = { /* e6c7a441-8d3c-4135-abc2-bc4dd7c6a4d7 */ + 0xe6c7a441, + 0x8d3c, + 0x4135, + {0xab, 0xc2, 0xbc, 0x4d, 0xd7, 0xc6, 0xa4, 0xd7} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 5da277d04e87b..17c14cfcd50ac 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -925,9 +925,6 @@ https://github.com/dotnet/runtimelab/issues/155: Non-exception throw - - Need to pass flag to enable object stack allocation in RyuJIT - Multimodule incompatible (GVM) From 4f9ff466f8d2d62e2dcdc0dec91b51442fc79e93 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 12 Jul 2024 15:47:06 +0200 Subject: [PATCH 12/16] Update ObjectStackAllocationTests.cs --- .../JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs index fb0aaeaef9c0e..c4fbcc052451f 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs @@ -179,6 +179,8 @@ static bool SPCOptimizationsEnabled() Assembly objectAssembly = Assembly.GetAssembly(typeof(object)); object[] attribs = objectAssembly.GetCustomAttributes(typeof(DebuggableAttribute), false); + if (attribs.Length == 0) + return false; DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute; return ((debuggableAttribute == null) || !debuggableAttribute.IsJITOptimizerDisabled); } From ac65ff6286ee14c6ae714e1ea67d451ea6889979 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 12 Jul 2024 15:48:04 +0200 Subject: [PATCH 13/16] Update ObjectStackAllocationTests.cs --- .../JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs index c4fbcc052451f..670ebf8b57e06 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs @@ -180,7 +180,7 @@ static bool SPCOptimizationsEnabled() object[] attribs = objectAssembly.GetCustomAttributes(typeof(DebuggableAttribute), false); if (attribs.Length == 0) - return false; + return true; // Assume corelib is optimized in this case DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute; return ((debuggableAttribute == null) || !debuggableAttribute.IsJITOptimizerDisabled); } From ed2568c47ac55078a418c1794c04c58f8b10cde5 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 13 Jul 2024 18:03:13 +0200 Subject: [PATCH 14/16] Clean up in the test --- .../ObjectStackAllocationTests.cs | 15 --------------- .../ObjectStackAllocationTests.csproj | 4 ---- 2 files changed, 19 deletions(-) diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs index 670ebf8b57e06..b1f423cf13e56 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs @@ -112,10 +112,6 @@ public static int TestEntryPoint() Console.WriteLine("GCStress is enabled"); expectedAllocationKind = AllocationKind.Undefined; } - else if (!SPCOptimizationsEnabled() && !Crossgen2Test()) { - Console.WriteLine("System.Private.CoreLib.dll optimizations are disabled"); - expectedAllocationKind = AllocationKind.Heap; - } if (expectedAllocationKind == AllocationKind.Stack) { @@ -174,17 +170,6 @@ public static int TestEntryPoint() return methodResult; } - static bool SPCOptimizationsEnabled() - { - Assembly objectAssembly = Assembly.GetAssembly(typeof(object)); - object[] attribs = objectAssembly.GetCustomAttributes(typeof(DebuggableAttribute), - false); - if (attribs.Length == 0) - return true; // Assume corelib is optimized in this case - DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute; - return ((debuggableAttribute == null) || !debuggableAttribute.IsJITOptimizerDisabled); - } - static bool GCStressEnabled() { return Environment.GetEnvironmentVariable("DOTNET_GCStress") != null; diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj index 4cbcbd0da97cd..ac8b20db8961a 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj @@ -16,9 +16,5 @@ - - - --codegenopt JitObjectStackAllocation=1 - From d6a32b300ef758d15980a4b6d6463e3d97505d0b Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Sun, 14 Jul 2024 19:03:59 +0200 Subject: [PATCH 15/16] Update ObjectStackAllocationTests.csproj --- .../ObjectStackAllocationTests.csproj | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj index ac8b20db8961a..8a86f57ba24f3 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.csproj @@ -2,19 +2,11 @@ true - - None True + true - - - - - - - From 85340ae23371499eb9a2dacaca446a5f79a9d690 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Sun, 14 Jul 2024 19:04:58 +0200 Subject: [PATCH 16/16] Update ObjectStackAllocationTests.cs --- .../opt/ObjectStackAllocation/ObjectStackAllocationTests.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs index b1f423cf13e56..33303daf7a07b 100644 --- a/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs +++ b/src/tests/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs @@ -175,12 +175,6 @@ static bool GCStressEnabled() return Environment.GetEnvironmentVariable("DOTNET_GCStress") != null; } - static bool Crossgen2Test() - { - // CrossGen2 doesn't respect the debuggable attribute - return Environment.GetEnvironmentVariable("RunCrossGen2") != null; - } - static void CallTestAndVerifyAllocation(Test test, int expectedResult, AllocationKind expectedAllocationsKind) { long allocatedBytesBefore = GC.GetAllocatedBytesForCurrentThread();