Question

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?

Was it helpful?

Solution

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:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top