Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 385404 - [1.7][compiler] invokeExact is not translated correctly if the arguments is an array of Object
Summary: [1.7][compiler] invokeExact is not translated correctly if the arguments is a...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.8.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 09:05 EDT by Rémi Forax CLA
Modified: 2012-08-14 05:28 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (982 bytes, patch)
2012-07-18 12:20 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (2.18 KB, patch)
2012-07-18 12:20 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rémi Forax CLA 2012-07-18 09:05:26 EDT
Build Identifier: I20120608-1400

Eclipse compiler fails to implement the JLS regarding to the way MethodHandle.invokeExact should be compiled (section 15.12.3 of JLS7).

The bug seams to only occur if invokeExact (and I suppose invoke) takes an array of Object as parameters.





Reproducible: Always

Steps to Reproduce:
try to compile the following program using eclipse, it currently fails at runtime because invokeExact signature is compiled as (Object[])Object instead of (Object[])I.

import static java.lang.invoke.MethodHandles.*; 

import java.lang.invoke.MethodHandle;

public class EclipseInvokeExactBug {
  public static void main(String[] args) throws Throwable {
    MethodHandle mh = dropArguments(insertArguments(identity(int.class), 0, 42), 0, Object[].class);
    int value = (int)mh.invokeExact(new Object[0]);
  }
}

Here is the corresponding bytecode:
public static void main(java.lang.String[]) throws java.lang.Throwable;
    Code:
       0: getstatic     #19                 // Field java/lang/Integer.TYPE:Ljava/lang/Class;
       3: invokestatic  #25                 // Method java/lang/invoke/MethodHandles.identity:(Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle;
       6: iconst_0      
       7: iconst_1      
       8: anewarray     #3                  // class java/lang/Object
      11: dup           
      12: iconst_0      
      13: bipush        42
      15: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: aastore       
      19: invokestatic  #35                 // Method java/lang/invoke/MethodHandles.insertArguments:(Ljava/lang/invoke/MethodHandle;I[Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;
      22: iconst_0      
      23: iconst_1      
      24: anewarray     #39                 // class java/lang/Class
      27: dup           
      28: iconst_0      
      29: ldc           #41                 // class "[Ljava/lang/Object;"
      31: aastore       
      32: invokestatic  #43                 // Method java/lang/invoke/MethodHandles.dropArguments:(Ljava/lang/invoke/MethodHandle;I[Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle;
      35: astore_1      
      36: aload_1       
      37: iconst_0      
      38: anewarray     #3                  // class java/lang/Object
      41: invokevirtual #47                 // Method java/lang/invoke/MethodHandle.invokeExact:([Ljava/lang/Object;)Ljava/lang/Object;
      44: checkcast     #20                 // class java/lang/Integer
      47: invokevirtual #53                 // Method java/lang/Integer.intValue:()I
      50: istore_2      
      51: return        
}

as you can see the descriptor of invokevirtual at bytecode 41 is wrong.
Comment 1 Olivier Thomann CLA 2012-07-18 11:47:10 EDT
I think the fix is trivial. The method binding for invokeExact(..) is not a PolymorphicMethodBinding.
Comment 2 Olivier Thomann CLA 2012-07-18 12:20:17 EDT
Created attachment 218879 [details]
Proposed fix
Comment 3 Olivier Thomann CLA 2012-07-18 12:20:37 EDT
Created attachment 218880 [details]
Regression test
Comment 4 Olivier Thomann CLA 2012-07-18 12:21:13 EDT
I think this is a good candidate for 3.8.1 as there is no workaround to get the right method binding.
Comment 5 Ayushman Jain CLA 2012-07-18 14:10:57 EDT
Thanks Olivier! I'll release it for 3.8.1
Comment 7 Ayushman Jain CLA 2012-07-20 06:39:08 EDT
Reviewed the patch and released in R3_8_maintenance via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R3_8_maintenance&id=6c8426c089e0f0c1552bad64f3deb5fdf6dfbdec
Comment 8 Srikanth Sankaran CLA 2012-08-06 05:46:43 EDT
Verified for 4.3 M1 using Build id: I20120805-2000
Comment 9 Srikanth Sankaran CLA 2012-08-14 05:28:11 EDT
Verified for 3.8.1 using Build id: M20120809-1000