<p dir="ltr">Since we&#39;re in wishful thinking territory now :), the two things I&#39;d really like are:</p>
<p dir="ltr">1) value/struct types (i.e. avoid heap and be able to pack data closer together).  I don&#39;t how much we can rely on EA.<br>
2) more auto-vectorization</p>
<p dir="ltr">I think 2 is being worked on by Vladimir but unclear if there are any concrete plans for 1.  I know John Rose has written about it, but don&#39;t know if anything&#39;s actually planned.</p>
<p dir="ltr">Sent from my phone</p>
<div class="gmail_quote">On Sep 28, 2012 3:59 PM, &quot;Charles Oliver Nutter&quot; &lt;<a href="mailto:headius@headius.com" target="_blank">headius@headius.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Now what we need is a way to inject new intrinsics into the JVM, so I<br>
can make an asm version of something and tell hotspot &quot;no no, use<br>
this, not the JVM bytecode&quot; :)<br>
<br>
- Charlie<br>
<br>
On Fri, Sep 28, 2012 at 11:53 AM, Vitaly Davidovich &lt;<a href="mailto:vitalyd@gmail.com" target="_blank">vitalyd@gmail.com</a>&gt; wrote:<br>
&gt; Yup, it would have to do extensive pattern matching otherwise.  C/C++<br>
&gt; compilers do the same thing (I.e. have intimate knowledge of stdlib calls<br>
&gt; and may optimize more aggressively or replace code with intrinsic<br>
&gt; altogether).<br>
&gt;<br>
&gt; In this case, jit uses the bsf x86 assembly instruction whereas hand rolled<br>
&gt; &quot;copy version&quot; generates asm pretty much matching the java code.<br>
&gt;<br>
&gt; Sent from my phone<br>
&gt;<br>
&gt; On Sep 28, 2012 2:42 PM, &quot;Raffaello Giulietti&quot;<br>
&gt; &lt;<a href="mailto:raffaello.giulietti@gmail.com" target="_blank">raffaello.giulietti@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Fri, Sep 28, 2012 at 8:15 PM, Charles Oliver Nutter<br>
&gt;&gt; &lt;<a href="mailto:headius@headius.com" target="_blank">headius@headius.com</a>&gt; wrote:<br>
&gt;&gt; &gt; On Fri, Sep 28, 2012 at 10:21 AM, Raffaello Giulietti<br>
&gt;&gt; &gt; &lt;<a href="mailto:raffaello.giulietti@gmail.com" target="_blank">raffaello.giulietti@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt; I&#39;m not sure that we are speaking about the same thing.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; The Java source code of numberOfTrailingZeros() is exactly the same in<br>
&gt;&gt; &gt;&gt; Integer as it is in MyInteger. But, as far as I understand, what<br>
&gt;&gt; &gt;&gt; really runs on the metal upon invocation of the Integer method is not<br>
&gt;&gt; &gt;&gt; JITted code but something else that probably makes use of CPU specific<br>
&gt;&gt; &gt;&gt; instructions. This code is built directly into the JVM and need not<br>
&gt;&gt; &gt;&gt; bear any resemblance with the code that would have been produced by<br>
&gt;&gt; &gt;&gt; JITting the bytecode.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Regardless of whether the method is implemented in Java or not, the<br>
&gt;&gt; &gt; JVM &quot;knows&quot; native/intrinsic/optimized versions of many java.lang core<br>
&gt;&gt; &gt; methods. numberOfTrailingZeros is one such method.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Here, the JVM is using its intrinsified version rather than the JITed<br>
&gt;&gt; &gt; version, presumably because the intrinsified version is pre-optimized<br>
&gt;&gt; &gt; and faster than what the JVM JIT can do for the JVM bytecode version.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; system ~/projects/jruby-ruby $ java -XX:+PrintCompilation<br>
&gt;&gt; &gt; -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining Blah<br>
&gt;&gt; &gt;      65    1             java.lang.String::hashCode (55 bytes)<br>
&gt;&gt; &gt;      78    2             Blah::doIt (5 bytes)<br>
&gt;&gt; &gt;      78    3             java.lang.Integer::numberOfTrailingZeros (79<br>
&gt;&gt; &gt; bytes)<br>
&gt;&gt; &gt;                             @ 1<br>
&gt;&gt; &gt; java.lang.Integer::numberOfTrailingZeros (79 bytes)   (intrinsic)<br>
&gt;&gt; &gt;      79    1 %           Blah::main @ 2 (29 bytes)<br>
&gt;&gt; &gt;                             @ 9   Blah::doIt (5 bytes)   inline (hot)<br>
&gt;&gt; &gt;                               @ 1<br>
&gt;&gt; &gt; java.lang.Integer::numberOfTrailingZeros (79 bytes)   (intrinsic)<br>
&gt;&gt; &gt;                             @ 15   Blah::doIt (5 bytes)   inline (hot)<br>
&gt;&gt; &gt;                               @ 1<br>
&gt;&gt; &gt; java.lang.Integer::numberOfTrailingZeros (79 bytes)   (intrinsic)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; system ~/projects/jruby-ruby $ cat Blah.java<br>
&gt;&gt; &gt; public class Blah {<br>
&gt;&gt; &gt; public static int value = 0;<br>
&gt;&gt; &gt; public static void main(String[] args) {<br>
&gt;&gt; &gt;   for (int i = 0; i &lt; 10_000_000; i++) {<br>
&gt;&gt; &gt;     value = doIt(i) + doIt(i * 2);<br>
&gt;&gt; &gt;   }<br>
&gt;&gt; &gt; }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; public static int doIt(int i) {<br>
&gt;&gt; &gt;   return Integer.numberOfTrailingZeros(i);<br>
&gt;&gt; &gt; }<br>
&gt;&gt; &gt; }<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Yes, this is what Vitaly stated and what happens behind the curtains.<br>
&gt;&gt;<br>
&gt;&gt; In the end, this means there are no chances for the rest of us to<br>
&gt;&gt; implement better Java code as a replacement for the intrinsified<br>
&gt;&gt; methods.<br>
&gt;&gt;<br>
&gt;&gt; For example, the following variant is about 2.5 times *faster*,<br>
&gt;&gt; averaged over all integers, than the JITted original method, the one<br>
&gt;&gt; copied verbatim! (Besides, everybody would agree that it is more<br>
&gt;&gt; readable, I hope.)<br>
&gt;&gt;<br>
&gt;&gt; But since the Integer version is intrinsified, it still runs about 2<br>
&gt;&gt; times slower than that (mysterious) code.<br>
&gt;&gt;<br>
&gt;&gt;     public static int numberOfTrailingZeros(int i) {<br>
&gt;&gt;         int n = 0;<br>
&gt;&gt;         for (; n &lt; 32 &amp;&amp; (i &amp; 1 &lt;&lt; n) == 0; ++n);<br>
&gt;&gt;         return n;<br>
&gt;&gt;     }<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; mlvm-dev mailing list<br>
&gt;&gt; <a href="mailto:mlvm-dev@openjdk.java.net" target="_blank">mlvm-dev@openjdk.java.net</a><br>
&gt;&gt; <a href="http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev" target="_blank">http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; mlvm-dev mailing list<br>
&gt; <a href="mailto:mlvm-dev@openjdk.java.net" target="_blank">mlvm-dev@openjdk.java.net</a><br>
&gt; <a href="http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev" target="_blank">http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev</a><br>
&gt;<br>
_______________________________________________<br>
mlvm-dev mailing list<br>
<a href="mailto:mlvm-dev@openjdk.java.net" target="_blank">mlvm-dev@openjdk.java.net</a><br>
<a href="http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev" target="_blank">http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev</a><br>
</blockquote></div>