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

8330094: RISC-V: Save and restore FRM in the call stub #18758

Closed

Conversation

Hamlin-Li
Copy link

@Hamlin-Li Hamlin-Li commented Apr 12, 2024

Hi,
Can you help to review this patch?
As discussed at #17745 (comment), we should do the similar thing as JDK-8319973 on aarch64.
Thanks!

Tests running ...


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-8330094: RISC-V: Save and restore FRM in the call stub (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18758

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 12, 2024

👋 Welcome back mli! 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
Copy link

openjdk bot commented Apr 12, 2024

@Hamlin-Li 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:

8330094: RISC-V: Save and restore FRM in the call stub

Reviewed-by: fyang, luhenry

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 94 new commits pushed to the master branch:

  • 003e86f: 8324755: Enable parallelism in vmTestbase/gc/gctests/LargeObjects tests
  • 706b421: 8330467: NoClassDefFoundError when lambda is in a hidden class
  • fe0227e: 8311098: Change comment in verificationType.hpp to refer to _sym
  • 0646284: 8317376: Minor improvements to the 'this' escape analyzer
  • 4895a15: 8319516: AIX System::loadLibrary needs support to load a shared library from an archive object
  • fd331ff: 8325469: Freeze/Thaw code can crash in the presence of OSR frames
  • 9fd7802: 8325494: C2: Broken graph after not skipping CastII node anymore for Assertion Predicates after JDK-8309902
  • 192ec38: 8329595: spurious variable "might not have been initialized" on static final field
  • 03e8417: 8329948: Remove string template feature
  • ff3e76f: 8330053: JFR: Use LocalDateTime instead ZonedDateTime
  • ... and 84 more: https://git.openjdk.org/jdk/compare/7df492627b933f48750985c26de69be3f86115cb...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 rfr Pull request is ready for review label Apr 12, 2024
@openjdk
Copy link

openjdk bot commented Apr 12, 2024

@Hamlin-Li The following label will be automatically applied to this pull request:

  • hotspot

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.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Apr 12, 2024
@mlbridge
Copy link

mlbridge bot commented Apr 12, 2024

Webrevs

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks.
BTW: There is another path where FP control register could got clobbered is through JNI.
See: https://bugs.openjdk.org/browse/JDK-8320892. I think we might want to fix it for riscv too.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 15, 2024
@@ -415,6 +424,10 @@ class StubGenerator: public StubCodeGenerator {

__ ld(x9, x9_save);

// restore fcsr
__ ld(t1, fcsr_save);
__ csrw(CSR_FCSR, t1);
Copy link
Member

@luhenry luhenry Apr 15, 2024

Choose a reason for hiding this comment

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

It would be better to avoid the csrw in case the CSR is already set to RoundingMode::rne on some hardware. You can have avoid it with a simple check on the current value of FCSR.

Something along the line of:

__ ld(t1, fcsr_save);
__ csrr(t0, CSR_FCSR);
__ beq(t1, t0, skip_csrw);
__ csrw(CSR_FCSR, t1);
__ bind(skip_csrw);

Some doc about it: https://riscv-optimization-guide.riseproject.dev/#_controlling_rounding_behavior_scalar

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. So is it safe to claim that csrr is faster than csrw? I didn't measure the difference.

Copy link
Member

@luhenry luhenry Apr 15, 2024

Choose a reason for hiding this comment

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

It's fair to claim that csrw has side effects which may be more detrimental to performance, side effects that csrr that doesn't have (and can't as it's only reading).

I didn't measure the difference.

I don't know how that affects current hardware, but remember that current hardware are in-order CPUs which may not be impacted by many of these performance problems.

Copy link
Member

Choose a reason for hiding this comment

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

Another thing that is worth considering is that the fflags (exception flags) contained in fcsr is very likely to change after the Java call which does floating point calculations.

Copy link
Author

Choose a reason for hiding this comment

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

Should we replace read/write/comp of fcsr with frm only?

Copy link
Member

@RealFYang RealFYang Apr 15, 2024

Choose a reason for hiding this comment

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

Yeah, that make sense to me. I think fflags is safe to ignore here.
(And you will also need to update this code comment in file: src/hotspot/cpu/riscv/stubGenerator_riscv.cpp if you do that: // -34 [ saved Floating-point Control and Status Register ] <--- sp_after_call)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for discussion, all updated.

// don't want non-IEEE rounding modes.
Label skip_fsrmi;
__ mv(t1, __ RoundingMode::rne);
__ beq(t0, t1, skip_fsrmi);
Copy link
Member

Choose a reason for hiding this comment

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

You can take advantage of RoundingMode::rne == 0 by doing __ beq(t0, zr, skip_fsrmi) and remove the above __ mv(t1, __ RoundingMode::rne);. Please add a guarantee(__ RoundingMode::rne == 0) as well, just to self-document.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, fixed.

// don't want non-IEEE rounding modes.
Label skip_fsrmi;
guarantee(__ RoundingMode::rne == 0, "must be");
__ beq(t0, zr, skip_fsrmi);
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: __ beqz(t0, skip_fsrmi);

Copy link
Author

Choose a reason for hiding this comment

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

fixed, thanks

@@ -296,6 +299,16 @@ class StubGenerator: public StubCodeGenerator {
__ fsd(f26, f26_save);
__ fsd(f27, f27_save);

__ frrm(t0);
__ sd(t0, frm_save);
// Set fcsr to the state we need. We do want Round to Nearest. We
Copy link
Member

@RealFYang RealFYang Apr 17, 2024

Choose a reason for hiding this comment

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

I think it will be more accurate to mention frm instead of fcsr in both code comment and the JBS title?

Copy link
Author

Choose a reason for hiding this comment

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

agree, fixed

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 17, 2024
@Hamlin-Li Hamlin-Li changed the title 8330094: RISC-V: Save and restore FCSR in the call stub 8330094: RISC-V: Save and restore FRM in the call stub Apr 17, 2024
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 17, 2024
@Hamlin-Li
Copy link
Author

Thanks @luhenry @RealFYang for your reviewing.

/integrate

@openjdk
Copy link

openjdk bot commented Apr 18, 2024

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

  • 4b55fe5: 8330520: linux clang build fails in os_linux.cpp with static_assert with no message is a C++17 extension
  • 5eb2c59: 8330475: Remove unused default value for ModRefBarrierSet::write_ref_array_pre
  • 003e86f: 8324755: Enable parallelism in vmTestbase/gc/gctests/LargeObjects tests
  • 706b421: 8330467: NoClassDefFoundError when lambda is in a hidden class
  • fe0227e: 8311098: Change comment in verificationType.hpp to refer to _sym
  • 0646284: 8317376: Minor improvements to the 'this' escape analyzer
  • 4895a15: 8319516: AIX System::loadLibrary needs support to load a shared library from an archive object
  • fd331ff: 8325469: Freeze/Thaw code can crash in the presence of OSR frames
  • 9fd7802: 8325494: C2: Broken graph after not skipping CastII node anymore for Assertion Predicates after JDK-8309902
  • 192ec38: 8329595: spurious variable "might not have been initialized" on static final field
  • ... and 86 more: https://git.openjdk.org/jdk/compare/7df492627b933f48750985c26de69be3f86115cb...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Apr 18, 2024

@Hamlin-Li Pushed as commit b049609.

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

@Hamlin-Li Hamlin-Li deleted the save-store-fcsr-in-callstub branch April 18, 2024 11:20
@Hamlin-Li Hamlin-Li mentioned this pull request Apr 18, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants