One object can be an instance of only one class. The class may have a
superclass, the superclass another superclass and so on, until we reach
java.lang.Object.
During the loading of a class, a table with the instance methods declared in
this class is constructed. Each entry contains a string-identifier for the
method. It may also have the address of the method.
For a class to be loaded, the superclass must have been already loaded. The
table with the instance methods for a class contains the entries of the
direct superclass and some new entries for the new instance methods declared
in this class. In the case of method overloading the corresponding entry in
the clone of the superclass table is updated so as to point to the method
that overloads the previous.
The methods in the tables are indexed with an offset.
When calling an instance method, the object reference is passed as an
argument (is pushed in the stack).The object reference is the address of the
object in the heap. In the representation of an object, the first word
contains the address of its class. Thus we determine the class of the
object. We can now search in the instance methods table of this class to
find the entry that matches the method's name. When a match is found, we use
the address in the entry to call the method. The invokevirtual that caused
the call is replaced with a quick version, that contains the offset of the
method in the corresponding table.
In the case of interface methods the mechanism is a bit more complicated,
but the basic principle is the same. In this case a lot of tables are
constructed, one for each interface.
The resolution of a symbolic reference introduces an overhead, but after the
replacement of the invokevirtual with an invokevirtual_quick it is
eliminated.
> How does Java resolve a virtual method at runtime? If a particular
> virtual call site can have many potential targets because the object
[quoted text clipped - 5 lines]
> Thanks!
> KL