Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ private unsafe bool TryGetMethodForOriginalLdFtnResult_InvokeMap_Inner(NativeFor
QTypeDefinition qTypeDefinition = GetMetadataForNamedType(declaringTypeHandleDefinition);

MethodHandle nativeFormatMethodHandle =
(((int)HandleType.Method << 24) | (int)entryMethodHandleOrNameAndSigRaw).AsMethodHandle();
(((int)HandleType.Method << 25) | (int)entryMethodHandleOrNameAndSigRaw).AsMethodHandle();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have 25 defined as a constant somewhere so that it is not hardcoded in so many places?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it if you insist but it doesn't seem like a great use of time (especially given we'd need to also do the same for 25/7/1FFFFFF/7F and we'd need to include this from like 5 csproj files). It's unlikely we're going to change this ever again. The existing numbers survived for longer than my tenure on the .NET team.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have a strong opinion


methodHandle = new QMethodDefinition(qTypeDefinition.NativeFormatReader, nativeFormatMethodHandle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static MethodHandle AsMethodHandle(this int i)
{
unsafe
{
Debug.Assert((HandleType)((uint)i >> 24) == HandleType.Method);
Debug.Assert((HandleType)((uint)i >> 25) == HandleType.Method);
return *(MethodHandle*)&i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ private unsafe void PopulateRvaToTokenMap(TypeManagerHandle handle, byte* pMap,
if ((command & StackTraceDataCommand.UpdateOwningType) != 0)
{
currentOwningType = Handle.FromIntToken((int)NativePrimitiveDecoder.ReadUInt32(ref pCurrent));
Debug.Assert(currentOwningType.HandleType is HandleType.TypeDefinition or HandleType.TypeReference or HandleType.TypeSpecification);
Debug.Assert((command & StackTraceDataCommand.IsStackTraceHidden) != 0 ||
currentOwningType.HandleType is HandleType.TypeDefinition or HandleType.TypeReference or HandleType.TypeSpecification);
Comment on lines +350 to +351
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is non-obvious: if TypeDef/TypeSpec/TypeRef handles have their highest bit set, we'd compare them as negative numbers when sorting and StackTraceHidden records (that don't bother filing out owning type) will sort after them. We don't currently see UpdateOwningType command for those since they sort before everything else and owning type == 0 is the initial assumption in the code above (and also in the emitter).

}

if ((command & StackTraceDataCommand.UpdateName) != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static unsafe bool TryGetFieldAccessMetadataFromFieldAccessMap(

if ((entryFlags & FieldTableFlags.HasMetadataHandle) != 0)
{
Handle entryFieldHandle = (((int)HandleType.Field << 24) | (int)entryParser.GetUnsigned()).AsHandle();
Handle entryFieldHandle = (((int)HandleType.Field << 25) | (int)entryParser.GetUnsigned()).AsHandle();
if (!fieldHandle.Equals(entryFieldHandle))
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ public void GetNext(
if (_moduleHandle != _moduleForMethodHandle)
return;

Handle entryMethodHandle = (((uint)HandleType.Method << 24) | entryParser.GetUnsigned()).AsHandle();
Handle entryMethodHandle = (((uint)HandleType.Method << 25) | entryParser.GetUnsigned()).AsHandle();
if (!_methodHandle.Equals(entryMethodHandle))
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ private void EmitHandle(RecordDef record)
CloseScope();

OpenScope($"internal {handleName}(int value)");
WriteLine("HandleType hType = (HandleType)(value >> 24);");
WriteLine($"Debug.Assert(hType == 0 || hType == HandleType.{record.Name} || hType == HandleType.Null);");
WriteLine($"_value = (value & 0x00FFFFFF) | (((int)HandleType.{record.Name}) << 24);");
WriteLine("HandleType hType = (HandleType)((uint)value >> 25);");
WriteLine($"Debug.Assert(hType == HandleType.{record.Name} || hType == HandleType.Null);");
WriteLine($"_value = (value & 0x01FFFFFF) | (((int)HandleType.{record.Name}) << 25);");
WriteLine("_Validate();");
CloseScope();

Expand All @@ -157,18 +157,18 @@ private void EmitHandle(RecordDef record)
WriteLine(" => new Handle(handle._value);");

WriteLineIfNeeded();
WriteLine("internal int Offset => (_value & 0x00FFFFFF);");
WriteLine("internal int Offset => (_value & 0x01FFFFFF);");

WriteLineIfNeeded();
WriteLine($"public {record.Name} Get{record.Name}(MetadataReader reader)");
WriteLine($" => new {record.Name}(reader, this);");

WriteLineIfNeeded();
WriteLine("public bool IsNil => (_value & 0x00FFFFFF) == 0;");
WriteLine("public bool IsNil => (_value & 0x01FFFFFF) == 0;");

WriteScopeAttribute("[System.Diagnostics.Conditional(\"DEBUG\")]");
OpenScope("internal void _Validate()");
WriteLine($"if ((HandleType)((_value & 0xFF000000) >> 24) != HandleType.{record.Name})");
WriteLine($"if ((HandleType)((uint)_value >> 25) != HandleType.{record.Name})");
WriteLine(" throw new ArgumentException();");
CloseScope("_Validate");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static uint Read(this NativeReader reader, uint offset, out Handle handle
{
uint rawValue;
offset = reader.DecodeUnsigned(offset, out rawValue);
handle = new Handle((HandleType)(byte)rawValue, (int)(rawValue >> 8));
handle = new Handle((HandleType)(rawValue & 0x7F), (int)(rawValue >> 7));
return offset;
}

Expand Down
Loading
Loading