Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass metadata pointers to RyuJIT #79806

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,12 +1915,19 @@ private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls)

private byte* getClassNameFromMetadata(CORINFO_CLASS_STRUCT_* cls, byte** namespaceName)
{
var type = HandleToObject(cls) as MetadataType;
if (type != null)
TypeDesc type = HandleToObject(cls);
if (type.GetTypeDefinition() is EcmaType ecmaType)
{
var reader = ecmaType.MetadataReader;
if (namespaceName != null)
*namespaceName = (byte*)GetPin(StringToUTF8(type.Namespace));
return (byte*)GetPin(StringToUTF8(type.Name));
*namespaceName = reader.GetTypeNamespacePointer(ecmaType.Handle);
return reader.GetTypeNamePointer(ecmaType.Handle);
}
else if (type is MetadataType mdType)
{
if (namespaceName != null)
*namespaceName = (byte*)GetPin(StringToUTF8(mdType.Namespace));
return (byte*)GetPin(StringToUTF8(mdType.Name));
}

if (namespaceName != null)
Expand Down Expand Up @@ -3172,21 +3179,47 @@ private static string getMethodNameFromMetadataImpl(MethodDesc method, out strin
{
MethodDesc method = HandleToObject(ftn);

string result;
string classResult;
string namespaceResult;
string enclosingResult;
if (method.GetTypicalMethodDefinition() is EcmaMethod ecmaMethod)
{
EcmaType owningType = (EcmaType)ecmaMethod.OwningType;
var reader = owningType.MetadataReader;

result = getMethodNameFromMetadataImpl(method, out classResult, out namespaceResult, out enclosingResult);
if (className != null)
*className = reader.GetTypeNamePointer(owningType.Handle);
if (namespaceName != null)
*namespaceName = reader.GetTypeNamespacePointer(owningType.Handle);

if (className != null)
*className = classResult != null ? (byte*)GetPin(StringToUTF8(classResult)) : null;
if (namespaceName != null)
*namespaceName = namespaceResult != null ? (byte*)GetPin(StringToUTF8(namespaceResult)) : null;
if (enclosingClassName != null)
*enclosingClassName = enclosingResult != null ? (byte*)GetPin(StringToUTF8(enclosingResult)) : null;
// Query enclosingClassName when the method is in a nested class
// and get the namespace of enclosing classes (nested class's namespace is empty)
var containingType = owningType.ContainingType as EcmaType;
if (containingType != null)
{
if (enclosingClassName != null)
*enclosingClassName = reader.GetTypeNamePointer(containingType.Handle);
if (namespaceName != null)
*namespaceName = reader.GetTypeNamespacePointer(containingType.Handle);
}

return reader.GetMethodNamePointer(ecmaMethod.Handle);
}
else
{
string result;
string classResult;
string namespaceResult;
string enclosingResult;

result = getMethodNameFromMetadataImpl(method, out classResult, out namespaceResult, out enclosingResult);

return result != null ? (byte*)GetPin(StringToUTF8(result)) : null;
if (className != null)
*className = classResult != null ? (byte*)GetPin(StringToUTF8(classResult)) : null;
if (namespaceName != null)
*namespaceName = namespaceResult != null ? (byte*)GetPin(StringToUTF8(namespaceResult)) : null;
if (enclosingClassName != null)
*enclosingClassName = enclosingResult != null ? (byte*)GetPin(StringToUTF8(enclosingResult)) : null;

return result != null ? (byte*)GetPin(StringToUTF8(result)) : null;
}
}

private uint getMethodHash(CORINFO_METHOD_STRUCT_* ftn)
Expand Down
15 changes: 15 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,20 @@ public static bool IsPublic(this MethodAttributes flags)
{
return (flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
}

public static unsafe byte* GetTypeNamePointer(this MetadataReader reader, TypeDefinitionHandle handle)
{
return reader.GetBlobReader(reader.GetTypeDefinition(handle).Name).CurrentPointer;
}

public static unsafe byte* GetTypeNamespacePointer(this MetadataReader reader, TypeDefinitionHandle handle)
{
return reader.GetBlobReader(reader.GetTypeDefinition(handle).Namespace).CurrentPointer;
}

public static unsafe byte* GetMethodNamePointer(this MetadataReader reader, MethodDefinitionHandle handle)
{
return reader.GetBlobReader(reader.GetMethodDefinition(handle).Name).CurrentPointer;
}
}
}