void frame::follow_roots() { if (is_interpreted_frame()) { if (has_interpreted_float_marker() && follow_roots_interpreted_float_frame()) return; // Follow the roots of the frame for (oop* p = sp(); p <= temp_addr(0); p++) { MarkSweep::follow_root(p); } MarkSweep::follow_root((oop*)hp_addr()); MarkSweep::follow_root(receiver_addr()); return; } if (is_compiled_frame()) { if (has_compiled_float_marker() && follow_roots_compiled_float_frame()) return; for (oop* p = sp(); p < (oop*)fp(); p++) MarkSweep::follow_root(p); return; } if (is_entry_frame()) { for (oop* p = sp(); p < (oop*)fp(); p++) MarkSweep::follow_root(p); return; } if (is_deoptimized_frame()) { // Expression stack oop* end = (oop*)fp() + frame_real_sender_sp_offset; for (oop* p = sp(); p < end; p++) MarkSweep::follow_root(p); MarkSweep::follow_root((oop*)frame_array_addr()); return; } }
frame frame::sender(RegisterMap* map) const { // Default is not to follow arguments; the various // sender_for_xxx methods update this accordingly. map->set_include_argument_oops(false); if (is_entry_frame()) return sender_for_entry_frame(map); else return sender_for_nonentry_frame(map); }
frame frame::sender(RegisterMap* map) const { assert(map != NULL, "map must be set"); assert(CodeCache::find_blob_unsafe(_pc) == _cb, "inconsistent"); // Default is not to follow arguments; update it accordingly below map->set_include_argument_oops(false); if (is_entry_frame()) return sender_for_entry_frame(map); intptr_t* younger_sp = sp(); intptr_t* sp = sender_sp(); // Note: The version of this operation on any platform with callee-save // registers must update the register map (if not null). // In order to do this correctly, the various subtypes of // of frame (interpreted, compiled, glue, native), // must be distinguished. There is no need on SPARC for // such distinctions, because all callee-save registers are // preserved for all frames via SPARC-specific mechanisms. // // *** HOWEVER, *** if and when we make any floating-point // registers callee-saved, then we will have to copy over // the RegisterMap update logic from the Intel code. // The constructor of the sender must know whether this frame is interpreted so it can set the // sender's _sp_adjustment_by_callee field. An osr adapter frame was originally // interpreted but its pc is in the code cache (for c1 -> osr_frame_return_id stub), so it must be // explicitly recognized. if (is_ricochet_frame()) return sender_for_ricochet_frame(map); bool frame_is_interpreted = is_interpreted_frame(); if (frame_is_interpreted) { map->make_integer_regs_unsaved(); map->shift_window(sp, younger_sp); } else if (_cb != NULL) { // Update the locations of implicitly saved registers to be their // addresses in the register save area. // For %o registers, the addresses of %i registers in the next younger // frame are used. map->shift_window(sp, younger_sp); if (map->update_map()) { // Tell GC to use argument oopmaps for some runtime stubs that need it. // For C1, the runtime stub might not have oop maps, so set this flag // outside of update_register_map. map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); if (_cb->oop_maps() != NULL) { OopMapSet::update_register_map(this, map); } } } return frame(sp, younger_sp, frame_is_interpreted); }
frame frame::sender() const { frame result; if (is_entry_frame()) { // Delta frame called from C; skip all C frames and return top C // frame of that chunk as the sender assert(has_next_Delta_fp(), "next Delta fp must be non zero"); assert(next_Delta_fp() > _fp, "must be above this frame on stack"); result = frame(next_Delta_sp(), next_Delta_fp()); } else if (is_deoptimized_frame()) { result = frame(real_sender_sp(), link(), return_addr()); } else { result = frame(sender_sp(), link(), return_addr()); } return result; }
//------------------------------------------------------------------------------ // frame::sender frame frame::sender(RegisterMap* map) const { // Default is we done have to follow them. The sender_for_xxx will // update it accordingly map->set_include_argument_oops(false); if (is_entry_frame()) return sender_for_entry_frame(map); if (is_interpreted_frame()) return sender_for_interpreter_frame(map); assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); if (_cb != NULL) { return sender_for_compiled_frame(map); } // Must be native-compiled frame, i.e. the marshaling code for native // methods that exists in the core system. return frame(sender_sp(), link(), sender_pc()); }
void frame::oop_iterate(OopClosure* blk) { if (is_interpreted_frame()) { if (has_interpreted_float_marker() && oop_iterate_interpreted_float_frame(blk)) return; // lprintf("Frame: fp = %#lx, sp = %#lx]\n", fp(), sp()); for (oop* p = sp(); p <= temp_addr(0); p++) { // lprintf("\t[%#lx]: ", p); // (*p)->short_print(); // lprintf("\n"); blk->do_oop(p); } // lprintf("\t{%#lx}: ", receiver_addr()); // (*receiver_addr())->short_print(); // lprintf("\n"); blk->do_oop(receiver_addr()); return; } if (is_compiled_frame()) { if (has_compiled_float_marker() && oop_iterate_compiled_float_frame(blk)) return; // All oops are [sp..fp[ for (oop* p = sp(); p < (oop*)fp(); p++) { blk->do_oop(p); } return; } if (is_entry_frame()) { // All oops are [sp..fp[ for (oop* p = sp(); p < (oop*)fp(); p++) { blk->do_oop(p); } return; } if (is_deoptimized_frame()) { // Expression stack oop* end = (oop*)fp() + frame_real_sender_sp_offset; // All oops are [sp..end[ for (oop* p = sp(); p < end; p++) { blk->do_oop(p); } blk->do_oop((oop*)frame_array_addr()); return; } }
void frame::describe_pd(FrameValues& values, int frame_no) { if (is_interpreted_frame()) { DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp); DESCRIBE_FP_OFFSET(interpreter_frame_last_sp); DESCRIBE_FP_OFFSET(interpreter_frame_method); DESCRIBE_FP_OFFSET(interpreter_frame_mdx); DESCRIBE_FP_OFFSET(interpreter_frame_cache); DESCRIBE_FP_OFFSET(interpreter_frame_locals); DESCRIBE_FP_OFFSET(interpreter_frame_bcx); DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp); } else if (is_entry_frame()) { // This could be more descriptive if we use the enum in // stubGenerator to map to real names but it's most important to // claim these frame slots so the error checking works. for (int i = 0; i < entry_frame_after_call_words; i++) { values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i)); } } }
bool frame::safe_for_sender(JavaThread *thread) { address sp = (address)_sp; address fp = (address)_fp; address unextended_sp = (address)_unextended_sp; // consider stack guards when trying to determine "safe" stack pointers static size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0; size_t usable_stack_size = thread->stack_size() - stack_guard_size; // sp must be within the usable part of the stack (not in guards) bool sp_safe = (sp < thread->stack_base()) && (sp >= thread->stack_base() - usable_stack_size); if (!sp_safe) { return false; } // unextended sp must be within the stack and above or equal sp bool unextended_sp_safe = (unextended_sp < thread->stack_base()) && (unextended_sp >= sp); if (!unextended_sp_safe) { return false; } // an fp must be within the stack and above (but not equal) sp // second evaluation on fp+ is added to handle situation where fp is -1 bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base()))); // We know sp/unextended_sp are safe only fp is questionable here // If the current frame is known to the code cache then we can attempt to // to construct the sender and do some validation of it. This goes a long way // toward eliminating issues when we get in frame construction code if (_cb != NULL ) { // First check if frame is complete and tester is reliable // Unfortunately we can only check frame complete for runtime stubs and nmethod // other generic buffer blobs are more problematic so we just assume they are // ok. adapter blobs never have a frame complete and are never ok. if (!_cb->is_frame_complete_at(_pc)) { if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) { return false; } } // Could just be some random pointer within the codeBlob if (!_cb->code_contains(_pc)) { return false; } // Entry frame checks if (is_entry_frame()) { // an entry frame must have a valid fp. if (!fp_safe) return false; // Validate the JavaCallWrapper an entry frame must have address jcw = (address)entry_frame_call_wrapper(); bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > fp); return jcw_safe; } intptr_t* sender_sp = NULL; address sender_pc = NULL; if (is_interpreted_frame()) { // fp must be safe if (!fp_safe) { return false; } sender_pc = (address) this->fp()[return_addr_offset]; sender_sp = (intptr_t*) addr_at(sender_sp_offset); } else { // must be some sort of compiled/runtime frame // fp does not have to be safe (although it could be check for c1?) // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc if (_cb->frame_size() <= 0) { return false; } sender_sp = _unextended_sp + _cb->frame_size(); // On Intel the return_address is always the word on the stack sender_pc = (address) *(sender_sp-1); } // If the potential sender is the interpreter then we can do some more checking if (Interpreter::contains(sender_pc)) { // ebp is always saved in a recognizable place in any code we generate. However // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp // is really a frame pointer. intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); if (!saved_fp_safe) { return false; } // construct the potential sender frame sender(sender_sp, saved_fp, sender_pc); return sender.is_interpreted_frame_valid(thread); } // We must always be able to find a recognizable pc CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); if (sender_pc == NULL || sender_blob == NULL) { return false; } // Could be a zombie method if (sender_blob->is_zombie() || sender_blob->is_unloaded()) { return false; } // Could just be some random pointer within the codeBlob if (!sender_blob->code_contains(sender_pc)) { return false; } // We should never be able to see an adapter if the current frame is something from code cache if (sender_blob->is_adapter_blob()) { return false; } // Could be the call_stub if (StubRoutines::returns_to_call_stub(sender_pc)) { intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); if (!saved_fp_safe) { return false; } // construct the potential sender frame sender(sender_sp, saved_fp, sender_pc); // Validate the JavaCallWrapper an entry frame must have address jcw = (address)sender.entry_frame_call_wrapper(); bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp()); return jcw_safe; } if (sender_blob->is_nmethod()) { nmethod* nm = sender_blob->as_nmethod_or_null(); if (nm != NULL) { if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc)) { return false; } } } // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size // because the return address counts against the callee's frame. if (sender_blob->frame_size() <= 0) { assert(!sender_blob->is_nmethod(), "should count return address at least"); return false; } // We should never be able to see anything here except an nmethod. If something in the // code cache (current frame) is called by an entity within the code cache that entity // should not be anything but the call stub (already covered), the interpreter (already covered) // or an nmethod. if (!sender_blob->is_nmethod()) { return false; } // Could put some more validation for the potential non-interpreted sender // frame we'd create by calling sender if I could think of any. Wait for next crash in forte... // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb // We've validated the potential sender that would be created return true; } // Must be native-compiled frame. Since sender will try and use fp to find // linkages it must be safe if (!fp_safe) { return false; } // Will the pc we fetch be non-zero (which we'll find at the oldest frame) if ( (address) this->fp()[return_addr_offset] == NULL) return false; // could try and do some more potential verification of native frame if we could think of some... return true; }
bool frame::safe_for_sender(JavaThread *thread) { address _SP = (address) sp(); address _FP = (address) fp(); address _UNEXTENDED_SP = (address) unextended_sp(); // sp must be within the stack bool sp_safe = (_SP <= thread->stack_base()) && (_SP >= thread->stack_base() - thread->stack_size()); if (!sp_safe) { return false; } // unextended sp must be within the stack and above or equal sp bool unextended_sp_safe = (_UNEXTENDED_SP <= thread->stack_base()) && (_UNEXTENDED_SP >= _SP); if (!unextended_sp_safe) return false; // an fp must be within the stack and above (but not equal) sp bool fp_safe = (_FP <= thread->stack_base()) && (_FP > _SP); // We know sp/unextended_sp are safe only fp is questionable here // If the current frame is known to the code cache then we can attempt to // to construct the sender and do some validation of it. This goes a long way // toward eliminating issues when we get in frame construction code if (_cb != NULL ) { // First check if frame is complete and tester is reliable // Unfortunately we can only check frame complete for runtime stubs and nmethod // other generic buffer blobs are more problematic so we just assume they are // ok. adapter blobs never have a frame complete and are never ok. if (!_cb->is_frame_complete_at(_pc)) { if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) { return false; } } // Entry frame checks if (is_entry_frame()) { // an entry frame must have a valid fp. if (!fp_safe) { return false; } // Validate the JavaCallWrapper an entry frame must have address jcw = (address)entry_frame_call_wrapper(); bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > _FP); return jcw_safe; } intptr_t* younger_sp = sp(); intptr_t* _SENDER_SP = sender_sp(); // sender is actually just _FP bool adjusted_stack = is_interpreted_frame(); address sender_pc = (address)younger_sp[I7->sp_offset_in_saved_window()] + pc_return_offset; // We must always be able to find a recognizable pc CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); if (sender_pc == NULL || sender_blob == NULL) { return false; } // It should be safe to construct the sender though it might not be valid frame sender(_SENDER_SP, younger_sp, adjusted_stack); // Do we have a valid fp? address sender_fp = (address) sender.fp(); // an fp must be within the stack and above (but not equal) current frame's _FP bool sender_fp_safe = (sender_fp <= thread->stack_base()) && (sender_fp > _FP); if (!sender_fp_safe) { return false; } // If the potential sender is the interpreter then we can do some more checking if (Interpreter::contains(sender_pc)) { return sender.is_interpreted_frame_valid(thread); } // Could just be some random pointer within the codeBlob if (!sender.cb()->code_contains(sender_pc)) { return false; } // We should never be able to see an adapter if the current frame is something from code cache if (sender_blob->is_adapter_blob()) { return false; } if( sender.is_entry_frame()) { // Validate the JavaCallWrapper an entry frame must have address jcw = (address)sender.entry_frame_call_wrapper(); bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > sender_fp); return jcw_safe; } // If the frame size is 0 something is bad because every nmethod has a non-zero frame size // because you must allocate window space if (sender_blob->frame_size() == 0) { assert(!sender_blob->is_nmethod(), "should count return address at least"); return false; } // The sender should positively be an nmethod or call_stub. On sparc we might in fact see something else. // The cause of this is because at a save instruction the O7 we get is a leftover from an earlier // window use. So if a runtime stub creates two frames (common in fastdebug/jvmg) then we see the // stale pc. So if the sender blob is not something we'd expect we have little choice but to declare // the stack unwalkable. pd_get_top_frame_for_signal_handler tries to recover from this by unwinding // that initial frame and retrying. if (!sender_blob->is_nmethod()) { return false; } // Could put some more validation for the potential non-interpreted sender // frame we'd create by calling sender if I could think of any. Wait for next crash in forte... // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb // We've validated the potential sender that would be created return true; } // Must be native-compiled frame. Since sender will try and use fp to find // linkages it must be safe if (!fp_safe) return false; // could try and do some more potential verification of native frame if we could think of some... return true; }
inline bool frame::is_first_frame() const { return is_entry_frame() && entry_frame_is_first(); }
bool frame::is_first_frame() const { return is_entry_frame() && !has_next_Delta_fp(); }
IC_Iterator* frame::sender_ic_iterator() const { return is_entry_frame() ? NULL : sender().current_ic_iterator(); }
// Tells whether this is a Java frame. bool is_java_frame( void ) const { return !is_entry_frame(); }