jdk/src/jdk.dev/share/classes/com/sun/tools/hat/resources/oqlhelp.html
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23010 jdk/src/share/classes/com/sun/tools/hat/resources/oqlhelp.html@6dadb192ad81
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<!--
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 19222
diff changeset
     2
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
5551
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    21
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    22
or visit www.oracle.com if you need additional information or have any
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    23
questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
<head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
<style>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
.key  { color: red; font-weight: bold }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
</style>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
<title>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
Object Query Language (OQL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
</title>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
</head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
<body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
<h1>Object Query Language (OQL)</h1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
OQL is SQL-like query language to query Java heap. OQL allows to filter/select information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
wanted from Java heap. While pre-defined queries such as "show all instances of class X"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
are already supported by HAT, OQL adds more flexibility. OQL is based on JavaScript expression
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
OQL query is of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
         <span class="key">select</span> &lt;JavaScript expression to select&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
         [ <span class="key">from</span> [<span class="key">instanceof</span>] &lt;class name&gt; &lt;identifier&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         [ <span class="key">where</span> &lt;JavaScript boolean expression to filter&gt; ] ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
where class name is fully qualified Java class name (example: java.net.URL) or array class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
[C is char array name, [Ljava.io.File; is name of java.io.File[] and so on. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
Note that fully qualified class name does not always uniquely identify a 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
Java class at runtime. There may be more than one Java class with the same 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
name but loaded by different loaders. So, class name is permitted to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
id string of the class object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
If <span class="key">instanceof</span> keyword is used, subtype objects are selected. If this 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
keyword is not specified, only the instances of exact class specified are selected. Both
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
<span class="key">from</span> and <span class="key">where</span> clauses are optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
In <span class="key">select</span> and (optional) <span class="key">where</span> clauses, the expression 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
used in JavaScript expression. Java heap objects are wrapped as convenient script objects so that 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
fields may be accessed in natural syntax. For example, Java fields can be accessed with obj.field_name 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
syntax and array elements can be accessed with array[index] syntax. Each Java object selected is 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
bound to a JavaScript variable of the identifier name specified in <span class="key">from</span> clause.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
<h2>OQL Examples</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
<li>select all Strings of length 100 or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
    82
    select s from java.lang.String s where s.value.length >= 100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
<li>select all int arrays of length 256 or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    select a from [I a where a.length >= 256
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
<li>show content of Strings that match a regular expression
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    select s.value.toString() from java.lang.String s 
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
    95
    where /java/.test(s.value.toString())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
<li>show path value of all File objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
<code</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    select file.path.value.toString() from java.io.File file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
<li>show names of all ClassLoader classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    select <a href="#classof">classof</a>(cl).name 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    from instanceof java.lang.ClassLoader cl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
<li>show instances of the Class identified by given id string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    select o from instanceof 0xd404b198 o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
Note that 0xd404b198 is id of a Class (in a session). This is found by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
looking at the id shown in that class's page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
<h2>OQL built-in objects, functions</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
<h3>heap object</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
The <b>heap</b> built-in object supports the following methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
<ul> 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
<li><b>heap.forEachClass</b> -- calls a callback function for each Java Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    heap.forEachClass(callback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
<li><b>heap.forEachObject</b> -- calls a callback function for each Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    heap.forEachObject(callback, clazz, includeSubtypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
<code>clazz</code> is the class whose instances are selected. If not specified, defaults to java.lang.Object. <code>includeSubtypes</code> is a boolean flag 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
that specifies whether to include subtype instances or not. Default value of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
this flag is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
<a name="findClass"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
<li><b>heap.findClass</b> -- finds Java Class of given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    heap.findClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
where <code>className</code> is name of the class to find. The resulting Class 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
object has following properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
<li>name - name of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
<li>superclass - Class object for super class (or null if java.lang.Object).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
<li>statics - name, value pairs for static fields of the Class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
<li>fields - array of field objects. field object has name, signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
<li>loader - ClassLoader object that loaded this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
<li>signers - signers that signed this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
<li>protectionDomain - protection domain to which this class belongs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
Class objects have the following methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
<li>isSubclassOf - tests whether given class is direct or indirect 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
subclass of this class or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
<li>isSuperclassOf - tests whether given Class is direct or indirect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
superclass of this class or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
<li>subclasses - returns array of direct and indirect subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
<li>superclasses - returns array of direct and indirect superclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
<a name="findObject"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
<li><b>heap.findObject</b> -- finds object from given object id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    heap.findObject(stringIdOfObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
<a name="classes"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
<li><b>heap.classes</b> -- returns an enumeration of all Java classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
<a name="objects"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
<li><b>heap.objects</b> -- returns an enumeration of Java objects 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    heap.objects(clazz, [includeSubtypes], [filter])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
<code>clazz</code> is the class whose instances are selected. If not specified, defaults to java.lang.Object. <code>includeSubtypes</code> is a boolean flag 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
that specifies whether to include subtype instances or not. Default value of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
this flag is true. This method accepts an optional filter expression to filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
the result set of objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
<a name="finalizables"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
<li><b>heap.finalizables</b> -- returns an enumeration of Java objects that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
pending to be finalized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
<li><b>heap.livepaths</b> -- return an array of paths by which a given object 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
is alive. This method accepts optional second parameter that is a boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
flag. This flag tells whether to include paths with weak reference(s) or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
By default, paths with weak reference(s) are not included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    select heap.livepaths(s) from java.lang.String s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
Each element of this array itself is another array. The later array is 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
contains an objects that are in the 'reference chain' of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
<li><b>heap.roots</b> -- returns an Enumeration of Roots of the heap. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
<a name="rootobj"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
Each Root object has the following properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
<li>id - String id of the object that is referred by this root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
<li>type - descriptive type of Root (JNI Global, JNI Local, Java Static etc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
<li>description - String description of the Root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
<li>referrer - Thread Object or Class object that is responsible for this root or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
<li>access static field 'props' of class java.lang.System
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    select heap.findClass("java.lang.System").statics.props
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
<li>get number of fields of java.lang.String class 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    select heap.findClass("java.lang.String").fields.length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
<li> find the object whose object id is given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    select heap.findObject("0xf3800b58")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
<li>select all classes that have name pattern java.net.*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   239
    select <a href="#filter">filter</a>(heap.classes(), "/java.net./.test(it.name)")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
<h3>functions on individual objects</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
<li><a href="#allocTrace">allocTrace(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
<li><a href="#classof">classof(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
<li><a href="#forEachReferrer">forEachReferrer(callback, jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
<li><a href="#identical">identical(o1, o2)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
<li><a href="#objectid">objectid(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
<li><a href="#reachables">reachables(jobject, excludedFields)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
<li><a href="#referrers">referrers(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
<li><a href="#referees">referees(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
<li><a href="#refers">refers(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
<li><a href="#root">root(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
<li><a href="#sizeof">sizeof(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
<li><a href="#toHtml">toHtml(obj)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
<a name="allocTrace"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
<h4>allocTrace function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
This returns allocation site trace of a given Java object if available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
allocTrace returns array of frame objects. Each frame object has the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
<li>className - name of the Java class whose method is running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
<li>methodName - name of the Java method running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
<li>methodSignature - signature of the Java method running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
<li>sourceFileName - name of source file of the Java class running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
<li>lineNumber - source line number within the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
<a name="classof"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
<h4>classof function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
Returns Class object of a given Java Object. The result object supports the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
following properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
<li>name - name of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
<li>superclass - Class object for super class (or null if java.lang.Object).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
<li>statics - name, value pairs for static fields of the Class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
<li>fields - array of field objects. Field objects have name, signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
<li>loader - ClassLoader object that loaded this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
<li>signers - signers that signed this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
<li>protectionDomain - protection domain to which this class belongs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
Class objects have the following methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
<li>isSubclassOf - tests whether given class is direct or indirect 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
subclass of this class or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
<li>isSuperclassOf - tests whether given Class is direct or indirect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
superclass of this class or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
<li>subclasses - returns array of direct and indirect subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
<li>superclasses - returns array of direct and indirect superclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
<li>show class name of each Reference type object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    select classof(o).name from instanceof java.lang.ref.Reference o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
<li>show all subclasses of java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    select heap.findClass("java.io.InputStream").subclasses()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
<li>show all superclasses of java.io.BufferedInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    select heap.findClass("java.io.BufferedInputStream").superclasses()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
<a name="forEachReferrer"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
<h4>forEachReferrer function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
calls a callback function for each referrer of a given Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
<a name="identical"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
<h4>identical function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
Returns whether two given Java objects are identical or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    select identical(heap.findClass("Foo").statics.bar, heap.findClass("AnotherClass").statics.bar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
<a name="objectid"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
<h4>objectid function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
Returns String id of a given Java object. This id can be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
<a href="#findObject">heap.findObject</a> and may also be used to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
objects for identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    select objectid(o) from java.lang.Object o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
<a name="reachables"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
<h4>reachables function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
Returns an array of Java objects that are transitively referred from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
given Java object. Optionally accepts a second parameter that is comma
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
separated field names to be excluded from reachability computation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
Fields are written in class_name.field_name pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
Examples: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
<li>print all reachable objects from each Properties instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    select reachables(p) from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
<li>print all reachables from each java.net.URL but omit the objects reachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
via the fields specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    select reachables(u, 'java.net.URL.handler') from java.net.URL u
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
<a name="referrers"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
<h4>referrers function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
Returns an enumeration of Java objects that hold reference to a given Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
<li> print number of referrers for each java.lang.Object instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    select count(referrers(o)) from java.lang.Object o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
<li>print referrers for each java.io.File object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    select referrers(f) from java.io.File f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
<li>print URL objects only if referred by 2 or more 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    select u from java.net.URL u where count(referrers(u)) > 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
<a name="referees"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
<h4>referees function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
Returns an array of Java objects to which the given Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
object directly refers to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
Example: to print all static reference fields of java.io.File class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    select referees(<a href="#findClass">heap.findClass</a>("java.io.File"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
<a name="refers"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
<h4>refers function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
Returns whether first Java object refers to second Java object or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
<a name="root"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
<h4>root function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
If given object is a member of root set of objects, this function returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
a descriptive <a href="#rootobj">Root object</a> describing why it is so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
If given object is not a root, then this function returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
<a name="sizeof"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
<h4>sizeof function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
Returns size of the given Java object in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
Example: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    select sizeof(o) from [I o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
<a name="toHtml"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
<h4>toHtml function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
Returns HTML string for the given Java object. Note that this is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
automatically for objects selected by select expression. But, it may be useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
to print more complex output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
Example: print hyperlink in bold font weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    select "&lt;b&gt;" + toHtml(o) + "&lt;/b&gt;" from java.lang.Object o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
<h3>Selecting multiple values</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
Multiple values can be selected using JavaScript object literals or arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
Example: show name and thread for each thread object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    select { name: t.name? t.name.toString() : "null", thread: t } 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    from instanceof java.lang.Thread t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
<h3>array/iterator/enumeration manipulation functions</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
These functions accept an array/iterator/enumeration and an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
expression string [or a callback function] as input. These functions iterate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
the array/iterator/enumeration and apply the expression (or function) on 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
each element. Note that JavaScript objects are associative arrays. So, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
these functions may also be used with arbitrary JavaScript objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
<li><a href="#concat">concat(array1/enumeration1, array2/enumeration2)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
<li><a href="#contains">contains(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
<li><a href="#count">count(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
<li><a href="#filter">filter(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
<li><a href="#length">length(array/enumeration)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
<li><a href="#map">map(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
<li><a href="#max">max(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
<li><a href="#min">min(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
<li><a href="#sort">sort(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
<li><a href="#sum">sum(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
<li><a href="#toArray">toArray(array/enumeration)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
<li><a href="#unique">unique(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
<a name="concat"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
<h4>concat function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
Concatenates two arrays or enumerations (i.e., returns composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
enumeration).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
<a name="contains"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
<h4>contains function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
Returns whether the given array/enumeration contains an element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
the given boolean expression specified in code. The code evaluated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
can refer to the following built-in variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
Example: select all Properties objects that are referred by 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
some static field some class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    select p from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    where contains(<a href="#referrers">referrers</a>(p), "<a href="#classof">classof</a>(it).name == 'java.lang.Class'")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
<a name="count"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
<h4>count function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
count function returns the count of elements of the input array/enumeration 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
that satisfy the given boolean expression. The boolean expression code can 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
refer to the following built-in variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
Example: print number of classes that have specific name pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   538
    select count(<a href="#classes">heap.classes()</a>, "/java.io./.test(it.name)")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
<a name="filter"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
<h4>filter function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
filter function returns an array/enumeration that contains elements 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
of the input array/enumeration that satisfy the given boolean 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
expression. The boolean expression code can refer to the following built-in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
<li>result -> result array/enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
<li>show all classes that have java.io.* name pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   561
    select filter(<a href="#classes">heap.classes</a>(), "/java.io./.test(it.name)")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
<li> show all referrers of URL object where the referrer is not from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
java.net package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   568
    select filter(<a href="#referrers">referrers</a>(u), "! /java.net./.test(<a href="#classof">classof</a>(it).name)")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    from java.net.URL u
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
<a name="length"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
<h4>length function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
length function returns number of elements of an array/enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
<a name="map"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
<h4>map function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
Transforms the given array/enumeration by evaluating given code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
on each element. The code evaluated can refer to the following built-in 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
<li>result -> result array/enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
map function returns an array/enumeration of values created by repeatedly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
calling code on each element of input array/enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
Example: show all static fields of java.io.File with name and value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    select map(<a href="#findClass">heap.findClass</a>("java.io.File").statics, "index + '=' + <a href="#toHtml">toHtml</a>(it)")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
<a name="max"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
<h4>max function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
returns the maximum element of the  given array/enumeration. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
Optionally accepts code expression to compare elements of the array. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
By default numerical comparison is used. The comparison expression can 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
use the following built-in variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
<li>lhs -> left side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
<li>rhs -> right side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
<li>find the maximum length of any String instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   621
    select max(map(heap.objects('java.lang.String', false), 'it.value.length'))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
<li>find string instance that has the maximum length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   627
    select max(heap.objects('java.lang.String'), 'lhs.value.length > rhs.value.length')
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
<a name="min"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
<h4>min function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
returns the minimum element of the  given array/enumeration. Optionally 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
accepts code expression to compare elements of the array. By default numerical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
comparison is used. The comparison expression can use the following built-in 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
<li>lhs -> left side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
<li>rhs -> right side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
<li>find the minimum size of any Vector instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    select min(map(heap.objects('java.util.Vector', false), 'it.elementData.length'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
<li>find Vector instance that has the maximum length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    select min(heap.objects('java.util.Vector'), 'lhs.elementData.length < rhs.elementData.length')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
<a name="sort"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
<h4>sort function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
sorts given array/enumeration. Optionally accepts code expression to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
compare elements of the array. By default numerical comparison is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
The comparison expression can use the following built-in variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
<li>lhs -> left side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
<li>rhs -> right side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
<li> print all char[] objects in the order of size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    select sort(<a href="#objects">heap.objects</a>('[C'), '<a href="#sizeof">sizeof</a>(lhs) - sizeof(rhs)')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
<li> print all char[] objects in the order of size but print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
size as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    select <a href="#map">map</a>(sort(<a href="#objects">heap.objects</a>('[C'), '<a href="#sizeof">sizeof</a>(lhs) - sizeof(rhs)'), '{ size: sizeof(it), obj: it }')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
<a name="sum"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
<h4>sum function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
This function returns the sum of all the elements of the given input array or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
enumeration. Optionally, accepts an expression as second param. This is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
to map the input elements before summing those.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
Example: return sum of sizes of the reachable objects from each Properties object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    select sum(<a href="#map">map</a>(<a href="#reachables">reachables</a>(p), '<a href="#sizeof">sizeof</a>(it)')) 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    // or omit the map as in ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    select sum(<a href="#reachables">reachables</a>(p), '<a href="#sizeof">sizeof</a>(it)') 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
<a name="toArray"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
<h4>toArray function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
This function returns an array that contains elements of the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
array/enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
<a name="unique"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
<h4>unique function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
This function returns an array/enumeration containing unique elements of the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
given input array/enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
Example: select unique char[] instances referenced from Strings. Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
more than one String instance can share the same char[] for the content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
   // number of unique char[] instances referenced from any String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
   select count(unique(map(heap.objects('java.lang.String'), 'it.value')))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
   // total number of Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
   select count(heap.objects('java.lang.String'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
<h3>More complex examples</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
<h4>Print histogram of each class loader and number of classes loaded by it</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
   select <a href="#map">map</a>(<a href="#sort">sort</a>(map(heap.objects('java.lang.ClassLoader'), 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
   '{ loader: it, count: it.classes.elementCount }'), 'lhs.count < rhs.count'),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
   'toHtml(it) + "&lt;br&gt;"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
The above query uses the fact that, <b>java.lang.ClassLoader</b> has a private 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
field called <b>classes</b> of type <b>java.util.Vector</b> and Vector has a 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
private field named <b>elementCount</b> that is number of elements in the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
vector. We select multiple values (loader, count) using JavaScript object 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
literal and map function. We sort the result by count (i.e., number of classes 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
loaded) using sort function with comparison expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
<h4>Show parent-child chain for each class loader instance</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
   select <a href="#map">map</a>(heap.objects('java.lang.ClassLoader'),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
      function (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         var res = '';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         while (it != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            res += toHtml(it) + "-&gt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            it = it.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         res += "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         return res + "&lt;br&gt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      })
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
Note that we use <b>parent</b> field of <b>java.lang.ClassLoader</b> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
and walk until parent is null using the callback function to map call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
<h4>Printing value of all System properties</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
<code>
19222
19707772a06c 8022483: Nashorn compatibility issues in jhat's OQL feature
sundar
parents: 5551
diff changeset
   777
   select <a href="#map">map</a>(<a href="#filter">filter(<a href="#findClass">heap.findClass</a>('java.lang.System').statics.props.table, 'it != null'), 
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            function (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                var res = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                while (it != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    res += it.key.value.toString() + '=' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                           it.value.value.toString() + '&lt;br&gt;';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    it = it.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
The above query uses the following facts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
<li>java.lang.System has static field by name 'props' of type java.util.Properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
<li>java.util.Properties has field by 'table' of type java.util.Hashtable$Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
(this field is inherited from java.util.Hashtable). This is the hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
buckets array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
<li>java.util.Hashtable$Entry has 'key', 'value' and 'next' fields. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
entry points the next entry (or null) in the same hashtable bucket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
<li>java.lang.String class has 'value' field of type char[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
<b>Note that this query (and many other queries) may not be stable - because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
private fields of Java platform classes may be modified/removed without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
notification! (implementation detail)</b>. But, using such queries on user 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
classes may be safe - given that user has the control over the classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
</body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
</html>