ThreadObjects.kt
TLDR
This file contains the ThreadObjects
object which provides methods related to thread objects in the shark.internal
package.
Methods
getThreadObjectsByIdMap
This private method retrieves a map of thread objects by their IDs from a HeapGraph
object.
getThreadObjects
This method returns a collection of all thread objects in a HeapGraph
object.
getByThreadObjectId
This method retrieves a specific thread object from a HeapGraph
object using its ID.
package shark.internal
import shark.GcRoot.ThreadObject
import shark.HeapGraph
internal object ThreadObjects {
private fun getThreadObjectsByIdMap(graph: HeapGraph) = graph.context.getOrPut(ThreadObjects::class.java.name) {
graph.gcRoots.asSequence().filterIsInstance<ThreadObject>().associateBy { it.id }
}
fun getThreadObjects(graph: HeapGraph) = getThreadObjectsByIdMap(graph).values
fun getByThreadObjectId(graph: HeapGraph, objectId: Long): ThreadObject? {
val threadObjectsById = getThreadObjectsByIdMap(graph)
return threadObjectsById[objectId]
}
}