• Post Reply Bookmark Topic Watch Topic
  • New Topic

how is dynamic dispatch implemented in java  RSS feed

 
vaibhav vishal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how is dynamic method dispatch implemented in java?
is it similar to use of virtual method tables as in C++?
In C++, each instance of the class will contain in addition to its data members, a pointer to the virtual table of the class,
how is this functionality implemented in java??

Also please provide any source for further reading.

I know this is too much to ask considering that i am a java beginner but just out of curiosity i want to explore this.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vaibhav vishal wrote:how is dynamic method dispatch implemented in java?
is it similar to use of virtual method tables as in C++?
In C++, each instance of the class will contain in addition to its data members, a pointer to the virtual table of the class,
how is this functionality implemented in java??

Also please provide any source for further reading.

I know this is too much to ask considering that i am a java beginner but just out of curiosity i want to explore this.


The Java specification doesn't define the implementation, so JVMs are free to do it any way they like. However, the Sun Oracle reference implementation does use jump tables -- just like how most C++ compilers do (generate code for) it.

Henry
 
vaibhav vishal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
vaibhav vishal wrote:how is dynamic method dispatch implemented in java?
is it similar to use of virtual method tables as in C++?
In C++, each instance of the class will contain in addition to its data members, a pointer to the virtual table of the class,
how is this functionality implemented in java??

Also please provide any source for further reading.

I know this is too much to ask considering that i am a java beginner but just out of curiosity i want to explore this.


The Java specification doesn't define the implementation, so JVMs are free to do it any way they like. However, the Sun Oracle reference implementation does use jump tables -- just like how most C++ compilers do (generate code for) it.

Henry

ok...is this an optimization technique or is a requirement which has to be implemented but JVMs are free to do it their own way?
can you provide me a source of good reading for this?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vaibhav vishal wrote:
Henry Wong wrote:
vaibhav vishal wrote:how is dynamic method dispatch implemented in java?
is it similar to use of virtual method tables as in C++?
In C++, each instance of the class will contain in addition to its data members, a pointer to the virtual table of the class,
how is this functionality implemented in java??

Also please provide any source for further reading.

I know this is too much to ask considering that i am a java beginner but just out of curiosity i want to explore this.


The Java specification doesn't define the implementation, so JVMs are free to do it any way they like. However, the Sun Oracle reference implementation does use jump tables -- just like how most C++ compilers do (generate code for) it.

Henry

ok...is this an optimization technique or is a requirement which has to be implemented but JVMs are free to do it their own way?


As you can see just a few lines up, he already told you: The Java specification doesn't define the implementation, so JVMs are free to do it any way they like.

can you provide me a source of good reading for this?


What kind of reading? What are you trying to learn? You can start with the JVM spec, but since it doesn't define any particular implementation, you won't find much there. In fact, you probably won't find much anywhere on how Java does something that's not defined in the spec.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to know how the JVM works then you can get the source code of the complete JVM from the OpenJDK project. It won't be easy, however, to understand all of it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!