duplicate class signatures by GetLoadedClasses

(Unknown problem with this posting, all my paragraphs are no more visible after preview - using IE6).

Hi,

using a heap analyser (jvmti based) on our application results in detecting multiple classes having exactly (really exacty - nothing about inner classes or stuff) the same fully qualified name (package and class name). One thing is special as a maximum of two classes have the same name.

Those two classes having the same name do not appear directly after another. Two examples here: One class name appears first at position 310 and second at 3279. Another class name appears first at 4372 and second at 7916.

The algorithm used (around the iteration over all classes) is only a slightly enhanced version of the part of source of your heap viewer demo. Wether the heap viewer gives the same results could not be tested yet but I am sure as there is no important difference in the (interesting part of) source code.

On later memory consumption analysis those two classes do not always (only sometimes) have the same count of instances or consume the same amount of memory.

How could this be?

Using:

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)

Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)

-- Robert

[1312 byte] By [lldaedaluslla] at [2007-10-2 21:35:16]
# 1
Confirmed: Heap viewer demo does the same.-- Robert
lldaedaluslla at 2007-7-14 0:49:15 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Right, but if you examine the class loader you should find they are different.
alan.batemana at 2007-7-14 0:49:15 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

And how is it possible? Whats the difference between those duplicates? In the mean time I made it that way to merge all data (size, count, references to and from) of the "duplicate" (second occurence) to the "original" (first occurence). But I fear this might be no good decision...

Robert

lldaedaluslla at 2007-7-14 0:49:15 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

Ok, looked at those class loaders.

What I see are two different class loaders for each of both duplicates. For several duplicates I have tried it are always the same two class loaders. Those class loaders are of the same type (class). Further both class loaders have a type 2 reference (among other references) to another class loader, which is exactly the same object referenced in both cases. Those 3 class loaders are the only ones used in our application (except reflection loaders for some sun.reflect.* stuff)

In your VM Spec I read: "At run time, a class or interface is determined not by its name alone, but by a pair: its fully qualified name and its defining class loader. Each such class or interface belongs to a single runtime package. The runtime package of a class or interface is determined by the package name and defining class loader of the class or interface."

So the rest of this effect comes from application behavior or are there some JVM internals behind loading a class twice by two different loaders?

Robert

Message was edited by:

lldaedalusll

lldaedaluslla at 2007-7-14 0:49:15 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...