Accessing properties
You can use OQL statements to access Java™ properties, such as object fields or objects in arrays. You can also run Java methods within an OQL statement.
Accessing fields of the heap object
[ <alias>. ] <field> . <field>. <field>
You can define an alias in the FROM clause, to
identify the current object on which the OQL statement operates. Fields
are attributes of the Java object
in the heap dump. Without the alias, the field defaults to one of
the fields of the current object. You can use the Inspector view to
find out about the available fields of an object.
Alternatively,
in the standard edition of the product only, use the autocompletion
function as described in Using the autocompletion function of the OQL view.
SELECT s.count, s.value FROM java.lang.String s
Accessing bean properties
[ <alias>. ] @<attribute> ...
SELECT s.@usedHeapSize, s.@retainedHeapSize FROM java.lang.String s
In the standard edition of the product, you can use the
autocompletion function to show common bean names, as described in Using the autocompletion function of the OQL view.
| Any heap object | IObject | objectId | ID of the snapshot object |
|---|---|---|---|
| objectAddress | address of the snapshot object | ||
| class | Java class of this object | ||
| clazz | IClass of this object. See also classof(object) | ||
| usedHeapSize | shallow heap size | ||
| retainedHeapSize | retained heap size | ||
| displayName | display name | ||
| Class object | IClass | classLoaderId | ID of the class loader |
| Any array | IArray | length | length of the array |
| Primitive array | IPrimitiveArray | valueArray | the values in the array |
| Reference array | IObjectArray | referenceArray | the objects in the array (the addresses of the objects as long values). Access a particular element by using the get() method, then convert to an object by using the OBJECTS keyword. |
Calling Java methods
[ <alias> . ] <method>( [ <expression>, <expression> ] ) ...
SELECT s.toString(s) FROM java.lang.String s
In the standard edition of the product, you can
also use the autocompletion function to suggest some methods, as described
in Using the autocompletion function of the OQL view.
| Heap object | IObject | Method | Return object |
|---|---|---|---|
| ${snapshot} | ISnapshot |
|
A collection of all classes |
|
A collection of classes | ||
| Class object | IClass |
|
The result is true if the class has a super class |
|
The result is true if the class is an array type | ||
| Any heap object | IObject |
|
The address of a snapshot object as a long integer |
| Primitive array | IPrimitiveArray |
|
A value from the array |
| Java primitive array, Java object array, or Java list (returned from reflection) | [] or List |
|
A value from the array or list |
Array access
You can access primitive
arrays and object arrays directly from the snapshot, and Java arrays and Java lists
by using reflective method calls. You access arrays in this way by
using the [index] notation.
The index is an integer, which starts at 0 for the first element.
If the array is null or the index is out of range, the access result
is null. 
You can also access a
range of elements within an array, by using the [index_1:index_2] notation,
where index_1 and index_2 indicate the start and end of the
range, and are inclusive. Negative index values indicate that the
range starts at the end of the array and moves backwards, so an index
value of -1 specifies the last element in the array. 
Reading values from primitive arrays
You can access elements of primitive arrays by using one of the following methods:
Index notation
For example:
This example reads the value of the element at index 2 from all int[] arrays that have at least three elements.SELECT s[2] FROM int[] s WHERE (s.@length > 2)
- Method call
- For example:
This example has the same result as the previous example.SELECT s.getValueAt(2) FROM int[] s WHERE (s.@length > 2)
Reading objects from object arrays
You can access elements of object arrays by using one of the following methods:
Index notation
For example:
This example reads the element at index 2 from all Object arrays that have at least three elements. The element referenced by the s[2] code is an IObject object, so fields and Java bean properties can be accessed.SELECT s[2] FROM java.lang.Object[] s WHERE (s.@length > 2)
In this example, the OBJECTS keyword converts the object to show a tree view rather than a table result. The WHERE clause is not required because out-of-range accesses return null, and the OBJECTS keyword ignores null values.SELECT OBJECTS s[2] FROM java.lang.Object[] s
- Method call
- For example:
This example reads, as an address of data type long, the element at index 2 from all Object arrays that have at least three elements, then converts the results into objects.SELECT OBJECTS s.@referenceArray.get(2) FROM java.lang.Object[] s WHERE (s.@length > 2)
This example reads, as an array of data type long, one element, starting at index 2, from all Object arrays that have at least three elements, then converts the contents of those arrays into objects.SELECT OBJECTS s.getReferenceArray(2,1) FROM java.lang.Object[] s WHERE (s.@length > 2)
Reading from Java arrays
You can access elements of Java arrays by using one of the following methods:
Index notation
For example:SELECT s.@GCRoots[2] FROM OBJECTS ${snapshot} s
- Method call
- For example:
SELECT s.@GCRoots.get(2) FROM OBJECTS ${snapshot} s WHERE s.@GCRoots.@length > 2
Reading from Java lists
You can access elements of Java List objects by using one of the following methods:
Index notation
For example:SELECT s.@GCRoots.subList(1,3)[1] FROM OBJECTS ${snapshot} s
- Method call
- For example:
SELECT s.@GCRoots.subList(1,3).get(1) FROM OBJECTS ${snapshot} s
Built-in OQL functions
<function>( <parameter> )
Built-in functions:
| Function | Description |
|---|---|
|
Prints the number as hexadecimal. |
|
Returns the value of an object, for example, the content of a String object. |
|
Returns the objects that are immediately dominated by the object. |
|
Returns the outbound referrer. |
|
Returns the inbound referrer. |
|
Returns the class of the current object. |
|
Returns the immediate dominator, or -1 if there is none |

Using the autocompletion function of the OQL view
- Type a space after the class name. A context information box displays the class name, showing that this class is now selected as the active class.
- Type a period (.), at sign (@), or press Ctrl+Space in the SELECT or WHERE clauses, for example after the alias in the SELECT clause. A list is displayed. The list contains available fields, attributes, and suggestions for methods on key Memory Analyzer objects that represent the contents of the snapshot.
- You can start typing while the list is displayed, to filter the list according to the text that you type.
- Select an item from the list and press Enter, or double-click the item, to add the item to your OQL statement.
