Confusing number of objects in "Merged Paths" view

Questions about YourKit Java Profiler
Post Reply
Matthias
Posts: 6
Joined: Sun Nov 14, 2010 11:27 pm

Confusing number of objects in "Merged Paths" view

Post by Matthias »

Hi,

I am puzzled by the "number of objects" (column Objects) shown in the "Merged paths" view. It doesn't add up with the really existing number of objects in a memory snapshot.

An example:

Code: Select all

Class list

+-----------------------+--------------+----------------+-------------------+
|         Class         |   Objects    |  Shallow Size  |   Retained Size   |
+-----------------------+--------------+----------------+-------------------+
|  test.MemoryTest$A[]  |    1    0 %  |     32    0 %  |     4'704    0 %  |
|  test.MemoryTest$A    |    4    0 %  |     96    0 %  |  ~  4'480    0 %  |
|  test.MemoryTest$B[]  |    4    0 %  |    224    0 %  |  ~  4'384    0 %  |
|  test.MemoryTest$B    |   40    0 %  |    960    0 %  |  ~  4'160    0 %  |
|  test.MemoryTest$C[]  |   40    0 %  |  1'280    0 %  |  ~  3'200    0 %  |
|  test.MemoryTest$C    |  120    0 %  |  1'920    0 %  |  ~  1'920    0 %  |
|  test.MemoryTest      |    1    0 %  |     16    0 %  |        16    0 %  |
+-----------------------+--------------+----------------+-------------------+
I select the row "test.MemoryTest$C " above in the class list and click on "Calculate paths" in the "Merged Paths" tab and this is what I get:

Code: Select all

Merged paths

+---------------------------------------------------------------+--------------+-----------------+
|                             Name                              |   Objects    |  Retained Size  |
+---------------------------------------------------------------+--------------+-----------------+
|  +---<All the objects>                                        |  120  100 %  |   1'920  100 %  |
|    |                                                          |              |                 |
|    +---test.MemoryTest$C[]                                    |  120  100 %  |   1'920  100 %  |
|      |                                                        |              |                 |
|      +---test.MemoryTest$B                                    |  120  100 %  |   1'920  100 %  |
|        |                                                      |              |                 |
|        +---test.MemoryTest$B[]                                |  120  100 %  |   1'920  100 %  |
|          |                                                    |              |                 |
|          +---test.MemoryTest$A                                |  120  100 %  |   1'920  100 %  |
|            |                                                  |              |                 |
|            +---test.MemoryTest$A[]                            |  120  100 %  |   1'920  100 %  |
|              |                                                |              |                 |
|              +---statics or constant pool of test.MemoryTest  |  120  100 %  |   1'920  100 %  |
+---------------------------------------------------------------+--------------+-----------------+
As you can see, the number of objects for A,B,C are always shown as 120, which is actually not correct, if I would expect to see the "number of distinct/really existing objects" of a type.

The example code used to generate the objects seen in the snapshot:

Code: Select all

package test;

import org.junit.Test;

public class MemoryTest {

	public static class A {
		public int id;
		public B[] b;
	}

	public static class B {
		public int id;
		public C[] c;
	}

	public static class C {
		public int id;
	}

	private static A[] as;

	@Test
	public void test() throws Exception {
		as = new A[4];
		for (int a = 0; a < as.length; a++) {
			as[a] = new A();
			as[a].id = a;
			as[a].b = new B[10];
			for (int b = 0; b < as[a].b.length; b++) {
				as[a].b[b] = new B();
				as[a].b[b].id = b;
				as[a].b[b].c = new C[3];
				for (int c = 0; c < as[a].b[b].c.length; c++) {
					as[a].b[b].c[c] = new C();
					as[a].b[b].c[c].id = c;
				}
			}
		}
		System.out.println("Now take a snapshot while waiting...");
		Thread.sleep(50 * 1000);
		System.out.println("*Bye");
	}
}

I just couldn't think of a reason why you calculate the number of objects that way, but nevertheless, wouldn't it be helpful that you allow us to see also the number of distinct objects?

Cheers,
Matthias
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Confusing number of objects in "Merged Paths" view

Post by Anton Katilin »

Hi Matthias

Merged paths view works as intended. 120 is always the number of C. It may seem useless in your particular case, because all C are retained via the same path C <- B <- A, but in a more complex case these numbers make sense. For example, you might have 20 of C (or, replace C with some common class like int[] or String which usually has a lot of instances) retained from Foo and 100 from Bar; the view would tell that of total 120 C the biggest part, 100 C, are Bar's responsibility, etc.

However, as far as I understand, you expected to see something like: total 120 C retained from 40 B, which, in their turn, retained from 4 A. It's indeed useful to known this fact.

Currently this information can be obtained via a popup menu action "Selection dominators": right click on a line in the Merged paths.

To make this information immediately visible, we might add a special column "Dominator count" to the Merged paths view. It would show 40 for MemoryTest$C[] and MemoryTest$B, and 4 for MemoryTest$B[] and MemoryTest$A.

What do you think?

Best regards,
Anton
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Confusing number of objects in "Merged Paths" view

Post by Anton Katilin »

Hi Matthias

Please try the recent build 14076:
http://www.yourkit.com/eap

It adds the dominator count column ("Dominators") to the Merged paths view.

Best regards,
Anton
Matthias
Posts: 6
Joined: Sun Nov 14, 2010 11:27 pm

Re: Confusing number of objects in "Merged Paths" view

Post by Matthias »

Thank you very much.

Regards,
Matthias
Post Reply