frame frame::sender_for_entry_frame(RegisterMap *map) const { assert(zeroframe()->is_entry_frame(), "wrong type of frame"); assert(map != NULL, "map must be set"); assert(!entry_frame_is_first(), "next Java fp must be non zero"); assert(entry_frame_call_wrapper()->anchor()->last_Java_sp() == sender_sp(), "sender should be next Java frame"); map->clear(); assert(map->include_argument_oops(), "should be set by clear"); return frame(zeroframe()->next(), sender_sp()); }
frame frame::sender_for_interpreter_frame(RegisterMap *map) const { // Pass callers initial_caller_sp as unextended_sp. return frame(sender_sp(), sender_pc(), CC_INTERP_ONLY((intptr_t*)((parent_ijava_frame_abi *)callers_abi())->initial_caller_sp) NOT_CC_INTERP((intptr_t*)get_ijava_state()->sender_sp) ); }
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()); }
frame frame::sender_for_interpreter_frame(RegisterMap *map) const { // Pass callers initial_caller_sp as unextended_sp. return frame(sender_sp(), sender_pc(), (intptr_t*)get_ijava_state()->sender_sp); }
intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const { return sender_sp(); }
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; }
frame frame::sender_for_nonentry_frame(RegisterMap *map) const { assert(zeroframe()->is_interpreter_frame() || zeroframe()->is_shark_frame() || zeroframe()->is_fake_stub_frame(), "wrong type of frame"); return frame(zeroframe()->next(), sender_sp()); }
inline int frame::frame_size(RegisterMap* map) const { return sender_sp() - sp(); }
inline int frame::frame_size() const { return sender_sp() - sp(); }
inline int frame::frame_size(RegisterMap* map) const { // Stack grows towards smaller addresses on PPC64: sender is at a higher address. return sender_sp() - sp(); }