# 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!

## Autocompletion

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

Parent topic: OQL Syntax