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

Extra checkcast instruction in compiled code with "Pattern Matching" feature

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, openjdk-14-ea+30_windows-x64

      A DESCRIPTION OF THE PROBLEM :
      Source code:

      void m(Object obj) {
          if (obj instanceof String s) {
              s.hashCode();
          }
      }

      Emitted code:

        void m(java.lang.Object);
          Code:
             0: aload_1
             1: astore_3
             2: aload_3
             3: instanceof #7 // class java/lang/String
             6: ifeq 27
             9: aload_3
            10: checkcast #7 // class java/lang/String
            13: dup
            14: astore_2
            15: aload_3
            16: checkcast #7 // class java/lang/String
            19: if_acmpne 27
            22: aload_2
            23: invokevirtual #9 // Method java/lang/String.hashCode:()I
            26: pop
            27: return

      For me it looks like instructions 9-19 produce code:

      if ((String)obj == (String)obj) {...}

      which seems pointless.


      FREQUENCY : always


            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: