FROM Clause

Specify the class

The FROM clause defines the classes on which to operate. Specify the class by one of the following means:

by class name:
SELECT * FROM java.lang.String
by a regular expression matching the class name:
SELECT * FROM "java\.lang\..*"
by the object address of the class:
SELECT * FROM 0x2b7468c8
by the object addresses of more than one class:
SELECT * FROM 0x2b7468c8,0x2b74aee0
by the object id of the class:
SELECT * FROM 20815
by the object ids of more than one class:
SELECT * FROM 20815,20975
by a sub select:
SELECT * FROM ( SELECT *
                FROM java.lang.Class c
                WHERE c implements org.eclipse.mat.snapshot.model.IClass )

The statement returns all objects in the heap. The implements check is necessary, as the heap dump can contain java.lang.Class instances caused by proxy classes or classes representing primitive types such as int.class or Integer.TYPE. The following query has the same effect, which calls a method directly on the ISnapshot object:

SELECT * FROM ${snapshot}.getClasses()

Include sub classes

Use the INSTANCEOF keyword to include objects of sub-classes into the query:

SELECT * FROM INSTANCEOF java.lang.ref.Reference

The resulting table contains, amongst others, WeakReference and SoftReference objects because both classes extend from java.lang.ref.Reference . By the way, the same result has the following query

SELECT * FROM ${snapshot}.getClassesByName("java.lang.ref.Reference", true)

Prevent interpretation of the from term as classes

Use the OBJECTS keyword if you do not want to process the term as classes. Specify the object or objects by one of the following means:

by class name:
SELECT * FROM OBJECTS java.lang.String

The result is just one object, the java.lang.String class object.

by the object address of the particular object:
SELECT * FROM OBJECTS 0x2b7468c8
by the object addresses of particular objects:
SELECT * FROM OBJECTS 0x2b7468c8,0x2b746868
by the object id of the particular object:
SELECT * FROM OBJECTS 20815
by the object ids of particular objects:
SELECT * FROM OBJECTS 20815,20814
by a sub expression (Memory Analyzer 1.4 or later):
SELECT * FROM OBJECTS (1 + ${snapshot}.GCRoots.length)
by a sub select returning an object list
SELECT v, v.@length FROM OBJECTS ( SELECT OBJECTS s.value FROM java.lang.String s  ) v
In Memory Analyzer 1.10 and later, sub-selects are now also permitted which have select items.
SELECT v,v.s,v.val FROM OBJECTS ( SELECT s,s.value as val FROM java.lang.String s  ) v
See Wiki Sub select with select items for more details.
Note: Please note, that currently the FROM OBJECTS term is in the test phase!

Unindexed objects

Normally heap objects are indexed in the snapshot and are referred to by an object id, not an address. If objects have been discarded from the snapshot during parsing, either because they are unreachable, or because of the discard option then sometimes they can still be accessed in OQL. If you know the object address, then a query such as
SELECT * FROM OBJECTS 0x2b7468c8
will retrieve it. The result of the query is different however. Instead of the object being processed as an object id and displayed in a list objects query tree view, it is returned as part of a list of IObject and is displayed as a table view.
Unindexed objects will not be returned as a result of
  • outbound()
  • inbound()
  • dominators()
  • dominatorof()
and will cause an error if supplied as an argument to those functions. The built-in function classof() does work with unindexed objects.

See how unindexed objects appear in the inspector view when retrieved by OQL. Note the yellow warning triangle icon warning triangle and the Unindexed in the inspector view top panel, and the Unindexed suffix in the object view. The retained size is 0 as the retained size is not calculated for unindexed objects. Inspector View with unindexed object"

Note: Please note, that currently the unindexed objects facility is in the test phase!

Autocompletion

The OQL pane now has autocompletion for class names, class name regular expressions, field names, attributes and methods. See OQL autocompletion.