JDK-8024368 : private methods are allocated vtable indices
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-09-05
  • Updated: 2021-06-22
  • Resolved: 2018-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12
11.0.13-oracleFixed 12 b18Fixed
Related Reports
Relates :  
Relates :  
Description
Here is a description of current JVM behavior:

"Private methods always get a vtable entry to handle backward compatibility
with classes - i.e. you can have the same name of a private method local to your class and also
inherit a method of from your superclass, which will get inherited around the private method, by
your child." http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2013-August/011500.html

But, it seems to be a waste of space, and a needless "surprise" in the code, to give vtable entries to private methods.  Surely there must be a better way to handle the relevant corner cases.

When the code in klassVtable::update_inherited_vtable encounters a private method, it does this:
  // private methods always have a new entry in the vtable
  // specification interpretation since classic has
  // private methods not overriding
  if (target_method is private) {
    return (probably true)
  }

In most case, a 'false' return value would be correct and would use less metadata space for vtables.

There may be a case where a vtable index would need to be assigned retroactively but this would only have to apply to subclasses that somehow manage to override to the private method (if that were possible).

In cases where the private method somehow manages to override a superclass method (if that were possible) then the vtable index would already be allocated in the superclass, and would not need to be re-allocated in the method holder class.
Comments
Fix Request (OpenJDK 11u): Please approve backporting this to OpenJDK 11u. It no longer adds vtable entries for private methods after this patch. I'd like to backport change as it's a dependency for a JVMCI backport we'd like to do: JDK-8223050. JDK-8223050 expects for private methods to not have vtable entries for the test change for it's can_be_statically_bound() function. JDK-8223050, in turn, fixes an issue of OpenJDK 11u-based graal vm (mandrel) asserting in some circumstances when the build JDK is a debug VM. The JDK 12 patch applies clean and passes tier 1 tests.
17-06-2021

I would like to defer the detailed investigation of how to best handle private methods in superclasses until JDK9. Private methods neither override nor are overridden, so in theory they could be treated like final methods without explicit vtable entries.
09-12-2013