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

Uninitialized register when performing casting + auto(un)boxing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 7
    • 6u12
    • tools
    • b55
    • x86
    • linux
    • Verified

    Description

      FULL PRODUCT VERSION :
      javac 1.6.0_11
      javac 1.6.0_12

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Wersja 6.0.6001] - Microsoft Vista,
      Linux 32-bit

      A DESCRIPTION OF THE PROBLEM :
      Compilation of the attached test case results in a java.lang.VerifyError. This is due to a bad compilation of the class (see expected and actual results).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the attached test case. Run the test case. Observe the error. Decompile the .class file to get the bad bytecode.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected bytecode:

      > javap -c test.Test

      Compiled from "Test.java"
      public class test.Test extends java.lang.Object{
      public test.Test();
        Code:
         0: aload_0
         1: invokespecial #8; //Method java/lang/Object."<init>":()V
         4: return

      public static void main(java.lang.String[]);
        Code:
         0: iconst_0
         1: istore_2
         2: iconst_0
         3: invokestatic #16; //Method java/lang/Byte.valueOf:(B)Ljava/lang/Byte;
         6: astore_1
         7: return

      }

      0 is assigned to 'fi' (lines 0-1 of main()) but later a constant 0 is used for assignment to 'B' (by means of Byte.valueOf() method) as 'fi' is a compile-time constant and should be inlined.
      ACTUAL -
      Actual bytecode:

      > javap -c test.Test

      Compiled from "Test.java"
      public class test.Test extends java.lang.Object{
      public test.Test();
        Code:
         0: aload_0
         1: invokespecial #1; //Method java/lang/Object."<init>":()V
         4: return

      public static void main(java.lang.String[]);
        Code:
         0: iload_2
         1: i2b
         2: invokestatic #2; //Method java/lang/Byte.valueOf:(B)Ljava/lang/Byte;
         5: astore_1
         6: return

      }

      in line 0 of the main() method the code tries lo load a local integer variable #2 ('fi'). But there is no initialisation of that variable. The whole main() method is reduced to the 'B=fi;' assignment, but neither the constant 0 value is used nor is 'fi' initialised with 0 previously.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      > java test.Test

      Exception in thread "main" java.lang.VerifyError: (class: test/Test, method: main signature: ([Ljava/lang/String;)V) Accessing value from uninitialized register 2
      Could not find the main class: test.Test. Program will exit.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;
       
      public class Test {
       
      public static void main(String[] args) {
      Byte B;
      final int fi = 0;
      B = fi; // narrowing pri. (int -> byte) + boxing (byte -> Byte)
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Assignment in two steps solves the case.

      class Test {
       public static void main(String[] args) {
        final int fi = 0;
        byte b = fi; // int -> byte
        Byte B = b; // byte -> Byte
       }
      }

      Attachments

        Activity

          People

            mcimadamore Maurizio Cimadamore
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: