JDK-8186112 : Using G1 Garbage Collector causes in use variable to be cleared
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows
  • CPU: x86_64
  • Submitted: 2017-08-10
  • Updated: 2017-08-17
  • Resolved: 2017-08-17
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

FULL OS VERSION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Running the attached code with the -XX:+UseG1GC flag causes a double that is in scope and declared as final to be changed from a value of 20 to a value of 0. It is cleared during a loop that is writing to an array of enums. 

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached source and run it with the -XX:+UseG1GC flag

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected Result: "Incrementing Cell Size 21.0" is printed to the console.
Actual Result: "Now it's broken. Iteration: ######" is repeatedly printed to the console after the variable values changes to 0 in the loop.
REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/**
 * @author bkirst
 *
 */

public class BugTest
{
  public enum EnumUTMHemisphere
  {
    N, S;

    public String value()
    {
      return name();
    }

    public static EnumUTMHemisphere fromValue(String v)
    {
      return valueOf(v);
    }
  }

  /**
   * @param args
   */
  public static void main(String[] args)
  {
    fillArray(20);
  }

  public static void fillArray(double cellSize)
  {
    final double cellSize_m = cellSize;
    EnumUTMHemisphere hemisphere = EnumUTMHemisphere.N;
    EnumUTMHemisphere[] hemispheres = new EnumUTMHemisphere[565504];

    for (int i = 0; i < 565504; i++)
    {
      hemispheres[i] = hemisphere;
      if (cellSize_m == 0)
      {
        System.out.println("Now it's broken. Iteration: " + i + " " + cellSize_m);
      }
    }
    System.out.println("Incrementing Cell Size " + (cellSize_m + 1));
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use the G1 Garbage Collector, or use the -Xint flag 


Comments
Thanks, Fairoz. I agree, please close it as duplicate then.
17-08-2017

Thanks Tobias, below are the results 9 ea b113 - Fail 9 ea b114 - Pass //Issue fixed here 9 ea b181 - Pass I guess it is duplicate of JDK-8148175: "C1: G1 barriers don't preserve FP registers" which got fixed in 9 ea b114 and backport created for 8u152 (In Open state)
16-08-2017

[~fmatte], if it does not reproduce without Tiered Compilation (i.e., with C2 only) this is a hint that it's a C1 issue. I verified that this is a C1 issue by reproducing with -XX:TieredStopAtLevel=1. Please also check when this stops to reproduce with JDK 9. Maybe we missed to backport something. I'm adding the "sustaining" label because as of now it seems like this does not affect JDK 9.
15-08-2017

-XX:-TieredCompilation could not reproduce this issue. C2 is causing this issue.
11-08-2017

This is a serious issue, G1GC is allowing final to be changed from a value of 20 to a value of 0 Only reproducible on jdk8 on windows (Verified with windows7 and windows 2012) 9 ea b181 - Pass 8u152 b09 - Fail 8u144 - Fail
11-08-2017