annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/sa.js @ 8103:5ed317b25e23

7165259: Remove BugSpot Reviewed-by: coleenp, mgronlun
author sla
date Fri, 22 Feb 2013 10:03:02 +0100
parents 5a98bf7d847b
children e37ab280bbce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2042
diff changeset
2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // shorter names for SA packages
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // SA package name abbreviations are kept in 'sapkg' object
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // to avoid global namespace pollution
a61af66fc99e Initial load
duke
parents:
diff changeset
30 var sapkg = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 sapkg.hotspot = Packages.sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 sapkg.asm = sapkg.hotspot.asm;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 sapkg.c1 = sapkg.hotspot.c1;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 sapkg.code = sapkg.hotspot.code;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 sapkg.compiler = sapkg.hotspot.compiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // 'debugger' is a JavaScript keyword :-(
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // sapkg.debugger = sapkg.hotspot.debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 sapkg.interpreter = sapkg.hotspot.interpreter;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 sapkg.jdi = sapkg.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 sapkg.memory = sapkg.hotspot.memory;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 sapkg.oops = sapkg.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 sapkg.runtime = sapkg.hotspot.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 sapkg.tools = sapkg.hotspot.tools;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 sapkg.types = sapkg.hotspot.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 sapkg.ui = sapkg.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 sapkg.utilities = sapkg.hotspot.utilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // SA singletons are kept in 'sa' object
a61af66fc99e Initial load
duke
parents:
diff changeset
52 var sa = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 sa.vm = sapkg.runtime.VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 sa.dbg = sa.vm.getDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 sa.cdbg = sa.dbg.CDebugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 sa.heap = sa.vm.universe.heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 sa.systemDictionary = sa.vm.systemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 sa.sysDict = sa.systemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 sa.symbolTable = sa.vm.symbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 sa.symTbl = sa.symbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 sa.threads = sa.vm.threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 sa.interpreter = sa.vm.interpreter;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 sa.typedb = sa.vm.typeDataBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 sa.codeCache = sa.vm.codeCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // 'objHeap' is different from 'heap'!.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // This is SA's Oop factory and heap-walker
a61af66fc99e Initial load
duke
parents:
diff changeset
67 sa.objHeap = sa.vm.objectHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // few useful global variables
a61af66fc99e Initial load
duke
parents:
diff changeset
70 var OS = sa.vm.OS;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 var CPU = sa.vm.CPU;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 var LP64 = sa.vm.LP64;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 var isClient = sa.vm.clientCompiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 var isServer = sa.vm.serverCompiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 var isCore = sa.vm.isCore();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 var addressSize = sa.vm.addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 var oopSize = sa.vm.oopSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // this "main" function is called immediately
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // after loading this script file
a61af66fc99e Initial load
duke
parents:
diff changeset
81 function main(globals, jvmarg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // wrap a sun.jvm.hotspot.utilities.soql.ScriptObject
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // object so that the properties of it can be accessed
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // in natural object.field syntax.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 function wrapScriptObject(so) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 function unwrapScriptObject(wso) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 var objType = typeof(wso);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if ((objType == 'object' ||
a61af66fc99e Initial load
duke
parents:
diff changeset
89 objType == 'function')
a61af66fc99e Initial load
duke
parents:
diff changeset
90 && "__wrapped__" in wso) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return wso.__wrapped__;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return wso;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 function prepareArgsArray(array) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 var args = new Array(array.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 for (var a = 0; a < array.length; a++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 var elem = array[a];
a61af66fc99e Initial load
duke
parents:
diff changeset
101 elem = unwrapScriptObject(elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (typeof(elem) == 'function') {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 args[a] = new sapkg.utilities.soql.Callable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 call: function(myargs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 var tmp = new Array(myargs.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 for (var i = 0; i < myargs.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 tmp[i] = wrapScriptObject(myargs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return elem.apply(this, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 args[a] = elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return args;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (so instanceof sapkg.utilities.soql.ScriptObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return new JSAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 __getIds__: function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return so.getIds();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 },
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 __has__ : function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (typeof(name) == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return so["has(int)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (name == '__wrapped__') {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 } else if (so["has(java.lang.String)"](name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 } else if (name.equals('toString')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 },
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 __delete__ : function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (typeof(name) == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return so["delete(int)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return so["delete(java.lang.String)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 },
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 __get__ : function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (! this.__has__(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return undefined;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (typeof(name) == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return wrapScriptObject(so["get(int)"](name));
a61af66fc99e Initial load
duke
parents:
diff changeset
155 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (name == '__wrapped__') {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return so;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 var value = so["get(java.lang.String)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (value instanceof sapkg.utilities.soql.Callable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 var args = prepareArgsArray(arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 var r;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 r = value.call(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } catch (e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 println("call to " + name + " failed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 throw e;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return wrapScriptObject(r);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } else if (name == 'toString') {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 return function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return so.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return wrapScriptObject(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 };
a61af66fc99e Initial load
duke
parents:
diff changeset
183 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return so;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // set "jvm" global variable that wraps a
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // sun.jvm.hotspot.utilities.soql.JSJavaVM instance
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (jvmarg != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 jvm = wrapScriptObject(jvmarg);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // expose "heap" global variable
a61af66fc99e Initial load
duke
parents:
diff changeset
193 heap = jvm.heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // expose all "function" type properties of
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // sun.jvm.hotspot.utilitites.soql.JSJavaScriptEngine
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // as global functions here.
a61af66fc99e Initial load
duke
parents:
diff changeset
199 globals = wrapScriptObject(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 for (var prop in globals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (typeof(globals[prop]) == 'function') {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 this[prop] = globals[prop];
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // define "writeln" and "write" if not defined
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (typeof(writeln) == 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 writeln = println;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (typeof(write) == 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 write = print;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // "registerCommand" function is defined if we
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // are running as part of "CLHSDB" tool. CLHSDB
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // tool exposes Unix-style commands.
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // if "registerCommand" function is defined
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // then register few global functions as "commands".
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (typeof(registerCommand) == 'function') {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 this.jclass = function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (typeof(name) == "string") {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 var clazz = sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (clazz) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2042
diff changeset
226 writeln(clazz.getName().asString() + " @" + clazz.getAddress().toString());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
227 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 writeln("class not found: " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 writeln("Usage: class name");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 registerCommand("class", "class name", "jclass");
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 this.jclasses = function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 forEachKlass(function (clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 writeln(clazz.getName().asString() + " @" + clazz.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
239 });
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 registerCommand("classes", "classes", "jclasses");
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 this.dclass = function(clazz, dir) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 if (!clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 writeln("Usage: dumpclass { address | name } [ directory ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
246 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (!dir) { dir = "."; }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 dumpClass(clazz, dir);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 registerCommand("dumpclass", "dumpclass { address | name } [ directory ]", "dclass");
a61af66fc99e Initial load
duke
parents:
diff changeset
252 registerCommand("dumpheap", "dumpheap [ file ]", "dumpHeap");
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 this.jseval = function(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (!str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 writeln("Usage: jseval script");
a61af66fc99e Initial load
duke
parents:
diff changeset
257 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 var res = eval(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (res) { writeln(res); }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 registerCommand("jseval", "jseval script", "jseval");
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 this.jsload = function(file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (!file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 writeln("Usage: jsload file");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 load(file);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 registerCommand("jsload", "jsload file", "jsload");
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 this.printMem = function(addr, len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 writeln("Usage: mem [ length ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 mem(addr, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 registerCommand("mem", "mem address [ length ]", "printMem");
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 this.sysProps = function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 for (var i in jvm.sysProps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 writeln(i + ' = ' + jvm.sysProps[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 registerCommand("sysprops", "sysprops", "sysProps");
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 this.printWhatis = function(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 writeln("Usage: whatis address");
a61af66fc99e Initial load
duke
parents:
diff changeset
292 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 writeln(whatis(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296 registerCommand("whatis", "whatis address", "printWhatis");
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // debugger functionality
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // string-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
303 function str2addr(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 return sa.dbg.parseAddress(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // number-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (addressSize == 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 eval("function num2addr(num) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return str2addr('0x' + java.lang.Integer.toHexString(0xffffffff & num)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }");
a61af66fc99e Initial load
duke
parents:
diff changeset
312 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 eval("function num2addr(num) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
314 return str2addr('0x' + java.lang.Long.toHexString(num)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }");
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // generic any-type-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // use this convenience function to accept address in any
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // format -- number, string or an Address instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
321 function any2addr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 var type = typeof(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (type == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return num2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 } else if (type == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 return str2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // Address-to-string
a61af66fc99e Initial load
duke
parents:
diff changeset
333 function addr2str(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 return (addressSize == 4)? '0x00000000' : '0x0000000000000000';
a61af66fc99e Initial load
duke
parents:
diff changeset
336 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 return addr + '';
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Address-to-number
a61af66fc99e Initial load
duke
parents:
diff changeset
342 function addr2num(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 return sa.dbg.getAddressValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // symbol-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
347 function sym2addr(dso, sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 return sa.dbg.lookup(dso, sym);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 // returns the ClosestSymbol or null
a61af66fc99e Initial load
duke
parents:
diff changeset
352 function closestSymbolFor(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // no CDebugger support, return null
a61af66fc99e Initial load
duke
parents:
diff changeset
355 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 var dso = sa.cdbg.loadObjectContainingPC(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (dso != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 return dso.closestSymbolToPC(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // Address-to-symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // returns nearest symbol as string if found
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // else returns address as string
a61af66fc99e Initial load
duke
parents:
diff changeset
369 function addr2sym(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 return addr2str(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // read 'num' words at 'addr' and return an array as result.
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // returns Java long[] type result and not a JavaScript array.
a61af66fc99e Initial load
duke
parents:
diff changeset
380 function readWordsAt(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 var res = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, num);
a61af66fc99e Initial load
duke
parents:
diff changeset
383 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
384 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 res[i] = addr2num(addr.getAddressAt(i * addressSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 // read the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
391 function readCStrAt(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
393 return sapkg.utilities.CStringUtilities.getString(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // read the length of the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
397 function readCStrLen(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
398 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 return sapkg.utilities.CStringUtilities.getStringLength(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402 // iterate through ThreadList of CDebugger
a61af66fc99e Initial load
duke
parents:
diff changeset
403 function forEachThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
404 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
406 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 var itr = sa.cdbg.threadList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
409 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // read register set of a ThreadProxy as name-value pairs
a61af66fc99e Initial load
duke
parents:
diff changeset
416 function readRegs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 var ctx = threadProxy.context;
a61af66fc99e Initial load
duke
parents:
diff changeset
418 var num = ctx.numRegisters;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 var res = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
420 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 res[ctx.getRegisterName(i)]= addr2str(ctx.getRegisterAsAddress(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // print register set for a given ThreaProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
428 function regs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 var res = readRegs(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 for (i in res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 writeln(i, '=', res[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // iterate through each CFrame of a given ThreadProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
436 function forEachCFrame(threadProxy, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
439 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
440 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 var cframe = sa.cdbg.topFrameForThread(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 while (cframe != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 if (callback(cframe) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 cframe = cframe.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // iterate through list of load objects (DLLs, DSOs)
a61af66fc99e Initial load
duke
parents:
diff changeset
450 function forEachLoadObject(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
453 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 var itr = sa.cdbg.loadObjectList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
456 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // print 'num' words at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
463 function mem(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (num == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 num = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
469 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 var value = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
471 writeln(addr2sym(addr) + ':', addr2str(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
472 addr = addr.addOffsetTo(addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // System dictionary functions
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // find InstanceKlass by name
a61af66fc99e Initial load
duke
parents:
diff changeset
480 function findInstanceKlass(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 return sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // get Java system loader (i.e., application launcher loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
485 function systemLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 return sa.sysDict.javaSystemLoader();
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // iterate system dictionary for each 'Klass'
a61af66fc99e Initial load
duke
parents:
diff changeset
490 function forEachKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
492 var visitor = new VisitorClass() { visit: callback };
a61af66fc99e Initial load
duke
parents:
diff changeset
493 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassVisitor)"](visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // iterate system dictionary for each 'Klass' and initiating loader
a61af66fc99e Initial load
duke
parents:
diff changeset
497 function forEachKlassAndLoader(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 var visitor = new VisitorClass() { visit: callback };
a61af66fc99e Initial load
duke
parents:
diff changeset
500 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassAndLoaderVisitor)"](visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // iterate system dictionary for each primitive array klass
a61af66fc99e Initial load
duke
parents:
diff changeset
504 function forEachPrimArrayKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 sa.sysDict.primArrayClassesDo(new VisitorClass() { visit: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // 'oop' to higher-level java object wrapper in which for(i in o)
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // works by iterating java level fields and javaobject.javafield
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // syntax works.
a61af66fc99e Initial load
duke
parents:
diff changeset
512 function oop2obj(oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 return object(addr2str(oop.handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // higher level java object wrapper to oop
a61af66fc99e Initial load
duke
parents:
diff changeset
517 function obj2oop(obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 return addr2oop(str2addr(address(obj)));
a61af66fc99e Initial load
duke
parents:
diff changeset
519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 // Java heap iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // iterates Java heap for each Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
524 function forEachOop(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 sa.objHeap.iterate(new sapkg.oops.HeapVisitor() { doObj: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // iterates Java heap for each Oop of given 'klass'.
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // 'includeSubtypes' tells whether to include objects
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // of subtypes of 'klass' or not
a61af66fc99e Initial load
duke
parents:
diff changeset
531 function forEachOopOfKlass(callback, klass, includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 if (klass == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
533 klass = findInstanceKlass("java.lang.Object");
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (includeSubtypes == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 includeSubtypes = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539 sa.objHeap.iterateObjectsOfKlass(
a61af66fc99e Initial load
duke
parents:
diff changeset
540 new sapkg.oops.HeapVisitor() { doObj: callback },
a61af66fc99e Initial load
duke
parents:
diff changeset
541 klass, includeSubtypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // Java thread
a61af66fc99e Initial load
duke
parents:
diff changeset
545
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // iterates each Thread
a61af66fc99e Initial load
duke
parents:
diff changeset
547 function forEachJavaThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 var threads = sa.threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 var thread = threads.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
550 while (thread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
551 if (callback(thread) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 thread = thread.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // iterate Frames of a given thread
a61af66fc99e Initial load
duke
parents:
diff changeset
557 function forEachFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 var fr = javaThread.getLastFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
559 while (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 if (callback(fr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
561 fr = fr.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 // iterate JavaVFrames of a given JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
566 function forEachVFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 var vfr = javaThread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
568 while (vfr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 if (callback(vfr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 vfr = vfr.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
571 }
a61af66fc99e Initial load
duke
parents:
diff changeset
572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
573
a61af66fc99e Initial load
duke
parents:
diff changeset
574 function printStackTrace(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 write("Thread ");
a61af66fc99e Initial load
duke
parents:
diff changeset
576 javaThread.printThreadIDOn(java.lang.System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
577 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
578 forEachVFrame(javaThread, function (vf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 var method = vf.method;
a61af66fc99e Initial load
duke
parents:
diff changeset
580 write(' - ', method.externalNameAndSignature(), '@bci =', vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
581 var line = method.getLineNumberFromBCI(vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
582 if (line != -1) { write(', line=', line); }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 if (vf.isCompiledFrame()) { write(" (Compiled Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (vf.isInterpretedFrame()) { write(" (Interpreted Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
586 });
a61af66fc99e Initial load
duke
parents:
diff changeset
587 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // print Java stack trace for all threads
a61af66fc99e Initial load
duke
parents:
diff changeset
592 function where(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 if (javaThread == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
594 forEachJavaThread(function (jt) { printStackTrace(jt); });
a61af66fc99e Initial load
duke
parents:
diff changeset
595 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 printStackTrace(javaThread);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 }
a61af66fc99e Initial load
duke
parents:
diff changeset
598 }
a61af66fc99e Initial load
duke
parents:
diff changeset
599
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // vmStructs access -- type database functions
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 // find a VM type
a61af66fc99e Initial load
duke
parents:
diff changeset
603 function findVMType(typeName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 return sa.typedb.lookupType(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606
a61af66fc99e Initial load
duke
parents:
diff changeset
607 // iterate VM types
a61af66fc99e Initial load
duke
parents:
diff changeset
608 function forEachVMType(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 var itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
610 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
613 }
a61af66fc99e Initial load
duke
parents:
diff changeset
614
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // find VM int constant
a61af66fc99e Initial load
duke
parents:
diff changeset
616 function findVMIntConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 return sa.typedb.lookupIntConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // find VM long constant
a61af66fc99e Initial load
duke
parents:
diff changeset
621 function findVMLongConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
622 return sa.typedb.lookupLongConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // iterate VM int constants
a61af66fc99e Initial load
duke
parents:
diff changeset
626 function forEachVMIntConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
627 var itr = sa.typedb.intConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
628 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // iterate VM long constants
a61af66fc99e Initial load
duke
parents:
diff changeset
634 function forEachVMLongConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 var itr = sa.typedb.longConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
636 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // returns VM Type at address
a61af66fc99e Initial load
duke
parents:
diff changeset
642 function vmTypeof(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 return sa.typedb.guessTypeForAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // does the given 'addr' points to an object of given 'type'?
a61af66fc99e Initial load
duke
parents:
diff changeset
648 // OR any valid Type at all (if type is undefined)
a61af66fc99e Initial load
duke
parents:
diff changeset
649 function isOfVMType(addr, type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
651 if (type == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
652 return vmTypeof(addr) != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
653 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
655 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657 return sa.typedb.addressTypeIsEqualToType(addr, type);
a61af66fc99e Initial load
duke
parents:
diff changeset
658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
660
a61af66fc99e Initial load
duke
parents:
diff changeset
661 // reads static field value
a61af66fc99e Initial load
duke
parents:
diff changeset
662 function readVMStaticField(field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
664 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 return field.value;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 return field.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
669 return field.oopHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 return field.staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 }
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 // reads given instance field of VM object at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
676 function readVMInstanceField(field, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
677 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
678 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 return field.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
680 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 return field.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
683 return field.getOopHandle(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
684 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 return addr.addOffsetTo(field.offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // returns name-value of pairs of VM type at given address.
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // If address is unspecified, reads static fields as name-value pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
691 function readVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695 if (addr != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
697 }
a61af66fc99e Initial load
duke
parents:
diff changeset
698
a61af66fc99e Initial load
duke
parents:
diff changeset
699 var result = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
700 var staticOnly = (addr == undefined);
a61af66fc99e Initial load
duke
parents:
diff changeset
701 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
704 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
705 var isStatic = field.isStatic();
a61af66fc99e Initial load
duke
parents:
diff changeset
706 if (staticOnly && isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 result[field.name] = readVMStaticField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
708 } else if (!staticOnly && !isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 result[field.name] = readVMInstanceField(field, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
714 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 function printVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
718 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
721 var obj = readVMType(type, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
723 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
724 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
726 var name = field.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
727 var value = obj[name];
a61af66fc99e Initial load
duke
parents:
diff changeset
728 if (value != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
729 writeln(field.type.name, type.name + '::' + name, '=', value);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }
a61af66fc99e Initial load
duke
parents:
diff changeset
734 }
a61af66fc99e Initial load
duke
parents:
diff changeset
735
a61af66fc99e Initial load
duke
parents:
diff changeset
736 // define readXXX and printXXX functions for each VM struct/class Type
a61af66fc99e Initial load
duke
parents:
diff changeset
737 tmp = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
738 tmp.itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
739 while (tmp.itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 tmp.type = tmp.itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
741 tmp.name = tmp.type.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
742 if (tmp.type.isPointerType() || tmp.type.isOopType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
743 tmp.type.isCIntegerType() || tmp.type.isJavaPrimitiveType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
744 tmp.name.equals('address') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
745 tmp.name.equals("<opaque>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 // ignore;
a61af66fc99e Initial load
duke
parents:
diff changeset
747 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
748 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
749 // some type names have ':'. replace to make it as a
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // JavaScript identifier
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 0
diff changeset
751 tmp.name = tmp.name.replace(':', '_').replace('<', '_').replace('>', '_').replace('*', '_').replace(' ', '_');
0
a61af66fc99e Initial load
duke
parents:
diff changeset
752 eval("function read" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
753 " return readVMType('" + tmp.name + "', addr);}");
a61af66fc99e Initial load
duke
parents:
diff changeset
754 eval("function print" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
755 " printVMType('" + tmp.name + "', addr); }");
a61af66fc99e Initial load
duke
parents:
diff changeset
756
a61af66fc99e Initial load
duke
parents:
diff changeset
757 /* FIXME: do we need this?
a61af66fc99e Initial load
duke
parents:
diff changeset
758 if (typeof(registerCommand) != 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 var name = "print" + tmp.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
760 registerCommand(name, name + " [address]", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
762 */
a61af66fc99e Initial load
duke
parents:
diff changeset
763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
764 }
a61af66fc99e Initial load
duke
parents:
diff changeset
765 //clean-up the temporary
a61af66fc99e Initial load
duke
parents:
diff changeset
766 delete tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
767
a61af66fc99e Initial load
duke
parents:
diff changeset
768 // VMObject factory
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 // VM type to SA class map
a61af66fc99e Initial load
duke
parents:
diff changeset
771 var vmType2Class = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // This is *not* exhaustive. Add more if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // code blobs
a61af66fc99e Initial load
duke
parents:
diff changeset
775 vmType2Class["BufferBlob"] = sapkg.code.BufferBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
776 vmType2Class["nmethod"] = sapkg.code.NMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
777 vmType2Class["RuntimeStub"] = sapkg.code.RuntimeStub;
a61af66fc99e Initial load
duke
parents:
diff changeset
778 vmType2Class["SafepointBlob"] = sapkg.code.SafepointBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
779 vmType2Class["C2IAdapter"] = sapkg.code.C2IAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
780 vmType2Class["DeoptimizationBlob"] = sapkg.code.DeoptimizationBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
781 vmType2Class["ExceptionBlob"] = sapkg.code.ExceptionBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 vmType2Class["I2CAdapter"] = sapkg.code.I2CAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 vmType2Class["OSRAdapter"] = sapkg.code.OSRAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
784 vmType2Class["UncommonTrapBlob"] = sapkg.code.UncommonTrapBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
785 vmType2Class["PCDesc"] = sapkg.code.PCDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787 // interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
788 vmType2Class["InterpreterCodelet"] = sapkg.interpreter.InterpreterCodelet;
a61af66fc99e Initial load
duke
parents:
diff changeset
789
a61af66fc99e Initial load
duke
parents:
diff changeset
790 // Java Threads
a61af66fc99e Initial load
duke
parents:
diff changeset
791 vmType2Class["JavaThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
792 vmType2Class["CompilerThread"] = sapkg.runtime.CompilerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
793 vmType2Class["SurrogateLockerThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
794 vmType2Class["DebuggerThread"] = sapkg.runtime.DebuggerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
795
a61af66fc99e Initial load
duke
parents:
diff changeset
796 // gc
a61af66fc99e Initial load
duke
parents:
diff changeset
797 vmType2Class["GenCollectedHeap"] = sapkg.memory.GenCollectedHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
798 vmType2Class["DefNewGeneration"] = sapkg.memory.DefNewGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
799 vmType2Class["TenuredGeneration"] = sapkg.memory.TenuredGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
800
a61af66fc99e Initial load
duke
parents:
diff changeset
801 // generic VMObject factory for a given address
a61af66fc99e Initial load
duke
parents:
diff changeset
802 // This is equivalent to VirtualConstructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
803 function newVMObject(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
804 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
805 var result = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
806 forEachVMType(function (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (isOfVMType(addr, type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 var clazz = vmType2Class[type.name];
a61af66fc99e Initial load
duke
parents:
diff changeset
809 if (clazz != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 result = new clazz(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
812 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
813 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
816 });
a61af66fc99e Initial load
duke
parents:
diff changeset
817 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
818 }
a61af66fc99e Initial load
duke
parents:
diff changeset
819
a61af66fc99e Initial load
duke
parents:
diff changeset
820 function vmobj2addr(vmobj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
821 return vmobj.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
822 }
a61af66fc99e Initial load
duke
parents:
diff changeset
823
a61af66fc99e Initial load
duke
parents:
diff changeset
824 function addr2vmobj(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
825 return newVMObject(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
826 }
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 // Miscellaneous utilities
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 // returns PointerLocation that describes the given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
831 function findPtr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
832 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
833 return sapkg.utilities.PointerFinder.find(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
834 }
a61af66fc99e Initial load
duke
parents:
diff changeset
835
a61af66fc99e Initial load
duke
parents:
diff changeset
836 // is given address a valid Oop?
a61af66fc99e Initial load
duke
parents:
diff changeset
837 function isOop(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
838 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
839 var oopHandle = addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
840 return sapkg.utilities.RobustOopDeterminator.oopLooksValid(oopHandle);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 // returns description of given pointer as a String
a61af66fc99e Initial load
duke
parents:
diff changeset
844 function whatis(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 var ptrLoc = findPtr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 if (ptrLoc.isUnknown()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 var vmType = vmTypeof(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
849 if (vmType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 return "pointer to " + vmType.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
851 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
855 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
856 return ptrLoc.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
857 }
a61af66fc99e Initial load
duke
parents:
diff changeset
858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
859 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 return ptrLoc.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }