jdk/src/share/classes/com/sun/tools/hat/resources/oqlhelp.html
author ohair
Wed, 26 May 2010 20:28:04 -0700
changeset 5551 327690766109
parent 5506 202f599c92aa
child 19222 19707772a06c
permissions -rw-r--r--
6956202: Fix a few missed rebranding issues, please contact lines etc. Reviewed-by: jjg, darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<!--
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
Copyright (c) 2005, 2006, 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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    select s from java.lang.String s where s.count >= 100
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 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    where /java/(s.value.toString())
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
    select heap.findClass("java.lang.System").props
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
<li>get number of fields of java.lang.String class 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    select heap.findClass("java.lang.String").fields.length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
<li> find the object whose object id is given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    select heap.findObject("0xf3800b58")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
<li>select all classes that have name pattern java.net.*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    select <a href="#filter">filter</a>(heap.classes(), "/java.net./(it.name)")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
<h3>functions on individual objects</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
<li><a href="#allocTrace">allocTrace(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
<li><a href="#classof">classof(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
<li><a href="#forEachReferrer">forEachReferrer(callback, jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
<li><a href="#identical">identical(o1, o2)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
<li><a href="#objectid">objectid(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
<li><a href="#reachables">reachables(jobject, excludedFields)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
<li><a href="#referrers">referrers(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
<li><a href="#referees">referees(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
<li><a href="#refers">refers(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
<li><a href="#root">root(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
<li><a href="#sizeof">sizeof(jobject)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
<li><a href="#toHtml">toHtml(obj)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
<a name="allocTrace"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
<h4>allocTrace function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
This returns allocation site trace of a given Java object if available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
allocTrace returns array of frame objects. Each frame object has the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
<li>className - name of the Java class whose method is running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
<li>methodName - name of the Java method running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
<li>methodSignature - signature of the Java method running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
<li>sourceFileName - name of source file of the Java class running in the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
<li>lineNumber - source line number within the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
<a name="classof"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
<h4>classof function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
Returns Class object of a given Java Object. The result object supports the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
following properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
<li>name - name of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
<li>superclass - Class object for super class (or null if java.lang.Object).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
<li>statics - name, value pairs for static fields of the Class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
<li>fields - array of field objects. Field objects have name, signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
<li>loader - ClassLoader object that loaded this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
<li>signers - signers that signed this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
<li>protectionDomain - protection domain to which this class belongs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
Class objects have the following methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
<li>isSubclassOf - tests whether given class is direct or indirect 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
subclass of this class or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
<li>isSuperclassOf - tests whether given Class is direct or indirect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
superclass of this class or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
<li>subclasses - returns array of direct and indirect subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
<li>superclasses - returns array of direct and indirect superclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
<li>show class name of each Reference type object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    select classof(o).name from instanceof java.lang.ref.Reference o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
<li>show all subclasses of java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    select heap.findClass("java.io.InputStream").subclasses()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
<li>show all superclasses of java.io.BufferedInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    select heap.findClass("java.io.BufferedInputStream").superclasses()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
<a name="forEachReferrer"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
<h4>forEachReferrer function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
calls a callback function for each referrer of a given Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
<a name="identical"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
<h4>identical function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
Returns whether two given Java objects are identical or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    select identical(heap.findClass("Foo").statics.bar, heap.findClass("AnotherClass").statics.bar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
<a name="objectid"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
<h4>objectid function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
Returns String id of a given Java object. This id can be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
<a href="#findObject">heap.findObject</a> and may also be used to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
objects for identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    select objectid(o) from java.lang.Object o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
<a name="reachables"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
<h4>reachables function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
Returns an array of Java objects that are transitively referred from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
given Java object. Optionally accepts a second parameter that is comma
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
separated field names to be excluded from reachability computation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
Fields are written in class_name.field_name pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
Examples: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
<li>print all reachable objects from each Properties instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    select reachables(p) from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
<li>print all reachables from each java.net.URL but omit the objects reachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
via the fields specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    select reachables(u, 'java.net.URL.handler') from java.net.URL u
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
<a name="referrers"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
<h4>referrers function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
Returns an enumeration of Java objects that hold reference to a given Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
<li> print number of referrers for each java.lang.Object instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    select count(referrers(o)) from java.lang.Object o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
<li>print referrers for each java.io.File object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    select referrers(f) from java.io.File f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
<li>print URL objects only if referred by 2 or more 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    select u from java.net.URL u where count(referrers(u)) > 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
<a name="referees"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
<h4>referees function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
Returns an array of Java objects to which the given Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
object directly refers to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
Example: to print all static reference fields of java.io.File class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    select referees(<a href="#findClass">heap.findClass</a>("java.io.File"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
<a name="refers"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
<h4>refers function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
Returns whether first Java object refers to second Java object or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
<a name="root"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
<h4>root function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
If given object is a member of root set of objects, this function returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
a descriptive <a href="#rootobj">Root object</a> describing why it is so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
If given object is not a root, then this function returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
<a name="sizeof"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
<h4>sizeof function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
Returns size of the given Java object in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
Example: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    select sizeof(o) from [I o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
<a name="toHtml"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
<h4>toHtml function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
Returns HTML string for the given Java object. Note that this is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
automatically for objects selected by select expression. But, it may be useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
to print more complex output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
Example: print hyperlink in bold font weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    select "&lt;b&gt;" + toHtml(o) + "&lt;/b&gt;" from java.lang.Object o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
<h3>Selecting multiple values</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
Multiple values can be selected using JavaScript object literals or arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
Example: show name and thread for each thread object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    select { name: t.name? t.name.toString() : "null", thread: t } 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    from instanceof java.lang.Thread t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
<h3>array/iterator/enumeration manipulation functions</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
These functions accept an array/iterator/enumeration and an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
expression string [or a callback function] as input. These functions iterate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
the array/iterator/enumeration and apply the expression (or function) on 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
each element. Note that JavaScript objects are associative arrays. So, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
these functions may also be used with arbitrary JavaScript objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
<li><a href="#concat">concat(array1/enumeration1, array2/enumeration2)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
<li><a href="#contains">contains(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
<li><a href="#count">count(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
<li><a href="#filter">filter(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
<li><a href="#length">length(array/enumeration)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
<li><a href="#map">map(array/enumeration, expression)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
<li><a href="#max">max(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
<li><a href="#min">min(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
<li><a href="#sort">sort(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
<li><a href="#sum">sum(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
<li><a href="#toArray">toArray(array/enumeration)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
<li><a href="#unique">unique(array/enumeration, [expression])</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
<a name="concat"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
<h4>concat function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
Concatenates two arrays or enumerations (i.e., returns composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
enumeration).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
<a name="contains"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
<h4>contains function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
Returns whether the given array/enumeration contains an element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
the given boolean expression specified in code. The code evaluated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
can refer to the following built-in variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
Example: select all Properties objects that are referred by 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
some static field some class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    select p from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    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
   521
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
<a name="count"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
<h4>count function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
count function returns the count of elements of the input array/enumeration 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
that satisfy the given boolean expression. The boolean expression code can 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
refer to the following built-in variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
Example: print number of classes that have specific name pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    select count(<a href="#classes">heap.classes()</a>, "/java.io./(it.name)")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
<a name="filter"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
<h4>filter function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
filter function returns an array/enumeration that contains elements 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
of the input array/enumeration that satisfy the given boolean 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
expression. The boolean expression code can refer to the following built-in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
<li>result -> result array/enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
<li>show all classes that have java.io.* name pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    select filter(<a href="#classes">heap.classes</a>(), "/java.io./(it.name)")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
<li> show all referrers of URL object where the referrer is not from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
java.net package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    select filter(<a href="#referrers">referrers</a>(u), "! /java.net./(<a href="#classof">classof</a>(it).name)")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    from java.net.URL u
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
<a name="length"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
<h4>length function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
length function returns number of elements of an array/enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
<a name="map"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
<h4>map function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
Transforms the given array/enumeration by evaluating given code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
on each element. The code evaluated can refer to the following built-in 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
<li>it -> currently visited element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
<li>index -> index of the current element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
<li>array -> array/enumeration that is being iterated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
<li>result -> result array/enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
map function returns an array/enumeration of values created by repeatedly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
calling code on each element of input array/enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
Example: show all static fields of java.io.File with name and value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    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
   602
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
<a name="max"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
<h4>max function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
returns the maximum element of the  given array/enumeration. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
Optionally accepts code expression to compare elements of the array. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
By default numerical comparison is used. The comparison expression can 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
use the following built-in variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
<li>lhs -> left side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
<li>rhs -> right side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
<li>find the maximum length of any String instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    select max(map(heap.objects('java.lang.String', false), 'it.count'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
<li>find string instance that has the maximum length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    select max(heap.objects('java.lang.String'), 'lhs.count > rhs.count')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
<a name="min"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
<h4>min function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
returns the minimum element of the  given array/enumeration. Optionally 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
accepts code expression to compare elements of the array. By default numerical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
comparison is used. The comparison expression can use the following built-in 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
<li>lhs -> left side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
<li>rhs -> right side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
<li>find the minimum size of any Vector instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    select min(map(heap.objects('java.util.Vector', false), 'it.elementData.length'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
<li>find Vector instance that has the maximum length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    select min(heap.objects('java.util.Vector'), 'lhs.elementData.length < rhs.elementData.length')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
<a name="sort"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
<h4>sort function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
sorts given array/enumeration. Optionally accepts code expression to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
compare elements of the array. By default numerical comparison is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
The comparison expression can use the following built-in variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
<li>lhs -> left side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
<li>rhs -> right side element for comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
<li> print all char[] objects in the order of size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    select sort(<a href="#objects">heap.objects</a>('[C'), '<a href="#sizeof">sizeof</a>(lhs) - sizeof(rhs)')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
<li> print all char[] objects in the order of size but print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
size as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    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
   684
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
<a name="sum"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
<h4>sum function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
This function returns the sum of all the elements of the given input array or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
enumeration. Optionally, accepts an expression as second param. This is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
to map the input elements before summing those.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
Example: return sum of sizes of the reachable objects from each Properties object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    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
   699
    from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    // or omit the map as in ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    select sum(<a href="#reachables">reachables</a>(p), '<a href="#sizeof">sizeof</a>(it)') 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    from java.util.Properties p
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
<a name="toArray"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
<h4>toArray function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
This function returns an array that contains elements of the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
array/enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
<a name="unique"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
<h4>unique function</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
This function returns an array/enumeration containing unique elements of the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
given input array/enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
Example: select unique char[] instances referenced from Strings. Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
more than one String instance can share the same char[] for the content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
   // number of unique char[] instances referenced from any String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
   select count(unique(map(heap.objects('java.lang.String'), 'it.value')))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
   // total number of Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
   select count(heap.objects('java.lang.String'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
<h3>More complex examples</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
<h4>Print histogram of each class loader and number of classes loaded by it</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
   select <a href="#map">map</a>(<a href="#sort">sort</a>(map(heap.objects('java.lang.ClassLoader'), 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
   '{ loader: it, count: it.classes.elementCount }'), 'lhs.count < rhs.count'),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
   'toHtml(it) + "&lt;br&gt;"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
The above query uses the fact that, <b>java.lang.ClassLoader</b> has a private 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
field called <b>classes</b> of type <b>java.util.Vector</b> and Vector has a 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
private field named <b>elementCount</b> that is number of elements in the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
vector. We select multiple values (loader, count) using JavaScript object 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
literal and map function. We sort the result by count (i.e., number of classes 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
loaded) using sort function with comparison expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
<h4>Show parent-child chain for each class loader instance</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
   select <a href="#map">map</a>(heap.objects('java.lang.ClassLoader'),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
      function (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         var res = '';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         while (it != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            res += toHtml(it) + "-&gt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            it = it.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         res += "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         return res + "&lt;br&gt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      })
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
Note that we use <b>parent</b> field of <b>java.lang.ClassLoader</b> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
and walk until parent is null using the callback function to map call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
<h4>Printing value of all System properties</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
   select <a href="#map">map</a>(<a href="#filter">filter(<a href="#findClass">heap.findClass</a>('java.lang.System').props.table, 'it != null'), 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            function (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                var res = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                while (it != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    res += it.key.value.toString() + '=' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                           it.value.value.toString() + '&lt;br&gt;';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    it = it.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
The above query uses the following facts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
<li>java.lang.System has static field by name 'props' of type java.util.Properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
<li>java.util.Properties has field by 'table' of type java.util.Hashtable$Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
(this field is inherited from java.util.Hashtable). This is the hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
buckets array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
<li>java.util.Hashtable$Entry has 'key', 'value' and 'next' fields. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
entry points the next entry (or null) in the same hashtable bucket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
<li>java.lang.String class has 'value' field of type char[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
<b>Note that this query (and many other queries) may not be stable - because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
private fields of Java platform classes may be modified/removed without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
notification! (implementation detail)</b>. But, using such queries on user 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
classes may be safe - given that user has the control over the classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
</body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
</html>