On 05/04/2012 10:51 AM, Miguel Garcia wrote:

I'm wondering what performance can be expected when composing many small MethodHandles, for example composing constant MHs at the granularity of "iadd" below:

  public class Instructions {
public static int iadd(int a, int b) { return a + b; } // ie this is placeholder for the lonely instruction "iadd"
    . . .
  }

The experiment thus involves piecing together all those little MHs (not unlike AST building) thus making up the desired functionality (the motivation for this is picking bytecodes for primitive types on a per-type-instantiation basis, but that's another story).

at runtime or not ?


Q1: Would the resulting MH be JITted down to native code without invocation overhead whatsover?

I suppose you use foldArguments to link the pieces together.
The guarantee is that all codes involving method handles will disappear but you have no guarantee that methods iadd will be inlined, i.e it can be a method call, so you can end up with
something like:
  iadd(const(2), const(3))
with each call being a real method call.

With ForceInlining (new annotation added in jdk8 but Hotspot specific),
you can ask all instruction methods to be inlined, so in that case, the generated assembler code
should be equivalent with the one generated from the equivalent bytecode.

You also have to simulate your own invokevirtual, invokeinterface instructions
by using invokedynamic and your own inlining cache.


Q2: If not JITted (but after everything has been resolved) would the resulting MH perform in the worst case as the corresponding (statically emitted) bytecode?

No.
You such guarantee exists even if it may be true with a peculiar VM implementation.


Q1 and Q2: Never? Sometimes? Always? ("Sometimes" would be tricky because then the cost model becomes difficult to reason about).

Q1 & Q2 => false



Miguel
http://lampwww.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/ <http://lampwww.epfl.ch/%7Emagarcia/ScalaCompilerCornerReloaded/>


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 jvm-languages@googlegroups.com.
To unsubscribe from this group, send email to 
jvm-languages+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to