src/share/vm/runtime/vframe.hpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 518
d3cd40645d0d
child 542
93b6525e3b82
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 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@518 233 bool _eliminated;
duke@435 234 public:
duke@435 235 // Constructor
kvn@518 236 MonitorInfo(oop owner, BasicLock* lock, bool eliminated) {
duke@435 237 _owner = owner;
duke@435 238 _lock = lock;
kvn@518 239 _eliminated = eliminated;
duke@435 240 }
duke@435 241 // Accessors
duke@435 242 oop owner() const { return _owner; }
duke@435 243 BasicLock* lock() const { return _lock; }
kvn@518 244 bool eliminated() const { return _eliminated; }
duke@435 245 };
duke@435 246
duke@435 247 class vframeStreamCommon : StackObj {
duke@435 248 protected:
duke@435 249 // common
duke@435 250 frame _frame;
duke@435 251 JavaThread* _thread;
duke@435 252 RegisterMap _reg_map;
duke@435 253 enum { interpreted_mode, compiled_mode, at_end_mode } _mode;
duke@435 254
duke@435 255 int _sender_decode_offset;
duke@435 256
duke@435 257 // Cached information
duke@435 258 methodOop _method;
duke@435 259 int _bci;
duke@435 260
duke@435 261 // Should VM activations be ignored or not
duke@435 262 bool _stop_at_java_call_stub;
duke@435 263
duke@435 264 bool fill_in_compiled_inlined_sender();
duke@435 265 void fill_from_compiled_frame(int decode_offset);
duke@435 266 void fill_from_compiled_native_frame();
duke@435 267
duke@435 268 void found_bad_method_frame();
duke@435 269
duke@435 270 void fill_from_interpreter_frame();
duke@435 271 bool fill_from_frame();
duke@435 272
duke@435 273 // Helper routine for security_get_caller_frame
duke@435 274 void skip_prefixed_method_and_wrappers();
duke@435 275
duke@435 276 public:
duke@435 277 // Constructor
duke@435 278 vframeStreamCommon(JavaThread* thread) : _reg_map(thread, false) {
duke@435 279 _thread = thread;
duke@435 280 }
duke@435 281
duke@435 282 // Accessors
duke@435 283 methodOop method() const { return _method; }
duke@435 284 int bci() const { return _bci; }
duke@435 285 intptr_t* frame_id() const { return _frame.id(); }
duke@435 286 address frame_pc() const { return _frame.pc(); }
duke@435 287
duke@435 288 CodeBlob* cb() const { return _frame.cb(); }
duke@435 289 nmethod* nm() const {
duke@435 290 assert( cb() != NULL && cb()->is_nmethod(), "usage");
duke@435 291 return (nmethod*) cb();
duke@435 292 }
duke@435 293
duke@435 294 // Frame type
duke@435 295 bool is_interpreted_frame() const { return _frame.is_interpreted_frame(); }
duke@435 296 bool is_entry_frame() const { return _frame.is_entry_frame(); }
duke@435 297
duke@435 298 // Iteration
duke@435 299 void next() {
duke@435 300 // handle frames with inlining
duke@435 301 if (_mode == compiled_mode && fill_in_compiled_inlined_sender()) return;
duke@435 302
duke@435 303 // handle general case
duke@435 304 do {
duke@435 305 _frame = _frame.sender(&_reg_map);
duke@435 306 } while (!fill_from_frame());
duke@435 307 }
duke@435 308
duke@435 309 bool at_end() const { return _mode == at_end_mode; }
duke@435 310
duke@435 311 // Implements security traversal. Skips depth no. of frame including
duke@435 312 // special security frames and prefixed native methods
duke@435 313 void security_get_caller_frame(int depth);
duke@435 314
duke@435 315 // Helper routine for JVM_LatestUserDefinedLoader -- needed for 1.4
duke@435 316 // reflection implementation
duke@435 317 void skip_reflection_related_frames();
duke@435 318 };
duke@435 319
duke@435 320 class vframeStream : public vframeStreamCommon {
duke@435 321 public:
duke@435 322 // Constructors
duke@435 323 vframeStream(JavaThread* thread, bool stop_at_java_call_stub = false)
duke@435 324 : vframeStreamCommon(thread) {
duke@435 325 _stop_at_java_call_stub = stop_at_java_call_stub;
duke@435 326
duke@435 327 if (!thread->has_last_Java_frame()) {
duke@435 328 _mode = at_end_mode;
duke@435 329 return;
duke@435 330 }
duke@435 331
duke@435 332 _frame = _thread->last_frame();
duke@435 333 while (!fill_from_frame()) {
duke@435 334 _frame = _frame.sender(&_reg_map);
duke@435 335 }
duke@435 336 }
duke@435 337
duke@435 338 // top_frame may not be at safepoint, start with sender
duke@435 339 vframeStream(JavaThread* thread, frame top_frame, bool stop_at_java_call_stub = false);
duke@435 340 };
duke@435 341
duke@435 342
duke@435 343 inline bool vframeStreamCommon::fill_in_compiled_inlined_sender() {
duke@435 344 if (_sender_decode_offset == DebugInformationRecorder::serialized_null) {
duke@435 345 return false;
duke@435 346 }
duke@435 347 fill_from_compiled_frame(_sender_decode_offset);
duke@435 348 return true;
duke@435 349 }
duke@435 350
duke@435 351
duke@435 352 inline void vframeStreamCommon::fill_from_compiled_frame(int decode_offset) {
duke@435 353 _mode = compiled_mode;
duke@435 354
duke@435 355 // Range check to detect ridiculous offsets.
duke@435 356 if (decode_offset == DebugInformationRecorder::serialized_null ||
duke@435 357 decode_offset < 0 ||
duke@435 358 decode_offset >= nm()->scopes_data_size()) {
duke@435 359 // 6379830 AsyncGetCallTrace sometimes feeds us wild frames.
duke@435 360 // If we attempt to read nmethod::scopes_data at serialized_null (== 0),
duke@435 361 // or if we read some at other crazy offset,
duke@435 362 // we will decode garbage and make wild references into the heap,
duke@435 363 // leading to crashes in product mode.
duke@435 364 // (This isn't airtight, of course, since there are internal
duke@435 365 // offsets which are also crazy.)
duke@435 366 #ifdef ASSERT
duke@435 367 if (WizardMode) {
duke@435 368 tty->print_cr("Error in fill_from_frame: pc_desc for "
duke@435 369 INTPTR_FORMAT " not found or invalid at %d",
duke@435 370 _frame.pc(), decode_offset);
duke@435 371 nm()->print();
duke@435 372 nm()->method()->print_codes();
duke@435 373 nm()->print_code();
duke@435 374 nm()->print_pcs();
duke@435 375 }
duke@435 376 #endif
duke@435 377 // Provide a cheap fallback in product mode. (See comment above.)
duke@435 378 found_bad_method_frame();
duke@435 379 fill_from_compiled_native_frame();
duke@435 380 return;
duke@435 381 }
duke@435 382
duke@435 383 // Decode first part of scopeDesc
duke@435 384 DebugInfoReadStream buffer(nm(), decode_offset);
duke@435 385 _sender_decode_offset = buffer.read_int();
duke@435 386 _method = methodOop(buffer.read_oop());
duke@435 387 _bci = buffer.read_bci();
duke@435 388
duke@435 389 assert(_method->is_method(), "checking type of decoded method");
duke@435 390 }
duke@435 391
duke@435 392 // The native frames are handled specially. We do not rely on ScopeDesc info
duke@435 393 // since the pc might not be exact due to the _last_native_pc trick.
duke@435 394 inline void vframeStreamCommon::fill_from_compiled_native_frame() {
duke@435 395 _mode = compiled_mode;
duke@435 396 _sender_decode_offset = DebugInformationRecorder::serialized_null;
duke@435 397 _method = nm()->method();
duke@435 398 _bci = 0;
duke@435 399 }
duke@435 400
duke@435 401 inline bool vframeStreamCommon::fill_from_frame() {
duke@435 402 // Interpreted frame
duke@435 403 if (_frame.is_interpreted_frame()) {
duke@435 404 fill_from_interpreter_frame();
duke@435 405 return true;
duke@435 406 }
duke@435 407
duke@435 408 // Compiled frame
duke@435 409
duke@435 410 if (cb() != NULL && cb()->is_nmethod()) {
duke@435 411 if (nm()->is_native_method()) {
duke@435 412 // Do not rely on scopeDesc since the pc might be unprecise due to the _last_native_pc trick.
duke@435 413 fill_from_compiled_native_frame();
duke@435 414 } else {
duke@435 415 PcDesc* pc_desc = nm()->pc_desc_at(_frame.pc());
duke@435 416 int decode_offset;
duke@435 417 if (pc_desc == NULL) {
duke@435 418 // Should not happen, but let fill_from_compiled_frame handle it.
duke@435 419 decode_offset = DebugInformationRecorder::serialized_null;
duke@435 420 } else {
duke@435 421 decode_offset = pc_desc->scope_decode_offset();
duke@435 422 }
duke@435 423 fill_from_compiled_frame(decode_offset);
duke@435 424 }
duke@435 425 return true;
duke@435 426 }
duke@435 427
duke@435 428 // End of stack?
duke@435 429 if (_frame.is_first_frame() || (_stop_at_java_call_stub && _frame.is_entry_frame())) {
duke@435 430 _mode = at_end_mode;
duke@435 431 return true;
duke@435 432 }
duke@435 433
duke@435 434 return false;
duke@435 435 }
duke@435 436
duke@435 437
duke@435 438 inline void vframeStreamCommon::fill_from_interpreter_frame() {
duke@435 439 methodOop method = _frame.interpreter_frame_method();
duke@435 440 intptr_t bcx = _frame.interpreter_frame_bcx();
duke@435 441 int bci = method->validate_bci_from_bcx(bcx);
duke@435 442 // 6379830 AsyncGetCallTrace sometimes feeds us wild frames.
duke@435 443 if (bci < 0) {
duke@435 444 found_bad_method_frame();
duke@435 445 bci = 0; // pretend it's on the point of entering
duke@435 446 }
duke@435 447 _mode = interpreted_mode;
duke@435 448 _method = method;
duke@435 449 _bci = bci;
duke@435 450 }

mercurial