polymorphism

J

josh

Hi,
can anyone tell me where can I find detailed info (or to explain me)
on how Java implements polymorphism and dynamic binding internally?

Thanks
 
C

Chris Uppal

josh said:
can anyone tell me where can I find detailed info (or to explain me)
on how Java implements polymorphism and dynamic binding internally?

That's rather a big topic. In fact it's a very big topic, and still the
subject of ongoing research.


If you look for "vtable" and "inline cache" (or "polymorphic inline cache")
then you should find some places to /start/ reading. The following Google
search query looks promising:
("vtable" OR "inline cache") java method dispatch
Assume that most of the best information on such subjects will be research
papers and therefore will be in PDF or PostScript format.

Beware of anything which seems to claim or assume that Java implementations
always use vtables unless the either:
The author is clear about when the implementation the implementation does
/not/ use vtables for dynamic dispatch.
or:
The author is part of the group that created the specific JVM
implementation
s/he is talking about.

-- chris
 
J

josh

That's rather a big topic. In fact it's a very big topic, and still the
subject of ongoing research.

If you look for "vtable" and "inline cache" (or "polymorphic inline cache")
then you should find some places to /start/ reading. The following Google
search query looks promising:
("vtable" OR "inline cache") java method dispatch
Assume that most of the best information on such subjects will be research
papers and therefore will be in PDF or PostScript format.

Beware of anything which seems to claim or assume that Java implementations
always use vtables unless the either:
The author is clear about when the implementation the implementation does
/not/ use vtables for dynamic dispatch.
or:
The author is part of the group that created the specific JVM
implementation
s/he is talking about.

-- chris

yes I know that it is a big topic and infact I'm seasrching something
to make
a comparative study with C++ where the polymorphism is implemented via
vtables...
 
C

Chris Smith

josh said:
yes I know that it is a big topic and infact I'm seasrching something
to make
a comparative study with C++ where the polymorphism is implemented via
vtables...

My own suggestion is that you shift the focus of your research a bit.
The implementation techniques for method dispatch are not properties of
languages; they are properties of implementations of languages. There
are a few C++ compilers that do not use vtables, and there are plenty of
Java virtual machines that implement method dispatch in different ways
from each other. In fact, the variations between Java implementations
are probably greater than the variations between early Java
implementations and C++. Modern Java implementations for widely used
platforms generally don't have one method; instead, they choose between
several means of dispatch depending on the performance footprint of the
code and the potential for optimization.
 
J

josh

My own suggestion is that you shift the focus of your research a bit.
The implementation techniques for method dispatch are not properties of
languages; they are properties of implementations of languages. There
are a few C++ compilers that do not use vtables, and there are plenty of
Java virtual machines that implement method dispatch in different ways
from each other. In fact, the variations between Java implementations
are probably greater than the variations between early Java
implementations and C++. Modern Java implementations for widely used
platforms generally don't have one method; instead, they choose between
several means of dispatch depending on the performance footprint of the
code and the potential for optimization.

so does SUN write only the language specification and not how the JVM
must
be implmented?

and there is not the SUN's jvm implemetation spec?
 
C

Chris Uppal

Chris said:
There
are a few C++ compilers that do not use vtables

Do you have any references/links for that ? I don't (currently) see how to
implement C++'s turn-off-polymorphism-during-the-ctor semantics without either
massive complexity (worse than "ordinary" PICs), vtables, or nasty run-time
tests.

-- chris
 
C

Chris Uppal

josh said:
so does SUN write only the language specification and not how the JVM
must be implmented?

and there is not the SUN's jvm implemetation spec?

Not in any relevant sense. Sun, obviously, decide /how/ any given release of
the JVM is implemented, but there's no public specification of the
implementation techniques used (how could there be -- if nothing else they need
the freedom to introduce new techniques as they are invented, or become
commercially feasible).

If you need /descriptions/ of how any particular version of any particular
vendor's JVM works, then you have several options:

Look at the source -- not always available, but sometimes it is. Sun make
their source available.

Look for published papers by their JVM development team. Sun also have
published a few, and some of them are listed somewhere on Sun's website:
http://research.sun.com/java-topics/pubs/
IBM have published quite a lot too. I don't have a link handy but searching
for
"jikes research JVM"
seems to throw up some promising leads (Note that the implementation
technologies in the Jikes JVM are not necessarily used in their commercial
JVMs).

Look for patents applied for by the JVM development teams.

Look for the JVM development teams' blogs (if any).

Look for other material which /claims/ to be about how JVMs are implemented --
but take anything you find with two pinches of salt. One pinch because stuff
changes over time, but out of date material hangs around on the Web and in
"folk law". The other because not too many people really know what's going on
inside a high performance JVM except it's designers.

-- chris
 
T

Tor Iver Wilhelmsen

Hi,
can anyone tell me where can I find detailed info (or to explain me)
on how Java implements polymorphism and dynamic binding internally?

You want to look for the Java Virtual Machine specification, and possibly
at least one of the implementations. Sources are available for a few JSE
implementations. Look in particular on how the invokevirtual instruction
is implemented.
 
C

Chris Smith

Chris Uppal said:
Do you have any references/links for that ?

Unfortunately, no. About 15 years ago, I used a C++ compiler for an
embedded processor that did not use vtables -- I know, because part of
the job involved examining the memory layout and writing assembly code
to interact with it. The processor was the Z80, but I don't recall the
compiler or vendor.

It is simply my assumption that other C++ compilers may not use vtables,
either. Perhaps my assumption is wrong.
I don't (currently) see how to
implement C++'s turn-off-polymorphism-during-the-ctor semantics without either
massive complexity (worse than "ordinary" PICs), vtables, or nasty run-time
tests.

The technique involved a single hidden field in each object to identify
its class. Each virtual method signature foo in some class hierarchy
would cause the compiler to synthesize a _foo_dispatch function, which
did a conditional branch based on the contents of that hidden field.
Calls to the member function would actually call _foo_dispatch, which
would jump to the appropriate code.

Although I can't guarantee this compiler did it, one could turn off
polymorphism beyond a certain superclass simply by changing the type
field.
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top