annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/sa.js @ 12097:e37ab280bbce

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