From 64966245c3a9b67cdf04cbeecccfeb377cf7cbe9 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 25 Mar 2021 07:45:51 -0700 Subject: [PATCH] Port misc changes from feature/NativeAOT (#50212) --- src/coreclr/gc/gc.cpp | 2 +- src/coreclr/gc/gcdesc.h | 2 + src/coreclr/gc/unix/gcenv.unix.cpp | 26 ++++++--- src/coreclr/inc/cvconst.h | 4 +- .../Common/Compiler/SingleMethodRootProvider.cs | 6 ++- .../Common/TypeSystem/Common/CastingHelper.cs | 63 ++++++++-------------- .../TypeSystem/Common/DefType.FieldLayout.cs | 2 +- .../CastingTests.cs | 2 +- src/coreclr/vm/gcinfodecoder.cpp | 16 ++++-- .../src/System.Private.CoreLib.Shared.projitems | 7 ++- .../System.Private.CoreLib/src/System/Attribute.cs | 2 - .../Tracing/NativeRuntimeEventSource.cs | 6 +-- .../src/System/Runtime/InteropServices/Marshal.cs | 4 +- 13 files changed, 73 insertions(+), 69 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 3aa5e6c..3df685e 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -4140,7 +4140,7 @@ public: _ASSERTE(IsStructAligned((uint8_t *)this, GetMethodTable()->GetBaseAlignment())); #endif // FEATURE_STRUCTALIGN -#ifdef FEATURE_64BIT_ALIGNMENT +#if defined(FEATURE_64BIT_ALIGNMENT) && !defined(FEATURE_REDHAWK) if (pMT->RequiresAlign8()) { _ASSERTE((((size_t)this) & 0x7) == (pMT->IsValueType() ? 4U : 0U)); diff --git a/src/coreclr/gc/gcdesc.h b/src/coreclr/gc/gcdesc.h index 5b557bd..9b461a7 100644 --- a/src/coreclr/gc/gcdesc.h +++ b/src/coreclr/gc/gcdesc.h @@ -223,10 +223,12 @@ public: } } +#ifndef FEATURE_REDHAWK if (pMT->Collectible()) { NumOfPointers += 1; } +#endif return NumOfPointers; } diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index ecef152..ba50e34 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -194,6 +194,24 @@ enum membarrier_cmd MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6) }; +bool CanFlushUsingMembarrier() +{ + // Starting with Linux kernel 4.14, process memory barriers can be generated + // using MEMBARRIER_CMD_PRIVATE_EXPEDITED. + + int mask = membarrier(MEMBARRIER_CMD_QUERY, 0); + + if (mask >= 0 && + mask & MEMBARRIER_CMD_PRIVATE_EXPEDITED && + // Register intent to use the private expedited command. + membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0) == 0) + { + return true; + } + + return false; +} + // // Tracks if the OS supports FlushProcessWriteBuffers using membarrier // @@ -354,13 +372,7 @@ bool GCToOSInterface::Initialize() assert(s_flushUsingMemBarrier == 0); - // Starting with Linux kernel 4.14, process memory barriers can be generated - // using MEMBARRIER_CMD_PRIVATE_EXPEDITED. - int mask = membarrier(MEMBARRIER_CMD_QUERY, 0); - if (mask >= 0 && - mask & MEMBARRIER_CMD_PRIVATE_EXPEDITED && - // Register intent to use the private expedited command. - membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0) == 0) + if (CanFlushUsingMembarrier()) { s_flushUsingMemBarrier = TRUE; } diff --git a/src/coreclr/inc/cvconst.h b/src/coreclr/inc/cvconst.h index 3a0e3b98..3fbbfdd 100644 --- a/src/coreclr/inc/cvconst.h +++ b/src/coreclr/inc/cvconst.h @@ -1580,10 +1580,12 @@ typedef enum CV_HREG_e { CV_ARM64_LR = 80, CV_ARM64_SP = 81, CV_ARM64_ZR = 82, + CV_ARM64_PC = 83, - // statue register + // status registers CV_ARM64_NZCV = 90, + CV_ARM64_CPSR = 91, // 32-bit floating point registers diff --git a/src/coreclr/tools/Common/Compiler/SingleMethodRootProvider.cs b/src/coreclr/tools/Common/Compiler/SingleMethodRootProvider.cs index bd20614..afd542d 100644 --- a/src/coreclr/tools/Common/Compiler/SingleMethodRootProvider.cs +++ b/src/coreclr/tools/Common/Compiler/SingleMethodRootProvider.cs @@ -19,7 +19,11 @@ namespace ILCompiler public void AddCompilationRoots(IRootingServiceProvider rootProvider) { - rootProvider.AddCompilationRoot(_method, rootMinimalDependencies: false, reason: "Single method root"); + rootProvider.AddCompilationRoot(_method, +#if READYTORUN + rootMinimalDependencies: false, +#endif + reason: "Single method root"); } } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs b/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs index 7b21c98..1b067af 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs @@ -271,17 +271,9 @@ namespace Internal.TypeSystem else if (fromParamUnderlyingType.IsPrimitive) { TypeDesc toParamUnderlyingType = paramType.UnderlyingType; - if (toParamUnderlyingType.IsPrimitive) + if (GetNormalizedIntegralArrayElementType(fromParamUnderlyingType) == GetNormalizedIntegralArrayElementType(toParamUnderlyingType)) { - if (toParamUnderlyingType == fromParamUnderlyingType) - { - return true; - } - - if (ArePrimitveTypesEquivalentSize(fromParamUnderlyingType, toParamUnderlyingType)) - { - return true; - } + return true; } } @@ -289,59 +281,48 @@ namespace Internal.TypeSystem return false; } - // Returns true of the two types are equivalent primitive types. Used by array casts. - private static bool ArePrimitveTypesEquivalentSize(TypeDesc type1, TypeDesc type2) + private static TypeFlags GetNormalizedIntegralArrayElementType(TypeDesc type) { - Debug.Assert(type1.IsPrimitive && type2.IsPrimitive); + Debug.Assert(!type.IsEnum); // Primitive types such as E_T_I4 and E_T_U4 are interchangeable // Enums with interchangeable underlying types are interchangable // BOOL is NOT interchangeable with I1/U1, neither CHAR -- with I2/U2 // Float and double are not interchangable here. - int sourcePrimitiveTypeEquivalenceSize = type1.GetIntegralTypeMatchSize(); - - // Quick check to see if the first type can be matched. - if (sourcePrimitiveTypeEquivalenceSize == 0) + TypeFlags elementType = type.Category; + switch (elementType) { - return false; + case TypeFlags.Byte: + case TypeFlags.UInt16: + case TypeFlags.UInt32: + case TypeFlags.UInt64: + case TypeFlags.UIntPtr: + return elementType - 1; } - int targetPrimitiveTypeEquivalenceSize = type2.GetIntegralTypeMatchSize(); - - return sourcePrimitiveTypeEquivalenceSize == targetPrimitiveTypeEquivalenceSize; + return elementType; } - private static int GetIntegralTypeMatchSize(this TypeDesc type) - { - Debug.Assert(type.IsPrimitive); - switch (type.Category) + public static bool IsArrayElementTypeCastableBySize(TypeDesc elementType) + { + switch (elementType.UnderlyingType.Category) { - case TypeFlags.SByte: case TypeFlags.Byte: - return 1; + case TypeFlags.SByte: case TypeFlags.UInt16: case TypeFlags.Int16: - return 2; - case TypeFlags.Int32: case TypeFlags.UInt32: - return 4; - case TypeFlags.Int64: + case TypeFlags.Int32: case TypeFlags.UInt64: - return 8; - case TypeFlags.IntPtr: + case TypeFlags.Int64: case TypeFlags.UIntPtr: - return type.Context.Target.PointerSize; - default: - return 0; + case TypeFlags.IntPtr: + return true; } - } - public static bool IsArrayElementTypeCastableBySize(TypeDesc elementType) - { - TypeDesc underlyingType = elementType.UnderlyingType; - return underlyingType.IsPrimitive && GetIntegralTypeMatchSize(underlyingType) != 0; + return false; } private static bool CanCastToClassOrInterface(this TypeDesc thisType, TypeDesc otherType, StackOverflowProtect protect) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/DefType.FieldLayout.cs b/src/coreclr/tools/Common/TypeSystem/Common/DefType.FieldLayout.cs index a92cca2..3e73dcf 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/DefType.FieldLayout.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/DefType.FieldLayout.cs @@ -12,7 +12,7 @@ namespace Internal.TypeSystem /// /// Bit flags for layout /// - private class FieldLayoutFlags + private static class FieldLayoutFlags { /// /// True if ContainsGCPointers has been computed diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CastingTests.cs b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CastingTests.cs index 06e87dc..f6cd2e1 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CastingTests.cs +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CastingTests.cs @@ -79,7 +79,7 @@ namespace TypeSystemTests Assert.True(byteType.MakeArrayType().CanCastTo(sbyteType.MakeArrayType())); Assert.False(byteType.CanCastTo(sbyteType)); - Assert.True(intPtrType.MakeArrayType().CanCastTo(ulongType.MakeArrayType())); + Assert.False(intPtrType.MakeArrayType().CanCastTo(ulongType.MakeArrayType())); Assert.False(intPtrType.CanCastTo(ulongType)); // These are same size, but not allowed to cast diff --git a/src/coreclr/vm/gcinfodecoder.cpp b/src/coreclr/vm/gcinfodecoder.cpp index 52c2c3c..8ca20ea 100644 --- a/src/coreclr/vm/gcinfodecoder.cpp +++ b/src/coreclr/vm/gcinfodecoder.cpp @@ -1508,7 +1508,7 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot( } -#ifdef TARGET_UNIX +#if defined(TARGET_UNIX) && !defined(FEATURE_REDHAWK) OBJECTREF* GcInfoDecoder::GetCapturedRegister( int regNum, PREGDISPLAY pRD @@ -1524,7 +1524,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister( return (OBJECTREF*)(pR0 + regNum); } -#endif // TARGET_UNIX +#endif // TARGET_UNIX && !FEATURE_REDHAWK bool GcInfoDecoder::IsScratchRegister(int regNum, PREGDISPLAY pRD) @@ -1598,6 +1598,11 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot( _ASSERTE(regNum >= 0 && regNum <= 30); _ASSERTE(regNum != 18); // TEB +#ifdef FEATURE_REDHAWK + PTR_UIntNative* ppReg = &pRD->pX0; + + return (OBJECTREF*)*(ppReg + regNum); +#else DWORD64 **ppReg; if(regNum <= 17) @@ -1617,6 +1622,7 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot( ppReg = &pRD->pCurrentContextPointers->X19; return (OBJECTREF*)*(ppReg + regNum-19); +#endif } bool GcInfoDecoder::IsScratchRegister(int regNum, PREGDISPLAY pRD) @@ -1658,7 +1664,7 @@ void GcInfoDecoder::ReportRegisterToGC( // ARM64 LOG((LF_GCROOTS, LL_INFO1000, "Reporting " FMT_REG, regNum )); OBJECTREF* pObjRef = GetRegisterSlot( regNum, pRD ); -#if defined(TARGET_UNIX) && !defined(SOS_TARGET_ARM64) +#if defined(TARGET_UNIX) && !defined(FEATURE_REDHAWK) && !defined(SOS_TARGET_AMD64) // On PAL, we don't always have the context pointers available due to // a limitation of an unwinding library. In such case, the context // pointers for some nonvolatile registers are NULL. @@ -1700,7 +1706,7 @@ void GcInfoDecoder::ReportRegisterToGC( // ARM64 pCallBack(hCallBack, pObjRef, gcFlags DAC_ARG(DacSlotLocation(regNum, 0, false))); } -#ifdef TARGET_UNIX +#if defined(TARGET_UNIX) && !defined(FEATURE_REDHAWK) OBJECTREF* GcInfoDecoder::GetCapturedRegister( int regNum, PREGDISPLAY pRD @@ -1725,7 +1731,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister( return (OBJECTREF*)(pX0 + regNum); } -#endif // TARGET_UNIX +#endif // TARGET_UNIX && !FEATURE_REDHAWK #else // Unknown platform 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 21e3214..c3231e6 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 @@ -65,6 +65,7 @@ + @@ -1210,7 +1211,7 @@ - + @@ -1246,7 +1247,7 @@ - + @@ -1905,7 +1906,6 @@ - @@ -1978,7 +1978,6 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/System/Attribute.cs b/src/libraries/System.Private.CoreLib/src/System/Attribute.cs index 27ff209..2bc115b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Attribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Attribute.cs @@ -14,7 +14,6 @@ namespace System { protected Attribute() { } -#if !CORERT [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "Unused fields don't make a difference for equality")] public override bool Equals([NotNullWhen(true)] object? obj) @@ -83,7 +82,6 @@ namespace System return type.GetHashCode(); } -#endif // Compares values of custom-attribute fields. private static bool AreFieldValuesEqual(object? thisValue, object? thatValue) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs index f7de902..bc59014 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs @@ -1,10 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - namespace System.Diagnostics.Tracing { /// @@ -27,6 +23,7 @@ namespace System.Diagnostics.Tracing // as you can't make a constructor partial. private NativeRuntimeEventSource(int _) { } +#if FEATURE_PERFTRACING /// /// Dispatch a single event with the specified event ID and payload. /// @@ -62,5 +59,6 @@ namespace System.Diagnostics.Tracing childActivityID: &childActivityId, args: decodedPayloadFields); } +#endif // FEATURE_PERFTRACING } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 2eef2d0..81c8797 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -635,7 +635,9 @@ namespace System.Runtime.InteropServices case HResults.COR_E_EXCEPTION: return new System.Exception(); case HResults.COR_E_EXECUTIONENGINE: +#pragma warning disable CS0618 // ExecutionEngineException is obsolete return new System.ExecutionEngineException(); +#pragma warning restore CS0618 case HResults.COR_E_FIELDACCESS: return new System.FieldAccessException(); case HResults.COR_E_FILELOAD: @@ -1097,7 +1099,7 @@ namespace System.Runtime.InteropServices throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t)); } - // For backward compatibility, we allow lookup up of existing delegate to + // For backward compatibility, we allow lookup of existing delegate to // function pointer mappings using abstract MulticastDelegate type. We will check // for the non-abstract delegate type later if no existing mapping is found. if (t.BaseType != typeof(MulticastDelegate) && t != typeof(MulticastDelegate)) -- 2.7.4