vcall wish for hotspot

Andrew Haley aph at redhat.com
Sun May 19 02:38:56 PDT 2013


On 05/19/2013 05:37 AM, Andy Nuss wrote:
> Well, I guess I don't know what I'm doing after all.
> 
> I ported my benchmark to C++, and found that C++ overhead for the
> virtual call was 6 nanos, way slower than the 0.5 nanos I was
> getting for hotspot.
> 
> Then I guessed, maybe Clemens is right, hotspot is seeing that Link1
> and Link2 are very similar in structure, and even though the
> iteration thru the list of base types would seem to force a virtual
> call, hotspot is just turning it into an if-else, and inlining
> everything else, and the extra 0.5 nanos is simply due to branch
> mispredict.
> 
> 
> So I create 10 variants of my Link class, Link1 thru Link10, and
> hotspot was about the same as C++, 6 nanos.
> 
> But that could mean that hotspot was now using a vtable, or it could
> mean hotspot was paying for 10 branch mispredictions.
> 
> So I tried 20 variants of my Link class, Link1 thru Link20, and
> hotspot was now about 11 nanos.  So it would seem that hotspot, for
> simple variants of a base class doesn't use a vtable at all, but
> just creates one big if-else inline.  Whereas C++, even with just 2
> variants of the class, always uses a vtable.
> 
> If this is true, that itself is very interesting.  Any ideas how to
> write a test that really forces hotspot to use the vtable?

If I were you I'd stop guessing, build a debug hotspot, and have a look
at the generated code.  The is no substitute.

Andrew.


More information about the hotspot-compiler-dev mailing list