7

It seems that openJDK 8 places private methods which are not final nor static into vtable. Why is it so when dynamic binding is not used for private methods (since they're invoked with invokespecial) or is it used?

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
Radek Micek
  • 447
  • 2
  • 9

1 Answers1

4

This is done to handle some rare situations when an overridable method with the same name and signature exists in a superclass. Though there is definitely a place for improvement, may be, targeted for JDK 9.

See https://bugs.openjdk.java.net/browse/JDK-8024368

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.

apangin
  • 92,924
  • 10
  • 193
  • 247
  • So when a private method is called its vtable entry is never used? – Radek Micek Feb 15 '15 at 21:15
  • @RadekMicek Right, this entry is not used in method calls. – apangin Feb 15 '15 at 22:24
  • I thought it over and over and still don’t get it. First, I don’t get which actual behavior should be achieved and second, every possible behavior that I can imagine could be implemented without adding `private` methods to the vTable. – Holger Feb 16 '15 at 16:42
  • As I understand it, it is needed by the code which builds vtables (maybe it makes that code simpler??) - but this is purely my speculation. – Radek Micek Feb 16 '15 at 18:21