Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Improved Exception handling #793

Merged
merged 1 commit into from
Sep 8, 2016

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented Sep 5, 2016

Throw the exceptions directly from the void method, don't mark as no-inlining

Post dotnet/coreclr#6103 "Do not inline methods that never return" this will give the best result. (As shown in dotnet/coreclr#6634)

It won't inline the exception Throw function, will mark the call to the Throw function as cold code, and won't preform any register prep for the function (push+pop)

@benaadams
Copy link
Member Author

e.g. public static void Requires(bool condition)

Pre

Inlines into 06000001 Contract:Requires(bool)
  [0 IL=0003 TR=000010 06000009] [FAILED: noinline per IL/cached result] Contract:NewArgumentException():ref
Budget: initialTime=90, finalTime=90, initialBudget=900, currentBudget=900
Budget: initialSize=359, finalSize=359
; Assembly listing for method Contract:Requires(bool)
; Emitting BLENDED_CODE for X64 CPU with SSE2
; optimized code
; rsp based frame
; partially interruptible
; Final local variable assignments
;
;  V00 arg0         [V00,T00] (  3,   3  )    bool  ->  rcx        
;  V01 OutArgs      [V01    ] (  1,   1  )  lclBlk (32) [rsp+0x00]  
;
; Lcl frame size = 40
G_M36318_IG01:
       sub      rsp, 40
       nop      
G_M36318_IG02:
       test     cl, cl
       je       SHORT G_M36318_IG04
G_M36318_IG03:
       add      rsp, 40
       ret      
G_M36318_IG04:
       call     [Contract:NewArgumentException():ref]
       mov      rcx, rax
       call     CORINFO_HELP_THROW
       int3     
; Total bytes of code 29, prolog size 5 for method Contract:Requires(bool)

Post

Inlines into 06000001 Contract:Requires(bool)
  [0 IL=0003 TR=000010 06000009] [FAILED: does not return] Contract:ThrowArgumentException()
Budget: initialTime=87, finalTime=87, initialBudget=870, currentBudget=870
Budget: initialSize=336, finalSize=336
; Assembly listing for method Contract:Requires(bool)
; Emitting BLENDED_CODE for X64 CPU with SSE2
; optimized code
; rsp based frame
; partially interruptible
; Final local variable assignments
;
;  V00 arg0         [V00,T00] (  3,   3  )    bool  ->  rcx        
;  V01 OutArgs      [V01    ] (  1,   1  )  lclBlk (32) [rsp+0x00]  
;
; Lcl frame size = 40
G_M36319_IG01:
       sub      rsp, 40
       nop      
G_M36319_IG02:
       test     cl, cl
       je       SHORT G_M36319_IG04
G_M36319_IG03:
       add      rsp, 40
       ret      
G_M36319_IG04:
       call     [Contract:ThrowArgumentException()]
       int3     
; Total bytes of code 21, prolog size 5 for method Contract:Requires(bool)

@benaadams
Copy link
Member Author

Likewise it means: Span`1:.ctor(ref):this

ends like

       ret      
G_M44205_IG06:
       call     [Contract:ThrowArgumentException()]
G_M44205_IG07:
       call     [Contract:ThrowArgumentException()]
       int3     
; Total bytes of code 137, prolog size 13 for method Span`1:.ctor(ref):this

instead of

       ret      
G_M44203_IG06:
       call     [Contract:NewArgumentException():ref]
       mov      rcx, rax
       call     CORINFO_HELP_THROW
G_M44203_IG07:
       call     [Contract:NewArgumentException():ref]
       mov      rcx, rax
       call     CORINFO_HELP_THROW
       int3     
; Total bytes of code 153, prolog size 13 for method Span`1:.ctor(ref):this

@KrzysztofCwalina
Copy link
Member

@dotnet-bot test this please

@KrzysztofCwalina
Copy link
Member

Thanks!

@KrzysztofCwalina KrzysztofCwalina merged commit bc5ad95 into dotnet:master Sep 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants