groovy
  1. groovy
  2. GROOVY-5008

Integer optimization is not executed

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: primtive opts
    • Labels:
      None
    • Environment:
      Groovy version: 1.8.2, 1.9.0-2-SNAPSHOT
      JVM version: 1.7.0
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      Integer optimization is not executed because BytecodeInterface8.isOrigZ() which is for boolean optimization and always returns false is called instead of BytecodeInterface8.isOrigInt().

      Steps to confirm the problem:

      1. Save the following script as Test.groovy
        int fib(int n) {
            if (n < 2) return n
            return rcfib(n - 1) + rcfib(n - 2)
        }
        
      2. Compile Test.groovy using groovyc
        groovyc Test.groovy
      3. Disassemble the Test.class
        javap -c Test
      4. You can see BytecodeInterface8.isOrigZ is called
          public int fib(int);
            Code:
               0: invokestatic  #20                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
               3: astore_2      
               4: invokestatic  #66                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.isOrigZ:()Z
               7: ifeq          25
              10: getstatic     #68                 // Field __$stMC:Z
              13: ifne          25
              16: invokestatic  #71                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.disabledStandardMetaClass:()Z
              19: ifne          25
              :
              :
        
      1. patch
        0.7 kB
        Masato Nagai

        Activity

        Hide
        Masato Nagai added a comment -

        The above script is wrong. Use the following one instead.

        int fib(int n) {
            if (n < 2) return n
            return fib(n - 1) + fib(n - 2)
        }
        
        Show
        Masato Nagai added a comment - The above script is wrong. Use the following one instead. int fib( int n) { if (n < 2) return n return fib(n - 1) + fib(n - 2) }
        Hide
        blackdrag blackdrag added a comment -

        thanks for the patch, but I actually fixed this for the next version already a few days ago

        Show
        blackdrag blackdrag added a comment - thanks for the patch, but I actually fixed this for the next version already a few days ago
        Hide
        Masato Nagai added a comment -

        OK, I got it. So will the fix be commited to https://svn.codehaus.org/groovy/trunk/groovy/groovy-core later?

        Show
        Masato Nagai added a comment - OK, I got it. So will the fix be commited to https://svn.codehaus.org/groovy/trunk/groovy/groovy-core later?
        Hide
        blackdrag blackdrag added a comment -

        No, we are about to deprecate that repository for normal Groovy development. Please use git://git.codehaus.org/groovy-git.git (ano access), http://git.codehaus.org/gitweb.cgi?p=groovy-git.git for browsing, ssh://git@git.codehaus.org/groovy-git.git (for commit)... Soon we will also be able to answer to pull requests on github

        Show
        blackdrag blackdrag added a comment - No, we are about to deprecate that repository for normal Groovy development. Please use git://git.codehaus.org/groovy-git.git (ano access), http://git.codehaus.org/gitweb.cgi?p=groovy-git.git for browsing, ssh://git@git.codehaus.org/groovy-git.git (for commit)... Soon we will also be able to answer to pull requests on github

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Masato Nagai
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: