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

7127191: SA JSDB does not display native symbols correctly for transported Linux cores Summary: Better handle SA_ALTROOT Reviewed-by: sla, sspitsyn
author dsamersoff
date Wed, 12 Feb 2014 23:39:53 +0400
parents 46eeb3056482
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
14223
de6a9e811145 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12097
diff changeset
2 * Copyright (c) 2004, 2013, 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
14373
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
374 function loadObjectContainingPC(addr) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
375 if (sa.cdbg == null) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // no CDebugger support, return null
a61af66fc99e Initial load
duke
parents:
diff changeset
377 return null;
14373
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
378 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
379
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
380 return sa.cdbg.loadObjectContainingPC(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
381 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
382
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
383 // returns the ClosestSymbol or null
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
384 function closestSymbolFor(addr) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
385 var dso = loadObjectContainingPC(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
386 if (dso != null) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
387 return dso.closestSymbolToPC(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
388 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
389
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
390 return null;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 // Address-to-symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
394 // returns nearest symbol as string if found
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // else returns address as string
a61af66fc99e Initial load
duke
parents:
diff changeset
396 function addr2sym(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 var sym = closestSymbolFor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 return sym.name + '+' + sym.offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 return addr2str(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
a61af66fc99e Initial load
duke
parents:
diff changeset
405 // read 'num' words at 'addr' and return an array as result.
a61af66fc99e Initial load
duke
parents:
diff changeset
406 // returns Java long[] type result and not a JavaScript array.
a61af66fc99e Initial load
duke
parents:
diff changeset
407 function readWordsAt(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 var res = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, num);
a61af66fc99e Initial load
duke
parents:
diff changeset
410 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 res[i] = addr2num(addr.getAddressAt(i * addressSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 return res;
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 the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
418 function readCStrAt(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
420 return sapkg.utilities.CStringUtilities.getString(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // read the length of the 'C' string at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
424 function readCStrLen(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 return sapkg.utilities.CStringUtilities.getStringLength(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // iterate through ThreadList of CDebugger
a61af66fc99e Initial load
duke
parents:
diff changeset
430 function forEachThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
433 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 var itr = sa.cdbg.threadList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
436 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
438 }
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // read register set of a ThreadProxy as name-value pairs
a61af66fc99e Initial load
duke
parents:
diff changeset
443 function readRegs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 var ctx = threadProxy.context;
a61af66fc99e Initial load
duke
parents:
diff changeset
445 var num = ctx.numRegisters;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 var res = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
447 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 res[ctx.getRegisterName(i)]= addr2str(ctx.getRegisterAsAddress(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // print register set for a given ThreaProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
455 function regs(threadProxy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
456 var res = readRegs(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
457 for (i in res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
458 writeln(i, '=', res[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // iterate through each CFrame of a given ThreadProxy
a61af66fc99e Initial load
duke
parents:
diff changeset
463 function forEachCFrame(threadProxy, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
466 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 var cframe = sa.cdbg.topFrameForThread(threadProxy);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 while (cframe != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 if (callback(cframe) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 cframe = cframe.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // iterate through list of load objects (DLLs, DSOs)
a61af66fc99e Initial load
duke
parents:
diff changeset
477 function forEachLoadObject(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if (sa.cdbg == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // no CDebugger support
a61af66fc99e Initial load
duke
parents:
diff changeset
480 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 var itr = sa.cdbg.loadObjectList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
483 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
485 }
a61af66fc99e Initial load
duke
parents:
diff changeset
486 }
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // print 'num' words at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
490 function mem(addr, num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 if (num == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 num = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
494 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
495 var i;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 for (i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 var value = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
498 writeln(addr2sym(addr) + ':', addr2str(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
499 addr = addr.addOffsetTo(addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
502 }
a61af66fc99e Initial load
duke
parents:
diff changeset
503
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // System dictionary functions
a61af66fc99e Initial load
duke
parents:
diff changeset
505
a61af66fc99e Initial load
duke
parents:
diff changeset
506 // find InstanceKlass by name
a61af66fc99e Initial load
duke
parents:
diff changeset
507 function findInstanceKlass(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 return sapkg.utilities.SystemDictionaryHelper.findInstanceKlass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // get Java system loader (i.e., application launcher loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
512 function systemLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 return sa.sysDict.javaSystemLoader();
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // iterate system dictionary for each 'Klass'
a61af66fc99e Initial load
duke
parents:
diff changeset
517 function forEachKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
519 var visitor = new VisitorClass() { visit: callback };
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
520 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor)"](visitor);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // iterate system dictionary for each 'Klass' and initiating loader
a61af66fc99e Initial load
duke
parents:
diff changeset
524 function forEachKlassAndLoader(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
526 var visitor = new VisitorClass() { visit: callback };
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
527 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary.ClassAndLoaderVisitor)"](visitor);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
528 }
a61af66fc99e Initial load
duke
parents:
diff changeset
529
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // iterate system dictionary for each primitive array klass
a61af66fc99e Initial load
duke
parents:
diff changeset
531 function forEachPrimArrayKlass(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 sa.sysDict.primArrayClassesDo(new VisitorClass() { visit: callback });
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // 'oop' to higher-level java object wrapper in which for(i in o)
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // works by iterating java level fields and javaobject.javafield
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // syntax works.
a61af66fc99e Initial load
duke
parents:
diff changeset
539 function oop2obj(oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 return object(addr2str(oop.handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
542
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // higher level java object wrapper to oop
a61af66fc99e Initial load
duke
parents:
diff changeset
544 function obj2oop(obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 return addr2oop(str2addr(address(obj)));
a61af66fc99e Initial load
duke
parents:
diff changeset
546 }
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // Java heap iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
549
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // iterates Java heap for each Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
551 function forEachOop(callback) {
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
552 function empty() { }
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
553 sa.objHeap.iterate(new sapkg.oops.HeapVisitor() {
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
554 prologue: empty,
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
555 doObj: callback,
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
556 epilogue: empty
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
557 });
0
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 // iterates Java heap for each Oop of given 'klass'.
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // 'includeSubtypes' tells whether to include objects
a61af66fc99e Initial load
duke
parents:
diff changeset
562 // of subtypes of 'klass' or not
a61af66fc99e Initial load
duke
parents:
diff changeset
563 function forEachOopOfKlass(callback, klass, includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 if (klass == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 klass = findInstanceKlass("java.lang.Object");
a61af66fc99e Initial load
duke
parents:
diff changeset
566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
567
a61af66fc99e Initial load
duke
parents:
diff changeset
568 if (includeSubtypes == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 includeSubtypes = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
571
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
572 function empty() { }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
573 sa.objHeap.iterateObjectsOfKlass(
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
574 new sapkg.oops.HeapVisitor() {
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
575 prologue: empty,
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
576 doObj: callback,
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
577 epilogue: empty
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
578 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
579 klass, includeSubtypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 // Java thread
a61af66fc99e Initial load
duke
parents:
diff changeset
583
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // iterates each Thread
a61af66fc99e Initial load
duke
parents:
diff changeset
585 function forEachJavaThread(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
586 var threads = sa.threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 var thread = threads.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 while (thread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
589 if (callback(thread) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
590 thread = thread.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592 }
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // iterate Frames of a given thread
a61af66fc99e Initial load
duke
parents:
diff changeset
595 function forEachFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 var fr = javaThread.getLastFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
597 while (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (callback(fr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 fr = fr.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 // iterate JavaVFrames of a given JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
604 function forEachVFrame(javaThread, callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 var vfr = javaThread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
606 while (vfr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 if (callback(vfr) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
608 vfr = vfr.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
609 }
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 function printStackTrace(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 write("Thread ");
a61af66fc99e Initial load
duke
parents:
diff changeset
614 javaThread.printThreadIDOn(java.lang.System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
615 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
616 forEachVFrame(javaThread, function (vf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 var method = vf.method;
a61af66fc99e Initial load
duke
parents:
diff changeset
618 write(' - ', method.externalNameAndSignature(), '@bci =', vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
619 var line = method.getLineNumberFromBCI(vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
620 if (line != -1) { write(', line=', line); }
a61af66fc99e Initial load
duke
parents:
diff changeset
621 if (vf.isCompiledFrame()) { write(" (Compiled Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
622 if (vf.isInterpretedFrame()) { write(" (Interpreted Frame)"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
623 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
624 });
a61af66fc99e Initial load
duke
parents:
diff changeset
625 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
626 writeln();
a61af66fc99e Initial load
duke
parents:
diff changeset
627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // print Java stack trace for all threads
a61af66fc99e Initial load
duke
parents:
diff changeset
630 function where(javaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
631 if (javaThread == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 forEachJavaThread(function (jt) { printStackTrace(jt); });
a61af66fc99e Initial load
duke
parents:
diff changeset
633 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 printStackTrace(javaThread);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 }
a61af66fc99e Initial load
duke
parents:
diff changeset
636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
637
a61af66fc99e Initial load
duke
parents:
diff changeset
638 // vmStructs access -- type database functions
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // find a VM type
a61af66fc99e Initial load
duke
parents:
diff changeset
641 function findVMType(typeName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 return sa.typedb.lookupType(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // iterate VM types
a61af66fc99e Initial load
duke
parents:
diff changeset
646 function forEachVMType(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
647 var itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
649 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
650 }
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // find VM int constant
a61af66fc99e Initial load
duke
parents:
diff changeset
654 function findVMIntConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
655 return sa.typedb.lookupIntConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 // find VM long constant
a61af66fc99e Initial load
duke
parents:
diff changeset
659 function findVMLongConst(name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 return sa.typedb.lookupLongConstant(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // iterate VM int constants
a61af66fc99e Initial load
duke
parents:
diff changeset
664 function forEachVMIntConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 var itr = sa.typedb.intConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // iterate VM long constants
a61af66fc99e Initial load
duke
parents:
diff changeset
672 function forEachVMLongConst(callback) {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 var itr = sa.typedb.longConstants;
a61af66fc99e Initial load
duke
parents:
diff changeset
674 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
675 if (callback(itr.next()) == false) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677 }
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 // returns VM Type at address
a61af66fc99e Initial load
duke
parents:
diff changeset
680 function vmTypeof(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 return sa.typedb.guessTypeForAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 // does the given 'addr' points to an object of given 'type'?
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // OR any valid Type at all (if type is undefined)
a61af66fc99e Initial load
duke
parents:
diff changeset
687 function isOfVMType(addr, type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
689 if (type == undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
690 return vmTypeof(addr) != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695 return sa.typedb.addressTypeIsEqualToType(addr, type);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697 }
a61af66fc99e Initial load
duke
parents:
diff changeset
698
a61af66fc99e Initial load
duke
parents:
diff changeset
699 // reads static field value
a61af66fc99e Initial load
duke
parents:
diff changeset
700 function readVMStaticField(field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
701 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
702 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 return field.value;
a61af66fc99e Initial load
duke
parents:
diff changeset
704 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 return field.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
706 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 return field.oopHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 return field.staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 // reads given instance field of VM object at 'addr'
a61af66fc99e Initial load
duke
parents:
diff changeset
714 function readVMInstanceField(field, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 var type = field.type;
a61af66fc99e Initial load
duke
parents:
diff changeset
716 if (type.isCIntegerType() || type.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
717 return field.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
718 } else if (type.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 return field.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 } else if (type.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 return field.getOopHandle(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
723 return addr.addOffsetTo(field.offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
724 }
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // returns name-value of pairs of VM type at given address.
a61af66fc99e Initial load
duke
parents:
diff changeset
728 // If address is unspecified, reads static fields as name-value pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
729 function readVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 if (addr != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
736
a61af66fc99e Initial load
duke
parents:
diff changeset
737 var result = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
738 var staticOnly = (addr == undefined);
a61af66fc99e Initial load
duke
parents:
diff changeset
739 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
741 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
743 var isStatic = field.isStatic();
a61af66fc99e Initial load
duke
parents:
diff changeset
744 if (staticOnly && isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 result[field.name] = readVMStaticField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
746 } else if (!staticOnly && !isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 result[field.name] = readVMInstanceField(field, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
750 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
a61af66fc99e Initial load
duke
parents:
diff changeset
752 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754
a61af66fc99e Initial load
duke
parents:
diff changeset
755 function printVMType(type, addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
756 if (typeof(type) == 'string') {
a61af66fc99e Initial load
duke
parents:
diff changeset
757 type = findVMType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
759 var obj = readVMType(type, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
760 while (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 var itr = type.fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
762 while (itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
763 var field = itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
764 var name = field.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
765 var value = obj[name];
a61af66fc99e Initial load
duke
parents:
diff changeset
766 if (value != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 writeln(field.type.name, type.name + '::' + name, '=', value);
a61af66fc99e Initial load
duke
parents:
diff changeset
768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 type = type.superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // define readXXX and printXXX functions for each VM struct/class Type
a61af66fc99e Initial load
duke
parents:
diff changeset
775 tmp = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
776 tmp.itr = sa.typedb.types;
a61af66fc99e Initial load
duke
parents:
diff changeset
777 while (tmp.itr.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
778 tmp.type = tmp.itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
779 tmp.name = tmp.type.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
780 if (tmp.type.isPointerType() || tmp.type.isOopType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
781 tmp.type.isCIntegerType() || tmp.type.isJavaPrimitiveType() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
782 tmp.name.equals('address') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
783 tmp.name.equals("<opaque>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
784 // ignore;
a61af66fc99e Initial load
duke
parents:
diff changeset
785 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 } else {
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
787 // some type names have ':', '<', '>', '*', ' '. replace to make it as a
0
a61af66fc99e Initial load
duke
parents:
diff changeset
788 // JavaScript identifier
12097
e37ab280bbce 8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"
allwin
parents: 8103
diff changeset
789 tmp.name = ("" + tmp.name).replace(/[:<>* ]/g, '_');
0
a61af66fc99e Initial load
duke
parents:
diff changeset
790 eval("function read" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
791 " return readVMType('" + tmp.name + "', addr);}");
a61af66fc99e Initial load
duke
parents:
diff changeset
792 eval("function print" + tmp.name + "(addr) {" +
a61af66fc99e Initial load
duke
parents:
diff changeset
793 " printVMType('" + tmp.name + "', addr); }");
a61af66fc99e Initial load
duke
parents:
diff changeset
794
a61af66fc99e Initial load
duke
parents:
diff changeset
795 /* FIXME: do we need this?
a61af66fc99e Initial load
duke
parents:
diff changeset
796 if (typeof(registerCommand) != 'undefined') {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 var name = "print" + tmp.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
798 registerCommand(name, name + " [address]", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
799 }
a61af66fc99e Initial load
duke
parents:
diff changeset
800 */
a61af66fc99e Initial load
duke
parents:
diff changeset
801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803 //clean-up the temporary
a61af66fc99e Initial load
duke
parents:
diff changeset
804 delete tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 // VMObject factory
a61af66fc99e Initial load
duke
parents:
diff changeset
807
a61af66fc99e Initial load
duke
parents:
diff changeset
808 // VM type to SA class map
a61af66fc99e Initial load
duke
parents:
diff changeset
809 var vmType2Class = new Object();
a61af66fc99e Initial load
duke
parents:
diff changeset
810
14367
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
811 // C2 only classes
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
812 try{
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
813 vmType2Class["ExceptionBlob"] = sapkg.code.ExceptionBlob;
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
814 vmType2Class["UncommonTrapBlob"] = sapkg.code.UncommonTrapBlob;
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
815 } catch(e) {
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
816 // Ignore exception. C2 specific objects might be not
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
817 // available in client VM
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
818 }
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
819
46eeb3056482 8023667: SA: ExceptionBlob and other C2 classes not available in client VM
dsamersoff
parents: 14223
diff changeset
820
0
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // This is *not* exhaustive. Add more if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
822 // code blobs
a61af66fc99e Initial load
duke
parents:
diff changeset
823 vmType2Class["BufferBlob"] = sapkg.code.BufferBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
824 vmType2Class["nmethod"] = sapkg.code.NMethod;
a61af66fc99e Initial load
duke
parents:
diff changeset
825 vmType2Class["RuntimeStub"] = sapkg.code.RuntimeStub;
a61af66fc99e Initial load
duke
parents:
diff changeset
826 vmType2Class["SafepointBlob"] = sapkg.code.SafepointBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
827 vmType2Class["C2IAdapter"] = sapkg.code.C2IAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
828 vmType2Class["DeoptimizationBlob"] = sapkg.code.DeoptimizationBlob;
a61af66fc99e Initial load
duke
parents:
diff changeset
829 vmType2Class["I2CAdapter"] = sapkg.code.I2CAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
830 vmType2Class["OSRAdapter"] = sapkg.code.OSRAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
831 vmType2Class["PCDesc"] = sapkg.code.PCDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
832
a61af66fc99e Initial load
duke
parents:
diff changeset
833 // interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
834 vmType2Class["InterpreterCodelet"] = sapkg.interpreter.InterpreterCodelet;
a61af66fc99e Initial load
duke
parents:
diff changeset
835
a61af66fc99e Initial load
duke
parents:
diff changeset
836 // Java Threads
a61af66fc99e Initial load
duke
parents:
diff changeset
837 vmType2Class["JavaThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
838 vmType2Class["CompilerThread"] = sapkg.runtime.CompilerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
839 vmType2Class["SurrogateLockerThread"] = sapkg.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
840 vmType2Class["DebuggerThread"] = sapkg.runtime.DebuggerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
841
a61af66fc99e Initial load
duke
parents:
diff changeset
842 // gc
a61af66fc99e Initial load
duke
parents:
diff changeset
843 vmType2Class["GenCollectedHeap"] = sapkg.memory.GenCollectedHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
844 vmType2Class["DefNewGeneration"] = sapkg.memory.DefNewGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
845 vmType2Class["TenuredGeneration"] = sapkg.memory.TenuredGeneration;
a61af66fc99e Initial load
duke
parents:
diff changeset
846
a61af66fc99e Initial load
duke
parents:
diff changeset
847 // generic VMObject factory for a given address
a61af66fc99e Initial load
duke
parents:
diff changeset
848 // This is equivalent to VirtualConstructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
849 function newVMObject(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
851 var result = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
852 forEachVMType(function (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (isOfVMType(addr, type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 var clazz = vmType2Class[type.name];
a61af66fc99e Initial load
duke
parents:
diff changeset
855 if (clazz != undefined) {
a61af66fc99e Initial load
duke
parents:
diff changeset
856 result = new clazz(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
857 }
a61af66fc99e Initial load
duke
parents:
diff changeset
858 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
859 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862 });
a61af66fc99e Initial load
duke
parents:
diff changeset
863 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
865
a61af66fc99e Initial load
duke
parents:
diff changeset
866 function vmobj2addr(vmobj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
867 return vmobj.address;
a61af66fc99e Initial load
duke
parents:
diff changeset
868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
869
a61af66fc99e Initial load
duke
parents:
diff changeset
870 function addr2vmobj(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
871 return newVMObject(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
872 }
a61af66fc99e Initial load
duke
parents:
diff changeset
873
a61af66fc99e Initial load
duke
parents:
diff changeset
874 // Miscellaneous utilities
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876 // returns PointerLocation that describes the given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
877 function findPtr(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
879 return sapkg.utilities.PointerFinder.find(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
880 }
a61af66fc99e Initial load
duke
parents:
diff changeset
881
a61af66fc99e Initial load
duke
parents:
diff changeset
882 // is given address a valid Oop?
a61af66fc99e Initial load
duke
parents:
diff changeset
883 function isOop(addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
884 addr = any2addr(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
885 var oopHandle = addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
886 return sapkg.utilities.RobustOopDeterminator.oopLooksValid(oopHandle);
a61af66fc99e Initial load
duke
parents:
diff changeset
887 }
a61af66fc99e Initial load
duke
parents:
diff changeset
888
a61af66fc99e Initial load
duke
parents:
diff changeset
889 // returns description of given pointer as a String
a61af66fc99e Initial load
duke
parents:
diff changeset
890 function whatis(addr) {
14373
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
891 addr = any2addr(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
892 var ptrLoc = findPtr(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
893 if (!ptrLoc.isUnknown()) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
894 return ptrLoc.toString();
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
895 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
896
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
897 var vmType = vmTypeof(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
898 if (vmType != null) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
899 return "pointer to " + vmType.name;
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
900 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
901
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
902 var dso = loadObjectContainingPC(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
903 if (dso == null) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
904 return ptrLoc.toString();
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
905 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
906
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
907 var sym = dso.closestSymbolToPC(addr);
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
908 if (sym != null) {
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
909 return sym.name + '+' + sym.offset;
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
910 }
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
911
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
912 var s = dso.getName();
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
913 var p = s.lastIndexOf("/");
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
914 var base = dso.getBase();
d7cb88bd7046 7127191: SA JSDB does not display native symbols correctly for transported Linux cores
dsamersoff
parents: 14367
diff changeset
915 return s.substring(p+1, s.length) + '+' + addr.minus(base);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
916 }