Java Magazine, Sept/Oct 2017
klassOop object toString toString feed groom purr groom klassOop Pet klassOop Cat klassOop Bear m kk m kk m kk m kk Figure 2 Structure of the vtables for the classes shown in Figure 1 ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 49 java 9 The vtables for these classes are laid out in Java 7 as shown in Figure 2 As you can see this figure shows the Java 7 layout within permgen so it refers to klassOops and has the two words of the object header shown as m and kk in the figure As discussed previously these entries would not be present in Java 8 and Java 9 but all else in the diagram remains the same If you call Cat feed the JVM will not find an override in the Cat class and instead will follow the pointer to the klass of Pet This klass does have an implementation for feed so this is the code that will be called This vtable structure works well because Java implements only single inheritance of classes This means there is only one direct superclass of any type except for Object which has no superclass In the case of invokeinterface the situation is a little more complicated For example the groom method will not necessarily appear in the same place in the vtable for every implementation of Furry The diferent offsets for Cat groom and Bear groom are caused by the fact that their class inheritance hierarchies differ The result of this is that some additional lookup
You must have JavaScript enabled to view digital editions.