annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/sa.js @ 1040:873ec3787992

6892186: SA does not dump debug info for scalar replaced objects Summary: Implement scalar replaced objects debug info dump in SA. Reviewed-by: twisti
author kvn
date Wed, 21 Oct 2009 09:15:33 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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.bugspot = sapkg.hotspot.bugspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 sapkg.c1 = sapkg.hotspot.c1;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 sapkg.code = sapkg.hotspot.code;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 sapkg.compiler = sapkg.hotspot.compiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // 'debugger' is a JavaScript keyword :-(
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // sapkg.debugger = sapkg.hotspot.debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 sapkg.interpreter = sapkg.hotspot.interpreter;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 sapkg.livejvm = sapkg.hotspot.livejvm;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 sapkg.jdi = sapkg.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 sapkg.memory = sapkg.hotspot.memory;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 sapkg.oops = sapkg.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 sapkg.runtime = sapkg.hotspot.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 sapkg.tools = sapkg.hotspot.tools;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 sapkg.types = sapkg.hotspot.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 sapkg.ui = sapkg.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 sapkg.utilities = sapkg.hotspot.utilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // SA singletons are kept in 'sa' object
a61af66fc99e Initial load
duke
parents:
diff changeset
54 var sa = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 sa.vm = sapkg.runtime.VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 sa.dbg = sa.vm.getDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 sa.cdbg = sa.dbg.CDebugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 sa.heap = sa.vm.universe.heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 sa.systemDictionary = sa.vm.systemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 sa.sysDict = sa.systemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 sa.symbolTable = sa.vm.symbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 sa.symTbl = sa.symbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 sa.threads = sa.vm.threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 sa.interpreter = sa.vm.interpreter;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 sa.typedb = sa.vm.typeDataBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 sa.codeCache = sa.vm.codeCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // 'objHeap' is different from 'heap'!.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // This is SA's Oop factory and heap-walker
a61af66fc99e Initial load
duke
parents:
diff changeset
69 sa.objHeap = sa.vm.objectHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // few useful global variables
a61af66fc99e Initial load
duke
parents:
diff changeset
72 var OS = sa.vm.OS;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 var CPU = sa.vm.CPU;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 var LP64 = sa.vm.LP64;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 var isClient = sa.vm.clientCompiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 var isServer = sa.vm.serverCompiler;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 var isCore = sa.vm.isCore();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 var addressSize = sa.vm.addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 var oopSize = sa.vm.oopSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // this "main" function is called immediately
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // after loading this script file
a61af66fc99e Initial load
duke
parents:
diff changeset
83 function main(globals, jvmarg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // wrap a sun.jvm.hotspot.utilities.soql.ScriptObject
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // object so that the properties of it can be accessed
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // in natural object.field syntax.
a61af66fc99e Initial load
duke
parents:
diff changeset
87 function wrapScriptObject(so) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 function unwrapScriptObject(wso) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 var objType = typeof(wso);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if ((objType == 'object' ||
a61af66fc99e Initial load
duke
parents:
diff changeset
91 objType == 'function')
a61af66fc99e Initial load
duke
parents:
diff changeset
92 && "__wrapped__" in wso) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return wso.__wrapped__;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return wso;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 function prepareArgsArray(array) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 var args = new Array(array.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for (var a = 0; a < array.length; a++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 var elem = array[a];
a61af66fc99e Initial load
duke
parents:
diff changeset
103 elem = unwrapScriptObject(elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (typeof(elem) == 'function') {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 args[a] = new sapkg.utilities.soql.Callable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 call: function(myargs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 var tmp = new Array(myargs.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 for (var i = 0; i < myargs.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 tmp[i] = wrapScriptObject(myargs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return elem.apply(this, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 args[a] = elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return args;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (so instanceof sapkg.utilities.soql.ScriptObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return new JSAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 __getIds__: function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return so.getIds();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 },
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 __has__ : function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (typeof(name) == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return so["has(int)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (name == '__wrapped__') {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 } else if (so["has(java.lang.String)"](name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 } else if (name.equals('toString')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 },
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 __delete__ : function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (typeof(name) == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return so["delete(int)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return so["delete(java.lang.String)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 },
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 __get__ : function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (! this.__has__(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 return undefined;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (typeof(name) == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return wrapScriptObject(so["get(int)"](name));
a61af66fc99e Initial load
duke
parents:
diff changeset
157 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (name == '__wrapped__') {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return so;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 var value = so["get(java.lang.String)"](name);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (value instanceof sapkg.utilities.soql.Callable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 var args = prepareArgsArray(arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 var r;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 r = value.call(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 } catch (e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 println("call to " + name + " failed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
170 throw e;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return wrapScriptObject(r);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 } else if (name == 'toString') {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 return so.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return wrapScriptObject(value);
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 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 };
a61af66fc99e Initial load
duke
parents:
diff changeset
185 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return so;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // set "jvm" global variable that wraps a
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // sun.jvm.hotspot.utilities.soql.JSJavaVM instance
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (jvmarg != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 jvm = wrapScriptObject(jvmarg);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // expose "heap" global variable
a61af66fc99e Initial load
duke
parents:
diff changeset
195 heap = jvm.heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // expose all "function" type properties of
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // sun.jvm.hotspot.utilitites.soql.JSJavaScriptEngine
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // as global functions here.
a61af66fc99e Initial load
duke
parents:
diff changeset
201 globals = wrapScriptObject(globals);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 for (var prop in globals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (typeof(globals[prop]) == 'function') {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 this[prop] = globals[prop];
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // define "writeln" and "write" if not defined
a61af66fc99e Initial load
duke
parents:
diff changeset
209 if (typeof(writeln) == 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 writeln = println;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (typeof(write) == 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 write = print;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // "registerCommand" function is defined if we
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // are running as part of "CLHSDB" tool. CLHSDB
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // tool exposes Unix-style commands.
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // if "registerCommand" function is defined
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // then register few global functions as "commands".
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (typeof(registerCommand) == 'function') {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 this.printDis = function(addr, len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 writeln("Usage: dis address [ length ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
227 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 dis(addr, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 registerCommand("dis", "dis address [ length ]", "printDis");
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 this.jclass = function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 if (typeof(name) == "string") {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 var clazz = sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 writeln(clazz.getName().asString() + " @" + clazz.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
238 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 writeln("class not found: " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 writeln("Usage: class name");
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 registerCommand("class", "class name", "jclass");
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 this.jclasses = function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 forEachKlass(function (clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 writeln(clazz.getName().asString() + " @" + clazz.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
250 });
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 registerCommand("classes", "classes", "jclasses");
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 this.printJDis = function(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 writeln("Usage: jdis address");
a61af66fc99e Initial load
duke
parents:
diff changeset
257 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 jdis(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261 registerCommand("jdis", "jdis address", "printJDis");
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 this.dclass = function(clazz, dir) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 if (!clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 writeln("Usage: dumpclass { address | name } [ directory ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (!dir) { dir = "."; }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 dumpClass(clazz, dir);
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("dumpclass", "dumpclass { address | name } [ directory ]", "dclass");
a61af66fc99e Initial load
duke
parents:
diff changeset
272 registerCommand("dumpheap", "dumpheap [ file ]", "dumpHeap");
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 this.jseval = function(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (!str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 writeln("Usage: jseval script");
a61af66fc99e Initial load
duke
parents:
diff changeset
277 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 var res = eval(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (res) { writeln(res); }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 registerCommand("jseval", "jseval script", "jseval");
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 this.jsload = function(file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (!file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 writeln("Usage: jsload file");
a61af66fc99e Initial load
duke
parents:
diff changeset
287 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 load(file);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 registerCommand("jsload", "jsload file", "jsload");
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 this.printMem = function(addr, len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 writeln("Usage: mem [ length ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
296 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 mem(addr, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 registerCommand("mem", "mem address [ length ]", "printMem");
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 this.sysProps = function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 for (var i in jvm.sysProps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 writeln(i + ' = ' + jvm.sysProps[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 registerCommand("sysprops", "sysprops", "sysProps");
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 this.printWhatis = function(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 writeln("Usage: whatis address");
a61af66fc99e Initial load
duke
parents:
diff changeset
312 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 writeln(whatis(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 registerCommand("whatis", "whatis address", "printWhatis");
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // debugger functionality
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // string-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
323 function str2addr(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return sa.dbg.parseAddress(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // number-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
328 if (addressSize == 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 eval("function num2addr(num) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return str2addr('0x' + java.lang.Integer.toHexString(0xffffffff & num)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }");
a61af66fc99e Initial load
duke
parents:
diff changeset
332 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 eval("function num2addr(num) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
334 return str2addr('0x' + java.lang.Long.toHexString(num)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }");
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // generic any-type-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // use this convenience function to accept address in any
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // format -- number, string or an Address instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
341 function any2addr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 var type = typeof(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (type == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return num2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 } else if (type == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return str2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
347 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // Address-to-string
a61af66fc99e Initial load
duke
parents:
diff changeset
353 function addr2str(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 return (addressSize == 4)? '0x00000000' : '0x0000000000000000';
a61af66fc99e Initial load
duke
parents:
diff changeset
356 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 return addr + '';
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // Address-to-number
a61af66fc99e Initial load
duke
parents:
diff changeset
362 function addr2num(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return sa.dbg.getAddressValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // symbol-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
367 function sym2addr(dso, sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 return sa.dbg.lookup(dso, sym);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // returns the ClosestSymbol or null
a61af66fc99e Initial load
duke
parents:
diff changeset
372 function closestSymbolFor(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // no CDebugger support, return null
a61af66fc99e Initial load
duke
parents:
diff changeset
375 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 var dso = sa.cdbg.loadObjectContainingPC(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if (dso != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 return dso.closestSymbolToPC(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // Address-to-symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // returns nearest symbol as string if found
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // else returns address as string
a61af66fc99e Initial load
duke
parents:
diff changeset
389 function addr2sym(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 return addr2str(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // read 'num' bytes at 'addr' and return an array as result.
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // returns Java byte[] type result and not a JavaScript array.
a61af66fc99e Initial load
duke
parents:
diff changeset
400 function readBytesAt(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 var res = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, num);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 res[i] = addr.getJByteAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // read 'num' words at 'addr' and return an array as result.
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // returns Java long[] type result and not a JavaScript array.
a61af66fc99e Initial load
duke
parents:
diff changeset
412 function readWordsAt(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 var res = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, num);
a61af66fc99e Initial load
duke
parents:
diff changeset
415 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 res[i] = addr2num(addr.getAddressAt(i * addressSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // read the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
423 function readCStrAt(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
425 return sapkg.utilities.CStringUtilities.getString(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // read the length of the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
429 function readCStrLen(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
431 return sapkg.utilities.CStringUtilities.getStringLength(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // iterate through ThreadList of CDebugger
a61af66fc99e Initial load
duke
parents:
diff changeset
435 function forEachThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
438 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 var itr = sa.cdbg.threadList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
441 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // read register set of a ThreadProxy as name-value pairs
a61af66fc99e Initial load
duke
parents:
diff changeset
448 function readRegs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 var ctx = threadProxy.context;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 var num = ctx.numRegisters;
a61af66fc99e Initial load
duke
parents:
diff changeset
451 var res = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
452 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 res[ctx.getRegisterName(i)]= addr2str(ctx.getRegisterAsAddress(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
456 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 // print register set for a given ThreaProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
460 function regs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
461 var res = readRegs(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 for (i in res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 writeln(i, '=', res[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 // iterate through each CFrame of a given ThreadProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
468 function forEachCFrame(threadProxy, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
471 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 var cframe = sa.cdbg.topFrameForThread(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 while (cframe != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (callback(cframe) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
476 cframe = cframe.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // iterate through list of load objects (DLLs, DSOs)
a61af66fc99e Initial load
duke
parents:
diff changeset
482 function forEachLoadObject(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
483 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
485 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 var itr = sa.cdbg.loadObjectList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
488 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
489 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // print 'num' words at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
495 function mem(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 if (num == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 num = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
500 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
501 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
502 var value = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
503 writeln(addr2sym(addr) + ':', addr2str(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
504 addr = addr.addOffsetTo(addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // return the disassemble class for current CPU
a61af66fc99e Initial load
duke
parents:
diff changeset
510 function disassemblerClass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 var DisAsmClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 if (CPU == 'x86') {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 DisAsmClass = sapkg.asm.x86.X86Disassembler;
a61af66fc99e Initial load
duke
parents:
diff changeset
514 } else if (CPU == 'sparc') {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 DisAsmClass = sapkg.asm.sparc.SPARCV9Disassembler;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517 return DisAsmClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // print native code disassembly of 'num' bytes at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
521 function dis(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
523 var nmethod = findNMethod(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
524 if (nmethod != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // disassemble it as nmethod
a61af66fc99e Initial load
duke
parents:
diff changeset
526 nmethoddis(nmethod);
a61af66fc99e Initial load
duke
parents:
diff changeset
527 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // raw disassembly
a61af66fc99e Initial load
duke
parents:
diff changeset
529 if (num == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // size of one SPARC instruction and
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // unknown number of Intel instructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
532 num = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 DisAsmClass = disassemblerClass();
a61af66fc99e Initial load
duke
parents:
diff changeset
535 if (DisAsmClass == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // unsupported CPU
a61af66fc99e Initial load
duke
parents:
diff changeset
537 writeln(CPU + " is not yet supported!");
a61af66fc99e Initial load
duke
parents:
diff changeset
538 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
539 }
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 var bytes = readBytesAt(addr, num);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 var disAsm = new DisAsmClass(addr2num(addr), bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 disAsm.decode(new sapkg.asm.InstructionVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
544 visit: function (pc, instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 write(addr2sym(num2addr(pc)) + ':', '\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
546 writeln(instr.asString(pc,
a61af66fc99e Initial load
duke
parents:
diff changeset
547 new sapkg.asm.SymbolFinder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 getSymbolFor: function(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 return addr2sym(num2addr(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
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
a61af66fc99e Initial load
duke
parents:
diff changeset
557 // System dictionary functions
a61af66fc99e Initial load
duke
parents:
diff changeset
558
a61af66fc99e Initial load
duke
parents:
diff changeset
559 // find InstanceKlass by name
a61af66fc99e Initial load
duke
parents:
diff changeset
560 function findInstanceKlass(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 return sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 // get Java system loader (i.e., application launcher loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
565 function systemLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 return sa.sysDict.javaSystemLoader();
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // iterate system dictionary for each 'Klass'
a61af66fc99e Initial load
duke
parents:
diff changeset
570 function forEachKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 var visitor = new VisitorClass() { visit: callback };
a61af66fc99e Initial load
duke
parents:
diff changeset
573 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassVisitor)"](visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 // iterate system dictionary for each 'Klass' and initiating loader
a61af66fc99e Initial load
duke
parents:
diff changeset
577 function forEachKlassAndLoader(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
578 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
579 var visitor = new VisitorClass() { visit: callback };
a61af66fc99e Initial load
duke
parents:
diff changeset
580 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassAndLoaderVisitor)"](visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 }
a61af66fc99e Initial load
duke
parents:
diff changeset
582
a61af66fc99e Initial load
duke
parents:
diff changeset
583 // iterate system dictionary for each primitive array klass
a61af66fc99e Initial load
duke
parents:
diff changeset
584 function forEachPrimArrayKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 sa.sysDict.primArrayClassesDo(new VisitorClass() { visit: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 // (hotspot) symbol table functions
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // String-to-Symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
592 function str2sym(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 return sa.symTbl.probe(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
595
a61af66fc99e Initial load
duke
parents:
diff changeset
596 // Symbol-to-String
a61af66fc99e Initial load
duke
parents:
diff changeset
597 function sym2str(sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 return sym.asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600
a61af66fc99e Initial load
duke
parents:
diff changeset
601 // oop functions
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 // Address-to-Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
604 function addr2oop(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
606 return sa.objHeap.newOop(addr.addOffsetToAsOopHandle(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // Oop-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
610 function oop2addr(oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 return oop.handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // 'oop' to higher-level java object wrapper in which for(i in o)
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // works by iterating java level fields and javaobject.javafield
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // syntax works.
a61af66fc99e Initial load
duke
parents:
diff changeset
617 function oop2obj(oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
618 return object(addr2str(oop.handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // higher level java object wrapper to oop
a61af66fc99e Initial load
duke
parents:
diff changeset
622 function obj2oop(obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 return addr2oop(str2addr(address(obj)));
a61af66fc99e Initial load
duke
parents:
diff changeset
624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // Java heap iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 // iterates Java heap for each Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
629 function forEachOop(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
630 sa.objHeap.iterate(new sapkg.oops.HeapVisitor() { doObj: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // iterates Java heap for each Oop of given 'klass'.
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // 'includeSubtypes' tells whether to include objects
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // of subtypes of 'klass' or not
a61af66fc99e Initial load
duke
parents:
diff changeset
636 function forEachOopOfKlass(callback, klass, includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 if (klass == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 klass = findInstanceKlass("java.lang.Object");
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 if (includeSubtypes == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 includeSubtypes = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644 sa.objHeap.iterateObjectsOfKlass(
a61af66fc99e Initial load
duke
parents:
diff changeset
645 new sapkg.oops.HeapVisitor() { doObj: callback },
a61af66fc99e Initial load
duke
parents:
diff changeset
646 klass, includeSubtypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // code cache functions
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651 // iterates CodeCache for each 'CodeBlob'
a61af66fc99e Initial load
duke
parents:
diff changeset
652 function forEachCodeBlob(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
653 var VisitorClass = sapkg.code.CodeCacheVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
654 sa.codeCache.iterate(new VisitorClass() { visit: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
656
a61af66fc99e Initial load
duke
parents:
diff changeset
657 // find the ClodBlob (if any) that contains given address
a61af66fc99e Initial load
duke
parents:
diff changeset
658 function findCodeBlob(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
660 return sa.codeCache.findBlobUnsafe(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // find the NMethod (if any) that contains given address
a61af66fc99e Initial load
duke
parents:
diff changeset
664 function findNMethod(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 var codeBlob = findCodeBlob(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
666 return (codeBlob != null && codeBlob.isNMethod())? codeBlob : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // returns PcDesc at given address or null
a61af66fc99e Initial load
duke
parents:
diff changeset
670 function pcDescAt(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
672 var nmethod = findNMethod(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
673 return (nmethod != null)? nmethod.safepoints.get(addr) : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // helpers for nmethod disassembler
a61af66fc99e Initial load
duke
parents:
diff changeset
677 function printScope(scopeDesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
678 if (scopeDesc == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
680 }
a61af66fc99e Initial load
duke
parents:
diff changeset
681 printScope(scopeDesc.sender());
a61af66fc99e Initial load
duke
parents:
diff changeset
682 var method = scopeDesc.method;
a61af66fc99e Initial load
duke
parents:
diff changeset
683 var bci = scopeDesc.BCI;
a61af66fc99e Initial load
duke
parents:
diff changeset
684 var line = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
685 if (method.hasLineNumberTable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 line = method.getLineNumberFromBCI(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688
a61af66fc99e Initial load
duke
parents:
diff changeset
689 write('\t', method.externalNameAndSignature(), '@', method.handle, 'bci=' + bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
690 if (line != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
691 write('line=' + line);
a61af66fc99e Initial load
duke
parents:
diff changeset
692 }
a61af66fc99e Initial load
duke
parents:
diff changeset
693 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695
a61af66fc99e Initial load
duke
parents:
diff changeset
696 function printSafepointInfo(nmethod, pcDesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 var scopeDesc = nmethod.getScopeDescAt(
a61af66fc99e Initial load
duke
parents:
diff changeset
698 pcDesc.getRealPC(nmethod),
a61af66fc99e Initial load
duke
parents:
diff changeset
699 pcDesc.isAtCall());
a61af66fc99e Initial load
duke
parents:
diff changeset
700 printScope(scopeDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
702
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // print disassembly for a given nmethod
a61af66fc99e Initial load
duke
parents:
diff changeset
704 function nmethoddis(nmethod) {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 var DisAsmClass = disassemblerClass();
a61af66fc99e Initial load
duke
parents:
diff changeset
706 if (DisAsmClass == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 writeln(CPU + " is not yet supported!");
a61af66fc99e Initial load
duke
parents:
diff changeset
708 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
710
a61af66fc99e Initial load
duke
parents:
diff changeset
711 var method = nmethod.method;
a61af66fc99e Initial load
duke
parents:
diff changeset
712 writeln('NMethod:', method.externalNameAndSignature(), '@', method.handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 var codeBegin = nmethod.codeBegin();
a61af66fc99e Initial load
duke
parents:
diff changeset
715 var codeEnd = nmethod.codeEnd();
a61af66fc99e Initial load
duke
parents:
diff changeset
716 var size = codeEnd.minus(codeBegin);
a61af66fc99e Initial load
duke
parents:
diff changeset
717 var code = readBytesAt(codeBegin, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
718 var startPc = addr2num(codeBegin);
a61af66fc99e Initial load
duke
parents:
diff changeset
719 var verifiedEntryPoint = addr2num(nmethod.verifiedEntryPoint);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 var entryPoint = addr2num(nmethod.entryPoint);
a61af66fc99e Initial load
duke
parents:
diff changeset
721 var interpreterEntryPoint = addr2num(nmethod.interpreterEntryPointOrNull);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 var safepoints = nmethod.safepoints;
a61af66fc99e Initial load
duke
parents:
diff changeset
723 var disAsm = new DisAsmClass(startPc, code);
a61af66fc99e Initial load
duke
parents:
diff changeset
724 disAsm.decode(new sapkg.asm.InstructionVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 visit: function(curPc, instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
726 if (curPc == verifiedEntryPoint) {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
728 writeln("Verified Entry Point:");
a61af66fc99e Initial load
duke
parents:
diff changeset
729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (curPc == entryPoint) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
732 writeln("Entry Point:");
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }
a61af66fc99e Initial load
duke
parents:
diff changeset
734 if (curPc == interpreterEntryPoint) {
a61af66fc99e Initial load
duke
parents:
diff changeset
735 writeln("");
a61af66fc99e Initial load
duke
parents:
diff changeset
736 writeln("Interpreter Entry Point:");
a61af66fc99e Initial load
duke
parents:
diff changeset
737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
738
a61af66fc99e Initial load
duke
parents:
diff changeset
739 var pcDesc = safepoints.get(num2addr(curPc));
a61af66fc99e Initial load
duke
parents:
diff changeset
740 var isSafepoint = (pcDesc != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
741 if (isSafepoint && pcDesc.isAtCall()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 printSafepointInfo(nmethod, pcDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
744
a61af66fc99e Initial load
duke
parents:
diff changeset
745 write(num2addr(curPc) + ':', '\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
746 writeln(instr.asString(curPc,
a61af66fc99e Initial load
duke
parents:
diff changeset
747 new sapkg.asm.SymbolFinder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
748 getSymbolFor: function(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
749 return addr2sym(num2addr(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
750 }
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
752
a61af66fc99e Initial load
duke
parents:
diff changeset
753 if (isSafepoint && !pcDesc.isAtCall()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
754 printSafepointInfo(nmethod, pcDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
757 });
a61af66fc99e Initial load
duke
parents:
diff changeset
758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
759
a61af66fc99e Initial load
duke
parents:
diff changeset
760 // bytecode interpreter functions
a61af66fc99e Initial load
duke
parents:
diff changeset
761
a61af66fc99e Initial load
duke
parents:
diff changeset
762 // iterates interpreter codelets for each interpreter codelet
a61af66fc99e Initial load
duke
parents:
diff changeset
763 function forEachInterpCodelet(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 var stubQueue = sa.interpreter.code;
a61af66fc99e Initial load
duke
parents:
diff changeset
765 var stub = stubQueue.first;
a61af66fc99e Initial load
duke
parents:
diff changeset
766 while (stub != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 if (callback(stub) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
768 stub = stubQueue.getNext(stub);
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // helper for bytecode disassembler
a61af66fc99e Initial load
duke
parents:
diff changeset
773 function printExceptionTable(method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
774 var expTbl = method.getExceptionTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
775 var len = expTbl.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
776 if (len != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
777 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
778 var cpool = method.constants;
a61af66fc99e Initial load
duke
parents:
diff changeset
779 writeln("start", '\t', "end", '\t', "handler", '\t', "exception");
a61af66fc99e Initial load
duke
parents:
diff changeset
780 writeln("");
a61af66fc99e Initial load
duke
parents:
diff changeset
781 for (i = 0; i < len; i += 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
782 write(expTbl.getIntAt(i), '\t',
a61af66fc99e Initial load
duke
parents:
diff changeset
783 expTbl.getIntAt(i + 1), '\t',
a61af66fc99e Initial load
duke
parents:
diff changeset
784 expTbl.getIntAt(i + 2), '\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
785 var cpIndex = expTbl.getIntAt(i + 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
786 var oop = (cpIndex == 0)? null : cpool.getObjAt(cpIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
787 if (oop == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
788 writeln("<any>");
a61af66fc99e Initial load
duke
parents:
diff changeset
789 } else if (oop.isSymbol()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
790 writeln(oop.asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
791 } else if (oop.isKlass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
792 writeln(oop.name.asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
793 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
794 writeln(cpIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796 }
a61af66fc99e Initial load
duke
parents:
diff changeset
797 }
a61af66fc99e Initial load
duke
parents:
diff changeset
798 }
a61af66fc99e Initial load
duke
parents:
diff changeset
799
a61af66fc99e Initial load
duke
parents:
diff changeset
800 // print Java bytecode disassembly
a61af66fc99e Initial load
duke
parents:
diff changeset
801 function jdis(method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
802 if (method.getByteCode == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // method oop may be specified by address
a61af66fc99e Initial load
duke
parents:
diff changeset
804 method = addr2oop(any2addr(method));
a61af66fc99e Initial load
duke
parents:
diff changeset
805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
806 writeln(method, '-', method.externalNameAndSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (method.isNative()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 writeln("native method");
a61af66fc99e Initial load
duke
parents:
diff changeset
809 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811 if (method.isAbstract()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 writeln("abstract method");
a61af66fc99e Initial load
duke
parents:
diff changeset
813 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
817 var BytecodeDisAsmClass = sapkg.interpreter.BytecodeDisassembler;
a61af66fc99e Initial load
duke
parents:
diff changeset
818 var disAsm = new BytecodeDisAsmClass(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
819 var bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
820 var hasLines = method.hasLineNumberTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
821 if (hasLines) {
a61af66fc99e Initial load
duke
parents:
diff changeset
822 writeln("bci", '\t', "line", '\t', "instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
823 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
824 writeln("bci", '\t', "instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
825 }
a61af66fc99e Initial load
duke
parents:
diff changeset
826 writeln("");
a61af66fc99e Initial load
duke
parents:
diff changeset
827 disAsm.decode(new sapkg.interpreter.BytecodeVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 visit: function(bytecode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 if (hasLines) {
a61af66fc99e Initial load
duke
parents:
diff changeset
830 var line = method.getLineNumberFromBCI(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
831 writeln(bci, '\t', line, '\t', bytecode);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 writeln(bci, '\t', bytecode);
a61af66fc99e Initial load
duke
parents:
diff changeset
834 }
a61af66fc99e Initial load
duke
parents:
diff changeset
835 bci++;
a61af66fc99e Initial load
duke
parents:
diff changeset
836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
837 });
a61af66fc99e Initial load
duke
parents:
diff changeset
838
a61af66fc99e Initial load
duke
parents:
diff changeset
839 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
840 printExceptionTable(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 // Java thread
a61af66fc99e Initial load
duke
parents:
diff changeset
844
a61af66fc99e Initial load
duke
parents:
diff changeset
845 // iterates each Thread
a61af66fc99e Initial load
duke
parents:
diff changeset
846 function forEachJavaThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 var threads = sa.threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
848 var thread = threads.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
849 while (thread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 if (callback(thread) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
851 thread = thread.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
854
a61af66fc99e Initial load
duke
parents:
diff changeset
855 // iterate Frames of a given thread
a61af66fc99e Initial load
duke
parents:
diff changeset
856 function forEachFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 var fr = javaThread.getLastFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
858 while (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 if (callback(fr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
860 fr = fr.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863
a61af66fc99e Initial load
duke
parents:
diff changeset
864 // iterate JavaVFrames of a given JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
865 function forEachVFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
866 var vfr = javaThread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
867 while (vfr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (callback(vfr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
869 vfr = vfr.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 function printStackTrace(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 write("Thread ");
a61af66fc99e Initial load
duke
parents:
diff changeset
875 javaThread.printThreadIDOn(java.lang.System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
877 forEachVFrame(javaThread, function (vf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 var method = vf.method;
a61af66fc99e Initial load
duke
parents:
diff changeset
879 write(' - ', method.externalNameAndSignature(), '@bci =', vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
880 var line = method.getLineNumberFromBCI(vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
881 if (line != -1) { write(', line=', line); }
a61af66fc99e Initial load
duke
parents:
diff changeset
882 if (vf.isCompiledFrame()) { write(" (Compiled Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 if (vf.isInterpretedFrame()) { write(" (Interpreted Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
884 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
885 });
a61af66fc99e Initial load
duke
parents:
diff changeset
886 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
887 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
888 }
a61af66fc99e Initial load
duke
parents:
diff changeset
889
a61af66fc99e Initial load
duke
parents:
diff changeset
890 // print Java stack trace for all threads
a61af66fc99e Initial load
duke
parents:
diff changeset
891 function where(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
892 if (javaThread == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
893 forEachJavaThread(function (jt) { printStackTrace(jt); });
a61af66fc99e Initial load
duke
parents:
diff changeset
894 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
895 printStackTrace(javaThread);
a61af66fc99e Initial load
duke
parents:
diff changeset
896 }
a61af66fc99e Initial load
duke
parents:
diff changeset
897 }
a61af66fc99e Initial load
duke
parents:
diff changeset
898
a61af66fc99e Initial load
duke
parents:
diff changeset
899 // vmStructs access -- type database functions
a61af66fc99e Initial load
duke
parents:
diff changeset
900
a61af66fc99e Initial load
duke
parents:
diff changeset
901 // find a VM type
a61af66fc99e Initial load
duke
parents:
diff changeset
902 function findVMType(typeName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
903 return sa.typedb.lookupType(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
904 }
a61af66fc99e Initial load
duke
parents:
diff changeset
905
a61af66fc99e Initial load
duke
parents:
diff changeset
906 // iterate VM types
a61af66fc99e Initial load
duke
parents:
diff changeset
907 function forEachVMType(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
908 var itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
910 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
911 }
a61af66fc99e Initial load
duke
parents:
diff changeset
912 }
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // find VM int constant
a61af66fc99e Initial load
duke
parents:
diff changeset
915 function findVMIntConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 return sa.typedb.lookupIntConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
917 }
a61af66fc99e Initial load
duke
parents:
diff changeset
918
a61af66fc99e Initial load
duke
parents:
diff changeset
919 // find VM long constant
a61af66fc99e Initial load
duke
parents:
diff changeset
920 function findVMLongConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
921 return sa.typedb.lookupLongConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
922 }
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924 // iterate VM int constants
a61af66fc99e Initial load
duke
parents:
diff changeset
925 function forEachVMIntConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
926 var itr = sa.typedb.intConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
927 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
928 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
930 }
a61af66fc99e Initial load
duke
parents:
diff changeset
931
a61af66fc99e Initial load
duke
parents:
diff changeset
932 // iterate VM long constants
a61af66fc99e Initial load
duke
parents:
diff changeset
933 function forEachVMLongConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 var itr = sa.typedb.longConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
935 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
936 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
937 }
a61af66fc99e Initial load
duke
parents:
diff changeset
938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
939
a61af66fc99e Initial load
duke
parents:
diff changeset
940 // returns VM Type at address
a61af66fc99e Initial load
duke
parents:
diff changeset
941 function vmTypeof(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
942 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
943 return sa.typedb.guessTypeForAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
944 }
a61af66fc99e Initial load
duke
parents:
diff changeset
945
a61af66fc99e Initial load
duke
parents:
diff changeset
946 // does the given 'addr' points to an object of given 'type'?
a61af66fc99e Initial load
duke
parents:
diff changeset
947 // OR any valid Type at all (if type is undefined)
a61af66fc99e Initial load
duke
parents:
diff changeset
948 function isOfVMType(addr, type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
949 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
950 if (type == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
951 return vmTypeof(addr) != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
952 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
953 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
954 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
955 }
a61af66fc99e Initial load
duke
parents:
diff changeset
956 return sa.typedb.addressTypeIsEqualToType(addr, type);
a61af66fc99e Initial load
duke
parents:
diff changeset
957 }
a61af66fc99e Initial load
duke
parents:
diff changeset
958 }
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 // reads static field value
a61af66fc99e Initial load
duke
parents:
diff changeset
961 function readVMStaticField(field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
962 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
964 return field.value;
a61af66fc99e Initial load
duke
parents:
diff changeset
965 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 return field.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
967 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
968 return field.oopHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
969 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
970 return field.staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
971 }
a61af66fc99e Initial load
duke
parents:
diff changeset
972 }
a61af66fc99e Initial load
duke
parents:
diff changeset
973
a61af66fc99e Initial load
duke
parents:
diff changeset
974 // reads given instance field of VM object at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
975 function readVMInstanceField(field, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
976 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
977 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 return field.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
979 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
980 return field.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
981 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
982 return field.getOopHandle(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
983 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
984 return addr.addOffsetTo(field.offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
985 }
a61af66fc99e Initial load
duke
parents:
diff changeset
986 }
a61af66fc99e Initial load
duke
parents:
diff changeset
987
a61af66fc99e Initial load
duke
parents:
diff changeset
988 // returns name-value of pairs of VM type at given address.
a61af66fc99e Initial load
duke
parents:
diff changeset
989 // If address is unspecified, reads static fields as name-value pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
990 function readVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
991 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
992 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
993 }
a61af66fc99e Initial load
duke
parents:
diff changeset
994 if (addr != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
995 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
996 }
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998 var result = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
999 var staticOnly = (addr == undefined);
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 var isStatic = field.isStatic();
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 if (staticOnly && isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 result[field.name] = readVMStaticField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 } else if (!staticOnly && !isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 result[field.name] = readVMInstanceField(field, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1015
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 function printVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 var obj = readVMType(type, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 var name = field.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 var value = obj[name];
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 if (value != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 writeln(field.type.name, type.name + '::' + name, '=', value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1034
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 // define readXXX and printXXX functions for each VM struct/class Type
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 tmp = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 tmp.itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 while (tmp.itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 tmp.type = tmp.itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 tmp.name = tmp.type.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 if (tmp.type.isPointerType() || tmp.type.isOopType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 tmp.type.isCIntegerType() || tmp.type.isJavaPrimitiveType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 tmp.name.equals('address') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 tmp.name.equals("<opaque>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 // ignore;
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 // some type names have ':'. replace to make it as a
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 // JavaScript identifier
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 0
diff changeset
1050 tmp.name = tmp.name.replace(':', '_').replace('<', '_').replace('>', '_').replace('*', '_').replace(' ', '_');
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 eval("function read" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 " return readVMType('" + tmp.name + "', addr);}");
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 eval("function print" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 " printVMType('" + tmp.name + "', addr); }");
a61af66fc99e Initial load
duke
parents:
diff changeset
1055
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 /* FIXME: do we need this?
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 if (typeof(registerCommand) != 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 var name = "print" + tmp.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 registerCommand(name, name + " [address]", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 //clean-up the temporary
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 delete tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // VMObject factory
a61af66fc99e Initial load
duke
parents:
diff changeset
1068
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 // VM type to SA class map
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 var vmType2Class = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1071
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 // This is *not* exhaustive. Add more if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 // code blobs
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 vmType2Class["BufferBlob"] = sapkg.code.BufferBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 vmType2Class["nmethod"] = sapkg.code.NMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 vmType2Class["RuntimeStub"] = sapkg.code.RuntimeStub;
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 vmType2Class["SafepointBlob"] = sapkg.code.SafepointBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 vmType2Class["C2IAdapter"] = sapkg.code.C2IAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 vmType2Class["DeoptimizationBlob"] = sapkg.code.DeoptimizationBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 vmType2Class["ExceptionBlob"] = sapkg.code.ExceptionBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 vmType2Class["I2CAdapter"] = sapkg.code.I2CAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 vmType2Class["OSRAdapter"] = sapkg.code.OSRAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 vmType2Class["UncommonTrapBlob"] = sapkg.code.UncommonTrapBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 vmType2Class["PCDesc"] = sapkg.code.PCDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 // interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 vmType2Class["InterpreterCodelet"] = sapkg.interpreter.InterpreterCodelet;
a61af66fc99e Initial load
duke
parents:
diff changeset
1088
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 // Java Threads
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 vmType2Class["JavaThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 vmType2Class["CompilerThread"] = sapkg.runtime.CompilerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 vmType2Class["SurrogateLockerThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 vmType2Class["DebuggerThread"] = sapkg.runtime.DebuggerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
1094
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 // gc
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 vmType2Class["GenCollectedHeap"] = sapkg.memory.GenCollectedHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 vmType2Class["CompactingPermGenGen"] = sapkg.memory.CompactingPermGenGen;
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 vmType2Class["DefNewGeneration"] = sapkg.memory.DefNewGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 vmType2Class["TenuredGeneration"] = sapkg.memory.TenuredGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
1100
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 // generic VMObject factory for a given address
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 // This is equivalent to VirtualConstructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 function newVMObject(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 var result = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 forEachVMType(function (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 if (isOfVMType(addr, type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 var clazz = vmType2Class[type.name];
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 if (clazz != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 result = new clazz(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1119
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 function vmobj2addr(vmobj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 return vmobj.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1123
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 function addr2vmobj(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 return newVMObject(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1127
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 // Miscellaneous utilities
a61af66fc99e Initial load
duke
parents:
diff changeset
1129
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 // returns PointerLocation that describes the given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 function findPtr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 return sapkg.utilities.PointerFinder.find(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1135
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 // is given address a valid Oop?
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 function isOop(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 var oopHandle = addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 return sapkg.utilities.RobustOopDeterminator.oopLooksValid(oopHandle);
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1142
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 // returns description of given pointer as a String
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 function whatis(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 var ptrLoc = findPtr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 if (ptrLoc.isUnknown()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 var vmType = vmTypeof(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 if (vmType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 return "pointer to " + vmType.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 return ptrLoc.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 return ptrLoc.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }