blob: 5bb4e36315929891d7899dc7b84ecc341a7ca51a [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2008, 2021 SAP AG and IBM Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
SAP AG - initial API and implementation
Andrew Johnson (IBM Corporation) - enhancements
-->
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd" >
<reference id="propertyaccessors" xml:lang="en-us">
<title>Property Accessors</title>
<shortdesc />
<prolog>
<copyright>
<copyryear year="2008"></copyryear>
<copyryear year="2021"></copyryear>
<copyrholder>
Copyright (c) 2008, 2021 SAP AG and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
</copyrholder>
</copyright>
</prolog>
<refbody>
<section>
<title>Accessing fields of the heap object</title>
<p> Properties of heap objects are accessed using a simple dot
notation:</p>
<p> [ &lt;alias&gt;. ] &lt;field&gt; . &lt;field&gt;.
&lt;field&gt;
</p>
<p>
An
<b>alias</b>
can be defined in the
<xref href="oqlsyntaxfrom.dita">FROM Clause</xref>
to identify the current object, i.e. row in the SQL
analogy, on which the OQL statement operates. Without
alias, the field is assumed to be one of the fields of
the current object.
<b>Fields</b>
are attributes of the Java objects in the heap dump. Use
<xref href="tipsandtricks.dita#oqlcompletion">OQL autocompletion</xref>
or the
<cmdname>Object Inspector</cmdname>
to find out about the available fields of an object.
</p>
</section>
<section>
<title>Accessing Java Bean properties</title>
<p>[ &lt;alias&gt;. ] @&lt;attribute&gt; ...</p>
<p>
Using the @ symbol, OQL accesses attributes of the
underlying Java objects used by Memory Analyzer to represent
objects in the heap dump. The attributes are resolved via
Bean Introspection. Use
<xref href="tipsandtricks.dita#oqlcompletion">OQL autocompletion</xref>
to find the common beans names.
The following table lists some
commonly used Java attributes.
</p>
<simpletable relcolwidth="2* 2* 2* 3*" id="javabean_prop">
<strow>
<stentry>Any heap object</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#method.summary" format="html">IObject</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getObjectId()" format="html">objectId</xref></stentry>
<stentry>id of snapshot object</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getObjectAddress()" format="html">objectAddress</xref></stentry>
<stentry>address of snapshot object</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry>class</stentry>
<stentry>Java class of this object as a Memory Analyzer object</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getClazz()" format="html">clazz</xref></stentry>
<stentry>IClass of this object. See also classof(object).</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getOutboundReferences()" format="html">outboundReferences</xref></stentry>
<stentry>The outbound references as a list of
<xref href="../doc/org/eclipse/mat/snapshot/model/NamedReference.html">NamedReference</xref> objects
from this object: the type as IClass of this object; the fields; the array entries.
This is retrieved from the heap dump, not an index, so could contain references
to unindexed objects.
</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getUsedHeapSize()" format="html">usedHeapSize</xref></stentry>
<stentry>shallow heap size</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getRetainedHeapSize()" format="html">retainedHeapSize</xref></stentry>
<stentry>retained heap size</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getTechnicalName()" format="html">technicalName</xref></stentry>
<stentry>the technical name (a combination of the class name and the object address)</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getClassSpecificName()" format="html">classSpecificName</xref></stentry>
<stentry>the value from a name resolver, if available, for example a readable value of a String</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getDisplayName()" format="html">displayName</xref></stentry>
<stentry>display name, a combination of the technical name and the class specific name</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getSnapshot()" format="html">snapshot</xref></stentry>
<stentry>the snapshot containing this object. An alternative to <codeph>${snapshot}</codeph></stentry>
</strow>
<strow>
<stentry>Class object</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IClass.html#method.summary" format="html">IClass</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IClass.html#getClassLoaderId()" format="html">classLoaderId</xref></stentry>
<stentry>id of the class loader</stentry>
</strow>
<strow>
<stentry>Any array</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IArray.html#method.summary" format="html">IArray</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IArray.html#getLength()" format="html">length</xref></stentry>
<stentry>length of the array</stentry>
</strow>
<strow>
<stentry>Primitive array</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IPrimitiveArray.html#method.summary" format="html">IPrimitiveArray</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IPrimitiveArray.html#getValueArray()" format="html">valueArray</xref></stentry>
<stentry>the values in the array</stentry>
</strow>
<strow>
<stentry>Reference array</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObjectArray.html#method.summary" format="html">IObjectArray</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObjectArray.html#getReferenceArray()" format="html">referenceArray</xref></stentry>
<stentry>the objects in the array (as long values, the addresses of the objects)
Access a particular element using get() and convert to an object using OBJECTS.
</stentry>
</strow>
<strow>
<stentry>Class loader object</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IClassloader.html#method.summary" format="html">IClassLoader</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IClassLoader.html#getClassLoaderId()" format="html">definedClasses</xref></stentry>
<stentry>the classes defined by the class loader</stentry>
</strow>
<strow>
<stentry>Object Reference</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/ObjectReference.html#method.summary" format="html">ObjectReference</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/ObjectReference.html#getObject()" format="html">object</xref></stentry>
<stentry>The IObject which the reference points to</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/ObjectReference.html#getObjectId()" format="html">objectId</xref></stentry>
<stentry>The id of the IObject which the reference points to. This will fail for unindexed objects.</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/ObjectReference.html#getObjectAddress()" format="html">objectAddress</xref></stentry>
<stentry>The address of the IObject which the reference points to. This works for unindexed objects.</stentry>
</strow>
<strow>
<stentry>Named Reference extends ObjectReference</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/NamedReference.html#method.summary" format="html">NamedReference</xref></stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/NamedReference.html#getName()" format="html">name</xref></stentry>
<stentry>The field name or array index in the form <codeph>[12357]</codeph> which describes the reference.</stentry>
</strow>
</simpletable>
</section>
<section>
<title>Calling Java methods</title>
<codeblock>[ &lt;alias&gt; . ] @&lt;method&gt;( [ &lt;expression&gt;, &lt;expression&gt; ] ) ...</codeblock>
<p>
Adding ( ) forces OQL to interpret this as a Java method
call. The call is executed via reflection.
The code is executed inside Memory Analyzer on the objects in the snapshot
representing the heap dump. Code from the Java program which generated the dump is not
available and is not executed.
The following table lists some
common Java methods on the underlying Java objects used by Memory Analyzer to represent
objects in the heap dump.
</p>
<simpletable relcolwidth="2* 2* 2* 3*" id="method_prop">
<strow>
<stentry>${snapshot}</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/ISnapshot.html#method.summary" format="html">ISnapshot</xref></stentry>
<stentry>
<codeblock><xref href="../doc/org/eclipse/mat/snapshot/ISnapshot.html#getClasses()" format="html">getClasses()</xref></codeblock>
</stentry>
<stentry>a collection of all classes</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry>
<codeblock><xref href="../doc/org/eclipse/mat/snapshot/ISnapshot.html#getClassesByName(java.util.regex.Pattern,%20boolean)" format="html">getClassesByName(String name, boolean includeSubClasses)</xref></codeblock>
</stentry>
<stentry>a collection of classes</stentry>
</strow>
<strow>
<stentry>Class object</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IClass.html#method.summary" format="html">IClass</xref></stentry>
<stentry>
<codeblock><xref href="../doc/org/eclipse/mat/snapshot/model/IClass.html#hasSuperClass()" format="html">hasSuperClass()</xref></codeblock>
</stentry>
<stentry>
result is true if the class has a super class
</stentry>
</strow>
<strow>
<stentry />
<stentry />
<stentry>
<codeblock><xref href="../doc/org/eclipse/mat/snapshot/model/IClass.html#isArrayType()" format="html">isArrayType()</xref></codeblock>
</stentry>
<stentry>
the result is true if the class is an array type
</stentry>
</strow>
<strow>
<stentry>Any heap object</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#method.summary" format="html">IObject</xref></stentry>
<stentry>
<codeblock><xref href="../doc/org/eclipse/mat/snapshot/model/IObject.html#getObjectAddress()" format="html">getObjectAddress()</xref></codeblock>
</stentry>
<stentry>
The address of a snapshot object as a long integer
</stentry>
</strow>
<strow>
<stentry>Primitive array</stentry>
<stentry><xref href="../doc/org/eclipse/mat/snapshot/model/IPrimitiveArray.html#method.summary" format="html">IPrimitiveArray</xref></stentry>
<stentry>
<codeblock><xref href="../doc/org/eclipse/mat/snapshot/model/IPrimitiveArray.html#getValueAt(int)" format="html">getValueAt(int index)</xref></codeblock>
</stentry>
<stentry>a value from the array</stentry>
</strow>
<strow>
<stentry>Java primitive array, Java object array or Java list (returned from reflection)</stentry>
<stentry>[] or List</stentry>
<stentry>
<codeblock>get(int index)</codeblock>
</stentry>
<stentry>a value from the array or list</stentry>
</strow>
</simpletable>
</section>
<section>
<title>Array Access</title>
<p>Memory Analyzer 1.3 or later allows direct array style access of
primitive arrays and objects arrays from the snapshot, and Java arrays and Java Lists
obtained from reflective method calls. The notation is <codeph>[index]</codeph>.
The index is a zero-based integer. If the array is null or the index is out of range
then the result is null.
</p>
<p>Memory Analyzer 1.4 or later allows array range access as well using the notation
<codeph>[index1:index2]</codeph> where index1 and index2 are inclusive. If the values
are negative then they are treated as indexing from the end of the array, so -1
means the last entry. This means the whole array can be accessed as a list as
<codeph>[0:-1]</codeph>.
</p>
</section>
<section>
<title>Reading values from primitive arrays (from the heap dump)</title>
<codeblock>SELECT s[2] FROM int[] s WHERE (s.@length > 2)</codeblock>
<p>This method is for Memory Analyzer 1.3 or later.</p>
<codeblock>SELECT s.getValueAt(2) FROM int[] s WHERE (s.@length > 2)</codeblock>
<p>This method is for all versions of Memory Analyzer.
This reads the value of the element at index 2 from all int[] arrays which have at least 3 elements.
</p>
</section>
<section>
<title>Reading objects from object arrays (from the heap dump)</title>
<codeblock>SELECT s[2] FROM java.lang.Object[] s WHERE (s.@length > 2)</codeblock>
<p>This method is for Memory Analyzer 1.3 or later.
<codeph>s[2]</codeph>is an IObject so fields and Java bean properties can be accessed</p>
<codeblock>SELECT OBJECTS s[2] FROM java.lang.Object[] s</codeblock>
<p>This method is for Memory Analyzer 1.3 or later.
The <keyword>OBJECTS</keyword> converts the object to give a tree view rather than
table result. We do not need the <keyword>WHERE</keyword> clause as out of range
accesses return null and the <keyword>OBJECTS</keyword> skips nulls.</p>
<codeblock>SELECT OBJECTS s.@referenceArray.get(2) FROM java.lang.Object[] s WHERE (s.@length > 2)</codeblock>
<p>This method is for Memory Analyzer 1.1 or later.
This reads as a long address the element at index 2 from all Object[] arrays which have at least 3 elements and
converts them into objects.
</p>
<codeblock>SELECT OBJECTS s.getReferenceArray(2,1) FROM java.lang.Object[] s WHERE (s.@length > 2)</codeblock>
<p>This method is for Memory Analyzer 1.1 or later.
This reads as an array of long[] 1 element starting at index 2 from all Object[] arrays which have at least 3 elements and
converts the contents of those arrays into objects.
</p>
</section>
<section>
<title>Reading from Java arrays (Memory Analyzer internal objects)</title>
<codeblock>SELECT s.@GCRoots[2] FROM OBJECTS ${snapshot} s</codeblock>
<p>This method is for Memory Analyzer 1.3 or later.</p>
<codeblock>SELECT s.get(2) FROM OBJECTS ${snapshot} s WHERE s.@GCRoots.@length > 2</codeblock>
<p>This method is for all versions of Memory Analyzer.</p>
</section>
<section>
<title>Reading from Java Lists (Memory Analyzer internal objects)</title>
<codeblock>SELECT s.@GCRoots.subList(1,3)[1] FROM OBJECTS ${snapshot} s</codeblock>
<p>This method is for Memory Analyzer 1.3 or later.</p>
<codeblock>SELECT s.@GCRoots.subList(1,3).get(1) FROM OBJECTS ${snapshot} s</codeblock>
<p>This method is for all versions of Memory Analyzer.</p>
</section>
<section>
<title>Reading subarrays</title>
<codeblock>SELECT s, s.count, s.offset, s.value[s.offset],
s.value[s.offset:((s.offset + s.count) - 1)],
s.value[s.offset:((s.offset + 0) - 1)],
s.value[0:-1].subList(s.offset,(s.offset + 0)),
s.value[s.offset:-1].subList(0,s.count)
FROM java.lang.String s</codeblock>
<p>This method is for Memory Analyzer 1.4 or later.</p>
<p>This shows how the whole array can be converted to a list using <codeph>[0:-1]</codeph> and
that how using array range <codeph>[offset:offset+count-1]</codeph> gives perhaps unexpected results
when <codeph>offset=0</codeph> and <codeph>count=0</codeph> as instead of an empty list it gives the whole array.
Using <codeph>subList(offset,offet+count)</codeph> once the whole array has been converted to a list
gives the expected result.
</p>
</section>
<section>
<title>Collection access</title>
<codeblock>SELECT a[0] FROM java.util.ArrayList a</codeblock>
<p>Many of the standard collections classes are well known by Memory Analyzer.
The <xref href="../tasks/analyzingjavacollectionusage.dita">collection queries</xref>
allow analysis of lists, sets, queues, deques and maps.
This access is extended to OQL so if the collection queries work with a particular
collection or map then so does OQL.
</p>
<note>Collection and map access is still experimental and subject to change.</note>
<codeblock>SELECT a[0:-1] FROM java.util.ArrayList a</codeblock>
<p>If the array access syntax is used on a collection (list,set, queue, deque) object
then particular elements of the collection can be extracted. If subarray syntax
is used then that part of collection is converted to a list ready for further processing</p>
<codeblock>SELECT h[0].@key, h[0].@value FROM java.util.HashMap h</codeblock>
<p>If the array access syntax is used on a map then the map is converted to a list of
map entries. These can then be examined using the bean access syntax to retrieve the key
<codeph>h[0].@key</codeph> or value <codeph>h[0].@value</codeph>.
See <xref format="html" scope="peer" href="http://wiki.eclipse.org/MemoryAnalyzer/OQL#Map_processing">Wiki OQL Map processing</xref>
for more details of OQL with maps and collections.</p>
</section>
<section>
<title>Built-in OQL functions</title>
<codeblock>&lt;function&gt;( &lt;parameter&gt; )</codeblock>
<p>Built-in functions.</p>
<simpletable relcolwidth="2* 3*" id="oql_functions">
<strow>
<stentry>
<codeblock>toHex( number )</codeblock>
</stentry>
<stentry>Print the number as hexadecimal</stentry>
</strow>
<strow>
<stentry>
<codeblock>toString( object )</codeblock>
</stentry>
<stentry>
Returns the value of an object, e.g. the content
of a String etc.
</stentry>
</strow>
<strow>
<stentry>
<codeblock>dominators( object )</codeblock>
</stentry>
<stentry>
The objects immediately dominated by the object
</stentry>
</strow>
<strow>
<stentry>
<codeblock>outbounds( object )</codeblock>
</stentry>
<stentry>outbound referrer</stentry>
</strow>
<strow>
<stentry>
<codeblock>inbounds( object )</codeblock>
</stentry>
<stentry>inbound referrer</stentry>
</strow>
<strow>
<stentry>
<codeblock>classof( object )</codeblock>
</stentry>
<stentry>the class of the current object</stentry>
</strow>
<strow>
<stentry>
<codeblock>dominatorof( object )</codeblock>
</stentry>
<stentry>
the immediate dominator, -1 if none
</stentry>
</strow>
<strow>
<stentry>
<codeblock>eval( expression )</codeblock>
</stentry>
<stentry>
(Experimental in Memory Analyzer 1.4 or later) evaluates the argument and returns it.
Could be useful to allow array/method access to the result of a sub-select or
expression.
</stentry>
</strow>
</simpletable>
</section>
</refbody>
</reference>