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

8299730: Add trivial call linker option #771

Conversation

JornVernee
Copy link
Member

@JornVernee JornVernee commented Jan 19, 2023

Add a trivial call linker option. This option acts as a hint to the runtime which indicates that a downcall is extremely short live (comparable to calling an empty function), and does not call back into Java.

Some implementations (like ours) might use this information to apply additional optimizations that are only applicable to trivial functions (dropping thread state transitions).

Note that the VM code diff looks kind of messy, but I essentially just put 3 if statements around the code that deals with the thread state transitions before and after the call. This also required moving the declarations of the Labels around though (so they are accessible from both ifs on the return path), which is probably messing up the diff view.


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed (1 review required, with at least 1 Committer)

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/panama-foreign pull/771/head:pull/771
$ git checkout pull/771

Update a local copy of the PR:
$ git checkout pull/771
$ git pull https://git.openjdk.org/panama-foreign pull/771/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 771

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/panama-foreign/pull/771.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 19, 2023

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

@JornVernee JornVernee force-pushed the Trivial_My_Old_Friend branch 2 times, most recently from 3855992 to 638f710 Compare January 19, 2023 16:19
@JornVernee JornVernee marked this pull request as ready for review January 23, 2023 19:09
@JornVernee JornVernee marked this pull request as draft January 23, 2023 19:09
@JornVernee JornVernee marked this pull request as ready for review January 24, 2023 15:40
@openjdk openjdk bot added the rfr Ready for review label Jan 24, 2023
@mlbridge
Copy link

mlbridge bot commented Jan 24, 2023

Webrevs

Co-authored-by: Maurizio Cimadamore <54672762+mcimadamore@users.noreply.github.com>
@openjdk
Copy link

openjdk bot commented Jan 24, 2023

@JornVernee 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:

8299730: Add trivial call linker option

Reviewed-by: mcimadamore

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 118 new commits pushed to the foreign-memaccess+abi branch:

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 foreign-memaccess+abi branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Ready to be integrated label Jan 24, 2023
@JornVernee
Copy link
Member Author

JornVernee commented Jan 27, 2023

Forgot to add the benchmarks before. Added them now.

Some numbers on my machine:

Benchmark                                  Mode  Cnt  Score   Error  Units
CallOverheadConstant.jni_blank             avgt   30  4.271 � 0.012  ns/op
CallOverheadConstant.panama_blank          avgt   30  3.300 � 0.022  ns/op
CallOverheadConstant.panama_blank_trivial  avgt   30  2.853 � 0.010  ns/op
CallOverheadVirtual.jni_blank              avgt   30  4.278 � 0.017  ns/op
CallOverheadVirtual.panama_blank           avgt   30  3.665 � 0.014  ns/op
CallOverheadVirtual.panama_blank_trivial   avgt   30  3.254 � 0.011  ns/op

The difference seems to be very minimal on my machine, but others have reported more significant improvements. This could still be improved by intrinsifying in C2 maybe, but not sure by how much, and if that's worth the complexity.

@mcimadamore
Copy link
Collaborator

Forgot to add the benchmarks before. Added them now.

Some numbers on my machine:

Benchmark                                  Mode  Cnt  Score   Error  Units
CallOverheadConstant.jni_blank             avgt   30  4.271 � 0.012  ns/op
CallOverheadConstant.panama_blank          avgt   30  3.300 � 0.022  ns/op
CallOverheadConstant.panama_blank_trivial  avgt   30  2.853 � 0.010  ns/op
CallOverheadVirtual.jni_blank              avgt   30  4.278 � 0.017  ns/op
CallOverheadVirtual.panama_blank           avgt   30  3.665 � 0.014  ns/op
CallOverheadVirtual.panama_blank_trivial   avgt   30  3.254 � 0.011  ns/op

The difference seems to be very minimal on my machine, but others have reported more significant improvements. This could still be improved by intrinsifying in C2 maybe, but not sure by how much, and if that's worth the complexity.

Nice!

@JornVernee
Copy link
Member Author

JornVernee commented Jan 30, 2023

The new test that tests that we can't do an upcall when a function is trivial was failing on the zero VM. zero just ignores the linker option, so it is also impossible to detect. I don't see any merit in trying to make sure that an upcall fails on zero though when the linker option is otherwise ignored. So, I've just disabled the test on zero instead.

@mcimadamore
Copy link
Collaborator

mcimadamore commented Jan 31, 2023

The new test that tests that we can't do an upcall when a function is trivial was failing on the zero VM. zero just ignores the linker option, so it is also impossible to detect. I don't see any merit in trying to make sure that an upcall fails on zero though when the linker option is otherwise ignored. So, I've just disabled the test on zero instead.

I agree - trivial should be best effort - perhaps something worth a note in the javadoc (e.g. that some linker implementation might reserve a right to refuse? Or even throw UOE when creating the unsupported option?)

@JornVernee
Copy link
Member Author

Note that the current javadoc already hints that the implementation may (or may not) apply additional optimizations:

         * Using this linker option is a hint which some implementations may use to apply
         * optimizations that are only valid for trivial functions.

I don't think throwing a UOE is necessary in this case. (Though in general I think a particular linker implementation refusing a linker option is something that we want to allow, if only just in case)

@JornVernee
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 31, 2023

Going to push as commit 200a116.
Since your change was applied there have been 118 commits pushed to the foreign-memaccess+abi branch:

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 31, 2023

@JornVernee Pushed as commit 200a116.

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

@JornVernee JornVernee deleted the Trivial_My_Old_Friend branch January 31, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
2 participants