Why does OpenJDK place private methods into vtable

2019-06-17 04:17发布

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?

1条回答
不美不萌又怎样
2楼-- · 2019-06-17 04:35

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.

查看更多
登录 后发表回答