Bug in MethodHandles.convertArguments
Raffaello Giulietti
raffaello.giulietti at gmail.com
Tue May 11 06:18:59 PDT 2010
On 2010-05-11 12:27, Rémi Forax wrote:
> Le 11/05/2010 09:31, Raffaello Giulietti a écrit :
>> Yes, this seems a bug to me, too.
>>
>> What about converting to Integer.class instead of int.class and letting
>> the boxing duties to the language compiler?
>>
>> Raffaello
>>
Mmmm, I see.
However, filterArguments might not combine well with tail calls. So,
let's hope that convertArguments will work as expected asap. Did you
find out if it's indeed a bug?
>
> This code is extracted from a bigger code that try to avoid boxing
> if not necessary.
>
> echo a + 3
> is compiled:
> aload (a)
> iconst_3
> invokedynamic plus(Object,int)Object
>
> and at runtime if 'a' contains an Integer, I install a fast path
> that checks if 'a' is an Integer and calls int+int.
> So the fast path doesn't need to box '3'.
> The slow path, box the int and call a method that will modify
> the fast path.
>
> I am currently not a able to call that method because converting
> an int to an object doesn't work.
>
> I see two workarounds:
> - have one slow path by signatures:
> (int,Object), (double, Object), (Object, int) (Object, double), etc.
> - don't rely on convert and use filterArguments.
>
>
> Rémi
>
>>
>> On 2010-05-10 21:11, Rémi Forax wrote:
>>
>>> For me it's a new bug.
>>> I have checked with jdk7 latest binaries
>>> I will check with the mlvm repository sources when I will be at my
>>> office with a fast connection.
>>>
>>> public class ConvertBug {
>>> public static Object foo(Object o1, Object o2) {
>>> return null;
>>> }
>>>
>>> public static void main(String[] args) {
>>> MethodHandle mh =
>>> MethodHandles.lookup().findStatic(ConvertBug.class, "foo",
>>> MethodType.methodType( Object.class, Object.class, Object.class));
>>> mh = MethodHandles.convertArguments(mh,
>>> MethodType.methodType(Object.class, int.class, Object.class));
>>> System.out.println("print mh "+mh);
>>> }
>>> }
>>>
>>> Exception in thread "main" java.lang.IllegalArgumentException:
>>> mismatched parameter count
>>> at sun.dyn.MemberName.newIllegalArgumentException(MemberName.java:409)
>>> at sun.dyn.MethodHandleImpl.convertArguments(MethodHandleImpl.java:654)
>>> at sun.dyn.ToGeneric.<init>(ToGeneric.java:102)
>>> at sun.dyn.ToGeneric.of(ToGeneric.java:257)
>>> at sun.dyn.ToGeneric.make(ToGeneric.java:249)
>>> at sun.dyn.MethodHandleImpl.convertArguments(MethodHandleImpl.java:671)
>>> at java.dyn.MethodHandles.convertArguments(MethodHandles.java:811)
>>> at ConvertBug.main(ConvertBug.java:15)
>>>
>>>
>>> and I don't see any workaround :(
>>>
>>> Rémi
>>> _______________________________________________
>>> mlvm-dev mailing list
>>> mlvm-dev at openjdk.java.net
>>> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>>>
>> _______________________________________________
>> mlvm-dev mailing list
>> mlvm-dev at openjdk.java.net
>> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>>
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
More information about the mlvm-dev
mailing list