Pregunta

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

I wonder if I can access arguments in bootstrap method. Because I cannot return appropriate 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 correct approach?

¿Fue útil?

Solución

I will answer myself.

  1. Bind CallSite with your own static method (for example lookup(CallSite cs, Object[] args)
  2. The args[0] is the receiver, the rest of them are arguments. Do whatever you wish in the lookup method.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top