<p>Remi, </p><div><br></div><div>Did you publish Dalvik changes somewhere? (or plan to?)</div><div><br></div><div>Cheers </div><br><br><div class="gmail_quote"><p>On Wed, Apr 3, 2013 at 6:32 PM, Remi Forax <span dir="ltr">&lt;<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>&gt;</span> wrote:<br></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><p>On 04/03/2013 06:12 PM, Cédric Champeau wrote:
<br>&gt; Le 03/04/2013 17:50, Remi Forax a Ã©crit :
<br>&gt;&gt; Sorry to be rude, but it's still a micro-benchmark ...
<br>&gt; First of all, yes, it is :) And as the classical fibonacci benchmark,
<br>&gt; it's useless but relevant for understanding how things work :)
<br>&gt;&gt; for invokedynamic, it's not in theory, if your method handle is constant
<br>&gt;&gt; either because it's a static final or because it is nested in a
<br>&gt;&gt; CallSite, it's constant for the JIT, thus fully optimized.
<br>&gt;&gt;
<br>&gt;&gt; for method handle on stack, the method handle is obviously not constant
<br>&gt;&gt; moreover the JIT is not able use trick to make it constant (like
<br>&gt;&gt; hoisting it out of the loop,
<br>&gt;&gt; or doing the inlining algorithm in a backward way etc.)
<br>&gt;&gt; More on that later ...
<br>&gt; Well, even if I make my MH variable declaration "final", the performance
<br>&gt; is the same, so I assume there's no local analysis, right?
<br><br>'final' on a local variable is a modifier for the compiler, not for the JIT.
<br>There are several local analysis, but not the ones you think.
<br><br>&gt;&gt; As you said it's a micro-benchmark so you end up with unusual good
<br>&gt;&gt; performance,
<br>&gt;&gt; by example the call to j.l.r.Method is optimized as never it will be in
<br>&gt;&gt; a real program
<br>&gt;&gt; (you call the method in the same unit it was declared and
<br>&gt;&gt; you have less than 3 instances of Method that are called more than 60
<br>&gt;&gt; times).
<br>&gt;&gt;
<br>&gt;&gt; Now, Krystal is currently working to add a cache when a method handle is
<br>&gt;&gt; called,
<br>&gt;&gt; so in few betas, the performance of method handles of your
<br>&gt;&gt; micro-benchmark will improve dramatically.
<br>&gt; That's good to know :)
<br>&gt;&gt; And the cache of MethodHandle is better that the cache which is used for
<br>&gt;&gt; j.l.r.Method because it can be local to a callsite and not global (in
<br>&gt;&gt; fact local to one callsite in the code of j.l.r.Method that is used by
<br>&gt;&gt; the invocation path when you call "invoke").
<br>&gt;&gt;
<br>&gt;&gt; Anyway, because it's a micro-benchmark the result will be as useless as
<br>&gt;&gt; now to predict the behaviour of a real world program.
<br>&gt; I can perfectly understand why some path is optimized or not, what I
<br>&gt; find surprising is more the order of magnitude here. So yes, calling
<br>&gt; invoke() takes more than 50s where reflection takes only 1.2s, and even
<br>&gt; invokeExact is slower (~3 to 1). My point is more than if MethodHandles
<br>&gt; are branded as "faster" than reflection (I heard you say it ;)), then
<br>&gt; there is something wrong.
<br><br>I say that in the context of proxies, i.e. where you can emit an 
<br>invokedynamic to store the method handle at callsite, method handle are 
<br>faster than using reflection because you don't need proxies anymore 
<br>(remember I said that too :).
<br><br>&gt; You should expect people doing stupid things  like me, thinking it will be faster than plain reflection. At least, the  docs should mention something about performance.
<br><br>The javadoc is the spec, we are talking about the Oracle implementation 
<br>of the spec.
<br>On Android, Jerome and I have run some tests that shows that a 
<br>MethodHandle.invokeExact is always faster than a call to the Reflection, 
<br>it's just because the reflection is super slow on Android not the opposite.
<br><br>&gt;&gt; cheers,
<br>&gt;&gt; Rémi
<br>&gt; Thanks for your answer :)
<br><br>Rémi
<br><br>_______________________________________________
<br>mlvm-dev mailing list
<br>mlvm-dev@openjdk.java.net
<br>http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
<br></p></blockquote></div><br>