Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11288

Unnecessary bytecode generated after variable assignment

    XMLWordPrintableJSON

Details

    Description

      I have the following code:

      package org.example
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      final class Main {
          static void main(String[] args) {
              int three = 3
              String str = 'foo'
          }
      }
      

      When looking at the compiled output, the variable is loaded and immediately popped after storing:

      // access flags 0x89
      public static varargs main([Ljava/lang/String;)V
       L0
        LINENUMBER 8 L0
        ICONST_3
        ISTORE 1
       L1
        ILOAD 1
        POP
       L2
        LINENUMBER 9 L2
        LDC "foo"
        ASTORE 2
       L3
        ALOAD 2
        POP
       L4
        LINENUMBER 10 L4
        RETURN
        LOCALVARIABLE args [Ljava/lang/String; L0 L4 0
        LOCALVARIABLE three I L1 L4 1
        LOCALVARIABLE str Ljava/lang/String; L3 L4 2
        MAXSTACK = 1
        MAXLOCALS = 3
      

      This issue also occurs in dynamic compilation mode.

      Attachments

        Activity

          People

            emilles Eric Milles
            paint_ninja Oscar N
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: