Skip to content

8306706: Support out-of-line code generation for MachNodes #13602

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

Closed
wants to merge 5 commits into from

Conversation

merykitty
Copy link
Member

@merykitty merykitty commented Apr 23, 2023

Hi,

This patch adds supports for MachNodes to emit an out-of-line piece of code in the stub section of the compiled method. This allows the separation of the uncommon path from the common one, which speeds up the common path a little bit and increases compiled code density. Please take a look and leave reviews.

Thanks a lot.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8306706: Support out-of-line code generation for MachNodes

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13602/head:pull/13602
$ git checkout pull/13602

Update a local copy of the PR:
$ git checkout pull/13602
$ git pull https://git.openjdk.org/jdk.git pull/13602/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13602

View PR using the GUI difftool:
$ git pr show -t 13602

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13602.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 23, 2023

👋 Welcome back qamai! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 23, 2023
@openjdk
Copy link

openjdk bot commented Apr 23, 2023

@merykitty The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Apr 23, 2023

Webrevs

@merykitty
Copy link
Member Author

With this patch, the compiled code for a float-to-int conversion is changed:

Before:

    vcvttss2si %xmm1,%eax
    cmp    $0x80000000,%eax
    jne    DONE
    sub    $0x8,%rsp
    vmovss %xmm1,(%rsp)
    call   Stub::f2i_fixup              ;   {runtime_call StubRoutines (initial stubs)}
    pop    %rax
DONE:


After:

    vcvttss2si %xmm1,%eax
    cmp    $0x80000000,%eax
    je     STUB
CONTINUE:

STUB:
    sub    $0x8,%rsp
    vmovss %xmm1,(%rsp)
    call   Stub::f2i_fixup              ;   {runtime_call StubRoutines (initial stubs)}
    pop    %rax
    jmp    CONTINUE

And there are slight improvements shown in microbenchmarks, although the result differs run-to-run, the patched version seems to be generally more performant:

                                      Before             After
Benchmark             Mode  Cnt    Score    Error    Score    Error  Units   Change
ConvertF2I.d2iArray   avgt    5  266.890 ±  3.277  260.720 ±  1.382  ns/op   -2.31%
ConvertF2I.d2iSingle  avgt    5    0.378 ±  0.005    0.317 ±  0.013  ns/op  -16.14%
ConvertF2I.d2lArray   avgt    5  273.999 ± 12.571  267.862 ±  4.806  ns/op   -2.24%
ConvertF2I.d2lSingle  avgt    5    0.379 ±  0.005    0.348 ±  0.044  ns/op   -8.18%
ConvertF2I.f2iArray   avgt    5  261.549 ±  1.391  255.522 ± 15.133  ns/op   -2.30%
ConvertF2I.f2iSingle  avgt    5    0.378 ±  0.005    0.311 ±  0.007  ns/op  -17.72%
ConvertF2I.f2lArray   avgt    5  272.745 ±  1.661  267.770 ±  7.033  ns/op   -1.82%
ConvertF2I.f2lSingle  avgt    5    0.379 ±  0.007    0.350 ±  0.022  ns/op   -7.65%

@merykitty
Copy link
Member Author

The generated node for the stub looks like this:

class convF2I_reg_regStub : public C2CodeStub {
private:
    const convF2I_reg_regNode* _node;
    PhaseRegAlloc* ra_;
    MachOper* opnd_array(uint index) const { return _node->opnd_array(index); }
public:
    convF2I_reg_regStub(const convF2I_reg_regNode* node, PhaseRegAlloc* ra) : _node(node), ra_(ra) {}
    int max_size() const { return 23; }
    void emit(C2_MacroAssembler& masm);
};

And the corresponding node's emit method has an additional section:

void convF2I_reg_regNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
    cbuf.set_insts_mark();
    convF2I_reg_regStub* stub = new (Compile::current()->comp_arena()) convF2I_reg_regStub(this, ra_);
    if (!Compile::current()->output()->in_scratch_emit_size()) {
        Compile::current()->output()->add_stub(stub);
    }
    ...
}

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Great work. I'm just wondering if the extra complexity is justified for optimizing only the floating point conversions. Do you plan to use this for other optimizations?

@merykitty
Copy link
Member Author

@TobiHartmann Thanks for taking a look, I think this can be used for the vectorized version of these nodes, as well as the max, min nodes for floating point numbers. I also see compact header uses out-of-line code to slow path LoadNKlass.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Is it possible to do this in c2_MacroAssembler_x86 instead (as for verified_entry)?
We are trying to move complex coding from .ad files to macroassembler.

@merykitty
Copy link
Member Author

@vnkozlov Yes we can explicitly define a stub without relying on code generation, it may be more preferable since it avoids adding complexity to adlc generation. The only downside is that there is some boilerplate for each usage but I think the boilerplate is not too terrible.

@vnkozlov
Copy link
Contributor

@vnkozlov Yes we can explicitly define a stub without relying on code generation, it may be more preferable since it avoids adding complexity to adlc generation. The only downside is that there is some boilerplate for each usage but I think the boilerplate is not too terrible.

Can you look on that? There could be other cases in Macroassembler which can use this

@openjdk
Copy link

openjdk bot commented May 18, 2023

@merykitty Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@openjdk openjdk bot removed the rfr Pull request is ready for review label May 18, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label May 18, 2023
@merykitty
Copy link
Member Author

@TobiHartmann @vnkozlov I have reworked the patch, now it relies on template instead of adlc generation to achieve the desired behaviours, I think this is a much more preferable approach.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Clever. Let me test it.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

My testing passed. Good.

@openjdk
Copy link

openjdk bot commented May 18, 2023

@merykitty This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8306706: Support out-of-line code generation for MachNodes

Reviewed-by: thartmann, kvn

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 83 new commits pushed to the master branch:

  • 710453c: 8308016: Use snippets in java.io package
  • e9320f3: 8308116: jdk.test.lib.compiler.InMemoryJavaCompiler.compile does not close files
  • 97d3b27: 8307523: [vectorapi] Optimize MaskFromLongBenchmark.java
  • bb0ff48: 8305091: Change ChaCha20 cipher init behavior to match AES-GCM
  • c0c4d77: 8308544: Fix compilation regression from JDK-8306983 on musl libc
  • 9e196b3: 8308565: HttpClient: Sanitize logging while stopping
  • 582ddeb: 8308545: java/net/httpclient/ShutdownNow.java fails with "stream 1 cancelled"
  • 1cfb265: 8307814: In the case of two methods with Record Patterns, the second one contains a line number from the first method
  • eb11508: 8308281: Java snippets in the FFM API need to be updated
  • 26227a6: 8305073: Fix VerifyLoopOptimizations - step 2 - verify idom
  • ... and 73 more: https://git.openjdk.org/jdk/compare/902585bec1d4d5681208213bea180302d1b52df9...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 18, 2023
Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Nice! The new version looks good to me.

@merykitty
Copy link
Member Author

@vnkozlov Thanks for your reviews and testing
@TobiHartmann Thanks for your suggestion, I have added comments to describe the purpose of C2GeneralStub

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

@merykitty
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented May 23, 2023

Going to push as commit ab241b3.
Since your change was applied there have been 83 commits pushed to the master branch:

  • 710453c: 8308016: Use snippets in java.io package
  • e9320f3: 8308116: jdk.test.lib.compiler.InMemoryJavaCompiler.compile does not close files
  • 97d3b27: 8307523: [vectorapi] Optimize MaskFromLongBenchmark.java
  • bb0ff48: 8305091: Change ChaCha20 cipher init behavior to match AES-GCM
  • c0c4d77: 8308544: Fix compilation regression from JDK-8306983 on musl libc
  • 9e196b3: 8308565: HttpClient: Sanitize logging while stopping
  • 582ddeb: 8308545: java/net/httpclient/ShutdownNow.java fails with "stream 1 cancelled"
  • 1cfb265: 8307814: In the case of two methods with Record Patterns, the second one contains a line number from the first method
  • eb11508: 8308281: Java snippets in the FFM API need to be updated
  • 26227a6: 8305073: Fix VerifyLoopOptimizations - step 2 - verify idom
  • ... and 73 more: https://git.openjdk.org/jdk/compare/902585bec1d4d5681208213bea180302d1b52df9...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 23, 2023
@openjdk openjdk bot closed this May 23, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 23, 2023
@openjdk
Copy link

openjdk bot commented May 23, 2023

@merykitty Pushed as commit ab241b3.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

}
}

auto stub = C2CodeStub::make<Register, XMMRegister, address>(dst, src, slowpath_target, 23, convertF2I_slowpath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @merykitty, could you please explain how the size 23 was computed? This value does not work with APX and I created a PR (#25787) for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

@vamsi-parasa Hi, I just manually assembled the snippet and see its size, for such a small snippet it is easy to see that the size is indeed the largest possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants