diff --git a/jol-core/src/main/java/org/openjdk/jol/info/GraphStatsWalker.java b/jol-core/src/main/java/org/openjdk/jol/info/GraphStatsWalker.java index 90c3d41c..3a91767d 100644 --- a/jol-core/src/main/java/org/openjdk/jol/info/GraphStatsWalker.java +++ b/jol-core/src/main/java/org/openjdk/jol/info/GraphStatsWalker.java @@ -67,6 +67,7 @@ public GraphStats walk(Object... roots) { for (Object e : (Object[]) o) { if (e != null && visited.add(e)) { + data.addRecord(vm.sizeOf(e)); s.push(e); } } diff --git a/jol-core/src/test/java/org/openjdk/jol/info/GraphStatsTest.java b/jol-core/src/test/java/org/openjdk/jol/info/GraphStatsTest.java index c87e5ff8..5de4cc72 100644 --- a/jol-core/src/test/java/org/openjdk/jol/info/GraphStatsTest.java +++ b/jol-core/src/test/java/org/openjdk/jol/info/GraphStatsTest.java @@ -23,6 +23,14 @@ static class D { public D(D d) { this.d = d; } } + static class E { + private final A[] as; + + E() { + as = new A[] { new A() }; + } + } + @Test public void basicCounts() { A a = new A(); @@ -85,4 +93,14 @@ public void compoundSizes() { } } + @Test + public void layoutAndStatsMatch() { + E e = new E(); + + GraphLayout layout = GraphLayout.parseInstance(e); + GraphStats stats = GraphStats.parseInstance(e); + + Assert.assertEquals(layout.totalSize(), stats.totalSize()); + Assert.assertEquals(layout.totalCount(), stats.totalCount()); + } }