Skip to content

Commit

Permalink
Port misc changes from feature/NativeAOT (#50212)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas authored Mar 25, 2021
1 parent 85e06bf commit 6496624
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4140,7 +4140,7 @@ class CObjectHeader : public Object
_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));
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/gcdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ class CGCDesc
}
}

#ifndef FEATURE_REDHAWK
if (pMT->Collectible())
{
NumOfPointers += 1;
}
#endif

return NumOfPointers;
}
Expand Down
26 changes: 19 additions & 7 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/inc/cvconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public SingleMethodRootProvider(MethodDesc method)

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");
}
}
}
63 changes: 22 additions & 41 deletions src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,77 +271,58 @@ private static bool CanCastParamTo(this ParameterizedType thisType, TypeDesc par
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;
}
}

// Anything else is not a match
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract partial class DefType : TypeDesc
/// <summary>
/// Bit flags for layout
/// </summary>
private class FieldLayoutFlags
private static class FieldLayoutFlags
{
/// <summary>
/// True if ContainsGCPointers has been computed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void TestSameSizeArrayTypeCasting()
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
Expand Down
16 changes: 11 additions & 5 deletions src/coreclr/vm/gcinfodecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot(

}

#ifdef TARGET_UNIX
#if defined(TARGET_UNIX) && !defined(FEATURE_REDHAWK)
OBJECTREF* GcInfoDecoder::GetCapturedRegister(
int regNum,
PREGDISPLAY pRD
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -1617,6 +1622,7 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot(
ppReg = &pRD->pCurrentContextPointers->X19;

return (OBJECTREF*)*(ppReg + regNum-19);
#endif
}

bool GcInfoDecoder::IsScratchRegister(int regNum, PREGDISPLAY pRD)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -1725,7 +1731,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister(

return (OBJECTREF*)(pX0 + regNum);
}
#endif // TARGET_UNIX
#endif // TARGET_UNIX && !FEATURE_REDHAWK

#else // Unknown platform

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -1210,7 +1211,7 @@
<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" />
Expand Down Expand Up @@ -1246,7 +1247,7 @@
<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">
Expand Down Expand Up @@ -1905,7 +1906,6 @@
</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" />
Expand Down Expand Up @@ -1978,7 +1978,6 @@
<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" />
Expand Down
2 changes: 0 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public abstract partial class Attribute
{
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)
Expand Down Expand Up @@ -83,7 +82,6 @@ public override int GetHashCode()

return type.GetHashCode();
}
#endif

// Compares values of custom-attribute fields.
private static bool AreFieldValuesEqual(object? thisValue, object? thatValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -27,6 +23,7 @@ internal sealed partial class NativeRuntimeEventSource : EventSource
// 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>
Expand Down Expand Up @@ -62,5 +59,6 @@ internal unsafe void ProcessEvent(uint eventID, uint osThreadID, DateTime timeSt
childActivityID: &childActivityId,
args: decodedPayloadFields);
}
#endif // FEATURE_PERFTRACING
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ public static void PtrToStructure<T>(IntPtr ptr, [DisallowNull] T structure)
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:
Expand Down Expand Up @@ -1097,7 +1099,7 @@ public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
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))
Expand Down

0 comments on commit 6496624

Please sign in to comment.