Reputation: 184
If I run the following code with the -XX:+UseG1GC flag, every couple of runs the cellSize_m variable will get set to 0 inside the loop and I'll get the "Now it's broken" printouts. What am I missing here?
public class BugTest
{
public static void main(String[] args)
{
fillArray(20);
}
public static void fillArray(double cellSize)
{
final double cellSize_m = cellSize;
Integer[] hemispheres = new Integer[565504];
for (int i = 0; i < 565504; i++)
{
hemispheres[i] = i;
if (cellSize_m == 0)
{
System.out.println("Now it's broken. Iteration: " + i + " " + cellSize_m);
}
}
System.out.println("Incrementing Cell Size " + (cellSize_m + 1));
}
}
I'm on windows 7 using 64bit Java 8 build 144.
Upvotes: 3
Views: 160
Reputation: 21
I have reported a similar bug JDK-8165766 last year, but it doesn't seem Oracle eager to fix this over optimization issue caused G1GC failed on floating point computation.
Upvotes: 1