I can query all the instances of com.google.common.cache.LocalCache$StrongAccessWriteEntry
in mat using OQL:
SELECT * FROM com.google.common.cache.LocalCache$StrongAccessWriteEntry
I've turned on Keep unreachable objects in mat. So the result contains both reachable and unreachable objects. Now I want to get all the unreachable com.google.common.cache.LocalCache$StrongAccessWriteEntry instances(aka. no gc roots), something like this:
SELECT * FROM com.google.common.cache.LocalCache$StrongAccessWriteEntry WHERE unreachable=true
Can I do it using OQL?
Yes, a query such as:
should do it.
Explanation:
Find the GC roots:
Find the GC roots, then for each GC root get the array of GC root information, then look at each GCRootInfo and find the type and see if it is Type.UNREACHABLE (2048) and only then select a GC root where the GC root information says it is unreachable. This finds the unreachable object roots. Keep unreachable objects only marks some of the unreachable objects as GC roots - the remaining unreachable objects are retained by these roots. Queries work better than way.
Find all the unreachable objects by finding all the objects retained by the unreachable GC roots:
Find all the LocalCache$StrongAccessWriteEntry objects
Find all the LocalCache$StrongAccessWriteEntry objects which are also in the unreachable objects set.
There is more information about writing queries in the Eclipse Memory Analyzer wiki.