Port misc changes from feature/NativeAOT (#50212)
authorJan Kotas <jkotas@microsoft.com>
Thu, 25 Mar 2021 14:45:51 +0000 (07:45 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Mar 2021 14:45:51 +0000 (15:45 +0100)
13 files changed:
src/coreclr/gc/gc.cpp
src/coreclr/gc/gcdesc.h
src/coreclr/gc/unix/gcenv.unix.cpp
src/coreclr/inc/cvconst.h
src/coreclr/tools/Common/Compiler/SingleMethodRootProvider.cs
src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs
src/coreclr/tools/Common/TypeSystem/Common/DefType.FieldLayout.cs
src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CastingTests.cs
src/coreclr/vm/gcinfodecoder.cpp
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/Attribute.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs

index 3aa5e6c..3df685e 100644 (file)
@@ -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));
index 5b557bd..9b461a7 100644 (file)
@@ -223,10 +223,12 @@ public:
             }
         }
 
+#ifndef FEATURE_REDHAWK
         if (pMT->Collectible())
         {
             NumOfPointers += 1;
         }
+#endif
 
         return NumOfPointers;
     }
index ecef152..ba50e34 100644 (file)
@@ -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;
     }
index 3a0e3b9..3fbbfdd 100644 (file)
@@ -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
 
index bd20614..afd542d 100644 (file)
@@ -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");
         }
     }
 }
index 7b21c98..1b067af 100644 (file)
@@ -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)
index a92cca2..3e73dcf 100644 (file)
@@ -12,7 +12,7 @@ namespace Internal.TypeSystem
         /// <summary>
         /// Bit flags for layout
         /// </summary>
-        private class FieldLayoutFlags
+        private static class FieldLayoutFlags
         {
             /// <summary>
             /// True if ContainsGCPointers has been computed
index 06e87dc..f6cd2e1 100644 (file)
@@ -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
index 52c2c3c..8ca20ea 100644 (file)
@@ -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
 
index 21e3214..c3231e6 100644 (file)
@@ -65,6 +65,7 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\AggregateException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\AppContext.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\AppContext.AnyOS.cs" Condition="'$(TargetsBrowser)' != 'true'" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\AppContextConfigHelper.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\AppDomain.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\AppDomainSetup.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\AppDomainUnloadedException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IEventProvider.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IncrementingEventCounter.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IncrementingPollingCounter.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\NativeRuntimeEventSource.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\PollingCounter.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\RuntimeEventSource.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\Winmeta.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingTypeInfo.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TypeAnalysis.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\XplatEventLogger.cs" Condition="'$(FeatureXplatEventSource)' == 'true'" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\QCallHandles.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\QCallHandles.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="$(MSBuildThisFileDirectory)\..\..\Common\src\System\HexConverter.cs">
   </ItemGroup>
   <ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
     <Compile Include="$(MSBuildThisFileDirectory)System\AppContext.Browser.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\AppContextConfigHelper.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Environment.Browser.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Browser.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Browser.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Sha256.PlatformNotSupported.cs" />
   </ItemGroup>
   <ItemGroup Condition="'$(FeaturePortableThreadPool)' == 'true'">
-    <Compile Include="$(MSBuildThisFileDirectory)System\AppContextConfigHelper.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPool.Portable.cs" Condition="'$(FeatureCoreCLR)' != 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPoolBoundHandle.PlatformNotSupported.cs" Condition="'$(FeatureCoreCLR)' != 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.cs" />
index 27ff209..2bc115b 100644 (file)
@@ -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)
index f7de902..bc59014 100644 (file)
@@ -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
 {
     /// <summary>
@@ -27,6 +23,7 @@ namespace System.Diagnostics.Tracing
         // as you can't make a constructor partial.
         private NativeRuntimeEventSource(int _) { }
 
+#if FEATURE_PERFTRACING
         /// <summary>
         /// Dispatch a single event with the specified event ID and payload.
         /// </summary>
@@ -62,5 +59,6 @@ namespace System.Diagnostics.Tracing
                 childActivityID: &childActivityId,
                 args: decodedPayloadFields);
         }
+#endif // FEATURE_PERFTRACING
     }
 }
index 2eef2d0..81c8797 100644 (file)
@@ -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))