How to find contents of an array or collection using OQL in Eclipse MAT in JBDS
Environment
- JBoss Developer Studio (JBDS)
- Eclipse Memory Analyser Tool (MAT)
Issue
We can use a OQL query in MAT to locate interesting objects. If those objects are an array, List or Map, how can we find the objects in side them with OQL?
Resolution
Given an array returned by "SELECT a from ... a", you can access the contained objects via "SELECT OBJECTS a.@referenceArray from ... a". Since most data structures are built on member variables and arrays, this can be extended to access the contents of Lists and Maps, although the details are specific to the implementations.
Consider the Maps found by "SELECT m from java.util.HashMap m" where you want a list of all values stored in them. You can use this to find all the tables inside them.
SELECT OBJECTS m.table from java.util.HashMap m
Then to get the contents of the tables
SELECT t FROM OBJECTS (SELECT OBJECTS m.table from java.util.HashMap m) t
And the values from the entries
SELECT e.value FROM OBJECTS (SELECT OBJECTS t.@referenceArray FROM OBJECTS (SELECT OBJECTS m.table from java.util.HashMap m) t) e
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.