What is "(something else)" in jol GraphLayout output?
Asked Answered
C

1

6

When using jol's GraphLayout class to print the graph of objects referenced from an object instance, some of the output entries say "(something else)" instead of a type and reference path. For example, consider the following code that prints the graph of a list of 20 random Integer objects:

List<Integer> foo = new Random().ints(20).boxed().collect(Collectors.toList());
System.out.println(GraphLayout.parseInstance(foo).toPrintable());

This code prints:

java.util.ArrayList object externals:
          ADDRESS       SIZE TYPE                PATH                           VALUE
         d642ecc8         24 java.util.ArrayList                                (object)
         d642ece0         16 java.lang.Integer   .elementData[0]                212716192
         d642ecf0         56 (something else)    (somewhere else)               (something else)
         d642ed28         16 java.lang.Integer   .elementData[1]                1503736768
         d642ed38         16 java.lang.Integer   .elementData[2]                -2099759732
         d642ed48         16 java.lang.Integer   .elementData[3]                445566433
         d642ed58         16 java.lang.Integer   .elementData[4]                -1528625708
         d642ed68         16 java.lang.Integer   .elementData[5]                -555424299
         d642ed78         16 java.lang.Integer   .elementData[6]                1607595284
         d642ed88         16 java.lang.Integer   .elementData[7]                763466772
         d642ed98         16 java.lang.Integer   .elementData[8]                638331919
         d642eda8         16 java.lang.Integer   .elementData[9]                -1742026575
         d642edb8         16 java.lang.Integer   .elementData[10]               1920101909
         d642edc8         80 (something else)    (somewhere else)               (something else)
         d642ee18         16 java.lang.Integer   .elementData[11]               2001035318
         d642ee28         16 java.lang.Integer   .elementData[12]               -1920666937
         d642ee38         16 java.lang.Integer   .elementData[13]               -991335829
         d642ee48         16 java.lang.Integer   .elementData[14]               -47760298
         d642ee58         16 java.lang.Integer   .elementData[15]               855824902
         d642ee68        104 [Ljava.lang.Object; .elementData                   [212716192, 1503736768, -2099759732, 445566433, -1528625708, -555424299, 1607595284, 763466772, 638331919, -1742026575, 1920101909, 2001035318, -1920666937, -991335829, -47760298, 855824902, 2137884845, -226328690, 1472718384, 890105604, null, null]
         d642eed0         16 java.lang.Integer   .elementData[16]               2137884845
         d642eee0         16 java.lang.Integer   .elementData[17]               -226328690
         d642eef0         16 java.lang.Integer   .elementData[18]               1472718384
         d642ef00         16 java.lang.Integer   .elementData[19]               890105604

Searching for jol "something else" on DuckDuckGo and Google did not return any useful hits.

What do the "(something else)" entries represent?

Colubrid answered 4/5, 2015 at 0:45 Comment(0)
C
7

"(something else)" means just that -- something not part of this object graph. There may be other (live or garbage) objects there, or just a gap in the heap for some VM-internal reason.

Note that the table of objects in the graph is sorted by address. The ArrayList's elementData array is lazily initialized when the first element is added, and when the tenth element is added to the list, elementData is reallocated to make room for more elements. This creates gaps in the heap area corresponding to the (now-garbage) arrays, and jol prints them as "(something else)" entries. The code responsible for printing these entries is GraphLayout line 246 (at least as of this posting).

jol prints this information about heap gaps to aid in understanding garbage collector behavior. Some of the later jol examples demonstrate this, such as the compaction example which shows how the objects referenced from an ArrayList are initially sparse but are compacted by the garbage collector.

Colubrid answered 4/5, 2015 at 0:45 Comment(1)
I like when people self-answer on stuff :) I am not sure "something else" is a good notion though: it seems to trip people over and over again. But, I fail to find a better (short) description.Schaub

© 2022 - 2024 — McMap. All rights reserved.