vcall wish for hotspot

Andy Nuss andrew_nuss at yahoo.com
Sat May 18 09:20:30 PDT 2013


After stuggling for some time for an easy way to force jvm to make bimorphic call and compare it with the same iterative loop not doing so, I hit upon this:

public class Test {

     private static Randomrandom = new Random();

     abstract class Link {
           Link next;
           abstract int get ();

     }

     class Link1 extends Link {
            private int v = random.nextInt();
            int get ()
            {
                  return v+1;
             }
      }

      clase Link2 extends Link {
              private int v = random.nextInt();
              int get ()
              {
                     return v+2;
              }
      }

      class Link3 {
             Link3 next;
             private int v = random.nextInt();
             int get ()
             {
                    return v+3;
              }
      }

   ........
}

Then create two cyclic link linked lists of the same number of elements, i.e. there is no front or rear.  And don't make the number of elements too big, or the processor caches are more involved.

One cycle is randomly intermixed Link1 and Link2 elements and the pointer to the cycle is of type Link.
Other cycle is of Link3 and pointer to entry point of cycle is of type Link3.

Then in two identical warmed up loop functions of 10 billion iterations, one the iterates and returns the sum of Link get() and one that returns the sum of Link3 get(), compare the time to execute both.  The difference is about .5 nanos per iteration on my machine.

      
....

As to how much faster c++ is, I haven't coded in C++ at all in 5 years, and then it was on a much slower laptop, so I'm not set up to benchmark it.  But in the other post, I linked to blog that said as much, that Java downcasts and bimorphic calls are very slow relative to C++.

But I'm sure if you have both java and C++ eclipse setup on your linux machine, the same Test snippet above can be coded in both, and both compilers should be forced to make a bimorphic call in the case of mixed links in the cyclic chain.



________________________________
 From: Andrew Haley <aph at redhat.com>
To: Andy Nuss <andrew_nuss at yahoo.com> 
Cc: hotspot <hotspot-compiler-dev at openjdk.java.net> 
Sent: Saturday, May 18, 2013 7:59 AM
Subject: Re: vcall wish for hotspot
 

On 05/17/2013 04:40 PM, Andy Nuss wrote:

> I profiled virtual calls on a very fast machine (core i7) after
> Aleksey pointing out some micro benchmark deficiencies in my
> benchmarking technique.  Corrected those.

Is this benchmark available somewhere?

> Nailed down the time of a virtual call on core i7: with or without
> interfaces involved, if a bimorphic call is enforced on hotspot due
> to inability to inline, the overhead is very close to 0.5 nanos,
> whether the method is in the base class or in an interface.
> 
> Knowing nothing about java's evolving design for interfaces and
> generics, I do know that C++ compilers can emit much much faster
> vcalls, especially when the class is not involving multiple
> inheritance.

How much faster?

> My wish:
> 
> That if Java knows that a class does not have interfaces, then
> theoretically, the bimorphic call thru the vtable of such a class
> should approach C++ speeds.
> 
> Is this wish ever achievable?

I think so.  But does it matter whether a class has interfaces?  Many
of them do, even if it's just something like Cloneable.

Andrew.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20130518/c285d0d8/attachment.html 


More information about the hotspot-compiler-dev mailing list