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

"-server" mode optimizer makes code hang

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 6u23
    • hotspot
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.6.0_23"
      Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]
      Linux localhost 2.6.36-gentoo-r5 #3 SMP PREEMPT Tue Dec 21 18:22:19 MSK 2010 x86_64 Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz GenuineIntel GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Sometimes the loop conditions are substituted the wrong way during the optimization, causing the code to malfunction.

      In the example included, the code should always terminate in finite time:
                  short value = 0;
                  do {
                      sum += Integer.bitCount(value);
                  } while (++value != 0);
      However, the loop condition seem to be substituted by "true", so the loop becomes infinite.

      This affects server versions of 32-bit and 64-bit JVMs of at least releases 1.6.0_23 under Windows and 1.6.0_24 under Linux.

      In Linux (java 1.6.0_24), the java process takes both (all?) available CPU cores and can be killed only by signal 9.
      In Windows (java 1.6.0_23), the process takes only one CPU core and can be killed from task manager.

      The client version of 32-bit JVM runs normally.
      java -Xint runs normally (but very slow).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the included source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program outputs the lines like the following and stops:
      1: 512
      2: 519
      3: 522
      4: 517
      doNotOptimizeOut value: -100663296

      ACTUAL -
      The program outputs the following lines and hangs:
      1: 363
      2: 348


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class OptimizerBug {
          private static final int ITERATIONS = 1000;
          private static int doNotOptimizeOut = 0;

          public static long bitCountShort() {
              long t0 = System.currentTimeMillis();
              int sum = 0;
              for (int it = 0; it < ITERATIONS; ++it) {
                  short value = 0;
                  do {
                      sum += Integer.bitCount(value);
                  } while (++value != 0);
              }
              doNotOptimizeOut += sum;
              return System.currentTimeMillis() - t0;
          }

          public static void main(String[] args) {
              for (int i = 0; i < 4; ++i) {
                  System.out.println((i + 1) + ": " + bitCountShort());
              }
              System.out.println("doNotOptimizeOut value: " + doNotOptimizeOut);
          }
      }

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

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: