Dynamic Method Lookuip in Java

D

dimitrik107

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.
 
J

Jim Korman

C

Chris Uppal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,073
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top