Skip to content

Conversation

@vpaprotsk
Copy link
Contributor

@vpaprotsk vpaprotsk commented Dec 10, 2024

(Also see 8319429: Resetting MXCSR flags degrades ecore)

This PR fixes two issues:

  • the original issue is a crash caused by __ warn corrupting the stack on Windows only
  • This issue also uncovered that -Xcheck:jni test cases were getting 65k lines of warning on HelloWorld (on both Linux and windows):
OpenJDK 64-Bit Server VM warning: MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall

First, the crash. Caused when FXRSTOR is attempting to write reserved bits into MXCSR. If those bits happen to be set, crash. (Hence the crash isn't deterministic. But frequent enough if __ warn is used). It is caused by the binding not reserving stack space for register parameters ()
image
Prolog of the warn function then proceeds to store the for arg registers onto the stack, overriding the fxstore save area. (See https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#calling-convention-defaults)

Fix uses frame::arg_reg_save_area_bytes to bump the stack pointer.


I also kept the fix to verify_mxcsr since without it, -Xcheck:jni is practically unusable when -XX:+EnableX86ECoreOpts are set (65k+ lines of warnings)


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-8344802: Crash in StubRoutines::verify_mxcsr with -XX:+EnableX86ECoreOpts and -Xcheck:jni (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22673

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 10, 2024

👋 Welcome back vpaprotski! 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 Dec 10, 2024

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

8344802: Crash in StubRoutines::verify_mxcsr with -XX:+EnableX86ECoreOpts and -Xcheck:jni

Reviewed-by: jwaters, kvn, sviswanathan

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

  • b8576eb: 6562489: Font-Renderer should ignore invisible characters \u2062 and \u2063
  • 7a0832f: 8349934: Wrong file regex for copyright header format check in .jcheck/conf
  • 2a5d1da: 8349571: Remove JavaThreadFactory interface from SA
  • 74e458b: 8349684: Remove SA core file tests from problem list for macosx-x64
  • ba28119: 8348427: DeferredLintHandler API should use JCTree instead of DiagnosticPosition
  • c5ac3c4: 8249831: Test sun/security/mscapi/nonUniqueAliases/NonUniqueAliases.java is marked with @ignore
  • 336d0d8: 8349926: [BACKOUT] Support static JDK in libfontmanager/freetypeScaler.c
  • 4b463ee: 8342103: C2 compiler support for Float16 type and associated scalar operations
  • 332d87c: 8349859: Support static JDK in libfontmanager/freetypeScaler.c
  • 73e1780: 8349836: G1: Improve group prediction log message
  • ... and 696 more: https://git.openjdk.org/jdk/compare/d6b5264c3f7d0c4157ebd73b2f1a98dd15273c61...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@sviswa7, @TheShermanTanker, @vnkozlov) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Dec 10, 2024

@vpaprotsk The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot

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

@openjdk openjdk bot added hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Dec 10, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 11, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 11, 2024

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 8, 2025

@vpaprotsk This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@vpaprotsk
Copy link
Contributor Author

vpaprotsk commented Jan 8, 2025

(back from vacation. After discussing this with Sandhya, will have an update soon)

@openjdk openjdk bot removed the rfr Pull request is ready for review label Jan 23, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 23, 2025
Comment on lines 182 to 185
if (EnableX86ECoreOpts) {
// On ECore, restore with signaling flags enabled
MxCsr |= 0x3F;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JornVernee I came across your comment https://github.com/openjdk/jdk/pull/14523/files#r1236920072

I believe I am following the 'spirit' of that comment here, but would appreciate you having a look.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think so. Originally I was seeing some cases where we were always resetting MxCsr, even for unrelated exceptions. The new code still only resets it for the FLT_* exceptions.


stmxcsr(mxcsr_save);
movl(tmp, mxcsr_save);
// Mask out any pending exceptions (only check control and mask bits)
Copy link

Choose a reason for hiding this comment

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

This comment should go on the else path and could be changed to "Mask out status bits (only check control and mask bits)"

Comment on lines 2395 to 2396
// On Ecore, status bits are set by default (for performance)
orl(tmp, 0x003f); // On Ecore, exception bits are set by default
Copy link

Choose a reason for hiding this comment

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

Duplication in comment. Comment could be modified to reflect something like "The mxcsr_std has status bits set for performance on ECore"

//
jint MxCsr = INITIAL_MXCSR; // set to 0x1f80` in winnt.h
if (EnableX86ECoreOpts) {
// On ECore, restore with signaling flags enabled
Copy link

Choose a reason for hiding this comment

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

Change comment to // On ECore restore with status bits enabled.

Copy link

@sviswa7 sviswa7 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 to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 11, 2025
@vpaprotsk
Copy link
Contributor Author

vpaprotsk commented Feb 12, 2025

(deleted integrate command)

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Feb 12, 2025
@openjdk
Copy link

openjdk bot commented Feb 12, 2025

@vpaprotsk
Your change (at version b23764a) is now ready to be sponsored by a Committer.

}

#if defined(_M_AMD64)
extern bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems strange to declare inside another method like this, not a showstopper but it might be better to declare it where handle_FLT_exception used to be defined in this file

Copy link
Contributor Author

@vpaprotsk vpaprotsk Feb 12, 2025

Choose a reason for hiding this comment

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

Oh.. I remember wondering where to put this. Meant to come back and find the right header.

I couldn't find the right header 'easily' and leaving it where the old function was looked even more out of place (i.e. "things like this belong in headers"?). So this was my alternative...

Copy link
Contributor

@TheShermanTanker TheShermanTanker 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 otherwise

Co-authored-by: Julian Waters <32636402+TheShermanTanker@users.noreply.github.com>
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Feb 12, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 12, 2025
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.

I submitted our internal testing. Please wait results.

@vpaprotsk
Copy link
Contributor Author

I submitted our internal testing. Please wait results.

Thanks! Deleted the integrate command

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 tier1-4, stress, xcomp testing passed.

@vpaprotsk
Copy link
Contributor Author

Thanks!

/integrate

@openjdk openjdk bot added ready Pull request is ready to be integrated sponsor Pull request is ready to be sponsored labels Feb 12, 2025
@openjdk
Copy link

openjdk bot commented Feb 12, 2025

@vpaprotsk
Your change (at version cbd3812) is now ready to be sponsored by a Committer.

@sviswa7
Copy link

sviswa7 commented Feb 12, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Feb 12, 2025

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

  • b8576eb: 6562489: Font-Renderer should ignore invisible characters \u2062 and \u2063
  • 7a0832f: 8349934: Wrong file regex for copyright header format check in .jcheck/conf
  • 2a5d1da: 8349571: Remove JavaThreadFactory interface from SA
  • 74e458b: 8349684: Remove SA core file tests from problem list for macosx-x64
  • ba28119: 8348427: DeferredLintHandler API should use JCTree instead of DiagnosticPosition
  • c5ac3c4: 8249831: Test sun/security/mscapi/nonUniqueAliases/NonUniqueAliases.java is marked with @ignore
  • 336d0d8: 8349926: [BACKOUT] Support static JDK in libfontmanager/freetypeScaler.c
  • 4b463ee: 8342103: C2 compiler support for Float16 type and associated scalar operations
  • 332d87c: 8349859: Support static JDK in libfontmanager/freetypeScaler.c
  • 73e1780: 8349836: G1: Improve group prediction log message
  • ... and 696 more: https://git.openjdk.org/jdk/compare/d6b5264c3f7d0c4157ebd73b2f1a98dd15273c61...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 12, 2025
@openjdk openjdk bot closed this Feb 12, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Feb 12, 2025
@openjdk
Copy link

openjdk bot commented Feb 12, 2025

@sviswa7 @vpaprotsk Pushed as commit 55097dd.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants