Rémi's ASM 4.0 RC1

Rémi Forax forax at univ-mlv.fr
Thu Apr 21 12:49:39 PDT 2011


On 04/21/2011 09:59 AM, Mark Roos wrote:
> Thanks for the update ( even if the class names are not orthogonal to 
> invoke dynamic)
>
> Two questions on usage
>
> In your blog you used MH_GETSTATIC  to access the bootstrap.  Did you 
> mean to use MH_INVOKESTATIC ?

Yes !

>
> I would like to use a bootstrap signature of:  ( no trailing arguments)
>
> *        static*ConstantCallSite 
> bootStrapConstant(MethodHandles.Lookup callerLookup, String template, 
> MethodType type)
>
> But I can't figure out how to invoke that in ASM.  My current code is:
>
>        bsmType = 
> java.lang.invoke.MethodType./methodType/(ConstantCallSite.*class*, 
> Lookup.*class*, String.*class*, java.lang.invoke.MethodType.*class*, 
> Object.*class*);;
>        mv.visitInvokeDynamicInsn( bsmName, "()Lri/core/rtalk/RtObject;",
> *  new*MethodHandle(Opcodes./MH_INVOKESTATIC/,
> "ri/core/rtalk/RtCallSite",
> "bootStrapConstant",
>                   bsmType.toMethodDescriptorString()),
>           (Object[]) *new*String[1]);
>
> How would I change it for the above bootstrap?

Your bsmType declare a boostrap argument, the last parameter is an Object.
so bsmType should be:

  bsmType = 
java.lang.invoke.MethodType./methodType/(ConstantCallSite.*class*, 
Lookup.*class*, String.*class*, java.lang.invoke.MethodType.*class*);

Now, the formal parameter corresponding to the boostrap arguments
in visitInvokeDynamicInsn is declared Object... , the elipsis/variadic 
'...' accept 0 or more
arguments separated by a comma.
So you can write:

  mv.visitInvokeDynamicInsn( bsmName, "()Lri/core/rtalk/RtObject;",
*  new*MethodHandle(Opcodes./MH_INVOKESTATIC/,
"ri/core/rtalk/RtCallSite",
"bootStrapConstant",
                   bsmType.toMethodDescriptorString()));


By the way, I know how to recognize a Caml guy that write Java code,
take a look to the last characters of your first line of code. ;;)

>
> thanks much
>
> mark

Rémi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20110421/872a73a6/attachment.html 


More information about the mlvm-dev mailing list