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

COMPARISON WITH INTEGER.MAX_INT DOES NOT WORK CORRECTLY IN THE CLIENT VM

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 6u21
    • Fix Version/s: None
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      If you run the following example on Linux and compare the
      Client VM versus the Server VM, you will notice that the with the client VM,
      the testcase does not terminate :

      public class Hailstone {

              public static void main(String[] args) {
              // System.out.println(827370449 * 3 + 1);
                      long start = System.currentTimeMillis();
                      int min = 2;
                      int max = Integer.MAX_VALUE;
                      System.out.println("maxMove:" + maxMoves(min, max));
                                      
                      System.out.println("time difference: " +
      (System.currentTimeMillis() - start));
                      
              }
              /**
               * Imperative implementation that returns the length hailstone moves
      for a given number.
               */
              public static long hailstoneLengthImp(long n) {
                      long moves = 0;
                      while (n != 1) {
                              assert n > 1;
                              if (isEven(n)) {
                                      n = n / 2;
                              } else {
                                      n = 3 * n + 1;
                              }
                              ++moves;
                      }
                      return moves;
              }

              private static boolean isEven(long n) {
                      return n % 2 == 0;
              }

              /**
               * Returns the maximum length of the hailstone sequence for numbers
               * between min to max.
               *
               * For rec1 - Assume that min is bigger than max.
               */
              public static long maxMoves(int min, int max) {
                      long maxmoves = 0;
                      for (int n = min; n <= max; n++) {
                              System.out.println(n);
                              long moves = hailstoneLengthImp(n);
                              if (moves > maxmoves) {
                                      maxmoves = moves;
                              }
                      }
                      return maxmoves;
              }
      }

      % java -client -version
      java version "1.6.0_21-ea"
      Java(TM) SE Runtime Environment (build 1.6.0_21-ea-b05)
      Java HotSpot(TM) Client VM (build 17.0-b15, mixed mode)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kevinw Kevin Walls
                Reporter:
                mbykov Misha Bykov
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: