annotate src/share/vm/runtime/vframe.hpp @ 196:d1605aabd0a1

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