• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Virtual method table

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, i need a detailed but simple explanation as to how Virtual method table works in java. I read a few articles but they were not specifically written for java. I need to to know what exactly a virtual method table is, and how and for what jvm uses it. Thanks in advance
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In C++, the virtual method table ("vtbl") is an explicit part of the object model. Discussions of a class's vtbl, where it is, what it looks like, are common. Likewise the virtual method table pointer (vptr) -- each C++ object with virtual methods has at least one of those.

But there is no implicit or explicit notion of a vtbl in Java. Virtual machine implementors are free to do things however they'd like. You won't find an article about vtbls and vptrs in Java -- and if you do, it'll be pure hogwash.
 
Oceana Wickramasinghe
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:In C++, the virtual method table ("vtbl") is an explicit part of the object model. Discussions of a class's vtbl, where it is, what it looks like, are common. Likewise the virtual method table pointer (vptr) -- each C++ object with virtual methods has at least one of those.

But there is no implicit or explicit notion of a vtbl in Java. Virtual machine implementors are free to do things however they'd like. You won't find an article about vtbls and vptrs in Java -- and if you do, it'll be pure hogwash.



Are you saying that Java does not use a method table?

Here's a part of one of the articles i found

"For each non-abstract class a Java virtual machine loads, it could generate a method table and include it as part of the class information it stores in the method area. A method table is an array of direct references to all the instance methods that may be invoked on a class instance, including instance methods inherited from superclasses. (A method table isn't helpful in the case of abstract classes or interfaces, because the program will never instantiate these.) A method table allows a virtual machine to quickly locate an instance method invoked on an object."

Im confused
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Oceana Wickramasinghe wrote:
Are you saying that Java does not use a method table?



No. What EFH is saying is that the VM specification doesn't define how methods are to be called -- it may use virtual tables or it may not.

Having said that, the reference implementation (from Sun) does indeed use jump tables. And the implementation that I had the pleasure to work with (Azul) didn't change that -- so it too used jump tables.

Henry

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic