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

You access fields of heap objects by using a simple dot notation:
[ <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. Start of changeAlternatively, in the standard edition of the product only, use the autocompletion function as described in Using the autocompletion function of the OQL view.End of change

In the following example, s is the alias for the java.lang.String object, and count and value are fields of that object:
SELECT s.count, s.value FROM java.lang.String s

Accessing bean properties

When you use the at sign (@), the OQL statement accesses the attributes of the underlying Java objects that are used by Memory Analyzer to represent objects in the heap dump. The attributes are resolved by using bean introspection.
[ <alias>. ] @<attribute> ...
In the following example, usedHeapSize and retainedHeapSize are attributes of the java.lang.String object s:
SELECT s.@usedHeapSize, s.@retainedHeapSize FROM java.lang.String s
The following table lists some commonly used Java attributes. Start of changeIn 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.End of change
Table 1. Common Java attributes
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

When you add braces, ( ), the OQL statement is interpreted as a Java method call. The call is run by using reflection.
[ <alias> . ] <method>( [ <expression>, <expression> ] ) ...
For example:
SELECT s.toString(s) FROM java.lang.String s
The following table lists some common Java methods that you can use on the underlying Java objects that are used by Memory Analyzer to represent objects in the heap dump. Start of changeIn 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.End of change
Heap object IObject Method Return object
${snapshot} ISnapshot
getClasses()
A collection of all classes
   
getClassesByName(String name, boolean includeSubClasses)
A collection of classes
Class object IClass
hasSuperClass()
The result is true if the class has a super class
   
isArrayType()
The result is true if the class is an array type
Any heap object IObject
getObjectAddress()
The address of a snapshot object as a long integer
Primitive array IPrimitiveArray
getValueAt(int index)
A value from the array
Java primitive array, Java object array, or Java list (returned from reflection) [] or List
get(int index)
A value from the array or list

Array access

Start of changeYou 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. End of change

Start of changeYou 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. End of change

Reading values from primitive arrays

You can access elements of primitive arrays by using one of the following methods:
Start of changeIndex notationEnd of change
Start of changeFor example:
SELECT s[2] FROM int[] s WHERE (s.@length > 2)
This example reads the value of the element at index 2 from all int[] arrays that have at least three elements.End of change
Method call
For example:
SELECT s.getValueAt(2) FROM int[] s WHERE (s.@length > 2)
This example has the same result as the previous example.

Reading objects from object arrays

You can access elements of object arrays by using one of the following methods:
Start of changeIndex notationEnd of change
Start of changeFor example:
SELECT s[2] FROM java.lang.Object[] s WHERE (s.@length > 2)
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 OBJECTS s[2] FROM java.lang.Object[] s
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.End of change
Method call
For example:
SELECT OBJECTS s.@referenceArray.get(2) FROM java.lang.Object[] s WHERE (s.@length > 2)
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.getReferenceArray(2,1) 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.

Reading from Java arrays

You can access elements of Java arrays by using one of the following methods:
Start of changeIndex notationEnd of change
Start of changeFor example:
SELECT s.@GCRoots[2] FROM OBJECTS ${snapshot} s
End of change
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:
Start of changeIndex notationEnd of change
Start of changeFor example:
SELECT s.@GCRoots.subList(1,3)[1] FROM OBJECTS ${snapshot} s
End of change
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
toHex(number)
Prints the number as hexadecimal.
toString(object)
Returns the value of an object, for example, the content of a String object.
dominators(object)
Returns the objects that are immediately dominated by the object.
outbounds(object)
Returns the outbound referrer.
inbounds(object)
Returns the inbound referrer.
classof(object)
Returns the class of the current object.
dominatorof(object)
Returns the immediate dominator, or -1 if there is none
Start of change

Using the autocompletion function of the OQL view

You can use the autocompletion function of the OQL view to show available object fields and attributes, and suggestions for methods.
Note: This function is not available in the Web Edition of the product.
  1. 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.
  2. 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.
  3. You can start typing while the list is displayed, to filter the list according to the text that you type.
  4. Select an item from the list and press Enter, or double-click the item, to add the item to your OQL statement.
End of change




© Copyright IBM Corporation 2011, 2015.
© Copyright 2008, 2015 SAP AG and others. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html

US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.