1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/frame.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,469 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +typedef class BytecodeInterpreter* interpreterState; 1.29 + 1.30 +class CodeBlob; 1.31 + 1.32 + 1.33 +// A frame represents a physical stack frame (an activation). Frames 1.34 +// can be C or Java frames, and the Java frames can be interpreted or 1.35 +// compiled. In contrast, vframes represent source-level activations, 1.36 +// so that one physical frame can correspond to multiple source level 1.37 +// frames because of inlining. 1.38 + 1.39 +class frame VALUE_OBJ_CLASS_SPEC { 1.40 + private: 1.41 + // Instance variables: 1.42 + intptr_t* _sp; // stack pointer (from Thread::last_Java_sp) 1.43 + address _pc; // program counter (the next instruction after the call) 1.44 + 1.45 + CodeBlob* _cb; // CodeBlob that "owns" pc 1.46 + enum deopt_state { 1.47 + not_deoptimized, 1.48 + is_deoptimized, 1.49 + unknown 1.50 + }; 1.51 + 1.52 + deopt_state _deopt_state; 1.53 + 1.54 + public: 1.55 + // Constructors 1.56 + frame(); 1.57 + 1.58 + // Accessors 1.59 + 1.60 + // pc: Returns the pc at which this frame will continue normally. 1.61 + // It must point at the beginning of the next instruction to execute. 1.62 + address pc() const { return _pc; } 1.63 + 1.64 + // This returns the pc that if you were in the debugger you'd see. Not 1.65 + // the idealized value in the frame object. This undoes the magic conversion 1.66 + // that happens for deoptimized frames. In addition it makes the value the 1.67 + // hardware would want to see in the native frame. The only user (at this point) 1.68 + // is deoptimization. It likely no one else should ever use it. 1.69 + address raw_pc() const; 1.70 + 1.71 + void set_pc( address newpc ); 1.72 + 1.73 + intptr_t* sp() const { return _sp; } 1.74 + void set_sp( intptr_t* newsp ) { _sp = newsp; } 1.75 + 1.76 + 1.77 + CodeBlob* cb() const { return _cb; } 1.78 + 1.79 + // patching operations 1.80 + void patch_pc(Thread* thread, address pc); 1.81 + 1.82 + // Every frame needs to return a unique id which distinguishes it from all other frames. 1.83 + // For sparc and ia32 use sp. ia64 can have memory frames that are empty so multiple frames 1.84 + // will have identical sp values. For ia64 the bsp (fp) value will serve. No real frame 1.85 + // should have an id() of NULL so it is a distinguishing value for an unmatchable frame. 1.86 + // We also have relationals which allow comparing a frame to anoth frame's id() allow 1.87 + // us to distinguish younger (more recent activation) from older (less recent activations) 1.88 + // A NULL id is only valid when comparing for equality. 1.89 + 1.90 + intptr_t* id(void) const; 1.91 + bool is_younger(intptr_t* id) const; 1.92 + bool is_older(intptr_t* id) const; 1.93 + 1.94 + // testers 1.95 + 1.96 + // Compares for strict equality. Rarely used or needed. 1.97 + // It can return a different result than f1.id() == f2.id() 1.98 + bool equal(frame other) const; 1.99 + 1.100 + // type testers 1.101 + bool is_interpreted_frame() const; 1.102 + bool is_java_frame() const; 1.103 + bool is_entry_frame() const; // Java frame called from C? 1.104 + bool is_native_frame() const; 1.105 + bool is_runtime_frame() const; 1.106 + bool is_compiled_frame() const; 1.107 + bool is_safepoint_blob_frame() const; 1.108 + bool is_deoptimized_frame() const; 1.109 + 1.110 + // testers 1.111 + bool is_first_frame() const; // oldest frame? (has no sender) 1.112 + bool is_first_java_frame() const; // same for Java frame 1.113 + 1.114 + bool is_interpreted_frame_valid() const; // performs sanity checks on interpreted frames. 1.115 + 1.116 + // tells whether this frame is marked for deoptimization 1.117 + bool should_be_deoptimized() const; 1.118 + 1.119 + // tells whether this frame can be deoptimized 1.120 + bool can_be_deoptimized() const; 1.121 + 1.122 + // returns the frame size in stack slots 1.123 + int frame_size() const; 1.124 + 1.125 + // returns the sending frame 1.126 + frame sender(RegisterMap* map) const; 1.127 + 1.128 + // for Profiling - acting on another frame. walks sender frames 1.129 + // if valid. 1.130 + frame profile_find_Java_sender_frame(JavaThread *thread); 1.131 + bool safe_for_sender(JavaThread *thread); 1.132 + 1.133 + // returns the sender, but skips conversion frames 1.134 + frame real_sender(RegisterMap* map) const; 1.135 + 1.136 + // returns the the sending Java frame, skipping any intermediate C frames 1.137 + // NB: receiver must not be first frame 1.138 + frame java_sender() const; 1.139 + 1.140 + private: 1.141 + // Helper methods for better factored code in frame::sender 1.142 + frame sender_for_compiled_frame(RegisterMap* map) const; 1.143 + frame sender_for_entry_frame(RegisterMap* map) const; 1.144 + frame sender_for_interpreter_frame(RegisterMap* map) const; 1.145 + frame sender_for_native_frame(RegisterMap* map) const; 1.146 + 1.147 + // All frames: 1.148 + 1.149 + // A low-level interface for vframes: 1.150 + 1.151 + public: 1.152 + 1.153 + intptr_t* addr_at(int index) const { return &fp()[index]; } 1.154 + intptr_t at(int index) const { return *addr_at(index); } 1.155 + 1.156 + // accessors for locals 1.157 + oop obj_at(int offset) const { return *obj_at_addr(offset); } 1.158 + void obj_at_put(int offset, oop value) { *obj_at_addr(offset) = value; } 1.159 + 1.160 + jint int_at(int offset) const { return *int_at_addr(offset); } 1.161 + void int_at_put(int offset, jint value) { *int_at_addr(offset) = value; } 1.162 + 1.163 + oop* obj_at_addr(int offset) const { return (oop*) addr_at(offset); } 1.164 + 1.165 + oop* adjusted_obj_at_addr(methodOop method, int index) { return obj_at_addr(adjust_offset(method, index)); } 1.166 + 1.167 + private: 1.168 + jint* int_at_addr(int offset) const { return (jint*) addr_at(offset); } 1.169 + 1.170 + public: 1.171 + // Link (i.e., the pointer to the previous frame) 1.172 + intptr_t* link() const; 1.173 + void set_link(intptr_t* addr); 1.174 + 1.175 + // Return address 1.176 + address sender_pc() const; 1.177 + 1.178 + // Support for deoptimization 1.179 + void deoptimize(JavaThread* thread, bool thread_is_known_safe = false); 1.180 + 1.181 + // The frame's original SP, before any extension by an interpreted callee; 1.182 + // used for packing debug info into vframeArray objects and vframeArray lookup. 1.183 + intptr_t* unextended_sp() const; 1.184 + 1.185 + // returns the stack pointer of the calling frame 1.186 + intptr_t* sender_sp() const; 1.187 + 1.188 + 1.189 + // Interpreter frames: 1.190 + 1.191 + private: 1.192 + intptr_t** interpreter_frame_locals_addr() const; 1.193 + intptr_t* interpreter_frame_bcx_addr() const; 1.194 + intptr_t* interpreter_frame_mdx_addr() const; 1.195 + 1.196 + public: 1.197 + // Tags for TaggedStackInterpreter 1.198 + enum Tag { 1.199 + TagValue = 0, // Important: must be zero to use G0 on sparc. 1.200 + TagReference = 0x555, // Reference type - is an oop that needs gc. 1.201 + TagCategory2 = 0x666 // Only used internally by interpreter 1.202 + // and not written to the java stack. 1.203 + // The values above are chosen so that misuse causes a crash 1.204 + // with a recognizable value. 1.205 + }; 1.206 + 1.207 + static Tag tag_for_basic_type(BasicType typ) { 1.208 + return (typ == T_OBJECT ? TagReference : TagValue); 1.209 + } 1.210 + 1.211 + // Locals 1.212 + 1.213 + // The _at version returns a pointer because the address is used for GC. 1.214 + intptr_t* interpreter_frame_local_at(int index) const; 1.215 + Tag interpreter_frame_local_tag(int index) const; 1.216 + void interpreter_frame_set_local_tag(int index, Tag tag) const; 1.217 + 1.218 + void interpreter_frame_set_locals(intptr_t* locs); 1.219 + 1.220 + // byte code index/pointer (use these functions for unchecked frame access only!) 1.221 + intptr_t interpreter_frame_bcx() const { return *interpreter_frame_bcx_addr(); } 1.222 + void interpreter_frame_set_bcx(intptr_t bcx); 1.223 + 1.224 + // byte code index 1.225 + jint interpreter_frame_bci() const; 1.226 + void interpreter_frame_set_bci(jint bci); 1.227 + 1.228 + // byte code pointer 1.229 + address interpreter_frame_bcp() const; 1.230 + void interpreter_frame_set_bcp(address bcp); 1.231 + 1.232 + // Unchecked access to the method data index/pointer. 1.233 + // Only use this if you know what you are doing. 1.234 + intptr_t interpreter_frame_mdx() const { return *interpreter_frame_mdx_addr(); } 1.235 + void interpreter_frame_set_mdx(intptr_t mdx); 1.236 + 1.237 + // method data pointer 1.238 + address interpreter_frame_mdp() const; 1.239 + void interpreter_frame_set_mdp(address dp); 1.240 + 1.241 + // Find receiver out of caller's (compiled) argument list 1.242 + oop retrieve_receiver(RegisterMap *reg_map); 1.243 + 1.244 + // Return the monitor owner and BasicLock for compiled synchronized 1.245 + // native methods so that biased locking can revoke the receiver's 1.246 + // bias if necessary. Takes optional nmethod for this frame as 1.247 + // argument to avoid performing repeated lookups in code cache. 1.248 + BasicLock* compiled_synchronized_native_monitor (nmethod* nm = NULL); 1.249 + oop compiled_synchronized_native_monitor_owner(nmethod* nm = NULL); 1.250 + 1.251 + // Find receiver for an invoke when arguments are just pushed on stack (i.e., callee stack-frame is 1.252 + // not setup) 1.253 + oop interpreter_callee_receiver(symbolHandle signature) { return *interpreter_callee_receiver_addr(signature); } 1.254 + 1.255 + 1.256 + oop *interpreter_callee_receiver_addr(symbolHandle signature); 1.257 + 1.258 + 1.259 + // expression stack (may go up or down, direction == 1 or -1) 1.260 + public: 1.261 + intptr_t* interpreter_frame_expression_stack() const; 1.262 + static jint interpreter_frame_expression_stack_direction(); 1.263 + 1.264 + // The _at version returns a pointer because the address is used for GC. 1.265 + intptr_t* interpreter_frame_expression_stack_at(jint offset) const; 1.266 + Tag interpreter_frame_expression_stack_tag(jint offset) const; 1.267 + void interpreter_frame_set_expression_stack_tag(jint offset, Tag tag) const; 1.268 + 1.269 + // top of expression stack 1.270 + intptr_t* interpreter_frame_tos_at(jint offset) const; 1.271 + intptr_t* interpreter_frame_tos_address() const; 1.272 + 1.273 + 1.274 + jint interpreter_frame_expression_stack_size() const; 1.275 + 1.276 + intptr_t* interpreter_frame_sender_sp() const; 1.277 + 1.278 +#ifndef CC_INTERP 1.279 + // template based interpreter deoptimization support 1.280 + void set_interpreter_frame_sender_sp(intptr_t* sender_sp); 1.281 + void interpreter_frame_set_monitor_end(BasicObjectLock* value); 1.282 +#endif // CC_INTERP 1.283 + 1.284 + // BasicObjectLocks: 1.285 + // 1.286 + // interpreter_frame_monitor_begin is higher in memory than interpreter_frame_monitor_end 1.287 + // Interpreter_frame_monitor_begin points to one element beyond the oldest one, 1.288 + // interpreter_frame_monitor_end points to the youngest one, or if there are none, 1.289 + // it points to one beyond where the first element will be. 1.290 + // interpreter_frame_monitor_size reports the allocation size of a monitor in the interpreter stack. 1.291 + // this value is >= BasicObjectLock::size(), and may be rounded up 1.292 + 1.293 + BasicObjectLock* interpreter_frame_monitor_begin() const; 1.294 + BasicObjectLock* interpreter_frame_monitor_end() const; 1.295 + BasicObjectLock* next_monitor_in_interpreter_frame(BasicObjectLock* current) const; 1.296 + BasicObjectLock* previous_monitor_in_interpreter_frame(BasicObjectLock* current) const; 1.297 + static int interpreter_frame_monitor_size(); 1.298 + 1.299 + void interpreter_frame_verify_monitor(BasicObjectLock* value) const; 1.300 + 1.301 + // Tells whether the current interpreter_frame frame pointer 1.302 + // corresponds to the old compiled/deoptimized fp 1.303 + // The receiver used to be a top level frame 1.304 + bool interpreter_frame_equals_unpacked_fp(intptr_t* fp); 1.305 + 1.306 + // Return/result value from this interpreter frame 1.307 + // If the method return type is T_OBJECT or T_ARRAY populates oop_result 1.308 + // For other (non-T_VOID) the appropriate field in the jvalue is populated 1.309 + // with the result value. 1.310 + // Should only be called when at method exit when the method is not 1.311 + // exiting due to an exception. 1.312 + BasicType interpreter_frame_result(oop* oop_result, jvalue* value_result); 1.313 + 1.314 + public: 1.315 + // Method & constant pool cache 1.316 + methodOop interpreter_frame_method() const; 1.317 + void interpreter_frame_set_method(methodOop method); 1.318 + methodOop* interpreter_frame_method_addr() const; 1.319 + constantPoolCacheOop* interpreter_frame_cache_addr() const; 1.320 + 1.321 + public: 1.322 + // Entry frames 1.323 + JavaCallWrapper* entry_frame_call_wrapper() const; 1.324 + intptr_t* entry_frame_argument_at(int offset) const; 1.325 + 1.326 + // tells whether there is another chunk of Delta stack above 1.327 + bool entry_frame_is_first() const; 1.328 + 1.329 + // Compiled frames: 1.330 + 1.331 + public: 1.332 + // Given the index of a local, and the number of argument words 1.333 + // in this stack frame, tell which word of the stack frame to find 1.334 + // the local in. Arguments are stored above the ofp/rpc pair, 1.335 + // while other locals are stored below it. 1.336 + // Since monitors (BasicLock blocks) are also assigned indexes, 1.337 + // but may have different storage requirements, their presence 1.338 + // can also affect the calculation of offsets. 1.339 + static int local_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors); 1.340 + 1.341 + // Given the index of a monitor, etc., tell which word of the 1.342 + // stack frame contains the start of the BasicLock block. 1.343 + // Note that the local index by convention is the __higher__ 1.344 + // of the two indexes allocated to the block. 1.345 + static int monitor_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors); 1.346 + 1.347 + // Tell the smallest value that local_offset_for_compiler will attain. 1.348 + // This is used to help determine how much stack frame to allocate. 1.349 + static int min_local_offset_for_compiler(int nof_args, int max_nof_locals, int max_nof_monitors); 1.350 + 1.351 + // Tells if this register must be spilled during a call. 1.352 + // On Intel, all registers are smashed by calls. 1.353 + static bool volatile_across_calls(Register reg); 1.354 + 1.355 + 1.356 + // Safepoints 1.357 + 1.358 + public: 1.359 + oop saved_oop_result(RegisterMap* map) const; 1.360 + void set_saved_oop_result(RegisterMap* map, oop obj); 1.361 + 1.362 + // For debugging 1.363 + private: 1.364 + const char* print_name() const; 1.365 + 1.366 + public: 1.367 + void print_value() const { print_value_on(tty,NULL); } 1.368 + void print_value_on(outputStream* st, JavaThread *thread) const; 1.369 + void print_on(outputStream* st) const; 1.370 + void interpreter_frame_print_on(outputStream* st) const; 1.371 + void print_on_error(outputStream* st, char* buf, int buflen, bool verbose = false) const; 1.372 + 1.373 + // Conversion from an VMReg to physical stack location 1.374 + oop* oopmapreg_to_location(VMReg reg, const RegisterMap* regmap) const; 1.375 + 1.376 + // Oops-do's 1.377 + void oops_compiled_arguments_do(symbolHandle signature, bool is_static, const RegisterMap* reg_map, OopClosure* f); 1.378 + void oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache = true); 1.379 + 1.380 + private: 1.381 + void oops_interpreted_locals_do(OopClosure *f, 1.382 + int max_locals, 1.383 + InterpreterOopMap *mask); 1.384 + void oops_interpreted_expressions_do(OopClosure *f, symbolHandle signature, 1.385 + bool is_static, int max_stack, int max_locals, 1.386 + InterpreterOopMap *mask); 1.387 + void oops_interpreted_arguments_do(symbolHandle signature, bool is_static, OopClosure* f); 1.388 + 1.389 + // Iteration of oops 1.390 + void oops_do_internal(OopClosure* f, RegisterMap* map, bool use_interpreter_oop_map_cache); 1.391 + void oops_entry_do(OopClosure* f, const RegisterMap* map); 1.392 + void oops_code_blob_do(OopClosure* f, const RegisterMap* map); 1.393 + int adjust_offset(methodOop method, int index); // helper for above fn 1.394 + // Iteration of nmethods 1.395 + void nmethods_code_blob_do(); 1.396 + public: 1.397 + // Memory management 1.398 + void oops_do(OopClosure* f, RegisterMap* map) { oops_do_internal(f, map, true); } 1.399 + void nmethods_do(); 1.400 + 1.401 + void gc_prologue(); 1.402 + void gc_epilogue(); 1.403 + void pd_gc_epilog(); 1.404 + 1.405 +# ifdef ENABLE_ZAP_DEAD_LOCALS 1.406 + private: 1.407 + class CheckValueClosure: public OopClosure { 1.408 + public: void do_oop(oop* p); 1.409 + }; 1.410 + static CheckValueClosure _check_value; 1.411 + 1.412 + class CheckOopClosure: public OopClosure { 1.413 + public: void do_oop(oop* p); 1.414 + }; 1.415 + static CheckOopClosure _check_oop; 1.416 + 1.417 + static void check_derived_oop(oop* base, oop* derived); 1.418 + 1.419 + class ZapDeadClosure: public OopClosure { 1.420 + public: void do_oop(oop* p); 1.421 + }; 1.422 + static ZapDeadClosure _zap_dead; 1.423 + 1.424 + public: 1.425 + // Zapping 1.426 + void zap_dead_locals (JavaThread* thread, const RegisterMap* map); 1.427 + void zap_dead_interpreted_locals(JavaThread* thread, const RegisterMap* map); 1.428 + void zap_dead_compiled_locals (JavaThread* thread, const RegisterMap* map); 1.429 + void zap_dead_entry_locals (JavaThread* thread, const RegisterMap* map); 1.430 + void zap_dead_deoptimized_locals(JavaThread* thread, const RegisterMap* map); 1.431 +# endif 1.432 + // Verification 1.433 + void verify(const RegisterMap* map); 1.434 + static bool verify_return_pc(address x); 1.435 + static bool is_bci(intptr_t bcx); 1.436 + // Usage: 1.437 + // assert(frame::verify_return_pc(return_address), "must be a return pc"); 1.438 + 1.439 + int pd_oop_map_offset_adjustment() const; 1.440 + 1.441 +# include "incls/_frame_pd.hpp.incl" 1.442 +}; 1.443 + 1.444 + 1.445 +// 1.446 +// StackFrameStream iterates through the frames of a thread starting from 1.447 +// top most frame. It automatically takes care of updating the location of 1.448 +// all (callee-saved) registers. Notice: If a thread is stopped at 1.449 +// a safepoint, all registers are saved, not only the callee-saved ones. 1.450 +// 1.451 +// Use: 1.452 +// 1.453 +// for(StackFrameStream fst(thread); !fst.is_done(); fst.next()) { 1.454 +// ... 1.455 +// } 1.456 +// 1.457 +class StackFrameStream : public StackObj { 1.458 + private: 1.459 + frame _fr; 1.460 + RegisterMap _reg_map; 1.461 + bool _is_done; 1.462 + public: 1.463 + StackFrameStream(JavaThread *thread, bool update = true); 1.464 + 1.465 + // Iteration 1.466 + bool is_done() { return (_is_done) ? true : (_is_done = _fr.is_first_frame(), false); } 1.467 + void next() { if (!_is_done) _fr = _fr.sender(&_reg_map); } 1.468 + 1.469 + // Query 1.470 + frame *current() { return &_fr; } 1.471 + RegisterMap* register_map() { return &_reg_map; } 1.472 +};