Skip to content

[mono][aot] Optimize constrained calls made from gsharedvt methods. - #79339

Merged
vargaz merged 1 commit into
dotnet:mainfrom
vargaz:constrained-gsharedvt-opt
Feb 8, 2023
Merged

[mono][aot] Optimize constrained calls made from gsharedvt methods.#79339
vargaz merged 1 commit into
dotnet:mainfrom
vargaz:constrained-gsharedvt-opt

Conversation

@vargaz

@vargazvargaz commented Dec 7, 2022

Copy link
Copy Markdown
Contributor

The calls are of the form:
.constrained T_GSHAREDVT
callvirt

Whenever T_GSHAREDVT is a reference or value type is only known at runtime.

Previously these were handled by passing the arguments to a JIT icall which computed the target method and did a runtime invoke.

Add 2 optimizations:

  • Precompute the data which depends only on the type and the method, store it in an rgctx slot and pass it to the JIT icall.
  • Add a fastpath for simpler cases which makes an indirect call from generated code.

@ghost

ghost commented Dec 7, 2022

Copy link
Copy Markdown

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@vargaz
vargaz removed the request for review from SamMonoRTDecember 7, 2022 10:46
@vargaz

Copy link
Copy Markdown
ContributorAuthor

This will also avoid some interpreter transitions on wasm, making the stack traces on BCL test suite crashes etc. smaller.

@vargaz

Copy link
Copy Markdown
ContributorAuthor

The failures look relevant.

@SamMonoRT

Copy link
Copy Markdown
Member

@vargaz
vargazforce-pushed the constrained-gsharedvt-opt branch from cbe44f4 to ef2aec6CompareDecember 9, 2022 01:21
Comment threadsrc/mono/mono/mini/mini-generic-sharing.c Outdated
Comment threadsrc/mono/mono/mini/mini-generic-sharing.c Outdated
@vargaz
vargazforce-pushed the constrained-gsharedvt-opt branch from 5229775 to f144a24CompareDecember 9, 2022 15:34
Comment threadsrc/mono/mono/mini/method-to-ir.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what would be the additional cases that would fit into the fastpath approach?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The cases excluded by the if.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am trying to understand the code and the effect that covering more cases would bring.

Comment threadsrc/mono/mono/mini/jit-icalls.c Outdated
@vargaz
vargazforce-pushed the constrained-gsharedvt-opt branch from f144a24 to 03e2564CompareDecember 12, 2022 17:40
@vargaz

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@vargazvargaz added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Dec 13, 2022
@vargaz

Copy link
Copy Markdown
ContributorAuthor

Failures are relevant.

@vargaz

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@vargazvargaz removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Dec 15, 2022
@vargaz

Copy link
Copy Markdown
ContributorAuthor

Failures are unrelated.

@lewinglewing closed this Dec 20, 2022
@lewinglewing reopened this Dec 20, 2022
@vargaz

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines 2639 to 2660

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't have some helper function that does this already?

The calls are of the form:
.constrained T_GSHAREDVT
callvirt <method>
Whenever T_GSHAREDVT is a reference or value type is only known at runtime.
Previously these were handled by passing the arguments to a JIT icall which
computed the target method and did a runtime invoke.
Added 2 optimizations:
* Precompute the data which depends only on the type and the method,
store it in an rgctx slot and pass it to the JIT icall.
* Add a fastpath for simpler cases which makes an indirect call
from generated code.
@vargaz
vargazforce-pushed the constrained-gsharedvt-opt branch from 68b30bc to 0033318CompareFebruary 7, 2023 19:48
@vargaz

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@vargaz

Copy link
Copy Markdown
ContributorAuthor

Failures are unrelated

@vargaz
vargaz merged commit 1b788f4 into dotnet:mainFeb 8, 2023
@vargaz
vargaz deleted the constrained-gsharedvt-opt branch February 8, 2023 04:01
@ghostghost locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@vargaz@SamMonoRT@lambdageek@kotlarmilos@ivanpovazan@lewing@marek-safar