InvokeDynamic - how to use arguments in bootstrap method?

I am trying to implement duck typing with invokedynamic in JVM7. I created two different classes, both of them have a greet() method that returns a String . I randomly select one of them, save the instance on the stack, and invokedynamic (using ASM).

I wonder if I can access the arguments in the bootstrap method. Because I cannot return the corresponding CallSite with target without knowing which object is on the stack and which of the greet() methods should be returned.

If my approach is wrong, what is the right approach?

+4
source share
1 answer

I will answer myself.

  • Bind CallSite with your own static method (eg lookup(CallSite cs, Object[] args)
  • args[0] is the receiver, the rest are arguments. Do whatever you want in the search method.

If you are interested in Inline Caching (I was), take a look at these two links:

+2
source

Source: https://habr.com/ru/post/1383322/


All Articles