src/share/vm/runtime/vframe.hpp

Tue, 16 Feb 2010 16:17:46 -0800

author
kvn
date
Tue, 16 Feb 2010 16:17:46 -0800
changeset 1698
e7b1cc79bd25
parent 1366
72088be4b386
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6926697: "optimized" VM build failed: The type "AdapterHandlerTableIterator" is incomplete
Summary: Define AdapterHandlerTableIterator class as non product instead of debug.
Reviewed-by: never

duke@435 1 /*
xdono@1279 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // vframes are virtual stack frames representing source level activations.
duke@435 26 // A single frame may hold several source level activations in the case of
duke@435 27 // optimized code. The debugging stored with the optimized code enables
duke@435 28 // us to unfold a frame as a stack of vframes.
duke@435 29 // A cVFrame represents an activation of a non-java method.
duke@435 30
duke@435 31 // The vframe inheritance hierarchy:
duke@435 32 // - vframe
duke@435 33 // - javaVFrame
duke@435 34 // - interpretedVFrame
duke@435 35 // - compiledVFrame ; (used for both compiled Java methods and native stubs)
duke@435 36 // - externalVFrame
duke@435 37 // - entryVFrame ; special frame created when calling Java from C
duke@435 38
duke@435 39 // - BasicLock
duke@435 40
duke@435 41 class vframe: public ResourceObj {
duke@435 42 protected:
duke@435 43 frame _fr; // Raw frame behind the virtual frame.
duke@435 44 RegisterMap _reg_map; // Register map for the raw frame (used to handle callee-saved registers).
duke@435 45 JavaThread* _thread; // The thread owning the raw frame.
duke@435 46
duke@435 47 vframe(const frame* fr, const RegisterMap* reg_map, JavaThread* thread);
duke@435 48 vframe(const frame* fr, JavaThread* thread);
duke@435 49 public:
duke@435 50 // Factory method for creating vframes
duke@435 51 static vframe* new_vframe(const frame* f, const RegisterMap *reg_map, JavaThread* thread);
duke@435 52
duke@435 53 // Accessors
duke@435 54 frame fr() const { return _fr; }
duke@435 55 CodeBlob* cb() const { return _fr.cb(); }
duke@435 56 nmethod* nm() const {
duke@435 57 assert( cb() != NULL && cb()->is_nmethod(), "usage");
duke@435 58 return (nmethod*) cb();
duke@435 59 }
duke@435 60
duke@435 61 // ???? Does this need to be a copy?
duke@435 62 frame* frame_pointer() { return &_fr; }
duke@435 63 const RegisterMap* register_map() const { return &_reg_map; }
duke@435 64 JavaThread* thread() const { return _thread; }
duke@435 65
duke@435 66 // Returns the sender vframe
duke@435 67 virtual vframe* sender() const;
duke@435 68
duke@435 69 // Returns the next javaVFrame on the stack (skipping all other kinds of frame)
duke@435 70 javaVFrame *java_sender() const;
duke@435 71
duke@435 72 // Answers if the this is the top vframe in the frame, i.e., if the sender vframe
duke@435 73 // is in the caller frame
duke@435 74 virtual bool is_top() const { return true; }
duke@435 75
duke@435 76 // Returns top vframe within same frame (see is_top())
duke@435 77 virtual vframe* top() const;
duke@435 78
duke@435 79 // Type testing operations
duke@435 80 virtual bool is_entry_frame() const { return false; }
duke@435 81 virtual bool is_java_frame() const { return false; }
duke@435 82 virtual bool is_interpreted_frame() const { return false; }
duke@435 83 virtual bool is_compiled_frame() const { return false; }
duke@435 84
duke@435 85 #ifndef PRODUCT
duke@435 86 // printing operations
duke@435 87 virtual void print_value() const;
duke@435 88 virtual void print();
duke@435 89 #endif
duke@435 90 };
duke@435 91
duke@435 92
duke@435 93 class javaVFrame: public vframe {
duke@435 94 public:
duke@435 95 // JVM state
duke@435 96 virtual methodOop method() const = 0;
duke@435 97 virtual int bci() const = 0;
duke@435 98 virtual StackValueCollection* locals() const = 0;
duke@435 99 virtual StackValueCollection* expressions() const = 0;
duke@435 100 // the order returned by monitors() is from oldest -> youngest#4418568
duke@435 101 virtual GrowableArray<MonitorInfo*>* monitors() const = 0;
duke@435 102
duke@435 103 // Debugging support via JVMTI.
duke@435 104 // NOTE that this is not guaranteed to give correct results for compiled vframes.
duke@435 105 // Deoptimize first if necessary.
duke@435 106 virtual void set_locals(StackValueCollection* values) const = 0;
duke@435 107
duke@435 108 // Test operation
duke@435 109 bool is_java_frame() const { return true; }
duke@435 110
duke@435 111 protected:
duke@435 112 javaVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread) : vframe(fr, reg_map, thread) {}
duke@435 113 javaVFrame(const frame* fr, JavaThread* thread) : vframe(fr, thread) {}
duke@435 114
duke@435 115 public:
duke@435 116 // casting
duke@435 117 static javaVFrame* cast(vframe* vf) {
duke@435 118 assert(vf == NULL || vf->is_java_frame(), "must be java frame");
duke@435 119 return (javaVFrame*) vf;
duke@435 120 }
duke@435 121
duke@435 122 // Return an array of monitors locked by this frame in the youngest to oldest order
duke@435 123 GrowableArray<MonitorInfo*>* locked_monitors();
duke@435 124
duke@435 125 // printing used during stack dumps
duke@435 126 void print_lock_info_on(outputStream* st, int frame_count);
duke@435 127 void print_lock_info(int frame_count) { print_lock_info_on(tty, frame_count); }
duke@435 128
duke@435 129 #ifndef PRODUCT
duke@435 130 public:
duke@435 131 // printing operations
duke@435 132 void print();
duke@435 133 void print_value() const;
duke@435 134 void print_activation(int index) const;
duke@435 135
duke@435 136 // verify operations
duke@435 137 virtual void verify() const;
duke@435 138
duke@435 139 // Structural compare
duke@435 140 bool structural_compare(javaVFrame* other);
duke@435 141 #endif
duke@435 142 friend class vframe;
duke@435 143 };
duke@435 144
duke@435 145 class interpretedVFrame: public javaVFrame {
duke@435 146 public:
duke@435 147 // JVM state
duke@435 148 methodOop method() const;
duke@435 149 int bci() const;
duke@435 150 StackValueCollection* locals() const;
duke@435 151 StackValueCollection* expressions() const;
duke@435 152 GrowableArray<MonitorInfo*>* monitors() const;
duke@435 153
duke@435 154 void set_locals(StackValueCollection* values) const;
duke@435 155
duke@435 156 // Test operation
duke@435 157 bool is_interpreted_frame() const { return true; }
duke@435 158
duke@435 159 protected:
duke@435 160 interpretedVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread) : javaVFrame(fr, reg_map, thread) {};
duke@435 161
duke@435 162 public:
duke@435 163 // Accessors for Byte Code Pointer
duke@435 164 u_char* bcp() const;
duke@435 165 void set_bcp(u_char* bcp);
duke@435 166
duke@435 167 // casting
duke@435 168 static interpretedVFrame* cast(vframe* vf) {
duke@435 169 assert(vf == NULL || vf->is_interpreted_frame(), "must be interpreted frame");
duke@435 170 return (interpretedVFrame*) vf;
duke@435 171 }
duke@435 172
duke@435 173 private:
duke@435 174 static const int bcp_offset;
duke@435 175 intptr_t* locals_addr_at(int offset) const;
duke@435 176
duke@435 177 // returns where the parameters starts relative to the frame pointer
duke@435 178 int start_of_parameters() const;
duke@435 179
duke@435 180 #ifndef PRODUCT
duke@435 181 public:
duke@435 182 // verify operations
duke@435 183 void verify() const;
duke@435 184 #endif
duke@435 185 friend class vframe;
duke@435 186 };
duke@435 187
duke@435 188
duke@435 189 class externalVFrame: public vframe {
duke@435 190 protected:
duke@435 191 externalVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread) : vframe(fr, reg_map, thread) {}
duke@435 192
duke@435 193 #ifndef PRODUCT
duke@435 194 public:
duke@435 195 // printing operations
duke@435 196 void print_value() const;
duke@435 197 void print();
duke@435 198 #endif
duke@435 199 friend class vframe;
duke@435 200 };
duke@435 201
duke@435 202 class entryVFrame: public externalVFrame {
duke@435 203 public:
duke@435 204 bool is_entry_frame() const { return true; }
duke@435 205
duke@435 206 protected:
duke@435 207 entryVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread);
duke@435 208
duke@435 209 public:
duke@435 210 // casting
duke@435 211 static entryVFrame* cast(vframe* vf) {
duke@435 212 assert(vf == NULL || vf->is_entry_frame(), "must be entry frame");
duke@435 213 return (entryVFrame*) vf;
duke@435 214 }
duke@435 215
duke@435 216 #ifndef PRODUCT
duke@435 217 public:
duke@435 218 // printing
duke@435 219 void print_value() const;
duke@435 220 void print();
duke@435 221 #endif
duke@435 222 friend class vframe;
duke@435 223 };
duke@435 224
duke@435 225
duke@435 226 // A MonitorInfo is a ResourceObject that describes a the pair:
duke@435 227 // 1) the owner of the monitor
duke@435 228 // 2) the monitor lock
duke@435 229 class MonitorInfo : public ResourceObj {
duke@435 230 private:
duke@435 231 oop _owner; // the object owning the monitor
duke@435 232 BasicLock* _lock;
kvn@1253 233 oop _owner_klass; // klass if owner was scalar replaced
kvn@518 234 bool _eliminated;
kvn@1253 235 bool _owner_is_scalar_replaced;
duke@435 236 public:
duke@435 237 // Constructor
kvn@1253 238 MonitorInfo(oop owner, BasicLock* lock, bool eliminated, bool owner_is_scalar_replaced) {
kvn@1253 239 if (!owner_is_scalar_replaced) {
kvn@1253 240 _owner = owner;
kvn@1253 241 _owner_klass = NULL;
kvn@1253 242 } else {
kvn@1253 243 assert(eliminated, "monitor should be eliminated for scalar replaced object");
kvn@1253 244 _owner = NULL;
kvn@1253 245 _owner_klass = owner;
kvn@1253 246 }
duke@435 247 _lock = lock;
kvn@518 248 _eliminated = eliminated;
kvn@1253 249 _owner_is_scalar_replaced = owner_is_scalar_replaced;
duke@435 250 }
duke@435 251 // Accessors
kvn@1253 252 oop owner() const {
kvn@1253 253 assert(!_owner_is_scalar_replaced, "should not be called for scalar replaced object");
kvn@1253 254 return _owner;
kvn@1253 255 }
kvn@1253 256 klassOop owner_klass() const {
kvn@1253 257 assert(_owner_is_scalar_replaced, "should not be called for not scalar replaced object");
kvn@1253 258 return (klassOop)_owner_klass;
kvn@1253 259 }
duke@435 260 BasicLock* lock() const { return _lock; }
kvn@518 261 bool eliminated() const { return _eliminated; }
kvn@1253 262 bool owner_is_scalar_replaced() const { return _owner_is_scalar_replaced; }
duke@435 263 };
duke@435 264
duke@435 265 class vframeStreamCommon : StackObj {
duke@435 266 protected:
duke@435 267 // common
duke@435 268 frame _frame;
duke@435 269 JavaThread* _thread;
duke@435 270 RegisterMap _reg_map;
duke@435 271 enum { interpreted_mode, compiled_mode, at_end_mode } _mode;
duke@435 272
duke@435 273 int _sender_decode_offset;
duke@435 274
duke@435 275 // Cached information
duke@435 276 methodOop _method;
duke@435 277 int _bci;
duke@435 278
duke@435 279 // Should VM activations be ignored or not
duke@435 280 bool _stop_at_java_call_stub;
duke@435 281
duke@435 282 bool fill_in_compiled_inlined_sender();
duke@435 283 void fill_from_compiled_frame(int decode_offset);
duke@435 284 void fill_from_compiled_native_frame();
duke@435 285
duke@435 286 void found_bad_method_frame();
duke@435 287
duke@435 288 void fill_from_interpreter_frame();
duke@435 289 bool fill_from_frame();
duke@435 290
duke@435 291 // Helper routine for security_get_caller_frame
duke@435 292 void skip_prefixed_method_and_wrappers();
duke@435 293
duke@435 294 public:
duke@435 295 // Constructor
duke@435 296 vframeStreamCommon(JavaThread* thread) : _reg_map(thread, false) {
duke@435 297 _thread = thread;
duke@435 298 }
duke@435 299
duke@435 300 // Accessors
duke@435 301 methodOop method() const { return _method; }
duke@435 302 int bci() const { return _bci; }
duke@435 303 intptr_t* frame_id() const { return _frame.id(); }
duke@435 304 address frame_pc() const { return _frame.pc(); }
duke@435 305
duke@435 306 CodeBlob* cb() const { return _frame.cb(); }
duke@435 307 nmethod* nm() const {
duke@435 308 assert( cb() != NULL && cb()->is_nmethod(), "usage");
duke@435 309 return (nmethod*) cb();
duke@435 310 }
duke@435 311
duke@435 312 // Frame type
duke@435 313 bool is_interpreted_frame() const { return _frame.is_interpreted_frame(); }
duke@435 314 bool is_entry_frame() const { return _frame.is_entry_frame(); }
duke@435 315
duke@435 316 // Iteration
duke@435 317 void next() {
duke@435 318 // handle frames with inlining
duke@435 319 if (_mode == compiled_mode && fill_in_compiled_inlined_sender()) return;
duke@435 320
duke@435 321 // handle general case
duke@435 322 do {
duke@435 323 _frame = _frame.sender(&_reg_map);
duke@435 324 } while (!fill_from_frame());
duke@435 325 }
duke@435 326
duke@435 327 bool at_end() const { return _mode == at_end_mode; }
duke@435 328
duke@435 329 // Implements security traversal. Skips depth no. of frame including
duke@435 330 // special security frames and prefixed native methods
duke@435 331 void security_get_caller_frame(int depth);
duke@435 332
duke@435 333 // Helper routine for JVM_LatestUserDefinedLoader -- needed for 1.4
duke@435 334 // reflection implementation
duke@435 335 void skip_reflection_related_frames();
duke@435 336 };
duke@435 337
duke@435 338 class vframeStream : public vframeStreamCommon {
duke@435 339 public:
duke@435 340 // Constructors
duke@435 341 vframeStream(JavaThread* thread, bool stop_at_java_call_stub = false)
duke@435 342 : vframeStreamCommon(thread) {
duke@435 343 _stop_at_java_call_stub = stop_at_java_call_stub;
duke@435 344
duke@435 345 if (!thread->has_last_Java_frame()) {
duke@435 346 _mode = at_end_mode;
duke@435 347 return;
duke@435 348 }
duke@435 349
duke@435 350 _frame = _thread->last_frame();
duke@435 351 while (!fill_from_frame()) {
duke@435 352 _frame = _frame.sender(&_reg_map);
duke@435 353 }
duke@435 354 }
duke@435 355
duke@435 356 // top_frame may not be at safepoint, start with sender
duke@435 357 vframeStream(JavaThread* thread, frame top_frame, bool stop_at_java_call_stub = false);
duke@435 358 };
duke@435 359
duke@435 360
duke@435 361 inline bool vframeStreamCommon::fill_in_compiled_inlined_sender() {
duke@435 362 if (_sender_decode_offset == DebugInformationRecorder::serialized_null) {
duke@435 363 return false;
duke@435 364 }
duke@435 365 fill_from_compiled_frame(_sender_decode_offset);
duke@435 366 return true;
duke@435 367 }
duke@435 368
duke@435 369
duke@435 370 inline void vframeStreamCommon::fill_from_compiled_frame(int decode_offset) {
duke@435 371 _mode = compiled_mode;
duke@435 372
duke@435 373 // Range check to detect ridiculous offsets.
duke@435 374 if (decode_offset == DebugInformationRecorder::serialized_null ||
duke@435 375 decode_offset < 0 ||
duke@435 376 decode_offset >= nm()->scopes_data_size()) {
duke@435 377 // 6379830 AsyncGetCallTrace sometimes feeds us wild frames.
duke@435 378 // If we attempt to read nmethod::scopes_data at serialized_null (== 0),
duke@435 379 // or if we read some at other crazy offset,
duke@435 380 // we will decode garbage and make wild references into the heap,
duke@435 381 // leading to crashes in product mode.
duke@435 382 // (This isn't airtight, of course, since there are internal
duke@435 383 // offsets which are also crazy.)
duke@435 384 #ifdef ASSERT
duke@435 385 if (WizardMode) {
duke@435 386 tty->print_cr("Error in fill_from_frame: pc_desc for "
duke@435 387 INTPTR_FORMAT " not found or invalid at %d",
duke@435 388 _frame.pc(), decode_offset);
duke@435 389 nm()->print();
duke@435 390 nm()->method()->print_codes();
duke@435 391 nm()->print_code();
duke@435 392 nm()->print_pcs();
duke@435 393 }
duke@435 394 #endif
duke@435 395 // Provide a cheap fallback in product mode. (See comment above.)
duke@435 396 found_bad_method_frame();
duke@435 397 fill_from_compiled_native_frame();
duke@435 398 return;
duke@435 399 }
duke@435 400
duke@435 401 // Decode first part of scopeDesc
duke@435 402 DebugInfoReadStream buffer(nm(), decode_offset);
duke@435 403 _sender_decode_offset = buffer.read_int();
duke@435 404 _method = methodOop(buffer.read_oop());
cfang@1366 405 _bci = buffer.read_bci();
duke@435 406
duke@435 407 assert(_method->is_method(), "checking type of decoded method");
duke@435 408 }
duke@435 409
duke@435 410 // The native frames are handled specially. We do not rely on ScopeDesc info
duke@435 411 // since the pc might not be exact due to the _last_native_pc trick.
duke@435 412 inline void vframeStreamCommon::fill_from_compiled_native_frame() {
duke@435 413 _mode = compiled_mode;
duke@435 414 _sender_decode_offset = DebugInformationRecorder::serialized_null;
duke@435 415 _method = nm()->method();
duke@435 416 _bci = 0;
duke@435 417 }
duke@435 418
duke@435 419 inline bool vframeStreamCommon::fill_from_frame() {
duke@435 420 // Interpreted frame
duke@435 421 if (_frame.is_interpreted_frame()) {
duke@435 422 fill_from_interpreter_frame();
duke@435 423 return true;
duke@435 424 }
duke@435 425
duke@435 426 // Compiled frame
duke@435 427
duke@435 428 if (cb() != NULL && cb()->is_nmethod()) {
duke@435 429 if (nm()->is_native_method()) {
duke@435 430 // Do not rely on scopeDesc since the pc might be unprecise due to the _last_native_pc trick.
duke@435 431 fill_from_compiled_native_frame();
duke@435 432 } else {
duke@435 433 PcDesc* pc_desc = nm()->pc_desc_at(_frame.pc());
duke@435 434 int decode_offset;
duke@435 435 if (pc_desc == NULL) {
duke@435 436 // Should not happen, but let fill_from_compiled_frame handle it.
sgoldman@542 437
sgoldman@542 438 // If we are trying to walk the stack of a thread that is not
sgoldman@542 439 // at a safepoint (like AsyncGetCallTrace would do) then this is an
sgoldman@542 440 // acceptable result. [ This is assuming that safe_for_sender
sgoldman@542 441 // is so bullet proof that we can trust the frames it produced. ]
sgoldman@542 442 //
sgoldman@542 443 // So if we see that the thread is not safepoint safe
sgoldman@542 444 // then simply produce the method and a bci of zero
sgoldman@542 445 // and skip the possibility of decoding any inlining that
sgoldman@542 446 // may be present. That is far better than simply stopping (or
sgoldman@542 447 // asserting. If however the thread is safepoint safe this
sgoldman@542 448 // is the sign of a compiler bug and we'll let
sgoldman@542 449 // fill_from_compiled_frame handle it.
sgoldman@542 450
sgoldman@542 451
sgoldman@542 452 JavaThreadState state = _thread->thread_state();
sgoldman@542 453
sgoldman@542 454 // in_Java should be good enough to test safepoint safety
sgoldman@542 455 // if state were say in_Java_trans then we'd expect that
sgoldman@542 456 // the pc would have already been slightly adjusted to
sgoldman@542 457 // one that would produce a pcDesc since the trans state
sgoldman@542 458 // would be one that might in fact anticipate a safepoint
sgoldman@542 459
sgoldman@542 460 if (state == _thread_in_Java ) {
sgoldman@542 461 // This will get a method a zero bci and no inlining.
sgoldman@542 462 // Might be nice to have a unique bci to signify this
sgoldman@542 463 // particular case but for now zero will do.
sgoldman@542 464
sgoldman@542 465 fill_from_compiled_native_frame();
sgoldman@542 466
sgoldman@542 467 // There is something to be said for setting the mode to
sgoldman@542 468 // at_end_mode to prevent trying to walk further up the
sgoldman@542 469 // stack. There is evidence that if we walk any further
sgoldman@542 470 // that we could produce a bad stack chain. However until
sgoldman@542 471 // we see evidence that allowing this causes us to find
sgoldman@542 472 // frames bad enough to cause segv's or assertion failures
sgoldman@542 473 // we don't do it as while we may get a bad call chain the
sgoldman@542 474 // probability is much higher (several magnitudes) that we
sgoldman@542 475 // get good data.
sgoldman@542 476
sgoldman@542 477 return true;
sgoldman@542 478 }
duke@435 479 decode_offset = DebugInformationRecorder::serialized_null;
duke@435 480 } else {
duke@435 481 decode_offset = pc_desc->scope_decode_offset();
duke@435 482 }
duke@435 483 fill_from_compiled_frame(decode_offset);
duke@435 484 }
duke@435 485 return true;
duke@435 486 }
duke@435 487
duke@435 488 // End of stack?
duke@435 489 if (_frame.is_first_frame() || (_stop_at_java_call_stub && _frame.is_entry_frame())) {
duke@435 490 _mode = at_end_mode;
duke@435 491 return true;
duke@435 492 }
duke@435 493
duke@435 494 return false;
duke@435 495 }
duke@435 496
duke@435 497
duke@435 498 inline void vframeStreamCommon::fill_from_interpreter_frame() {
duke@435 499 methodOop method = _frame.interpreter_frame_method();
duke@435 500 intptr_t bcx = _frame.interpreter_frame_bcx();
duke@435 501 int bci = method->validate_bci_from_bcx(bcx);
duke@435 502 // 6379830 AsyncGetCallTrace sometimes feeds us wild frames.
duke@435 503 if (bci < 0) {
duke@435 504 found_bad_method_frame();
duke@435 505 bci = 0; // pretend it's on the point of entering
duke@435 506 }
duke@435 507 _mode = interpreted_mode;
duke@435 508 _method = method;
duke@435 509 _bci = bci;
duke@435 510 }

mercurial