Does java has vtable and vptr like C++? I try to understand the
mechanism java used for dynamic method lookup, but my books don't say.
Can someone explain? Thank you.
Jim Korman - 27 Aug 2006 04:42 GMT
>Does java has vtable and vptr like C++? I try to understand the
>mechanism java used for dynamic method lookup, but my books don't say.
>Can someone explain? Thank you.
Take a look at
http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html
start with
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Overview.doc.html#1963
and move on to
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#1513
and
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Compiling.doc.html#14787
Jim
Chris Uppal - 27 Aug 2006 12:28 GMT
> Does java has vtable and vptr like C++? I try to understand the
> mechanism java used for dynamic method lookup, but my books don't say.
It's implementation dependent (actually it's implementation dependent in C++
too). The only way you can find out is to read the source for the /particular/
JVM implementation you are interested in.
In point of fact, and as far as I can tell, Sun's current range of JVMs use a
small inline cache at the point-of-call (a type-test and unconditional jump if
the test passes) with a fallback to the horrendously inefficient vtable-based
dispatch if that fails. (That's for optimised code, I have no idea how "eager"
the implementation is to use that optimisation).
Static method dispatch (invokestatic), interface method dispatch
(invokeinterface), and invocation of private methods and super-sends can be,
and have to be, handled differently.
-- chris