6125N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. 6125N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6125N/A * This code is free software; you can redistribute it and/or modify it 6125N/A * under the terms of the GNU General Public License version 2 only, as 6125N/A * published by the Free Software Foundation. Oracle designates this 6125N/A * particular file as subject to the "Classpath" exception as provided 6125N/A * by Oracle in the LICENSE file that accompanied this code. 6125N/A * This code is distributed in the hope that it will be useful, but WITHOUT 6125N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6125N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6125N/A * version 2 for more details (a copy is included in the LICENSE file that 6125N/A * You should have received a copy of the GNU General Public License version 6125N/A * 2 along with this work; if not, write to the Free Software Foundation, 6125N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6125N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6125N/A * or visit www.oracle.com if you need additional information or have any 6125N/A * The Original Code is HAT. The Initial Developer of the 6125N/A * Original Code is Bill Foote, with contributions from others 6125N/A * This is JavaScript interface for heap analysis using HAT 6125N/A * (Heap Analysis Tool). HAT classes are refered from 6125N/A * this file. In particular, refer to classes in hat.model 6125N/A * HAT model objects are wrapped as convenient script objects so that 6125N/A * fields may be accessed in natural syntax. For eg. Java fields can be 6125N/A * accessed with obj.field_name syntax and array elements can be accessed 6125N/A * with array[index] syntax. 6125N/A// returns an enumeration that wraps elements of 6125N/A// the input enumeration elements. 6125N/A// returns an enumeration that filters out elements 6125N/A// of input enumeration using the filter function. // user may not have called hasMoreElements? throw "NoSuchElementException";
// enumeration that has no elements .. throw "NoSuchElementException";
return obj[
'wrapped-object'];
// return whether given class is subclass of this class or not // return whether given class is superclass of this class or not // includes direct and indirect superclasses * Returns an array containing subclasses of this class. * @param indirect should include indirect subclasses or not. // Script wrapper for HAT model objects, values. // wraps a Java value as appropriate for script object // map primitive values to closest JavaScript primitives // wrap Java object as script object // wrap Java object with appropriate script object // HAT Java model object wrapper. Handles all cases // FIXME: Do I need this? or can I assume that these would // have been resolved already? // returns wrapper for Java instances // instance fields can be accessed in natural syntax return name ==
'class' ||
name ==
'toString' ||
name ==
'wrapped-object';
}
else if (
name ==
'toString') {
}
else if (
name ==
'wrapped-object') {
// return wrapper for Java Class objects // to access static fields of given Class cl, use // cl.statics.<static-field-name> syntax this[
'wrapped-object'] =
jclass;
// returns wrapper for Java object arrays // array elements can be accessed in natural syntax // also, 'length' property is supported. return (
typeof(
name) ==
'number' &&
name ==
'toString' ||
name ==
'wrapped-object';
if (
typeof(
name) ==
'number' &&
}
else if (
name ==
'length') {
}
else if (
name ==
'class') {
}
else if (
name ==
'toString') {
}
else if (
name ==
'wrapped-object') {
// returns wrapper for Java primitive arrays // array elements can be accessed in natural syntax // also, 'length' property is supported. return (
typeof(
name) ==
'number' &&
name ==
'toString' ||
name ==
'wrapped-object';
if (
typeof(
name) ==
'number' &&
}
else if (
name ==
'toString') {
}
else if (
name ==
'wrapped-object') {
}
else if (
name ==
'class') {
// unwrap a script object to corresponding HAT object * readHeapDump parses a heap dump file and returns script wrapper object. * @param file Heap dump file name * @param stack flag to tell if allocation site traces are available * @param refs flag to tell if backward references are needed or not * @param debug debug level for HAT * @return heap as a JavaScript object // default value of debug is 0 // by default, we assume no stack traces // by default, backward references are resolved // wrap Snapshot as convenient script object * The result object supports the following methods: * forEachClass -- calls a callback for each Java Class * forEachObject -- calls a callback for each Java object * findClass -- finds Java Class of given name * findObject -- finds object from given object id * objects -- returns all objects of given class as an enumeration * classes -- returns all classes in the heap as an enumeration * reachables -- returns all objects reachable from a given object * livepaths -- returns an array of live paths because of which an * describeRef -- returns description for a reference from a 'from' * object to a 'to' object. }
else if (
type ==
"object") {
// return heap as a script object with useful methods. * Class iteration: Calls callback function for each * Java Class in the heap. Default callback function * is 'print'. If callback returns true, the iteration * @param callback function to be called. * Returns an Enumeration of all roots. * Returns an Enumeration for all Java classes. * Object iteration: Calls callback function for each * Java Object in the heap. Default callback function * is 'print'.If callback returns true, the iteration * @param callback function to be called. * @param clazz Class whose objects are retrieved. * Optional, default is 'java.lang.Object' * @param includeSubtypes flag to tell if objects of subtypes * are included or not. optional, default is true. * Returns an enumeration of Java objects in the heap. * @param clazz Class whose objects are retrieved. * Optional, default is 'java.lang.Object' * @param includeSubtypes flag to tell if objects of subtypes * are included or not. optional, default is true. * @param where (optional) filter expression or function to * filter the objects. The expression has to return true * to include object passed to it in the result array. * Built-in variable 'it' refers to the current object in if (
typeof(
where) ==
'string') {
* Find Java Class of given name. * Find Java Object from given object id * @param id object id as string * Returns an enumeration of objects in the finalizer * queue waiting to be finalized. * Returns an array that contains objects referred from the * given Java object directly or indirectly (i.e., all * transitively referred objects are returned). * @param jobject Java object whose reachables are returned. * Returns array of paths of references by which the given * Java object is live. Each path itself is an array of * objects in the chain of references. Each path supports * toHtml method that returns html description of the path. * @param jobject Java object whose live paths are returned * @param weak flag to indicate whether to include paths with * weak references or not. default is false. // compute path array from refChain return (
typeof(
name) ==
'number' &&
if (
typeof(
name) ==
'number' &&
}
else if (
name ==
'length') {
}
else if (
name ==
'toHtml') {
}
else if (
name ==
'toString') {
* Return description string for reference from 'from' object * @param from source Java object * @param to destination Java object * Returns allocation site trace (if available) of a Java object * @param jobject object whose allocation site trace is returned * Returns Class object for given Java object * @param jobject object whose Class object is returned * Find referers (a.k.a in-coming references). Calls callback * for each referrer of the given Java object. If the callback * returns true, the iteration is stopped. * @param callback function to call for each referer * @param jobject object whose referers are retrieved * Compares two Java objects for object identity. * @param o1, o2 objects to compare for identity * Returns Java object id as string * @param jobject object whose id is returned * Prints allocation site trace of given object * @param jobject object whose allocation site trace is returned print(
"allocation site trace unavailable for " +
if (
src ==
null)
src =
'<unknown source>';
* Returns an enumeration of referrers of the given Java object. * @param jobject Java object whose referrers are returned. * Returns an array that contains objects referred from the * @param jobject Java object whose referees are returned. * Returns an array that contains objects referred from the * given Java object directly or indirectly (i.e., all * transitively referred objects are returned). * @param jobject Java object whose reachables are returned. * @param excludes optional comma separated list of fields to be * removed in reachables computation. Fields are * written as class_name.field_name form. }
else if (
typeof(
excludes) ==
'string') {
* Returns whether 'from' object refers to 'to' object or not. * @param from Java object that is source of the reference. * @param to Java object that is destination of the reference. * If rootset includes given jobject, return Root * object explanining the reason why it is a root. * @param jobject object whose Root is returned * Returns size of the given Java object * @param jobject object whose size is returned * Returns String by replacing Unicode chars and * HTML special chars (such as '<') with entities. * @param str string to be encoded * Returns HTML string for the given object. * @param obj object for which HTML string is returned. return "<a href='/class/" +
id +
"'>class " +
name +
"</a>";
return "<a href='/object/" +
id +
"'>" +
// script wrapped Java object // special case for enumeration }
else if (
obj instanceof Array) {
// if the object has a toHtml function property // JavaScript primitive value * and expression String or function. These functions iterate each // private function to wrap an Iterator as an Enumeration }
else if (
obj instanceof Array) {
* an element that satisfies the given boolean expression specified * @param code expression string or function * The code evaluated can refer to the following built-in variables. * 'it' -> currently visited element * 'index' -> index of the current element * 'array' -> array that is being iterated if (
typeof(
func) !=
'function') {
func =
new Function(
"it",
"index",
"array",
"return " +
code);
* @return concatenated array or composite enumeration * that satisfy the given boolean expression specified in code. * The code evaluated can refer to the following built-in variables. * @param code expression string or function * @return number of elements * 'it' -> currently visited element * 'index' -> index of the current element * 'array' -> array that is being iterated if (
typeof(
func) !=
'function') {
func =
new Function(
"it",
"index",
"array",
"return " +
code);
* the given boolean expression. The boolean expression code can * refer to the following built-in variables. * @param code expression string or function * 'it' -> currently visited element * 'index' -> index of the current element * 'array' -> array that is being iterated * 'result' -> result array if (
typeof(
code) !=
'function') {
func =
new Function(
"it",
"index",
"array",
"result",
"return " +
code);
if (
array instanceof Array) {
* Transforms the given object or array by evaluating given code * on each element of the object or array. The code evaluated * can refer to the following built-in variables. * @param code expression string or function * 'it' -> currently visited element * 'index' -> index of the current element * 'array' -> array that is being iterated * 'result' -> result array * by repeatedly calling code on each element of the input if(
typeof(
code) !=
'function') {
func =
new Function(
"it",
"index",
"array",
"result",
"return " +
code);
// private function used by min, max functions if (
typeof(
code) ==
'string') {
code =
new Function(
"lhs",
"rhs",
"return " +
code);
* @param code (optional) comparision expression or function * by default numerical maximum is computed. * @param code (optional) comparision expression or function * by default numerical minimum is computed. * sort function sorts the input array. optionally accepts * code to compare the elements. If code is not supplied, * numerical sort is done. * @param code expression string or function * The comparison expression can refer to the following * 'lhs' -> 'left side' element * 'rhs' -> 'right side' element // we need an array to sort, so convert non-arrays // by default use numerical comparison }
else if (
typeof(
code) ==
'string') {
func =
new Function(
"lhs",
"rhs",
"return " +
code);
* Returns the sum of the elements of the array * @param array input array that is summed. * @param code optional expression used to map * input elements before sum. * Returns array of unique elements from the given input * @param array from which unique elements are returned. * @param code optional expression (or function) giving unique * by default, objectid is used for uniqueness. code =
new Function(
"it",
"return objectid(it);");
}
else if (
typeof(
code) ==
'string') {
code =
new Function(
"it",
"return " +
code);