Skip to content

Commit

Permalink
7903262: JOL: GraphStatsWalker counts array elements incorrectly
Browse files Browse the repository at this point in the history
Reviewed-by: shade
  • Loading branch information
Toparvion authored and shipilev committed Aug 29, 2022
1 parent d8d374a commit 76c554a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
18 changes: 18 additions & 0 deletions jol-core/src/test/java/org/openjdk/jol/info/GraphStatsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 76c554a

Please sign in to comment.