Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / February 2005

Tip: Looking for answers? Try searching our database.

Virtual method resolution

Thread view: 
kernel_learner@yahoo.com - 24 Feb 2005 20:24 GMT
How does Java resolve a virtual method at runtime? If a particular
virtual call site can have many potential targets because the object
could possibly be one of many types, what exactly goes on in the
machine to resolve this call? Is there a lot of overhead associated
with this resolving process? I have heard of devirtualization as a
technique to overcome these overheads..what exactly is that?

Thanks!
KL
Isidoros Sideris - 26 Feb 2005 16:15 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.