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

Add disasm comments for field data addresses and code addresses #70437

Merged
merged 7 commits into from
Jun 10, 2022

Conversation

jakobbotsch
Copy link
Member

This adds disassembly comments for field addresses and function addresses. To make this more useful, it also supports displaying the comments for x64 instructions with addressing modes.

For example, for

public class Program
{
    public static int s_primitive;
    private static Guid s_guid;

    public static void Main()
    {
        Console.WriteLine(s_primitive);
        Console.WriteLine(s_guid);
        Action a = Main;
    }
}

the diff in the disasm on x64 is

        mov      rcx, 0xD1FFAB1E
        mov      edx, 1
        call     CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
-       mov      ecx, dword ptr [(reloc)]
+       mov      ecx, dword ptr [(reloc)]      ; data for Program:s_primitive
        call     [System.Console:WriteLine(int)]
        mov      rcx, 0xD1FFAB1E      ; System.Guid
        call     CORINFO_HELP_NEWSFAST
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; box for Program:s_guid
        mov      rcx, gword ptr [rcx]
        vmovupd  xmm0, xmmword ptr [rcx+8]
        vmovupd  xmmword ptr [rax+8], xmm0
        mov      rcx, rax
        call     [System.Console:WriteLine(System.Object)]
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; data for <>O:<0>__Main
        cmp      gword ptr [rcx], 0
        jne      SHORT G_M27646_IG04
 						;; size=95 bbWeight=1    PerfScore 23.50
 G_M27646_IG03:
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; token handle
        call     CORINFO_HELP_NEWSFAST
        mov      rsi, rax
        lea      rcx, bword ptr [rsi+8]
        mov      rdx, rsi
        call     CORINFO_HELP_ASSIGN_REF
-       mov      rdx, 0xD1FFAB1E
+       mov      rdx, 0xD1FFAB1E      ; function address
        mov      qword ptr [rsi+24], rdx
-       mov      rdx, 0xD1FFAB1E
+       mov      rdx, 0xD1FFAB1E      ; code address for Program:Main
        mov      qword ptr [rsi+32], rdx
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; data for <>O:<0>__Main
        mov      rdx, rsi
        call     CORINFO_HELP_ASSIGN_REF
 						;; size=76 bbWeight=0.50 PerfScore 3.62

For ARM64 it looks like (due to CSE not all of the static field accesses show up):

             mov     w1, #1
             bl      CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
             ldr     w0, [x19,#56]
-            movz    x1, #0xd1ffab1e
+            movz    x1, #0xd1ffab1e      // code address for System.Console:WriteLine
             movk    x1, #0xd1ffab1e LSL #16
             movk    x1, #0xd1ffab1e LSL #32
             ldr     x1, [x1]
@@ -40,13 +40,13 @@ G_M27646_IG02:
             movk    x0, #0xd1ffab1e LSL #16
             movk    x0, #0xd1ffab1e LSL #32
             bl      CORINFO_HELP_NEWSFAST
-            movz    x19, #0xd1ffab1e
+            movz    x19, #0xd1ffab1e      // box for Program:s_guid
             movk    x19, #0xd1ffab1e LSL #16
             movk    x19, #0xd1ffab1e LSL #32
             ldr     x1, [x19]
             ldr     q16, [x1,#8]
             str     q16, [x0,#8]
-            movz    x1, #0xd1ffab1e
+            movz    x1, #0xd1ffab1e      // code address for System.Console:WriteLine
             movk    x1, #0xd1ffab1e LSL #16
             movk    x1, #0xd1ffab1e LSL #32
             ldr     x1, [x1]
@@ -66,7 +66,7 @@ G_M27646_IG03:
             movk    x14, #0xd1ffab1e LSL #16
             movk    x14, #0xd1ffab1e LSL #32
             str     x14, [x0,#24]
-            movz    x14, #0xd1ffab1e
+            movz    x14, #0xd1ffab1e      // code address for Program:Main
             movk    x14, #0xd1ffab1e LSL #16
             movk    x14, #0xd1ffab1e LSL #32
             str     x14, [x0,#32]

@ghost ghost assigned jakobbotsch Jun 8, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 8, 2022
@ghost
Copy link

ghost commented Jun 8, 2022

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

This adds disassembly comments for field addresses and function addresses. To make this more useful, it also supports displaying the comments for x64 instructions with addressing modes.

For example, for

public class Program
{
    public static int s_primitive;
    private static Guid s_guid;

    public static void Main()
    {
        Console.WriteLine(s_primitive);
        Console.WriteLine(s_guid);
        Action a = Main;
    }
}

the diff in the disasm on x64 is

        mov      rcx, 0xD1FFAB1E
        mov      edx, 1
        call     CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
-       mov      ecx, dword ptr [(reloc)]
+       mov      ecx, dword ptr [(reloc)]      ; data for Program:s_primitive
        call     [System.Console:WriteLine(int)]
        mov      rcx, 0xD1FFAB1E      ; System.Guid
        call     CORINFO_HELP_NEWSFAST
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; box for Program:s_guid
        mov      rcx, gword ptr [rcx]
        vmovupd  xmm0, xmmword ptr [rcx+8]
        vmovupd  xmmword ptr [rax+8], xmm0
        mov      rcx, rax
        call     [System.Console:WriteLine(System.Object)]
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; data for <>O:<0>__Main
        cmp      gword ptr [rcx], 0
        jne      SHORT G_M27646_IG04
 						;; size=95 bbWeight=1    PerfScore 23.50
 G_M27646_IG03:
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; token handle
        call     CORINFO_HELP_NEWSFAST
        mov      rsi, rax
        lea      rcx, bword ptr [rsi+8]
        mov      rdx, rsi
        call     CORINFO_HELP_ASSIGN_REF
-       mov      rdx, 0xD1FFAB1E
+       mov      rdx, 0xD1FFAB1E      ; function address
        mov      qword ptr [rsi+24], rdx
-       mov      rdx, 0xD1FFAB1E
+       mov      rdx, 0xD1FFAB1E      ; code address for Program:Main
        mov      qword ptr [rsi+32], rdx
-       mov      rcx, 0xD1FFAB1E
+       mov      rcx, 0xD1FFAB1E      ; data for <>O:<0>__Main
        mov      rdx, rsi
        call     CORINFO_HELP_ASSIGN_REF
 						;; size=76 bbWeight=0.50 PerfScore 3.62

For ARM64 it looks like (due to CSE not all of the static field accesses show up):

             mov     w1, #1
             bl      CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
             ldr     w0, [x19,#56]
-            movz    x1, #0xd1ffab1e
+            movz    x1, #0xd1ffab1e      // code address for System.Console:WriteLine
             movk    x1, #0xd1ffab1e LSL #16
             movk    x1, #0xd1ffab1e LSL #32
             ldr     x1, [x1]
@@ -40,13 +40,13 @@ G_M27646_IG02:
             movk    x0, #0xd1ffab1e LSL #16
             movk    x0, #0xd1ffab1e LSL #32
             bl      CORINFO_HELP_NEWSFAST
-            movz    x19, #0xd1ffab1e
+            movz    x19, #0xd1ffab1e      // box for Program:s_guid
             movk    x19, #0xd1ffab1e LSL #16
             movk    x19, #0xd1ffab1e LSL #32
             ldr     x1, [x19]
             ldr     q16, [x1,#8]
             str     q16, [x0,#8]
-            movz    x1, #0xd1ffab1e
+            movz    x1, #0xd1ffab1e      // code address for System.Console:WriteLine
             movk    x1, #0xd1ffab1e LSL #16
             movk    x1, #0xd1ffab1e LSL #32
             ldr     x1, [x1]
@@ -66,7 +66,7 @@ G_M27646_IG03:
             movk    x14, #0xd1ffab1e LSL #16
             movk    x14, #0xd1ffab1e LSL #32
             str     x14, [x0,#24]
-            movz    x14, #0xd1ffab1e
+            movz    x14, #0xd1ffab1e      // code address for Program:Main
             movk    x14, #0xd1ffab1e LSL #16
             movk    x14, #0xd1ffab1e LSL #32
             str     x14, [x0,#32]
Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @kunalspathak @BruceForstall

This was mistakenly creating a handle for the parent (always a class)
but specifying the handle type of the child (e.g. constructor method
handle).
Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

Love it!

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@jakobbotsch
Copy link
Member Author

Running the tests with COMPlus_JitDisasm=* revealed a few places that lie about handles that I will need to track down first.

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 8, 2022

This will need to wait for #70452.

@jakobbotsch jakobbotsch merged commit 95e8cae into dotnet:main Jun 10, 2022
@jakobbotsch jakobbotsch deleted the disasm-handle-comments branch June 10, 2022 10:58
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants