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

javac emits duplicate checkcast when calling Array.newInstance(Class, int) etc

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 11
    • tools
    • None

      Something like this:

      String[] foo = (String[]) java.lang.reflect.Array.newInstance(String[].class.getComponentType(), 1);

      ... is emitted by javac as:

              11: iconst_1
              12: invokestatic #8 // Method java/lang/reflect/Array.newInstance:(Ljava/lang/Class;I)Ljava/lang/Object;
              15: checkcast #6 // class "[Ljava/lang/String;"
              18: checkcast #6 // class "[Ljava/lang/String;"
              21: astore_1

      I expect to see only one checkcast here.

      Related(?) issue in java.util.Arrays.deepHashCode, where something like

                  if (element instanceof Object[])
                      elementHash = deepHashCode((Object[]) element);

      appears to be translated to:

              33: instanceof #54 // class "[Ljava/lang/Object;"
              36: ifeq 55
              39: aload 5
              41: checkcast #54 // class "[Ljava/lang/Object;"
              44: checkcast #54 // class "[Ljava/lang/Object;"
              47: invokestatic #106 // Method deepHashCode:([Ljava/lang/Object;)I
              50: istore 6
              52: goto 259

      Duplicate checkcast, and perhaps these are both unnecessary due the preceding instanceof

            sadayapalam Srikanth Adayapalam (Inactive)
            redestad Claes Redestad
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: