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
2 changes: 1 addition & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private void PublishCode()
_methodCodeNode.InitializeEHInfo(ehInfo);

_methodCodeNode.InitializeDebugLocInfos(_debugLocInfos);
_methodCodeNode.InitializeDebugVarInfos(_debugVarInfos);
_methodCodeNode.InitializeDebugVarInfos(_debugVarInfos, _compilation.TypeSystemContext.Target);
#if READYTORUN
_methodCodeNode.InitializeInliningInfo(_inlinedMethods.ToArray());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

using Internal.JitInterface;
Expand Down Expand Up @@ -149,11 +150,13 @@ public static byte[] CreateBoundsBlobForMethod(OffsetMapping[] offsetMapping)
return writer.ToArray();
}

public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos)
public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos, TargetDetails target)
{
if (varInfos == null || varInfos.Length == 0)
return null;

bool isX86 = target.Architecture == TargetArchitecture.X86;

NibbleWriter writer = new NibbleWriter();
writer.WriteUInt((uint)varInfos.Length);

Expand All @@ -177,7 +180,7 @@ public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos)
case VarLocType.VLT_STK:
case VarLocType.VLT_STK_BYREF:
writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
writer.WriteInt(nativeVarInfo.varLoc.C);
WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.C, assume4ByteAligned : isX86);
break;
case VarLocType.VLT_REG_REG:
writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
Expand All @@ -186,16 +189,16 @@ public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos)
case VarLocType.VLT_REG_STK:
writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
writer.WriteUInt((uint)nativeVarInfo.varLoc.C);
writer.WriteInt(nativeVarInfo.varLoc.D);
WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.D, assume4ByteAligned : isX86);
break;
case VarLocType.VLT_STK_REG:
writer.WriteInt(nativeVarInfo.varLoc.B);
WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.B, assume4ByteAligned : isX86);
writer.WriteUInt((uint)nativeVarInfo.varLoc.C);
writer.WriteUInt((uint)nativeVarInfo.varLoc.D);
break;
case VarLocType.VLT_STK2:
writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
writer.WriteInt(nativeVarInfo.varLoc.C);
WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.C, assume4ByteAligned : isX86);
break;
case VarLocType.VLT_FPSTK:
writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
Expand All @@ -206,6 +209,19 @@ public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos)
default:
throw new BadImageFormatException("Unexpected var loc type");
}

static void WriteEncodedStackOffset(NibbleWriter _writer, int offset, bool assume4ByteAligned)
Copy link
Member

Choose a reason for hiding this comment

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

Nit - if at some point we considered expanding this behavior to other architectures, the name of the argument (assume4ByteAligned) would probably need to change to e.g. something like encodeUsingPointerSizeUnits or some such. If we believe this to be limited to X86 forever, it's probably OK.

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 just checked to see how valuable this really is, and we could save something like 0.08% of System.Private.CoreLib.dll size if we applied a similar size optimization on X64. I don't see that as worthwhile given the complexity it would impose on the reader in the runtime.

{
if (assume4ByteAligned)
{
Debug.Assert(offset % 4 == 0);
_writer.WriteInt(offset / 4);
}
else
{
_writer.WriteInt(offset);
}
}
}

return writer.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ public void InitializeDebugLocInfos(OffsetMapping[] debugLocInfos)
_debugLocInfos = DebugInfoTableNode.CreateBoundsBlobForMethod(debugLocInfos);
}

public void InitializeDebugVarInfos(NativeVarInfo[] debugVarInfos)
public void InitializeDebugVarInfos(NativeVarInfo[] debugVarInfos, TargetDetails target)
Copy link
Member

Choose a reason for hiding this comment

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

TargetDetails are available in _method.Context.Target. The additional parameter caused an unnecessary NativeAOT build break.

{
Debug.Assert(_debugVarInfos == null);
// Process the debug info from JIT format to R2R format immediately as it is large
// and not used in the rest of the process except to emit.
_debugVarInfos = DebugInfoTableNode.CreateVarBlobForMethod(debugVarInfos);
_debugVarInfos = DebugInfoTableNode.CreateVarBlobForMethod(debugVarInfos, target);
}

public void InitializeDebugEHClauseInfos(DebugEHClauseInfo[] debugEHClauseInfos)
Expand Down