Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/runtime-master' into merge-master
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Nov 24, 2020
2 parents 5de9ee2 + 1fa2054 commit dfa1945
Show file tree
Hide file tree
Showing 115 changed files with 1,099 additions and 610 deletions.
8 changes: 7 additions & 1 deletion src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
<CoreLibAssemblyName>System.Private.CoreLib</CoreLibAssemblyName>
<CoreLibInputPath>$(BinDir)\IL\$(CoreLibAssemblyName).dll</CoreLibInputPath>
<CoreLibOutputPath>$(BinDir)\$(CoreLibAssemblyName).dll</CoreLibOutputPath>
</PropertyGroup>

<PropertyGroup>
<CrossDir></CrossDir>
</PropertyGroup>
<PropertyGroup Condition="'$(BuildArchitecture)' != '$(TargetArchitecture)'">
<CrossDir Condition="'$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'arm64'">x64</CrossDir>
<CrossDir Condition="'$(TargetArchitecture)' == 'arm' and '$(UseCrossgen2)' != 'true' and '$(OS)' == 'Windows_NT'">x86</CrossDir>
<CrossDir Condition="'$(TargetArchitecture)' == 'x86' and '$(BuildArchitecture)' != '$(TargetArchitecture)' and '$(UseCrossgen2)' == 'true'">$(BuildArchitecture)</CrossDir>
<CrossDir Condition="'$(TargetArchitecture)' == 'x86' and '$(UseCrossgen2)' == 'true'">$(BuildArchitecture)</CrossDir>
</PropertyGroup>

<PropertyGroup>
<BuildDll>true</BuildDll>
<BuildDll Condition="'$(CrossBuild)' == 'true' and '$(CrossDir)' == ''">false</BuildDll>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private static Type[] GetIndexParameterTypes(PropertyInfo element)
return indexParamTypes;
}

return Array.Empty<Type>();
return Type.EmptyTypes;
}

private static void AddAttributesToList(List<Attribute> attributeList, Attribute[] attributes, Dictionary<Type, AttributeUsageAttribute> types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static IArraySortHelper<T> CreateArraySortHelper()

if (typeof(IComparable<T>).IsAssignableFrom(typeof(T)))
{
defaultArraySortHelper = (IArraySortHelper<T>)RuntimeTypeHandle.Allocate(typeof(GenericArraySortHelper<string>).TypeHandle.Instantiate(new Type[] { typeof(T) }));
defaultArraySortHelper = (IArraySortHelper<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericArraySortHelper<string>), (RuntimeType)typeof(T));
}
else
{
Expand Down Expand Up @@ -62,7 +62,7 @@ private static IArraySortHelper<TKey, TValue> CreateArraySortHelper()

if (typeof(IComparable<TKey>).IsAssignableFrom(typeof(TKey)))
{
defaultArraySortHelper = (IArraySortHelper<TKey, TValue>)RuntimeTypeHandle.Allocate(typeof(GenericArraySortHelper<string, string>).TypeHandle.Instantiate(new Type[] { typeof(TKey), typeof(TValue) }));
defaultArraySortHelper = (IArraySortHelper<TKey, TValue>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericArraySortHelper<string, string>), (RuntimeType)typeof(TKey), (RuntimeType)typeof(TValue));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs, Pr
}

// Make sure the property's type can take the given value.
// Note that there will be no coersion.
// Note that there will be no coercion.
if (propertyValue != null)
{
VerifyTypeAndPassedObjectType(propType, propertyValue.GetType(), $"{nameof(propertyValues)}[{i}]");
Expand Down Expand Up @@ -222,7 +222,7 @@ public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs, Pr
}

// Make sure the field's type can take the given value.
// Note that there will be no coersion.
// Note that there will be no coercion.
if (fieldValue != null)
{
VerifyTypeAndPassedObjectType(fldType, fieldValue.GetType(), $"{nameof(fieldValues)}[{i}]");
Expand Down Expand Up @@ -271,9 +271,7 @@ private bool ValidateType(Type t)
}
if (t.IsArray)
{
if (t.GetArrayRank() != 1)
return false;
return ValidateType(t.GetElementType()!);
return t.GetArrayRank() == 1 && ValidateType(t.GetElementType()!);
}
return t == typeof(object);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal void ReleaseBakedStructures()
m_exceptions = null;
}

internal override Type[] GetParameterTypes() => m_parameterTypes ??= Array.Empty<Type>();
internal override Type[] GetParameterTypes() => m_parameterTypes ??= Type.EmptyTypes;

internal static Type? GetMethodBaseReturnType(MethodBase? method)
{
Expand Down Expand Up @@ -306,7 +306,7 @@ internal void SetToken(int token)

internal SignatureHelper GetMethodSignature()
{
m_parameterTypes ??= Array.Empty<Type>();
m_parameterTypes ??= Type.EmptyTypes;

m_signature = SignatureHelper.GetMethodSigHelper(m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0,
m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers,
Expand Down Expand Up @@ -538,7 +538,7 @@ public override bool IsDefined(Type attributeType, bool inherit)

public override bool IsGenericMethod => m_inst != null;

public override Type[] GetGenericArguments() => m_inst ?? Array.Empty<Type>();
public override Type[] GetGenericArguments() => m_inst ?? Type.EmptyTypes;

public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal SymbolMethod(ModuleBuilder mod, int token, Type arrayClass, string meth
}
else
{
m_parameterTypes = Array.Empty<Type>();
m_parameterTypes = Type.EmptyTypes;
}

m_module = mod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public override Type[] GetInterfaces()

if (m_typeInterfaces == null)
{
return Array.Empty<Type>();
return Type.EmptyTypes;
}

return m_typeInterfaces.ToArray();
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public override Type MakeGenericType(params Type[] typeArguments)
return TypeBuilderInstantiation.MakeGenericType(this, typeArguments);
}

public override Type[] GetGenericArguments() => m_inst ?? Array.Empty<Type>();
public override Type[] GetGenericArguments() => m_inst ?? Type.EmptyTypes;

// If a TypeBuilder is generic, it must be a generic type definition
// All instantiated generic types are TypeBuilderInstantiation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public override Type FieldType

public override Type[] GetRequiredCustomModifiers()
{
return Array.Empty<Type>();
return Type.EmptyTypes;
}

public override Type[] GetOptionalCustomModifiers()
{
return Array.Empty<Type>();
return Type.EmptyTypes;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ internal RuntimeType[] GetGenericArgumentsInternal() =>
RuntimeMethodHandle.GetMethodInstantiationInternal(this);

public override Type[] GetGenericArguments() =>
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Array.Empty<Type>();
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Type.EmptyTypes;

public override MethodInfo GetGenericMethodDefinition()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public static void PrepareMethod(RuntimeMethodHandle method)

public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation)
{
// defensive copy of user-provided array, per CopyRuntimeTypeHandles contract
instantiation = (RuntimeTypeHandle[]?)instantiation?.Clone();

unsafe
{
IntPtr[]? instantiationHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(instantiation, out int length);
Expand Down Expand Up @@ -287,7 +290,7 @@ public static IntPtr AllocateTypeAssociatedMemory(Type type, int size)
private static extern IntPtr AllocTailCallArgBuffer(int size, IntPtr gcDesc);

[MethodImpl(MethodImplOptions.InternalCall)]
private static unsafe extern TailCallTls* GetTailCallInfo(IntPtr retAddrSlot, IntPtr* retAddr);
private static extern unsafe TailCallTls* GetTailCallInfo(IntPtr retAddrSlot, IntPtr* retAddr);

[StackTraceHidden]
private static unsafe void DispatchTailCalls(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ internal static bool HasElementType(RuntimeType type)
|| (corElemType == CorElementType.ELEMENT_TYPE_BYREF); // IsByRef
}

// ** WARNING **
// Caller bears responsibility for ensuring that the provided Types remain
// GC-reachable while the unmanaged handles are being manipulated. The caller
// may need to make a defensive copy of the input array to ensure it's not
// mutated by another thread, and this defensive copy should be passed to
// a KeepAlive routine.
internal static IntPtr[]? CopyRuntimeTypeHandles(RuntimeTypeHandle[]? inHandles, out int length)
{
if (inHandles == null || inHandles.Length == 0)
Expand All @@ -179,6 +185,12 @@ internal static bool HasElementType(RuntimeType type)
return outHandles;
}

// ** WARNING **
// Caller bears responsibility for ensuring that the provided Types remain
// GC-reachable while the unmanaged handles are being manipulated. The caller
// may need to make a defensive copy of the input array to ensure it's not
// mutated by another thread, and this defensive copy should be passed to
// a KeepAlive routine.
internal static IntPtr[]? CopyRuntimeTypeHandles(Type[]? inHandles, out int length)
{
if (inHandles == null || inHandles.Length == 0)
Expand All @@ -202,8 +214,49 @@ internal static bool HasElementType(RuntimeType type)
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern object Allocate(RuntimeType type);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern object CreateInstanceForAnotherGenericParameter(RuntimeType type, RuntimeType genericParameter);
internal static object CreateInstanceForAnotherGenericParameter(RuntimeType type, RuntimeType genericParameter)
{
object? instantiatedObject = null;

IntPtr typeHandle = genericParameter.GetTypeHandleInternal().Value;
CreateInstanceForAnotherGenericParameter(
new QCallTypeHandle(ref type),
&typeHandle,
1,
ObjectHandleOnStack.Create(ref instantiatedObject));

GC.KeepAlive(genericParameter);
return instantiatedObject!;
}

internal static object CreateInstanceForAnotherGenericParameter(RuntimeType type, RuntimeType genericParameter1, RuntimeType genericParameter2)
{
object? instantiatedObject = null;

IntPtr* pTypeHandles = stackalloc IntPtr[]
{
genericParameter1.GetTypeHandleInternal().Value,
genericParameter2.GetTypeHandleInternal().Value
};

CreateInstanceForAnotherGenericParameter(
new QCallTypeHandle(ref type),
pTypeHandles,
2,
ObjectHandleOnStack.Create(ref instantiatedObject));

GC.KeepAlive(genericParameter1);
GC.KeepAlive(genericParameter2);

return instantiatedObject!;
}

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void CreateInstanceForAnotherGenericParameter(
QCallTypeHandle baseType,
IntPtr* pTypeHandles,
int cTypeHandles,
ObjectHandleOnStack instantiatedObject);

internal RuntimeType GetRuntimeType()
{
Expand Down Expand Up @@ -471,7 +524,6 @@ internal Type[] GetInstantiationPublic()

internal RuntimeType Instantiate(Type[]? inst)
{
// defensive copy to be sure array is not mutated from the outside during processing
IntPtr[]? instHandles = CopyRuntimeTypeHandles(inst, out int instCount);

fixed (IntPtr* pInst = instHandles)
Expand Down Expand Up @@ -1199,6 +1251,10 @@ internal static RuntimeType ResolveTypeHandleInternal(RuntimeModule module, int
throw new ArgumentOutOfRangeException(nameof(typeToken),
SR.Format(SR.Argument_InvalidToken, typeToken, new ModuleHandle(module)));

// defensive copy of user-provided array, per CopyRuntimeTypeHandles contract
typeInstantiationContext = (RuntimeTypeHandle[]?)typeInstantiationContext?.Clone();
methodInstantiationContext = (RuntimeTypeHandle[]?)methodInstantiationContext?.Clone();

IntPtr[]? typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out int typeInstCount);
IntPtr[]? methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out int methodInstCount);

Expand Down Expand Up @@ -1232,6 +1288,9 @@ public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandl

internal static IRuntimeMethodInfo ResolveMethodHandleInternal(RuntimeModule module, int methodToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
// defensive copy of user-provided array, per CopyRuntimeTypeHandles contract
typeInstantiationContext = (RuntimeTypeHandle[]?)typeInstantiationContext?.Clone();
methodInstantiationContext = (RuntimeTypeHandle[]?)methodInstantiationContext?.Clone();

IntPtr[]? typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out int typeInstCount);
IntPtr[]? methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out int methodInstCount);
Expand Down Expand Up @@ -1277,6 +1336,10 @@ internal static IRuntimeFieldInfo ResolveFieldHandleInternal(RuntimeModule modul
throw new ArgumentOutOfRangeException(nameof(fieldToken),
SR.Format(SR.Argument_InvalidToken, fieldToken, new ModuleHandle(module)));

// defensive copy of user-provided array, per CopyRuntimeTypeHandles contract
typeInstantiationContext = (RuntimeTypeHandle[]?)typeInstantiationContext?.Clone();
methodInstantiationContext = (RuntimeTypeHandle[]?)methodInstantiationContext?.Clone();

// defensive copy to be sure array is not mutated from the outside during processing
IntPtr[]? typeInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(typeInstantiationContext, out int typeInstCount);
IntPtr[]? methodInstantiationContextHandles = RuntimeTypeHandle.CopyRuntimeTypeHandles(methodInstantiationContext, out int methodInstCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,7 @@ internal RuntimeType[] GetGenericArgumentsInternal()
public override Type[] GetGenericArguments()
{
Type[] types = GetRootElementType().GetTypeHandleInternal().GetInstantiationPublic();
return types ?? Array.Empty<Type>();
return types ?? Type.EmptyTypes;
}

public override Type MakeGenericType(Type[] instantiation)
Expand Down Expand Up @@ -3315,7 +3315,7 @@ public override Type[] GetGenericParameterConstraints()
throw new InvalidOperationException(SR.Arg_NotGenericParameter);

Type[] constraints = new RuntimeTypeHandle(this).GetConstraints();
return constraints ?? Array.Empty<Type>();
return constraints ?? Type.EmptyTypes;
}
#endregion

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ LWM(GetLazyStringLiteralHelper, DWORDLONG, DWORD)
LWM(GetLocationOfThisType, DWORDLONG, Agnostic_CORINFO_LOOKUP_KIND)
LWM(GetMethodAttribs, DWORDLONG, DWORD)
LWM(GetMethodClass, DWORDLONG, DWORDLONG)
LWM(GetMethodModule, DWORDLONG, DWORDLONG)
LWM(GetMethodDefFromMethod, DWORDLONG, DWORD)
LWM(GetMethodHash, DWORDLONG, DWORD)
LWM(GetMethodInfo, DWORDLONG, Agnostic_GetMethodInfo)
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,30 @@ CORINFO_CLASS_HANDLE MethodContext::repGetMethodClass(CORINFO_METHOD_HANDLE meth
return value;
}

void MethodContext::recGetMethodModule(CORINFO_METHOD_HANDLE methodHandle, CORINFO_MODULE_HANDLE moduleHandle)
{
if (GetMethodModule == nullptr)
GetMethodModule = new LightWeightMap<DWORDLONG, DWORDLONG>();

GetMethodModule->Add((DWORDLONG)methodHandle, (DWORDLONG)moduleHandle);
DEBUG_REC(dmpGetMethodModule((DWORDLONG)methodHandle, (DWORDLONG)moduleHandle));
}
void MethodContext::dmpGetMethodModule(DWORDLONG key, DWORDLONG value)
{
printf("GetMethodModule key %016llX, value %016llX", key, value);
}
CORINFO_MODULE_HANDLE MethodContext::repGetMethodModule(CORINFO_METHOD_HANDLE methodHandle)
{
AssertCodeMsg(GetMethodModule != nullptr, EXCEPTIONCODE_MC,
"Found a null GetMethodModule. Probably missing a fatTrigger for %016llX.", (DWORDLONG)methodHandle);
int index = GetMethodModule->GetIndex((DWORDLONG)methodHandle);
AssertCodeMsg(index != -1, EXCEPTIONCODE_MC, "Didn't find %016llX. Probably missing a fatTrigger",
(DWORDLONG)methodHandle);
CORINFO_MODULE_HANDLE value = (CORINFO_MODULE_HANDLE)GetMethodModule->Get((DWORDLONG)methodHandle);
DEBUG_REP(dmpGetMethodModule((DWORDLONG)methodHandle, (DWORDLONG)value));
return value;
}

void MethodContext::recGetClassAttribs(CORINFO_CLASS_HANDLE classHandle, DWORD attribs)
{
if (GetClassAttribs == nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ class MethodContext
void dmpGetMethodClass(DWORDLONG key, DWORDLONG value);
CORINFO_CLASS_HANDLE repGetMethodClass(CORINFO_METHOD_HANDLE methodHandle);

void recGetMethodModule(CORINFO_METHOD_HANDLE methodHandle, CORINFO_MODULE_HANDLE moduleHandle);
void dmpGetMethodModule(DWORDLONG key, DWORDLONG value);
CORINFO_MODULE_HANDLE repGetMethodModule(CORINFO_METHOD_HANDLE methodHandle);

void recGetClassAttribs(CORINFO_CLASS_HANDLE classHandle, DWORD attribs);
void dmpGetClassAttribs(DWORDLONG key, DWORD value);
DWORD repGetClassAttribs(CORINFO_CLASS_HANDLE classHandle);
Expand Down Expand Up @@ -1355,7 +1359,7 @@ class MethodContext
};

// ********************* Please keep this up-to-date to ease adding more ***************
// Highest packet number: 178
// Highest packet number: 181
// *************************************************************************************
enum mcPackets
{
Expand Down Expand Up @@ -1457,6 +1461,7 @@ enum mcPackets
Packet_GetLocationOfThisType = 69,
Packet_GetMethodAttribs = 70,
Packet_GetMethodClass = 71,
Packet_GetMethodModule = 181, // Added 11/20/2020
Packet_GetMethodDefFromMethod = 72,
Packet_GetMethodHash = 73,
Packet_GetMethodInfo = 74,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ CORINFO_CLASS_HANDLE interceptor_ICJI::getMethodClass(CORINFO_METHOD_HANDLE meth
CORINFO_MODULE_HANDLE interceptor_ICJI::getMethodModule(CORINFO_METHOD_HANDLE method)
{
mc->cr->AddCall("getMethodModule");
return original_ICorJitInfo->getMethodModule(method);
CORINFO_MODULE_HANDLE temp = original_ICorJitInfo->getMethodModule(method);
mc->recGetMethodModule(method, temp);
return temp;
}

// This function returns the offset of the specified method in the
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ CORINFO_CLASS_HANDLE MyICJI::getMethodClass(CORINFO_METHOD_HANDLE method)
CORINFO_MODULE_HANDLE MyICJI::getMethodModule(CORINFO_METHOD_HANDLE method)
{
jitInstance->mc->cr->AddCall("getMethodModule");
LogError("Hit unimplemented getMethodModule");
DebugBreakorAV(7);
return 0;
return jitInstance->mc->repGetMethodModule(method);
}

// This function returns the offset of the specified method in the
Expand Down
Loading

0 comments on commit dfa1945

Please sign in to comment.