RFR: CODETOOLS-7902930: JOL: Bring back GraphWalker visitors

Aleksey Shipilev shade at openjdk.java.net
Mon May 10 12:12:04 UTC 2021


On Mon, 12 Apr 2021 16:00:49 GMT, Martin Junghanns <github.com+318788+s1ck at openjdk.org> wrote:

> Hey @shipilev First of all: Thanks for this useful library. I wanted to switch from jol 0.10 to 0.15 in one of my projects because of some issues on openJDK 15. I discovered that the ability to register visitors had been removed at some point. The interface `org.openjdk.jol.info.GraphVisitor` is actually still around. I find that feature quite useful as it allows users to compute some custom statistics of the object graph. I tried to use the `GraphLayout` to access the GPRs, but it's all package-private.
> 
> It would be nice if we could bring the feature back. Also, if you think the approach is not ideal, we can maybe figure out something else.
> 
> Thanks for your time.

I did some benchmarking, and I think what you have is nearly the best we can do. I would like to avoid a few (sometimes virtual) calls on the walker hotpath. To that extent, please consider this change (note the `Map` -> `HashMap` rewrite too):


    private final GraphVisitor[] visitors;
    private final HashMap<Class<?>, Long> sizeCache;

    public GraphWalker(GraphVisitor... visitors) {
        this.visitors = visitors;
        sizeCache = new HashMap<>();
    }


...and then inline `visitObject` into two use sites.

I think you would be able to do `new GraphWalker(gpr -> { ... }).walk(...)` then.

-------------

Changes requested by shade (Committer).

PR: https://git.openjdk.java.net/jol/pull/15


More information about the jol-dev mailing list