Skip to content

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

Merged
jakobbotsch merged 7 commits into
dotnet:mainfrom
jakobbotsch:disasm-handle-comments
Jun 10, 2022
Merged

Add disasm comments for field data addresses and code addresses#70437
jakobbotsch merged 7 commits into
dotnet:mainfrom
jakobbotsch:disasm-handle-comments

Conversation

@jakobbotsch

Copy link
Copy Markdown
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

publicclassProgram{publicstaticints_primitive;privatestaticGuids_guid;publicstaticvoidMain(){Console.WriteLine(s_primitive);Console.WriteLine(s_guid);Actiona=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]

@ghostghost assigned jakobbotschJun 8, 2022
@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 8, 2022
@ghost

ghost commented Jun 8, 2022

Copy link
Copy Markdown

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

publicclassProgram{publicstaticints_primitive;privatestaticGuids_guid;publicstaticvoidMain(){Console.WriteLine(s_primitive);Console.WriteLine(s_guid);Actiona=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
Copy Markdown
MemberAuthor

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).

@BruceForstallBruceForstall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love it!

@kunalspathakkunalspathak left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
MemberAuthor

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

@jakobbotsch

jakobbotsch commented Jun 8, 2022

Copy link
Copy Markdown
MemberAuthor

This will need to wait for #70452.

@jakobbotsch
jakobbotsch merged commit 95e8cae into dotnet:mainJun 10, 2022
@jakobbotsch
jakobbotsch deleted the disasm-handle-comments branch June 10, 2022 10:58
@ghostghost locked as resolved and limited conversation to collaborators Jul 10, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR 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

@jakobbotsch@BruceForstall@kunalspathak