JDK-8186122 : Turning on G1GC inconsistently triggers strange JIT compilation which causes undesired results
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows
  • CPU: generic
  • Submitted: 2017-08-11
  • Updated: 2017-08-11
  • Resolved: 2017-08-11
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Java 8 update 144

ADDITIONAL OS VERSION INFORMATION :
Windows 7
Windows 10

A DESCRIPTION OF THE PROBLEM :
The bug is inconsistent - usually takes 3-8 launches before bug occurs.

The bug only occurs when using the -XX+UseG1GC vm argument.

The bug doen't occur when using both -XX:+UseG1GC and -Xcomp

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Launch the program in the "Source code" section until the bug reveals itself.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"This should not print" should not print to the console, since cellSize_m is final and initially set to 20 via parameter value, not the value 0. If it does print, "Incrementing cellSize_m" should print 1 to reflect consistency with a final primitive variable across scopes.
ACTUAL -
"This should not print" prints to the console, while "Incrementing cellSize_m" shows the value 21

REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
class BugDemo {
    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("This should not print. [Iteration: " + i + "] [cellSize_m: " + cellSize_m+"]);
            }
        }
        System.out.println("Incrementing cellSize_m: " + (cellSize_m + 1));
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Ensure methods are compiled on first execution via the -Xcomp vm argument.

SUPPORT :
YES


Comments
Duplicate report of JDK-8186112
11-08-2017