[jvm-l] Re: Small static method marked not entrant, inlining reversed?
john.r.rose at oracle.com
Wed Sep 8 00:22:53 PDT 2010
On Sep 8, 2010, at 12:08 AM, Charles Oliver Nutter wrote:
> Why is Hotspot able to cope with the
> cast+invokevirtual when it can't cope with invokeinterface always
> resolving to the same method?
Here's a possible answer, which could lead to JVM tweaks or bug fixes: Class hierarchy analysis allows devirtualization of the call, but only if the receiver is a real class. The JVM keeps some records about implementors of interfaces, but I don't think the compiler connects all the dots properly.
Note that if the call site is monomorphic then class hierarchy analysis doesn't apply at all, and calls are trivially devirtualized, since the receiver is an "exact" type (not quantified over a set of subtypes). This happens whether the receiver is a class or interface. But our current type profiles don't scale well beyond one or two exact types.
So a test case for this theory would have to make a call site which witnesses multiple receiver types but where all the types resolve to a common method (and that method has a single definition within the set of the receiver's subtypes). And the set of subtypes would have to be bounded by an interface, not a class.
More information about the hotspot-compiler-dev