On 01/20/2011 06:46 PM, Jochen Theodorou wrote:
Am 20.01.2011 18:04, schrieb Rémi Forax:
On 01/20/2011 05:49 PM, Jochen Theodorou wrote:
Hi all,

looks like some stupid fact left my center of attention for quite a
while, so I am asking here to see if I am right or not.

Assuming I have in pseudo code something like this:

Object o1 = foo1()
Object o2 = foo2()
invokeDynamic ("bar", this, o1, o2)

in fact, invokedynamic "bar" (this, o1, o2)
"bar" is constant so it's a boostrap argument not an argument that will
be send each time there is a call.

ah, yes, true

meaning I want to do an dynamic method invocation using o1 and o2 as
arguments to some method on this, which is called bar....

Do I see it right, that the MethodType that will get presented to my
bootstrap method and the call site will have Object for o1 and o2?

the descriptor will be typeOf(this), typeOf(o1), typeOf(o2) + return type

ehm.. so a yes or no? Does typeOf return the runtime type, or the the type on the java thinks this stack value has on the operand stack?

here typeOf stands for the type inserted by the compiler.
you have to provide a method descriptor when you encode invokedynamic, for your example
if we suppose the invokedynamic is an instruction (i.e; it returns void)
it should look like that:

aload 0
aload 1
aload 2
invokedynamic "bar" (Lorg/groovy/Script;Ljava/lang/Object;Ljava/lang/Object;)V

If I do an ALOAD to get the value from a local variable, then it is most likely Object, or not?

if the variable is a parameter, it has the type of the parameter, else it has the type of the previous ASTORE.


Actually the typing on the operand stack is still a mystery to me.

It works like Scala :)
You know the type of the parameter and you remember the type if there is a store.


And am I right in assuming, that if the runtime type for ox changes,
that this will not invalidate my callsite and that I will have to
guard this if I want that?

yes, you have to guard it. Unlike the DLR, invokedynamic doesn't do
anything by default.
Note that you can install a guard that checks the class of the first
parameter instead of testing its identity.

I have not only to test the first parameter, but all of them.

No. You have to check all of them if there are several overloads not always.
if there is only one applicable method and you install a guard that do a type check (not an instanceof),
you don't need to check all arguments.

That does not prevent me from doing a guard of course, but makes me wonder about the resulting performance.

invokedynamic is not magic (almost :), it's a way to avoid to do the lookup at each call by storing (caching) the target method by protecting it with one or several guards depending on
the assumptions you have done to find the target method.


bye blackrag


Rémi

--
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to