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

Invalid Optimization of switch statement

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_2.5, solaris_2.5.1, windows_nt
    • Verification:
      Not verified

      Description



      Name: dgC58589 Date: 12/17/97


      The following code works great when you use
      javac, but produces unexpected results when using
      javac -O

      class Test
      {
          public static void main (String argc[])
          {
              System.out.println ("test (0) = " + test (0));
              System.out.println ("test (1) = " + test (1));
              System.out.println ("test (0) = " + test (0));
              System.out.println ("test (1) = " + test (1));
          }

          private static String test (int i)
          {
              switch (i) {
              case 0:
                  return ("found 0");
              case 1:
                  return ("found 1");
              }
              return ("Error");
          }
      }

      More specifically...

      >> javac Test.java
      >> java Test

      test (0) = found 0
      test (1) = found 1
      test (0) = found 0
      test (1) = found 1

      Okay all is well, but then we try it with
      optimizations.

      >> javac -O Test.java
      >> java Test

      test (0) = Error
      test (1) = found 0
      test (0) = found 0
      test (1) = found 0

      Hmm, that doesn't look right.
      Notice there is two problems.
      The first result is wrong and
      all of the rest return 0 which is the first case.

      So we have three out of four incorrect.

      Note: The results don't change if you return int
      or anything else. It seems to have something to
      do with argument passing and the stack.

      -Paul Hill, ###@###.###
      -Wade Rees, ###@###.###

      (Review ID: 22047)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dstoutamsunw David Stoutamire (Inactive)
                Reporter:
                dgrahamcsunw David Graham-cumming (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: