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

Write barrier elision on object reference assignment to a return buffer? #92662

Closed
neon-sunset opened this issue Sep 26, 2023 · 3 comments
Closed
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI tenet-performance Performance related issue

Comments

@neon-sunset
Copy link
Contributor

neon-sunset commented Sep 26, 2023

Description

Consider the method static (object, object) GetObj() => (new(), new());.

On win-x64 JIT emits the following codegen for it:

G_M000_IG01:                ;; offset=0x0000
       push     rdi
       push     rsi
       push     rbx
       sub      rsp, 32
       mov      rbx, rcx

G_M000_IG02:                ;; offset=0x000A
       mov      rsi, 0x7FFCD3835FA0
       mov      rcx, rsi
       call     CORINFO_HELP_NEWSFAST
       mov      rdi, rax
       mov      rcx, rsi
       call     CORINFO_HELP_NEWSFAST
       mov      rsi, rax
       mov      rdx, rdi
       mov      rcx, rbx
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       lea      rcx, bword ptr [rbx+0x08]
       mov      rdx, rsi
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       mov      rax, rbx

G_M000_IG03:                ;; offset=0x0044
       add      rsp, 32
       pop      rbx
       pop      rsi
       pop      rdi
       ret      
; Total bytes of code: 76

Are write barriers necessary given the fact that it is known that object references are being assigned to a return buffer? Is there something I am missing?

Configuration

.NET SDK:
 Version:   8.0.100-rtm.23471.13
 Commit:    1de2c23f77

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-rtm.23471.13\
@neon-sunset neon-sunset added the tenet-performance Performance related issue label Sep 26, 2023
@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 Sep 26, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 26, 2023
@ghost
Copy link

ghost commented Sep 26, 2023

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

Issue Details

Description

Consider the method static (object, object) GetObj() => (new(), new());.

On win-x64 JIT emits the following codegen for it:

G_M000_IG01:                ;; offset=0x0000
       push     rdi
       push     rsi
       push     rbx
       sub      rsp, 32
       mov      rbx, rcx

G_M000_IG02:                ;; offset=0x000A
       mov      rsi, 0x7FFCD3835FA0
       mov      rcx, rsi
       call     CORINFO_HELP_NEWSFAST
       mov      rdi, rax
       mov      rcx, rsi
       call     CORINFO_HELP_NEWSFAST
       mov      rsi, rax
       mov      rdx, rdi
       mov      rcx, rbx
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       lea      rcx, bword ptr [rbx+0x08]
       mov      rdx, rsi
       call     CORINFO_HELP_CHECKED_ASSIGN_REF
       mov      rax, rbx

G_M000_IG03:                ;; offset=0x0044
       add      rsp, 32
       pop      rbx
       pop      rsi
       pop      rdi
       ret      
; Total bytes of code: 76

Are write barriers necessary given the fact that it is known that object references are being assigned to a return buffer which should not require write barriers? Is there something I am missing?

Configuration

.NET SDK:
 Version:   8.0.100-rtm.23471.13
 Commit:    1de2c23f77

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-rtm.23471.13\
Author: neon-sunset
Assignees: -
Labels:

tenet-performance, area-CodeGen-coreclr, untriaged

Milestone: -

@jakobbotsch
Copy link
Member

They are necessary because the JIT can optimize passed return buffers to point to heap. For example, check the codegen for something like c.obj = GetObj() where c is a class.

@neon-sunset
Copy link
Contributor Author

Today I learned, thanks!

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 26, 2023
@teo-tsirpanis teo-tsirpanis closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 27, 2023
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 tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

3 participants