FROM Clause

Specify the class

The FROM clause defines the classes on which to operate. Specifiy 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 0xe14a100
by the object id:
SELECT * FROM 3022
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. The same effect has the following query, 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:

SELECT * FROM OBJECTS java.lang.String

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

Note: Please note, that currently the FROM OBJECTS term is in the test phase!