KEMBAR78
JIT: Use faster unchecked write-barrier for boxed statics by EgorBo · Pull Request #98166 · dotnet/runtime · GitHub
Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Feb 8, 2024

And a small clean up.

Example:

struct MyStruct
{
    public object Obj;
}

static MyStruct boxedStatic;

[MethodImpl(MethodImplOptions.NoInlining)]
static void Test(string str1, string str2)
{
    // simple way to trigger CSE:
    boxedStatic.Obj = str1;
    boxedStatic.Obj = str2;
}

Codegen diff for Test:

; Method Prog:Test(System.String,System.String) (FullOpts)
G_M57713_IG01:  
       push     rdi
       push     rsi
       push     rbx
       sub      rsp, 32
       mov      rbx, rcx
       mov      rsi, rdx
G_M57713_IG02:  
       test     byte  ptr [(reloc 0x7ff8e243b942)], 1      ; global ptr
       je       SHORT G_M57713_IG05
G_M57713_IG03:  
       mov      rcx, 0x21A0D401E10      ; box for Prog:boxedStatic
       mov      rdi, gword ptr [rcx]
       add      rdi, 8
       mov      rcx, rdi
       mov      rdx, rbx
-      call     CORINFO_HELP_CHECKED_ASSIGN_REF
+      call     CORINFO_HELP_ASSIGN_REF
       mov      rcx, rdi
       mov      rdx, rsi
-      call     CORINFO_HELP_CHECKED_ASSIGN_REF
+      call     CORINFO_HELP_ASSIGN_REF
       nop      
G_M57713_IG04:  
       add      rsp, 32
       pop      rbx
       pop      rsi
       pop      rdi
       ret      
G_M57713_IG05:  
       mov      rcx, 0x7FF8E243B910
       mov      edx, 2
       call     CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
       jmp      SHORT G_M57713_IG03
; Total bytes of code: 92

@ghost ghost assigned EgorBo Feb 8, 2024
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 8, 2024
@ghost
Copy link

ghost commented Feb 8, 2024

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

Issue Details
  • small clean up.

Example:

struct MyStruct
{
    public object Obj;
}

static MyStruct boxedStatic;

[MethodImpl(MethodImplOptions.NoInlining)]
static void Test(string str1, string str2)
{
    boxedStatic.Obj = str1;
    boxedStatic.Obj = str2;
}

Codegen diff for Test:

; Method Prog:Test(System.String,System.String) (FullOpts)
G_M57713_IG01:  
       push     rdi
       push     rsi
       push     rbx
       sub      rsp, 32
       mov      rbx, rcx
       mov      rsi, rdx
G_M57713_IG02:  
       test     byte  ptr [(reloc 0x7ff8e243b942)], 1      ; global ptr
       je       SHORT G_M57713_IG05
G_M57713_IG03:  
       mov      rcx, 0x21A0D401E10      ; box for Prog:boxedStatic
       mov      rdi, gword ptr [rcx]
       add      rdi, 8
       mov      rcx, rdi
       mov      rdx, rbx
-      call     CORINFO_HELP_CHECKED_ASSIGN_REF
+      call     CORINFO_HELP_ASSIGN_REF
       mov      rcx, rdi
       mov      rdx, rsi
-      call     CORINFO_HELP_CHECKED_ASSIGN_REF
+      call     CORINFO_HELP_ASSIGN_REF
       nop      
G_M57713_IG04:  
       add      rsp, 32
       pop      rbx
       pop      rsi
       pop      rdi
       ret      
G_M57713_IG05:  
       mov      rcx, 0x7FF8E243B910
       mov      edx, 2
       call     CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
       jmp      SHORT G_M57713_IG03
; Total bytes of code: 92
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Feb 8, 2024

@MihuBot

@EgorBo
Copy link
Member Author

EgorBo commented Feb 9, 2024

@AndyAyersMS @kunalspathak (cc @dotnet/jit-contrib) a quick follow up to my previous PR There are only a few text diffs after marking boxed static address as unchecked barrier + a small clean up.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

LGTM

@EgorBo EgorBo requested a review from kunalspathak February 9, 2024 01:29
@EgorBo EgorBo merged commit 0a5e97f into dotnet:main Feb 9, 2024
@EgorBo EgorBo deleted the more-faster-wb branch February 9, 2024 11:12
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2024
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.

2 participants