-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8261397: Try Catch Method Failing to Work When Dividing An Integer By 0 #2615
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
Conversation
👋 Welcome back gziemski! A progress list of the required criteria for merging this PR into |
@gerard-ziemski The following label will be automatically applied to this pull request:
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. |
Webrevs
|
Simple native test case for those curious to try it out for themselves: /*
Natively on x86_64 we get:
sigHandler caught sig: 8, info->si_code: 7 [FPE_INTDIV]
Under Rossetta on M1 for x86_64 binary we get:
sigHandler caught sig: 8, info->si_code: 5 [FPE_FLTINV]
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
static void sigHandler(int sig, siginfo_t* info, void* arg) {
printf("sigHandler caught sig: %d, info->si_code: %d [", sig, info->si_code);
switch (info->si_code) {
case FPE_FLTDIV: printf("FPE_FLTDIV");break;
case FPE_INTDIV: printf("FPE_INTDIV");break;
case FPE_FLTINV: printf("FPE_FLTINV");break;
default: printf("???");
}
printf("]\n");
exit(sig);
}
int main(int argc, const char * argv[]) {
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = sigHandler;
sa.sa_flags = SA_SIGINFO|SA_RESETHAND;
sigaction(SIGFPE, &sa, NULL);
volatile int i = 0;
volatile int j = 47 / i;
return j;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. Remark below. Looks good otherwise.
Cheers, Thomas
@gerard-ziemski 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:
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 1008 new commits pushed to the
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me. I suppose there is a BSD unix port that uses this code hence the MACOS_ONLY ?
Exactly, any BSD platform uses this implementation. macOS is just one of them. Thanks Phil! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thumbs up. Nice job on keeping the work around very focused.
Thank you Dan! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Gerard,
I'm concerned by the general problem of encountering new bugs because we are running on an x64 emulation mode on ARM! Is there any way to detect this Rosetta environment? Is there a way to know from the hs_err file (we don't have one for this issue yet) that we executed under Rosetta?
How will we track this bug on Apple's side, such that we can eventually remove this workaround?
The workaround itself seems okay as far as it goes but what happens if native code triggers a real FPE_FLTINV that we will now treat as "div by zero"?
Thanks,
David
We can detect if we are running under emulation using this code provided by Apple https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment
One can infer such scenario by looking at the log under the system section:
We see RELEASE_ARM64_T8101 type kernel running x86_64 code, but we should detect this and report it to users directly. Filed a followup issue JDK-8261966 to track it. Thank you for the bringing this point up!
I have filed the issue a while ago with Apple here https://feedbackassistant.apple.com/feedback/8984455, but please note that you probably need Mac developer account to be able to see it. Apple has set the resolution of this issue as
Excellent question. According to https://en.wikipedia.org/wiki/IEEE_754 invalid operation is Regardless though, we absolutely need this workaround for the time being, though we might want to use only in emulation environment. |
According to the man pages for
and the man pages for
but what I see in our signal handler is a signal of type I can't seem to be able to get |
Mailing list message from David Holmes on hotspot-runtime-dev: Hi Gerard, On 19/02/2021 5:02 am, Gerard Ziemski wrote:
Thanks for the further investigation here. Possibly more bugs in FP handling. :( Though I'm unclear how to actually trigger SIGFPE in these cases - don't double d = ::sqrt(-1.0); and it just prints "-nan" with no signal generated.
Ok, but I think we should fix JDK-8261966 and include Thanks, |
I added the check in this fix - I don't think we should get this issue blocked by JDK-8261966 For JDK-8261966 we can further optimize the check to cache the results, if needed, and we can have a non rushed discussion on how exactly we want the API named (ex. I would prefer to follow Apple's usage and name it is_process_translated()) and how exactly we want it to look in the hs_err log files. cheers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Gerard,
The new VM_Version check should be in vm_version_bsd_x86.cpp so that we don't need to ifdef the code in the generic x86 file.
I don't think we need make is_cpu_emulated available on all platforms, jusyt bsd-x86.
Thanks,
David
I did not realize that there was Fixed. |
Hmm, I still think we need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Gerard,
Thanks for making the changes. I had hoped to completely isolate this to BSD/x86 (with Apple ifdefs) but it seems we are a bit inconsistent in platform management with VM_version code: we have os_cpu .cpp files but only cpu header files! Can't quite see the logic in that. :)
David
/integrate |
@gerard-ziemski Since your change was applied there have been 1022 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 0257caa. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
@VladimirKempik Unknown command |
On Mac ARM hardware running x86 JDK under Rosetta emulation, a div by 0 instruction causes the VM to crash.
The proposed fix (a workaround) for hotspot is to add FPE_FLTINV to the signal handler.
The actual fix needs to be done in macOS by Apple as the expected signal type here is FPE_FLTDIV
This issue has been filed with Apple and they are tracking it.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2615/head:pull/2615
$ git checkout pull/2615