ShortestPathFinder.kt
TLDR
This file contains the definition of the ShortestPathFinder
interface and its inner Factory
interface.
Methods
findShortestPathsFromGcRoots
This method is part of the ShortestPathFinder
interface. It takes a set of leaking object IDs and returns PathFindingResults
. It is responsible for finding the shortest paths from the GC roots to the leaking objects in the heap graph.
createFor
This method is part of the Factory
interface, which is an inner interface of ShortestPathFinder
. It takes a HeapGraph
as input and returns an instance of ShortestPathFinder
. It is responsible for creating instances of ShortestPathFinder
for a given heap graph.
package shark
// TODO Mention that this can also compute the dominator tree?
// Ideally this would be split out, e.g. ObjectDominators uses this without
// any target just to navigate the whole graph. But we do want to be able traverse the
// whole thing in one go, and both find leaking objects + compute dominators.
// Maybe there's a new "heap traversal" class that can navigate the whole heap starting from
// gc roots and following references, and we plug in 2 things on it: the one for leaks
// and the one for dominators. And both can say when to stop (dominators: never).
fun interface ShortestPathFinder {
fun findShortestPathsFromGcRoots(
leakingObjectIds: Set<Long>
): PathFindingResults
fun interface Factory {
fun createFor(heapGraph: HeapGraph): ShortestPathFinder
}
}