corretto/corretto-11

Divide by zero crash

franciem-c opened this issue · 3 comments

Thank you for taking the time to help improve OpenJDK and Corretto 11.

If your request concerns a security vulnerability then please report it by email to aws-security@amazon.com instead of here.
(You can find more information regarding security issues at https://aws.amazon.com/security/vulnerability-reporting/.)

Otherwise, if your issue concerns OpenJDK 11 and is not specific to Corretto 11 we ask that you raise it to the OpenJDK community. Depending on your contributor status for OpenJDK, please use the JDK bug system or
the appropriate mailing list for the given problem area or update project.

If your issue is specific to Corretto 11, then you are in the right place. Please proceed with the following.

Describe the bug

Program crashes with the following error when dividing by zero:
/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=55606:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/fmc/Documents/Exceptions/out/production/Exceptions com.company.Main
0

A fatal error has been detected by the Java Runtime Environment:

SIGFPE (0x8) at pc=0x000000011a08b548, pid=74187, tid=8451

JRE version: OpenJDK Runtime Environment Corretto-11.0.10.9.1 (11.0.10+9) (build 11.0.10+9-LTS)

Java VM: OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (11.0.10+9-LTS, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)

Problematic frame:

j com.company.Main.divideWithException(II)I+0

No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

An error report file with more information is saved as:

/Users/fmc/Documents//Exceptions/hs_err_pid74187.log

Could not load hsdis-amd64.dylib; library not loadable; PrintAssembly is disabled

If you would like to submit a bug report, please visit:

https://github.com/corretto/corretto-11/issues/

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

To Reproduce

public class Main {

public static void main(String[] args) {
    int x = 98;
    int y = 0;
    System.out.println(divideWithoutException(x, y));
    System.out.println(divideWithException(x, y));
}

private static int divideWithoutException(int x, int y) {
    if(y != 0) {
        return x / y;
    } else {
        return 0;
    }
}

private static int divideWithException(int x, int y) {
    try {
        return x / y;
    } catch(ArithmeticException e) {
        return 0;
    }
}

}

Expected behavior

I expected an exception to be thrown instead of crash.

Screenshots

Platform information

OS: Mac
Version: build 11.0.10+9-LTS

Additional context

Using IntelliJ IDE 2020.3.2.

Found this issue on the Oracle website: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8229496

For VM crashes, please attach the error report file. By default the file name is hs_err_pidpid.log, where pid is the process ID of the process.

hs_err_pid74187.log

Hi, thanks for contacting us about this issue.

I've attempted to reproduce the issue with your provided code in the following environment:

openjdk version "11.0.10" 2021-01-19 LTS
OpenJDK Runtime Environment Corretto-11.0.10.9.1 (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (build 11.0.10+9-LTS, mixed mode)

Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

This produces the following output when run with
javac Main.java && java Main:

0
0

If I add a simple line to print any caught exceptions in divideWithException I see

Caught exception: java.lang.ArithmeticException: / by zero

which I believe to be the expected behavior.

I see in the end of your provided hs_err_pid.log (thank you for including this!) the following:

OS:uname:Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 x86_64

Based on this, it appears you're running an x86_64 build of Corretto 11 with Rosetta 2 on an M1 (ARM64/aarch64) Mac running Big Sur - is this accurate?
If so, Corretto support for M1 hardware is not available yet.
See the related issues #165 and #175.
You could consider filing this as a bug against Rosetta 2 / Apple, since the code appears to work as expected on x86_64.

Yes, M1 Mac running Big Sur. Thanks for your quick response. This seems to be the only problem I have had so far with the VM crashing on the M1. Do you know when Corretto will have support for the M1?

Support for apple M1 in openjdk is being actively worked on. Corretto specific support can be tracked in the 2 issues mentioned above, but we don't have any timelines to share at this time.