Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186112

Using G1 Garbage Collector causes in use variable to be cleared

XMLWordPrintable

    • x86_64
    • windows

      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

            fmatte Fairoz Matte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: