Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JRE fatal error: too many multiplications

Tags:

java

I was trying to test speed of Math.pow() against multiplication "by hand" and stumbled upon this error:

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

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005ac46888, pid=1508, tid=6016

JRE version: Java(TM) SE Runtime Environment (8.0_25-b18) (build 1.8.0_25-b18)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode windows-amd64 compressed oops)
Problematic frame:
V [jvm.dll+0x496888]

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

Code generating it:

long t = System.nanoTime();
for (int i = 0; i < 10000000; i++) {
    double val = i*i*i*i*i /* 256 times *i */ *i*i*i;
    sum ^= Double.doubleToLongBits(val);
}
System.out.println((System.nanoTime() - t) / 10000000);

I get that this is really extreme case, but still, this is valid code and the worst thing that could happen should be having Inf in the value, and not JRE crash. Is this really standard behaviour described by oracle or just bug nobody wants to fix just because if you are seeing it, you are really bad person.

For the record run with NetBeans 8.0.2

UPDATE 1

It seems problem is in magnitude of multiplied number.

long t = System.nanoTime();
for(int j = 0; j < 10000000; j++) {
    int i = j % 50;
    double val = i*i*i*i*i /* 256 times *i */ *i*i*i;
    sum ^= Double.doubleToLongBits(val);
}
System.out.println((System.nanoTime() - t) / 10000000);

will pass just fine.

UPDATE 2

Tried to run it from console with

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

and passed just fine, so I assume it must be either issue with this specific JRE or with NetBeans.

like image 830
Vojtěch Kaiser Avatar asked Aug 06 '15 21:08

Vojtěch Kaiser


1 Answers

This definitely looks like a JVM bug to me. This is more suitable as a bug report than a question on SO. See http://bugreport.java.com/

like image 127
emu Avatar answered Oct 19 '22 00:10

emu