groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7542) CompileStatic class generation bug "register with message: rightShiftUnsigned and arguments X"
Date Sun, 16 Aug 2015 13:00:46 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14698650#comment-14698650
] 

ASF GitHub Bot commented on GROOVY-7542:
----------------------------------------

GitHub user antoaravinth opened a pull request:

    https://github.com/apache/incubator-groovy/pull/85

    Fix for the issue GROOVY-7542

    Hi @melix,
     
         I guess I have understood the problem. Looks like there is no method to handle `rightShiftUnsigned`
operation. Actually there is no method for `leftShift` as well; After this fix, I have tested
the code with and without `@CompileStatic`. Then did `groovyc`, could able to see the the
difference in the generated byte code. 
    
    Sample I have used, same as given in the exception:
    
    ```
    import groovy.transform.CompileStatic 
    
    test()
    
    @CompileStatic
    def test() {
      long register = 0xfac432b10cd5e44aL  
      
      [1,2,3].each { int element -> 
        int t = (int) (register >>> 56 ^ (long) element) & 0xff
        println t
      }  
    }
    ```
    
    doing `javap` on the compiled groovy class, I could able to get 
    
    ```
      public java.lang.Object test();
        Code:
           0: getstatic     #59                 // Field $const$0:J
           3: invokestatic  #65                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
           6: new           #67                 // class groovy/lang/Reference
           9: dup_x1        
          10: swap          
          11: invokespecial #70                 // Method groovy/lang/Reference."<init>":(Ljava/lang/Object;)V
          14: astore_1      
          15: aload_1       
          16: pop           
          17: iconst_3      
          18: anewarray     #72                 // class java/lang/Object
          21: dup           
          22: iconst_0      
          23: iconst_1      
          24: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          27: aastore       
          28: dup           
          29: iconst_1      
          30: iconst_2      
          31: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          34: aastore       
          35: dup           
          36: iconst_2      
          37: iconst_3      
          38: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          41: aastore       
          42: invokestatic  #83                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.createList:([Ljava/lang/Object;)Ljava/util/List;
          45: new           #85                 // class "GROOVY-7542$_test_closure1"
          48: dup           
          49: aload_0       
          50: aload_0       
          51: aload_1       
          52: invokespecial #88                 // Method "GROOVY-7542$_test_closure1"."<init>":(Ljava/lang/Object;Ljava/lang/Object;Lgroovy/lang/Reference;)V
          55: invokestatic  #94                 // Method org/codehaus/groovy/runtime/DefaultGroovyMethods.each:(Ljava/util/List;Lgroovy/lang/Closure;)Ljava/util/List;
          58: areturn       
          59: aconst_null   
          60: areturn      
    ```
    
    (only for `test` method)
    
    where as removing the `@CompileStatic` does gives the following bytecode:
    
    ```
    public java.lang.Object test();
        Code:
           0: invokestatic  #19                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
           3: astore_1      
           4: getstatic     #59                 // Field $const$0:J
           7: invokestatic  #65                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
          10: new           #67                 // class groovy/lang/Reference
          13: dup_x1        
          14: swap          
          15: invokespecial #70                 // Method groovy/lang/Reference."<init>":(Ljava/lang/Object;)V
          18: astore_2      
          19: aload_2       
          20: pop           
          21: aload_1       
          22: ldc           #71                 // int 2
          24: aaload        
          25: iconst_3      
          26: anewarray     #73                 // class java/lang/Object
          29: dup           
          30: iconst_0      
          31: iconst_1      
          32: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          35: aastore       
          36: dup           
          37: iconst_1      
          38: iconst_2      
          39: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          42: aastore       
          43: dup           
          44: iconst_2      
          45: iconst_3      
          46: invokestatic  #78                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          49: aastore       
          50: invokestatic  #84                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.createList:([Ljava/lang/Object;)Ljava/util/List;
          53: new           #86                 // class "GROOVY-7542$_test_closure1"
          56: dup           
          57: aload_0       
          58: aload_0       
          59: aload_2       
          60: invokespecial #89                 // Method "GROOVY-7542$_test_closure1"."<init>":(Ljava/lang/Object;Ljava/lang/Object;Lgroovy/lang/Reference;)V
          63: invokeinterface #92,  3           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
          68: areturn       
          69: aconst_null   
          70: areturn       
    ```
    
    I guess I'm in right path; I'm no-where an byte code engineer, so in case if I have missed
any of the cases, let me know. 
    
    So that I can write some generic method for handling the bit-wise operator on the compile
static mode!
    
    Thanks for your response. 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/antoaravinth/incubator-groovy GROOVY-7542

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-groovy/pull/85.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #85
    
----
commit 85904b51e21eb964ac0c3f22ac3dc3ad057d4440
Author: antoaravinth <anto.aravinth.cse@gmail.com>
Date:   2015-08-16T12:54:47Z

    GROOVY-7542: CompileStatic class generation bug 'register with message: rightShiftUnsigned
and arguments X'

----


> CompileStatic class generation bug "register with message: rightShiftUnsigned and arguments
X"
> ----------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7542
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7542
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.4
>         Environment: Groovy Version: 2.4.4 JVM: 1.7.0_55 Vendor: Oracle Corporation OS:
Linux
>            Reporter: Matias Bjarland
>
> Error caused by the following code snippet (was in the process of coding a crc64 algorithm):

> {code:language=groovy}
> import groovy.transform.CompileStatic 
> test()
> @CompileStatic
> def test() {
>   long register = 0xfac432b10cd5e44aL  
>   
>   [1,2,3].each { int element -> 
>     int t = (int) (register >>> 56 ^ (long) element) & 0xff
>   }  
> }
> {code}
> execution example: 
> {code}
> $ groovy test.groovy 
> Caught: BUG! exception in phase 'class generation' in source unit '/home/mbjarland/test.groovy'
At line 11 column 20
> On receiver: register with message: rightShiftUnsigned and arguments: 56
> This method should not have been called. Please try to create a simple example reproducing
this error and filea bug report at https://issues.apache.org/jira/browse/GROOVY
> BUG! exception in phase 'class generation' in source unit '/home/mbjarland/projects/kohler.project/projects/full-publish/test.groovy'
At line 11 column 20
> On receiver: register with message: rightShiftUnsigned and arguments: 56
> This method should not have been called. Please try to create a simple example reproducing
this error and filea bug report at https://issues.apache.org/jira/browse/GROOVY
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message