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

6879063: SA should use hsdis for disassembly Summary: We should in SA to use hsdis for it like the JVM does to replace the current java based disassembler. Reviewed-by: twisti, jrose, sla Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 24 Sep 2012 12:44:00 -0700
parents da91efe96a93
children 5ed317b25e23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2042
diff changeset
2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // shorter names for SA packages
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // SA package name abbreviations are kept in 'sapkg' object
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // to avoid global namespace pollution
a61af66fc99e Initial load
duke
parents:
diff changeset
30 var sapkg = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 sapkg.hotspot = Packages.sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 sapkg.asm = sapkg.hotspot.asm;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 sapkg.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.jclass = function(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (typeof(name) == "string") {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 var clazz = sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (clazz) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2042
diff changeset
228 writeln(clazz.getName().asString() + " @" + clazz.getAddress().toString());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
229 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 writeln("class not found: " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 writeln("Usage: class name");
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 registerCommand("class", "class name", "jclass");
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 this.jclasses = function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 forEachKlass(function (clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 writeln(clazz.getName().asString() + " @" + clazz.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
241 });
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 registerCommand("classes", "classes", "jclasses");
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 this.dclass = function(clazz, dir) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (!clazz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 writeln("Usage: dumpclass { address | name } [ directory ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
248 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (!dir) { dir = "."; }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 dumpClass(clazz, dir);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 registerCommand("dumpclass", "dumpclass { address | name } [ directory ]", "dclass");
a61af66fc99e Initial load
duke
parents:
diff changeset
254 registerCommand("dumpheap", "dumpheap [ file ]", "dumpHeap");
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 this.jseval = function(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (!str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 writeln("Usage: jseval script");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 var res = eval(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if (res) { writeln(res); }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 registerCommand("jseval", "jseval script", "jseval");
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 this.jsload = function(file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (!file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 writeln("Usage: jsload file");
a61af66fc99e Initial load
duke
parents:
diff changeset
269 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 load(file);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273 registerCommand("jsload", "jsload file", "jsload");
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 this.printMem = function(addr, len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 writeln("Usage: mem [ length ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
278 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 mem(addr, len);
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("mem", "mem address [ length ]", "printMem");
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 this.sysProps = function() {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 for (var i in jvm.sysProps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 writeln(i + ' = ' + jvm.sysProps[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 registerCommand("sysprops", "sysprops", "sysProps");
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 this.printWhatis = function(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if (!addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 writeln("Usage: whatis address");
a61af66fc99e Initial load
duke
parents:
diff changeset
294 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 writeln(whatis(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 registerCommand("whatis", "whatis address", "printWhatis");
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // debugger functionality
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // string-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
305 function str2addr(str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return sa.dbg.parseAddress(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // number-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (addressSize == 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 eval("function num2addr(num) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
312 return str2addr('0x' + java.lang.Integer.toHexString(0xffffffff & num)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }");
a61af66fc99e Initial load
duke
parents:
diff changeset
314 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 eval("function num2addr(num) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
316 return str2addr('0x' + java.lang.Long.toHexString(num)); \
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 // generic any-type-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // use this convenience function to accept address in any
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // format -- number, string or an Address instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
323 function any2addr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 var type = typeof(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 if (type == 'number') {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 return num2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 } else if (type == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 return str2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // Address-to-string
a61af66fc99e Initial load
duke
parents:
diff changeset
335 function addr2str(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 return (addressSize == 4)? '0x00000000' : '0x0000000000000000';
a61af66fc99e Initial load
duke
parents:
diff changeset
338 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 return addr + '';
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // Address-to-number
a61af66fc99e Initial load
duke
parents:
diff changeset
344 function addr2num(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 return sa.dbg.getAddressValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 // symbol-to-Address
a61af66fc99e Initial load
duke
parents:
diff changeset
349 function sym2addr(dso, sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 return sa.dbg.lookup(dso, sym);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // returns the ClosestSymbol or null
a61af66fc99e Initial load
duke
parents:
diff changeset
354 function closestSymbolFor(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // no CDebugger support, return null
a61af66fc99e Initial load
duke
parents:
diff changeset
357 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 var dso = sa.cdbg.loadObjectContainingPC(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 if (dso != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return dso.closestSymbolToPC(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // Address-to-symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // returns nearest symbol as string if found
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // else returns address as string
a61af66fc99e Initial load
duke
parents:
diff changeset
371 function addr2sym(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 return addr2str(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // read 'num' words at 'addr' and return an array as result.
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // returns Java long[] type result and not a JavaScript array.
a61af66fc99e Initial load
duke
parents:
diff changeset
382 function readWordsAt(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 var res = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, num);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 res[i] = addr2num(addr.getAddressAt(i * addressSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // read the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
393 function readCStrAt(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 return sapkg.utilities.CStringUtilities.getString(addr);
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 the length of the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
399 function readCStrLen(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 return sapkg.utilities.CStringUtilities.getStringLength(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // iterate through ThreadList of CDebugger
a61af66fc99e Initial load
duke
parents:
diff changeset
405 function forEachThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
408 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 var itr = sa.cdbg.threadList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
411 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // read register set of a ThreadProxy as name-value pairs
a61af66fc99e Initial load
duke
parents:
diff changeset
418 function readRegs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 var ctx = threadProxy.context;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 var num = ctx.numRegisters;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 var res = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
422 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 res[ctx.getRegisterName(i)]= addr2str(ctx.getRegisterAsAddress(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // print register set for a given ThreaProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
430 function regs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 var res = readRegs(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 for (i in res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 writeln(i, '=', res[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // iterate through each CFrame of a given ThreadProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
438 function forEachCFrame(threadProxy, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
441 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 var cframe = sa.cdbg.topFrameForThread(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 while (cframe != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 if (callback(cframe) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 cframe = cframe.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // iterate through list of load objects (DLLs, DSOs)
a61af66fc99e Initial load
duke
parents:
diff changeset
452 function forEachLoadObject(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
455 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 var itr = sa.cdbg.loadObjectList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
458 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463
a61af66fc99e Initial load
duke
parents:
diff changeset
464 // print 'num' words at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
465 function mem(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (num == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 num = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 var value = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 writeln(addr2sym(addr) + ':', addr2str(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
474 addr = addr.addOffsetTo(addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // System dictionary functions
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // find InstanceKlass by name
a61af66fc99e Initial load
duke
parents:
diff changeset
482 function findInstanceKlass(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
483 return sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // get Java system loader (i.e., application launcher loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
487 function systemLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return sa.sysDict.javaSystemLoader();
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // iterate system dictionary for each 'Klass'
a61af66fc99e Initial load
duke
parents:
diff changeset
492 function forEachKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
494 var visitor = new VisitorClass() { visit: callback };
a61af66fc99e Initial load
duke
parents:
diff changeset
495 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassVisitor)"](visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // iterate system dictionary for each 'Klass' and initiating loader
a61af66fc99e Initial load
duke
parents:
diff changeset
499 function forEachKlassAndLoader(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
500 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
501 var visitor = new VisitorClass() { visit: callback };
a61af66fc99e Initial load
duke
parents:
diff changeset
502 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassAndLoaderVisitor)"](visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // iterate system dictionary for each primitive array klass
a61af66fc99e Initial load
duke
parents:
diff changeset
506 function forEachPrimArrayKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
507 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 sa.sysDict.primArrayClassesDo(new VisitorClass() { visit: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // 'oop' to higher-level java object wrapper in which for(i in o)
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // works by iterating java level fields and javaobject.javafield
a61af66fc99e Initial load
duke
parents:
diff changeset
513 // syntax works.
a61af66fc99e Initial load
duke
parents:
diff changeset
514 function oop2obj(oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 return object(addr2str(oop.handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // higher level java object wrapper to oop
a61af66fc99e Initial load
duke
parents:
diff changeset
519 function obj2oop(obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 return addr2oop(str2addr(address(obj)));
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // Java heap iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // iterates Java heap for each Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
526 function forEachOop(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 sa.objHeap.iterate(new sapkg.oops.HeapVisitor() { doObj: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
528 }
a61af66fc99e Initial load
duke
parents:
diff changeset
529
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // iterates Java heap for each Oop of given 'klass'.
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // 'includeSubtypes' tells whether to include objects
a61af66fc99e Initial load
duke
parents:
diff changeset
532 // of subtypes of 'klass' or not
a61af66fc99e Initial load
duke
parents:
diff changeset
533 function forEachOopOfKlass(callback, klass, includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 if (klass == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 klass = findInstanceKlass("java.lang.Object");
a61af66fc99e Initial load
duke
parents:
diff changeset
536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 if (includeSubtypes == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
539 includeSubtypes = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541 sa.objHeap.iterateObjectsOfKlass(
a61af66fc99e Initial load
duke
parents:
diff changeset
542 new sapkg.oops.HeapVisitor() { doObj: callback },
a61af66fc99e Initial load
duke
parents:
diff changeset
543 klass, includeSubtypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
545
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // Java thread
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // iterates each Thread
a61af66fc99e Initial load
duke
parents:
diff changeset
549 function forEachJavaThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
550 var threads = sa.threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
551 var thread = threads.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
552 while (thread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 if (callback(thread) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
554 thread = thread.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // iterate Frames of a given thread
a61af66fc99e Initial load
duke
parents:
diff changeset
559 function forEachFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 var fr = javaThread.getLastFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
561 while (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 if (callback(fr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 fr = fr.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // iterate JavaVFrames of a given JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
568 function forEachVFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 var vfr = javaThread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
570 while (vfr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 if (callback(vfr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 vfr = vfr.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
573 }
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 function printStackTrace(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
577 write("Thread ");
a61af66fc99e Initial load
duke
parents:
diff changeset
578 javaThread.printThreadIDOn(java.lang.System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
580 forEachVFrame(javaThread, function (vf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 var method = vf.method;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 write(' - ', method.externalNameAndSignature(), '@bci =', vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
583 var line = method.getLineNumberFromBCI(vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (line != -1) { write(', line=', line); }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 if (vf.isCompiledFrame()) { write(" (Compiled Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
586 if (vf.isInterpretedFrame()) { write(" (Interpreted Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 });
a61af66fc99e Initial load
duke
parents:
diff changeset
589 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
590 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // print Java stack trace for all threads
a61af66fc99e Initial load
duke
parents:
diff changeset
594 function where(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 if (javaThread == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 forEachJavaThread(function (jt) { printStackTrace(jt); });
a61af66fc99e Initial load
duke
parents:
diff changeset
597 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 printStackTrace(javaThread);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 // vmStructs access -- type database functions
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 // find a VM type
a61af66fc99e Initial load
duke
parents:
diff changeset
605 function findVMType(typeName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 return sa.typedb.lookupType(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // iterate VM types
a61af66fc99e Initial load
duke
parents:
diff changeset
610 function forEachVMType(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 var itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615 }
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // find VM int constant
a61af66fc99e Initial load
duke
parents:
diff changeset
618 function findVMIntConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 return sa.typedb.lookupIntConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // find VM long constant
a61af66fc99e Initial load
duke
parents:
diff changeset
623 function findVMLongConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 return sa.typedb.lookupLongConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // iterate VM int constants
a61af66fc99e Initial load
duke
parents:
diff changeset
628 function forEachVMIntConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 var itr = sa.typedb.intConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
631 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // iterate VM long constants
a61af66fc99e Initial load
duke
parents:
diff changeset
636 function forEachVMLongConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 var itr = sa.typedb.longConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
639 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // returns VM Type at address
a61af66fc99e Initial load
duke
parents:
diff changeset
644 function vmTypeof(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 return sa.typedb.guessTypeForAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // does the given 'addr' points to an object of given 'type'?
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // OR any valid Type at all (if type is undefined)
a61af66fc99e Initial load
duke
parents:
diff changeset
651 function isOfVMType(addr, type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
652 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
653 if (type == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 return vmTypeof(addr) != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
655 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
656 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
657 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
659 return sa.typedb.addressTypeIsEqualToType(addr, type);
a61af66fc99e Initial load
duke
parents:
diff changeset
660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // reads static field value
a61af66fc99e Initial load
duke
parents:
diff changeset
664 function readVMStaticField(field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 return field.value;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
669 return field.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 return field.oopHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 return field.staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
676
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // reads given instance field of VM object at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
678 function readVMInstanceField(field, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
680 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 return field.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
683 return field.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
684 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 return field.getOopHandle(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
686 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 return addr.addOffsetTo(field.offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
688 }
a61af66fc99e Initial load
duke
parents:
diff changeset
689 }
a61af66fc99e Initial load
duke
parents:
diff changeset
690
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // returns name-value of pairs of VM type at given address.
a61af66fc99e Initial load
duke
parents:
diff changeset
692 // If address is unspecified, reads static fields as name-value pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
693 function readVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
694 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
695 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697 if (addr != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 var result = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
702 var staticOnly = (addr == undefined);
a61af66fc99e Initial load
duke
parents:
diff changeset
703 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
704 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
705 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
706 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
707 var isStatic = field.isStatic();
a61af66fc99e Initial load
duke
parents:
diff changeset
708 if (staticOnly && isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 result[field.name] = readVMStaticField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
710 } else if (!staticOnly && !isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
711 result[field.name] = readVMInstanceField(field, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
714 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719 function printVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
723 var obj = readVMType(type, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
724 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
726 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
728 var name = field.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
729 var value = obj[name];
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (value != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 writeln(field.type.name, type.name + '::' + name, '=', value);
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }
a61af66fc99e Initial load
duke
parents:
diff changeset
734 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
737
a61af66fc99e Initial load
duke
parents:
diff changeset
738 // define readXXX and printXXX functions for each VM struct/class Type
a61af66fc99e Initial load
duke
parents:
diff changeset
739 tmp = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
740 tmp.itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
741 while (tmp.itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 tmp.type = tmp.itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
743 tmp.name = tmp.type.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
744 if (tmp.type.isPointerType() || tmp.type.isOopType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
745 tmp.type.isCIntegerType() || tmp.type.isJavaPrimitiveType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
746 tmp.name.equals('address') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
747 tmp.name.equals("<opaque>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
748 // ignore;
a61af66fc99e Initial load
duke
parents:
diff changeset
749 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
750 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 // some type names have ':'. replace to make it as a
a61af66fc99e Initial load
duke
parents:
diff changeset
752 // JavaScript identifier
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 0
diff changeset
753 tmp.name = tmp.name.replace(':', '_').replace('<', '_').replace('>', '_').replace('*', '_').replace(' ', '_');
0
a61af66fc99e Initial load
duke
parents:
diff changeset
754 eval("function read" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
755 " return readVMType('" + tmp.name + "', addr);}");
a61af66fc99e Initial load
duke
parents:
diff changeset
756 eval("function print" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
757 " printVMType('" + tmp.name + "', addr); }");
a61af66fc99e Initial load
duke
parents:
diff changeset
758
a61af66fc99e Initial load
duke
parents:
diff changeset
759 /* FIXME: do we need this?
a61af66fc99e Initial load
duke
parents:
diff changeset
760 if (typeof(registerCommand) != 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 var name = "print" + tmp.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
762 registerCommand(name, name + " [address]", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
764 */
a61af66fc99e Initial load
duke
parents:
diff changeset
765 }
a61af66fc99e Initial load
duke
parents:
diff changeset
766 }
a61af66fc99e Initial load
duke
parents:
diff changeset
767 //clean-up the temporary
a61af66fc99e Initial load
duke
parents:
diff changeset
768 delete tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 // VMObject factory
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // VM type to SA class map
a61af66fc99e Initial load
duke
parents:
diff changeset
773 var vmType2Class = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
774
a61af66fc99e Initial load
duke
parents:
diff changeset
775 // This is *not* exhaustive. Add more if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
776 // code blobs
a61af66fc99e Initial load
duke
parents:
diff changeset
777 vmType2Class["BufferBlob"] = sapkg.code.BufferBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
778 vmType2Class["nmethod"] = sapkg.code.NMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
779 vmType2Class["RuntimeStub"] = sapkg.code.RuntimeStub;
a61af66fc99e Initial load
duke
parents:
diff changeset
780 vmType2Class["SafepointBlob"] = sapkg.code.SafepointBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
781 vmType2Class["C2IAdapter"] = sapkg.code.C2IAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 vmType2Class["DeoptimizationBlob"] = sapkg.code.DeoptimizationBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 vmType2Class["ExceptionBlob"] = sapkg.code.ExceptionBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
784 vmType2Class["I2CAdapter"] = sapkg.code.I2CAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
785 vmType2Class["OSRAdapter"] = sapkg.code.OSRAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 vmType2Class["UncommonTrapBlob"] = sapkg.code.UncommonTrapBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
787 vmType2Class["PCDesc"] = sapkg.code.PCDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 // interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
790 vmType2Class["InterpreterCodelet"] = sapkg.interpreter.InterpreterCodelet;
a61af66fc99e Initial load
duke
parents:
diff changeset
791
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // Java Threads
a61af66fc99e Initial load
duke
parents:
diff changeset
793 vmType2Class["JavaThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
794 vmType2Class["CompilerThread"] = sapkg.runtime.CompilerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
795 vmType2Class["SurrogateLockerThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
796 vmType2Class["DebuggerThread"] = sapkg.runtime.DebuggerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
797
a61af66fc99e Initial load
duke
parents:
diff changeset
798 // gc
a61af66fc99e Initial load
duke
parents:
diff changeset
799 vmType2Class["GenCollectedHeap"] = sapkg.memory.GenCollectedHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
800 vmType2Class["DefNewGeneration"] = sapkg.memory.DefNewGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
801 vmType2Class["TenuredGeneration"] = sapkg.memory.TenuredGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
802
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // generic VMObject factory for a given address
a61af66fc99e Initial load
duke
parents:
diff changeset
804 // This is equivalent to VirtualConstructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
805 function newVMObject(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
806 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
807 var result = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
808 forEachVMType(function (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 if (isOfVMType(addr, type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 var clazz = vmType2Class[type.name];
a61af66fc99e Initial load
duke
parents:
diff changeset
811 if (clazz != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 result = new clazz(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
815 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
816 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
817 }
a61af66fc99e Initial load
duke
parents:
diff changeset
818 });
a61af66fc99e Initial load
duke
parents:
diff changeset
819 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
820 }
a61af66fc99e Initial load
duke
parents:
diff changeset
821
a61af66fc99e Initial load
duke
parents:
diff changeset
822 function vmobj2addr(vmobj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
823 return vmobj.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
825
a61af66fc99e Initial load
duke
parents:
diff changeset
826 function addr2vmobj(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
827 return newVMObject(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
828 }
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 // Miscellaneous utilities
a61af66fc99e Initial load
duke
parents:
diff changeset
831
a61af66fc99e Initial load
duke
parents:
diff changeset
832 // returns PointerLocation that describes the given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
833 function findPtr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
834 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
835 return sapkg.utilities.PointerFinder.find(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
837
a61af66fc99e Initial load
duke
parents:
diff changeset
838 // is given address a valid Oop?
a61af66fc99e Initial load
duke
parents:
diff changeset
839 function isOop(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 var oopHandle = addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
842 return sapkg.utilities.RobustOopDeterminator.oopLooksValid(oopHandle);
a61af66fc99e Initial load
duke
parents:
diff changeset
843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
844
a61af66fc99e Initial load
duke
parents:
diff changeset
845 // returns description of given pointer as a String
a61af66fc99e Initial load
duke
parents:
diff changeset
846 function whatis(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
848 var ptrLoc = findPtr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
849 if (ptrLoc.isUnknown()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 var vmType = vmTypeof(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
851 if (vmType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 return "pointer to " + vmType.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
853 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
855 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
856 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
857 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 return ptrLoc.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
862 return ptrLoc.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }