comparison 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
comparison
equal deleted inserted replaced
12095:c6ec0a97b30a 12097:e37ab280bbce
33 sapkg.asm = sapkg.hotspot.asm; 33 sapkg.asm = sapkg.hotspot.asm;
34 sapkg.c1 = sapkg.hotspot.c1; 34 sapkg.c1 = sapkg.hotspot.c1;
35 sapkg.code = sapkg.hotspot.code; 35 sapkg.code = sapkg.hotspot.code;
36 sapkg.compiler = sapkg.hotspot.compiler; 36 sapkg.compiler = sapkg.hotspot.compiler;
37 37
38 // 'debugger' is a JavaScript keyword :-( 38 // 'debugger' is a JavaScript keyword, but ES5 relaxes the
39 // sapkg.debugger = sapkg.hotspot.debugger; 39 // restriction of using keywords as property name
40 sapkg.debugger = sapkg.hotspot.debugger;
40 41
41 sapkg.interpreter = sapkg.hotspot.interpreter; 42 sapkg.interpreter = sapkg.hotspot.interpreter;
42 sapkg.jdi = sapkg.hotspot.jdi; 43 sapkg.jdi = sapkg.hotspot.jdi;
43 sapkg.memory = sapkg.hotspot.memory; 44 sapkg.memory = sapkg.hotspot.memory;
44 sapkg.oops = sapkg.hotspot.oops; 45 sapkg.oops = sapkg.hotspot.oops;
114 } 115 }
115 } 116 }
116 return args; 117 return args;
117 } 118 }
118 119
120 // Handle __has__ specially to avoid metacircularity problems
121 // when called from __get__.
122 // Calling
123 // this.__has__(name)
124 // will in turn call
125 // this.__call__('__has__', name)
126 // which is not handled below
127 function __has__(name) {
128 if (typeof(name) == 'number') {
129 return so["has(int)"](name);
130 } else {
131 if (name == '__wrapped__') {
132 return true;
133 } else if (so["has(java.lang.String)"](name)) {
134 return true;
135 } else if (name.equals('toString')) {
136 return true;
137 } else {
138 return false;
139 }
140 }
141 }
142
119 if (so instanceof sapkg.utilities.soql.ScriptObject) { 143 if (so instanceof sapkg.utilities.soql.ScriptObject) {
120 return new JSAdapter() { 144 return new JSAdapter() {
121 __getIds__: function() { 145 __getIds__: function() {
122 return so.getIds(); 146 return so.getIds();
123 }, 147 },
124 148
125 __has__ : function(name) { 149 __has__ : __has__,
126 if (typeof(name) == 'number') {
127 return so["has(int)"](name);
128 } else {
129 if (name == '__wrapped__') {
130 return true;
131 } else if (so["has(java.lang.String)"](name)) {
132 return true;
133 } else if (name.equals('toString')) {
134 return true;
135 } else {
136 return false;
137 }
138 }
139 },
140 150
141 __delete__ : function(name) { 151 __delete__ : function(name) {
142 if (typeof(name) == 'number') { 152 if (typeof(name) == 'number') {
143 return so["delete(int)"](name); 153 return so["delete(int)"](name);
144 } else { 154 } else {
145 return so["delete(java.lang.String)"](name); 155 return so["delete(java.lang.String)"](name);
146 } 156 }
147 }, 157 },
148 158
149 __get__ : function(name) { 159 __get__ : function(name) {
150 if (! this.__has__(name)) { 160 // don't call this.__has__(name); see comments above function __has__
161 if (! __has__.call(this, name)) {
151 return undefined; 162 return undefined;
152 } 163 }
153 if (typeof(name) == 'number') { 164 if (typeof(name) == 'number') {
154 return wrapScriptObject(so["get(int)"](name)); 165 return wrapScriptObject(so["get(int)"](name));
155 } else { 166 } else {
160 if (value instanceof sapkg.utilities.soql.Callable) { 171 if (value instanceof sapkg.utilities.soql.Callable) {
161 return function() { 172 return function() {
162 var args = prepareArgsArray(arguments); 173 var args = prepareArgsArray(arguments);
163 var r; 174 var r;
164 try { 175 try {
165 r = value.call(args); 176 r = value.call(Java.to(args, 'java.lang.Object[]'));
166 } catch (e) { 177 } catch (e) {
167 println("call to " + name + " failed!"); 178 println("call to " + name + " failed!");
168 throw e; 179 throw e;
169 } 180 }
170 return wrapScriptObject(r); 181 return wrapScriptObject(r);
202 this[prop] = globals[prop]; 213 this[prop] = globals[prop];
203 } 214 }
204 } 215 }
205 216
206 // define "writeln" and "write" if not defined 217 // define "writeln" and "write" if not defined
218 if (typeof(println) == 'undefined') {
219 println = function (str) {
220 java.lang.System.out.println(String(str));
221 }
222 }
223
224 if (typeof(print) == 'undefined') {
225 print = function (str) {
226 java.lang.System.out.print(String(str));
227 }
228 }
229
207 if (typeof(writeln) == 'undefined') { 230 if (typeof(writeln) == 'undefined') {
208 writeln = println; 231 writeln = println;
209 } 232 }
210 233
211 if (typeof(write) == 'undefined') { 234 if (typeof(write) == 'undefined') {
233 } 256 }
234 registerCommand("class", "class name", "jclass"); 257 registerCommand("class", "class name", "jclass");
235 258
236 this.jclasses = function() { 259 this.jclasses = function() {
237 forEachKlass(function (clazz) { 260 forEachKlass(function (clazz) {
238 writeln(clazz.getName().asString() + " @" + clazz.getHandle().toString()); 261 writeln(clazz.getName().asString() + " @" + clazz.getAddress().toString());
239 }); 262 });
240 } 263 }
241 registerCommand("classes", "classes", "jclasses"); 264 registerCommand("classes", "classes", "jclasses");
242 265
243 this.dclass = function(clazz, dir) { 266 this.dclass = function(clazz, dir) {
488 511
489 // iterate system dictionary for each 'Klass' 512 // iterate system dictionary for each 'Klass'
490 function forEachKlass(callback) { 513 function forEachKlass(callback) {
491 var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor; 514 var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor;
492 var visitor = new VisitorClass() { visit: callback }; 515 var visitor = new VisitorClass() { visit: callback };
493 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassVisitor)"](visitor); 516 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor)"](visitor);
494 } 517 }
495 518
496 // iterate system dictionary for each 'Klass' and initiating loader 519 // iterate system dictionary for each 'Klass' and initiating loader
497 function forEachKlassAndLoader(callback) { 520 function forEachKlassAndLoader(callback) {
498 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor; 521 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
499 var visitor = new VisitorClass() { visit: callback }; 522 var visitor = new VisitorClass() { visit: callback };
500 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassAndLoaderVisitor)"](visitor); 523 sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary.ClassAndLoaderVisitor)"](visitor);
501 } 524 }
502 525
503 // iterate system dictionary for each primitive array klass 526 // iterate system dictionary for each primitive array klass
504 function forEachPrimArrayKlass(callback) { 527 function forEachPrimArrayKlass(callback) {
505 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor; 528 var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
520 543
521 // Java heap iteration 544 // Java heap iteration
522 545
523 // iterates Java heap for each Oop 546 // iterates Java heap for each Oop
524 function forEachOop(callback) { 547 function forEachOop(callback) {
525 sa.objHeap.iterate(new sapkg.oops.HeapVisitor() { doObj: callback }); 548 function empty() { }
549 sa.objHeap.iterate(new sapkg.oops.HeapVisitor() {
550 prologue: empty,
551 doObj: callback,
552 epilogue: empty
553 });
526 } 554 }
527 555
528 // iterates Java heap for each Oop of given 'klass'. 556 // iterates Java heap for each Oop of given 'klass'.
529 // 'includeSubtypes' tells whether to include objects 557 // 'includeSubtypes' tells whether to include objects
530 // of subtypes of 'klass' or not 558 // of subtypes of 'klass' or not
534 } 562 }
535 563
536 if (includeSubtypes == undefined) { 564 if (includeSubtypes == undefined) {
537 includeSubtypes = true; 565 includeSubtypes = true;
538 } 566 }
567
568 function empty() { }
539 sa.objHeap.iterateObjectsOfKlass( 569 sa.objHeap.iterateObjectsOfKlass(
540 new sapkg.oops.HeapVisitor() { doObj: callback }, 570 new sapkg.oops.HeapVisitor() {
571 prologue: empty,
572 doObj: callback,
573 epilogue: empty
574 },
541 klass, includeSubtypes); 575 klass, includeSubtypes);
542 } 576 }
543 577
544 // Java thread 578 // Java thread
545 579
744 tmp.name.equals('address') || 778 tmp.name.equals('address') ||
745 tmp.name.equals("<opaque>")) { 779 tmp.name.equals("<opaque>")) {
746 // ignore; 780 // ignore;
747 continue; 781 continue;
748 } else { 782 } else {
749 // some type names have ':'. replace to make it as a 783 // some type names have ':', '<', '>', '*', ' '. replace to make it as a
750 // JavaScript identifier 784 // JavaScript identifier
751 tmp.name = tmp.name.replace(':', '_').replace('<', '_').replace('>', '_').replace('*', '_').replace(' ', '_'); 785 tmp.name = ("" + tmp.name).replace(/[:<>* ]/g, '_');
752 eval("function read" + tmp.name + "(addr) {" + 786 eval("function read" + tmp.name + "(addr) {" +
753 " return readVMType('" + tmp.name + "', addr);}"); 787 " return readVMType('" + tmp.name + "', addr);}");
754 eval("function print" + tmp.name + "(addr) {" + 788 eval("function print" + tmp.name + "(addr) {" +
755 " printVMType('" + tmp.name + "', addr); }"); 789 " printVMType('" + tmp.name + "', addr); }");
756 790