On Fri, Sep 28, 2012 at 6:49 PM, Mark Roos <mr...@roos.com> wrote: > From Raffaello > are java.lang classes better served by the JVM than other classes? > Here's a small experiment. > I created a MyInteger class that exposes the very same implementation > of Integer.numberOfTrailingZeros(int), copied verbatim. > > We did similar micro benchmarks, using Hanoi as a test case, to see the > speed variations > the various types of integers would have. We tried int, long, Long and our > version of > a boxed long. One case where we saw a 3-5x difference was between boxed and > primitive versions. This was expected. > > The other case was when we compared our custom boxed long with the Java > Long. > We found the issue here was with the creation and collection of instances. > The use of > the integer cache made a huge difference. Once we did that out times became > very close. > So while there may be internal optimization by the JVM in the Hanoi case it > had a minor > effect. > > regards > mark > _______________________________________________
I'm not sure that we are speaking about the same thing. The Java source code of numberOfTrailingZeros() is exactly the same in Integer as it is in MyInteger. But, as far as I understand, what really runs on the metal upon invocation of the Integer method is not JITted code but something else that probably makes use of CPU specific instructions. This code is built directly into the JVM and need not bear any resemblance with the code that would have been produced by JITting the bytecode. On the other hand, the bytecode for the method in MyInteger, which stems from an identical source, will be JITted. It is not built into the JVM. Hence, in my example, there is no chance to get close to the performance of the Integer variant, since the Integer code that runs on the metal is probably highly optimized and probably quite different from the JITted code of the MyInteger method. I guess this happens for every method that is intrinsified into the JVM. As Vitaly points out, they are listed in http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/9b0ca45cd756/src/share/vm/opto/library_call.cpp and numberOfTrailingZeros() is among them. Cheers Raffaello _______________________________________________ mlvm-dev mailing list mlvm-dev@openjdk.java.net http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev