As I mentioned earlier, Mustang (Java SE 6) comes with jhat - Java Heap Analysis Tool. We have added more features to jhat as of build 53 (released on Sep, 22, 2005). jhat now comes with mechanism to query the heap. jhat supports OQL - Object Query Language -- a SQL-like language to query your Java heap! HAT always supported simple queries such as "show all instances of class X" (include subclasses or not), "show all referrers to a specific object", "show all objects reachable from a specific object" etc. But, these pre-defined queries (supported by hyperlinks) may always be sufficient to a specific problem in your hand. That is where OQL helps.
OQL query is of the form
[ from [instanceof] <class name> <identifier>
[ where <filter-expression> ] ]
identifier is a name bound for each Java heap object that is matching from and where clause. Note that both from and where clauses are optional. Few simple examples, would help in understanding basic OQL.
select s from java.lang.String s
where s.count > 100
select a from [I a where a.length >= 256
from instanceof java.lang.ClassLoader cl