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

javac produces the inconsistent variable debug in while loops.

    XMLWordPrintable

Details

    • mantis
    • sparc
    • solaris_7

    Description



      Name: md23716 Date: 04/20/2001

      1.3.0 HotSpot JDK. This bug is related to 4349534 & 4123204.
      Testcase declares local variables outside of a loop, but initializes
      them inside:
      /* 01 */ public class DebugLoop
      /* 02 */ {
      /* 03 */ public static void main(String[] args)
      /* 04 */ {
      /* 05 */ int i = 4, j, k;
      /* 06 */
      /* 07 */ while ((j = i) > 0)
      /* 08 */ {
      /* 09 */ k = j; i = k - 1;
      /* 10 */ }
      /* 11 */ }
      /* 12 */ }
      The 1.3.0 version of "javac" produces the following bytecode and debug
      information:
      Method void main(java.lang.String[])
      0 iconst_4
      1 istore_1
      2 goto 11
      5 iload_2 <--- loop body
      6 istore_3
      7 iload_3
      8 iconst_1
      9 isub
      10 istore_1
      11 iload_1 <--- loop condition
      12 dup
      13 istore_2
      14 ifgt 5
      17 return
      Line numbers for method void main(java.lang.String[])
      line 5: 0
      line 7: 2
      line 9: 5
      line 7: 11
      line 11: 17
      Local variables for method void main(java.lang.String[])
      java.lang.String[] args pc=0, length=18, slot=0
      int i pc=2, length=15, slot=1
      int j pc=14, length=3, slot=2
      int k pc=7, length=10, slot=3
      The "javac" compiler generates bytecode for the body of a loop before its
      condition. A goto is used to enter the loop condition for the first time.
      The local variable "j" is only marked as being valid from PC 14 to PC17.
      This means that a debugger cannot see "j" when it's inside the loop body.
      It only becomes visible when the debugger enters the loop condition.
      This will confuse users when they try to debug loops in their
      applications.

      Also the 1.3.0 version of "javac" only allows one entry per local
      variable.
      This causes problems if the range of a local variable has a
      discontinuity.

      Documentation of how root cause of failure was determined
      Used "javap" to examine local variable tables produced by various
      compilers.
      The 1.1.8 and 1.2.2 versions of "javac" have two entries for "j":
      Local variables for method void main(java.lang.String[])
      java.lang.String[] args pc=0, length=18, slot=0
      int i pc=2, length=16, slot=1
      int j pc=5, length=6, slot=2
      int k pc=7, length=4, slot=3
      int j pc=14, length=4, slot=2
      Using this table, "j" can be viewed from inside the loop by a
      debugger.


      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              gafter Neal Gafter
              mdevereuorcl Michelle Devereux (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: