duke@435: /* drchase@6680: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/markOop.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: #include "oops/oop.inline.hpp" iveresov@3495: #include "prims/methodHandles.hpp" stefank@2314: #include "runtime/frame.inline.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/javaCalls.hpp" stefank@2314: #include "runtime/monitorChunk.hpp" sla@5237: #include "runtime/os.hpp" stefank@2314: #include "runtime/signature.hpp" stefank@2314: #include "runtime/stubCodeGenerator.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@2314: #include "vmreg_x86.inline.hpp" stefank@2314: #ifdef COMPILER1 stefank@2314: #include "c1/c1_Runtime1.hpp" stefank@2314: #include "runtime/vframeArray.hpp" stefank@2314: #endif duke@435: duke@435: #ifdef ASSERT duke@435: void RegisterMap::check_location_valid() { duke@435: } duke@435: #endif duke@435: drchase@6680: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC duke@435: duke@435: // Profiling/safepoint support duke@435: duke@435: bool frame::safe_for_sender(JavaThread *thread) { duke@435: address sp = (address)_sp; duke@435: address fp = (address)_fp; duke@435: address unextended_sp = (address)_unextended_sp; sla@5237: sla@5237: // consider stack guards when trying to determine "safe" stack pointers sla@5237: static size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0; sla@5237: size_t usable_stack_size = thread->stack_size() - stack_guard_size; sla@5237: sla@5237: // sp must be within the usable part of the stack (not in guards) sla@5237: bool sp_safe = (sp < thread->stack_base()) && sla@5237: (sp >= thread->stack_base() - usable_stack_size); sla@5237: sgoldman@542: sgoldman@542: if (!sp_safe) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: // unextended sp must be within the stack and above or equal sp sla@5237: bool unextended_sp_safe = (unextended_sp < thread->stack_base()) && sgoldman@542: (unextended_sp >= sp); sgoldman@542: sgoldman@542: if (!unextended_sp_safe) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: // an fp must be within the stack and above (but not equal) sp sla@5237: // second evaluation on fp+ is added to handle situation where fp is -1 sla@5237: bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base()))); sgoldman@542: sgoldman@542: // We know sp/unextended_sp are safe only fp is questionable here sgoldman@542: sgoldman@542: // If the current frame is known to the code cache then we can attempt to sgoldman@542: // to construct the sender and do some validation of it. This goes a long way sgoldman@542: // toward eliminating issues when we get in frame construction code sgoldman@542: sgoldman@542: if (_cb != NULL ) { sgoldman@542: sgoldman@542: // First check if frame is complete and tester is reliable duke@435: // Unfortunately we can only check frame complete for runtime stubs and nmethod duke@435: // other generic buffer blobs are more problematic so we just assume they are duke@435: // ok. adapter blobs never have a frame complete and are never ok. sgoldman@542: sgoldman@542: if (!_cb->is_frame_complete_at(_pc)) { duke@435: if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) { duke@435: return false; duke@435: } duke@435: } rbackman@4645: rbackman@4645: // Could just be some random pointer within the codeBlob rbackman@4645: if (!_cb->code_contains(_pc)) { rbackman@4645: return false; rbackman@4645: } rbackman@4645: sgoldman@542: // Entry frame checks sgoldman@542: if (is_entry_frame()) { sgoldman@542: // an entry frame must have a valid fp. sgoldman@542: sgoldman@542: if (!fp_safe) return false; sgoldman@542: sgoldman@542: // Validate the JavaCallWrapper an entry frame must have sgoldman@542: sgoldman@542: address jcw = (address)entry_frame_call_wrapper(); sgoldman@542: sla@5237: bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > fp); sgoldman@542: sgoldman@542: return jcw_safe; sgoldman@542: sgoldman@542: } sgoldman@542: sgoldman@542: intptr_t* sender_sp = NULL; sgoldman@542: address sender_pc = NULL; sgoldman@542: sgoldman@542: if (is_interpreted_frame()) { sgoldman@542: // fp must be safe sgoldman@542: if (!fp_safe) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: sender_pc = (address) this->fp()[return_addr_offset]; sgoldman@542: sender_sp = (intptr_t*) addr_at(sender_sp_offset); sgoldman@542: sgoldman@542: } else { sgoldman@542: // must be some sort of compiled/runtime frame sgoldman@542: // fp does not have to be safe (although it could be check for c1?) sgoldman@542: mgronlun@6163: // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc mgronlun@6163: if (_cb->frame_size() <= 0) { mgronlun@6163: return false; mgronlun@6163: } mgronlun@6163: sgoldman@542: sender_sp = _unextended_sp + _cb->frame_size(); sgoldman@542: // On Intel the return_address is always the word on the stack sgoldman@542: sender_pc = (address) *(sender_sp-1); sgoldman@542: } sgoldman@542: sgoldman@542: sgoldman@542: // If the potential sender is the interpreter then we can do some more checking sgoldman@542: if (Interpreter::contains(sender_pc)) { sgoldman@542: sgoldman@542: // ebp is always saved in a recognizable place in any code we generate. However sgoldman@542: // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp sgoldman@542: // is really a frame pointer. sgoldman@542: sgoldman@542: intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); sla@5237: bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); sgoldman@542: sgoldman@542: if (!saved_fp_safe) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: // construct the potential sender sgoldman@542: sgoldman@542: frame sender(sender_sp, saved_fp, sender_pc); sgoldman@542: sgoldman@542: return sender.is_interpreted_frame_valid(thread); sgoldman@542: sgoldman@542: } sgoldman@542: sla@5237: // We must always be able to find a recognizable pc sla@5237: CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); sla@5237: if (sender_pc == NULL || sender_blob == NULL) { sla@5237: return false; sla@5237: } sla@5237: sla@5237: // Could be a zombie method sla@5237: if (sender_blob->is_zombie() || sender_blob->is_unloaded()) { sla@5237: return false; sla@5237: } sla@5237: sgoldman@542: // Could just be some random pointer within the codeBlob twisti@2103: if (!sender_blob->code_contains(sender_pc)) { twisti@2103: return false; twisti@2103: } sgoldman@542: sgoldman@542: // We should never be able to see an adapter if the current frame is something from code cache twisti@2103: if (sender_blob->is_adapter_blob()) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: // Could be the call_stub sgoldman@542: if (StubRoutines::returns_to_call_stub(sender_pc)) { sgoldman@542: intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); sla@5237: bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); sgoldman@542: sgoldman@542: if (!saved_fp_safe) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: // construct the potential sender sgoldman@542: sgoldman@542: frame sender(sender_sp, saved_fp, sender_pc); sgoldman@542: sgoldman@542: // Validate the JavaCallWrapper an entry frame must have sgoldman@542: address jcw = (address)sender.entry_frame_call_wrapper(); sgoldman@542: sla@5237: bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp()); sgoldman@542: sgoldman@542: return jcw_safe; sgoldman@542: } sgoldman@542: sla@5237: if (sender_blob->is_nmethod()) { sla@5237: nmethod* nm = sender_blob->as_nmethod_or_null(); sla@5237: if (nm != NULL) { zmajo@7854: if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) || zmajo@7854: nm->method()->is_method_handle_intrinsic()) { sla@5237: return false; sla@5237: } sla@5237: } sla@5237: } sla@5237: sla@5237: // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size sgoldman@542: // because the return address counts against the callee's frame. sgoldman@542: sla@5237: if (sender_blob->frame_size() <= 0) { sgoldman@542: assert(!sender_blob->is_nmethod(), "should count return address at least"); sgoldman@542: return false; sgoldman@542: } sgoldman@542: sgoldman@542: // We should never be able to see anything here except an nmethod. If something in the sgoldman@542: // code cache (current frame) is called by an entity within the code cache that entity sgoldman@542: // should not be anything but the call stub (already covered), the interpreter (already covered) sgoldman@542: // or an nmethod. sgoldman@542: sla@5237: if (!sender_blob->is_nmethod()) { sla@5237: return false; sla@5237: } sgoldman@542: sgoldman@542: // Could put some more validation for the potential non-interpreted sender sgoldman@542: // frame we'd create by calling sender if I could think of any. Wait for next crash in forte... sgoldman@542: sgoldman@542: // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb sgoldman@542: sgoldman@542: // We've validated the potential sender that would be created duke@435: return true; duke@435: } sgoldman@542: sgoldman@542: // Must be native-compiled frame. Since sender will try and use fp to find sgoldman@542: // linkages it must be safe sgoldman@542: sgoldman@542: if (!fp_safe) { sgoldman@542: return false; duke@435: } sgoldman@542: sgoldman@542: // Will the pc we fetch be non-zero (which we'll find at the oldest frame) sgoldman@542: sgoldman@542: if ( (address) this->fp()[return_addr_offset] == NULL) return false; sgoldman@542: sgoldman@542: sgoldman@542: // could try and do some more potential verification of native frame if we could think of some... sgoldman@542: sgoldman@542: return true; sgoldman@542: duke@435: } duke@435: duke@435: duke@435: void frame::patch_pc(Thread* thread, address pc) { twisti@3196: address* pc_addr = &(((address*) sp())[-1]); duke@435: if (TracePcPatching) { twisti@3252: tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]", twisti@3196: pc_addr, *pc_addr, pc); duke@435: } twisti@3252: // Either the return address is the original one or we are going to twisti@3252: // patch in the same address that's already there. twisti@3252: assert(_pc == *pc_addr || pc == *pc_addr, "must be"); twisti@3196: *pc_addr = pc; duke@435: _cb = CodeCache::find_blob(pc); twisti@1639: address original_pc = nmethod::get_deopt_original_pc(this); twisti@1639: if (original_pc != NULL) { twisti@1639: assert(original_pc == _pc, "expected original PC to be stored before patching"); duke@435: _deopt_state = is_deoptimized; duke@435: // leave _pc as is duke@435: } else { duke@435: _deopt_state = not_deoptimized; duke@435: _pc = pc; duke@435: } duke@435: } duke@435: duke@435: bool frame::is_interpreted_frame() const { duke@435: return Interpreter::contains(pc()); duke@435: } duke@435: cfang@1228: int frame::frame_size(RegisterMap* map) const { cfang@1228: frame sender = this->sender(map); duke@435: return sender.sp() - sp(); duke@435: } duke@435: duke@435: intptr_t* frame::entry_frame_argument_at(int offset) const { duke@435: // convert offset to index to deal with tsi duke@435: int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); duke@435: // Entry frame's arguments are always in relation to unextended_sp() duke@435: return &unextended_sp()[index]; duke@435: } duke@435: duke@435: // sender_sp duke@435: #ifdef CC_INTERP duke@435: intptr_t* frame::interpreter_frame_sender_sp() const { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: // QQQ why does this specialize method exist if frame::sender_sp() does same thing? duke@435: // seems odd and if we always know interpreted vs. non then sender_sp() is really duke@435: // doing too much work. duke@435: return get_interpreterState()->sender_sp(); duke@435: } duke@435: duke@435: // monitor elements duke@435: duke@435: BasicObjectLock* frame::interpreter_frame_monitor_begin() const { duke@435: return get_interpreterState()->monitor_base(); duke@435: } duke@435: duke@435: BasicObjectLock* frame::interpreter_frame_monitor_end() const { duke@435: return (BasicObjectLock*) get_interpreterState()->stack_base(); duke@435: } duke@435: duke@435: #else // CC_INTERP duke@435: duke@435: intptr_t* frame::interpreter_frame_sender_sp() const { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: return (intptr_t*) at(interpreter_frame_sender_sp_offset); duke@435: } duke@435: duke@435: void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp); duke@435: } duke@435: duke@435: duke@435: // monitor elements duke@435: duke@435: BasicObjectLock* frame::interpreter_frame_monitor_begin() const { duke@435: return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset); duke@435: } duke@435: duke@435: BasicObjectLock* frame::interpreter_frame_monitor_end() const { duke@435: BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset); duke@435: // make sure the pointer points inside the frame johnc@1843: assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer"); johnc@1843: assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer"); duke@435: return result; duke@435: } duke@435: duke@435: void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { duke@435: *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value; duke@435: } duke@435: duke@435: // Used by template based interpreter deoptimization duke@435: void frame::interpreter_frame_set_last_sp(intptr_t* sp) { duke@435: *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp; duke@435: } duke@435: #endif // CC_INTERP duke@435: duke@435: frame frame::sender_for_entry_frame(RegisterMap* map) const { duke@435: assert(map != NULL, "map must be set"); duke@435: // Java frame called from C; skip all C frames and return top C duke@435: // frame of that chunk as the sender duke@435: JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); duke@435: assert(!entry_frame_is_first(), "next Java fp must be non zero"); duke@435: assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); kevinw@8877: // Since we are walking the stack now this nested anchor is obviously walkable kevinw@8877: // even if it wasn't when it was stacked. kevinw@8877: if (!jfa->walkable()) { kevinw@8877: // Capture _last_Java_pc (if needed) and mark anchor walkable. kevinw@8877: jfa->capture_last_Java_pc(); kevinw@8877: } duke@435: map->clear(); duke@435: assert(map->include_argument_oops(), "should be set by clear"); kevinw@8877: assert(jfa->last_Java_pc() != NULL, "not walkable"); kevinw@8877: frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); duke@435: return fr; duke@435: } duke@435: twisti@1639: //------------------------------------------------------------------------------ twisti@1639: // frame::verify_deopt_original_pc twisti@1639: // twisti@1639: // Verifies the calculated original PC of a deoptimization PC for the zmajo@7854: // given unextended SP. jprovino@4721: #ifdef ASSERT zmajo@7854: void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp) { twisti@1639: frame fr; twisti@1639: twisti@1639: // This is ugly but it's better than to change {get,set}_original_pc twisti@1639: // to take an SP value as argument. And it's only a debugging twisti@1639: // method anyway. twisti@1639: fr._unextended_sp = unextended_sp; twisti@1639: twisti@1639: address original_pc = nm->get_original_pc(&fr); twisti@2103: assert(nm->insts_contains(original_pc), "original PC must be in nmethod"); twisti@1639: } twisti@1639: #endif twisti@1639: never@2895: //------------------------------------------------------------------------------ never@2895: // frame::adjust_unextended_sp never@2895: void frame::adjust_unextended_sp() { zmajo@7854: // On x86, sites calling method handle intrinsics and lambda forms are treated zmajo@7854: // as any other call site. Therefore, no special action is needed when we are zmajo@7854: // returning to any of these call sites. never@2895: never@2895: nmethod* sender_nm = (_cb == NULL) ? NULL : _cb->as_nmethod_or_null(); never@2895: if (sender_nm != NULL) { zmajo@7854: // If the sender PC is a deoptimization point, get the original PC. zmajo@7854: if (sender_nm->is_deopt_entry(_pc) || zmajo@7854: sender_nm->is_deopt_mh_entry(_pc)) { never@2895: DEBUG_ONLY(verify_deopt_original_pc(sender_nm, _unextended_sp)); never@2895: } never@2895: } never@2895: } never@2895: never@2895: //------------------------------------------------------------------------------ never@2895: // frame::update_map_with_saved_link never@2895: void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) { never@2895: // The interpreter and compiler(s) always save EBP/RBP in a known never@2895: // location on entry. We must record where that location is never@2895: // so this if EBP/RBP was live on callout from c2 we can find never@2895: // the saved copy no matter what it called. never@2895: never@2895: // Since the interpreter always saves EBP/RBP if we record where it is then never@2895: // we don't have to always save EBP/RBP on entry and exit to c2 compiled never@2895: // code, on entry will be enough. never@2895: map->set_location(rbp->as_VMReg(), (address) link_addr); never@2895: #ifdef AMD64 never@2895: // this is weird "H" ought to be at a higher address however the never@2895: // oopMaps seems to have the "H" regs at the same address and the never@2895: // vanilla register. never@2895: // XXXX make this go away never@2895: if (true) { never@2895: map->set_location(rbp->as_VMReg()->next(), (address) link_addr); never@2895: } never@2895: #endif // AMD64 never@2895: } never@2895: twisti@1639: twisti@1639: //------------------------------------------------------------------------------ twisti@1639: // frame::sender_for_interpreter_frame duke@435: frame frame::sender_for_interpreter_frame(RegisterMap* map) const { twisti@1639: // SP is the raw SP from the sender after adapter or interpreter twisti@1639: // extension. twisti@1639: intptr_t* sender_sp = this->sender_sp(); duke@435: duke@435: // This is the sp before any possible extension (adapter/locals). duke@435: intptr_t* unextended_sp = interpreter_frame_sender_sp(); duke@435: duke@435: #ifdef COMPILER2 duke@435: if (map->update_map()) { never@2895: update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset)); duke@435: } twisti@1639: #endif // COMPILER2 twisti@1639: never@2895: return frame(sender_sp, unextended_sp, link(), sender_pc()); duke@435: } duke@435: duke@435: twisti@1639: //------------------------------------------------------------------------------ twisti@1639: // frame::sender_for_compiled_frame duke@435: frame frame::sender_for_compiled_frame(RegisterMap* map) const { duke@435: assert(map != NULL, "map must be set"); duke@435: duke@435: // frame owned by optimizing compiler duke@435: assert(_cb->frame_size() >= 0, "must have non-zero frame size"); twisti@1639: intptr_t* sender_sp = unextended_sp() + _cb->frame_size(); twisti@1639: intptr_t* unextended_sp = sender_sp; duke@435: duke@435: // On Intel the return_address is always the word on the stack duke@435: address sender_pc = (address) *(sender_sp-1); duke@435: twisti@1639: // This is the saved value of EBP which may or may not really be an FP. twisti@1639: // It is only an FP if the sender is an interpreter frame (or C1?). never@2895: intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset); twisti@1570: duke@435: if (map->update_map()) { duke@435: // Tell GC to use argument oopmaps for some runtime stubs that need it. duke@435: // For C1, the runtime stub might not have oop maps, so set this flag duke@435: // outside of update_register_map. duke@435: map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); duke@435: if (_cb->oop_maps() != NULL) { duke@435: OopMapSet::update_register_map(this, map); duke@435: } never@2895: twisti@1639: // Since the prolog does the save and restore of EBP there is no oopmap duke@435: // for it so we must fill in its location as if there was an oopmap entry duke@435: // since if our caller was compiled code there could be live jvm state in it. never@2895: update_map_with_saved_link(map, saved_fp_addr); duke@435: } duke@435: duke@435: assert(sender_sp != sp(), "must have changed"); never@2895: return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc); duke@435: } duke@435: twisti@1639: twisti@1639: //------------------------------------------------------------------------------ twisti@1639: // frame::sender duke@435: frame frame::sender(RegisterMap* map) const { duke@435: // Default is we done have to follow them. The sender_for_xxx will duke@435: // update it accordingly duke@435: map->set_include_argument_oops(false); duke@435: duke@435: if (is_entry_frame()) return sender_for_entry_frame(map); duke@435: if (is_interpreted_frame()) return sender_for_interpreter_frame(map); duke@435: assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); duke@435: duke@435: if (_cb != NULL) { duke@435: return sender_for_compiled_frame(map); duke@435: } duke@435: // Must be native-compiled frame, i.e. the marshaling code for native duke@435: // methods that exists in the core system. duke@435: return frame(sender_sp(), link(), sender_pc()); duke@435: } duke@435: duke@435: duke@435: bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) { duke@435: assert(is_interpreted_frame(), "must be interpreter frame"); coleenp@4037: Method* method = interpreter_frame_method(); duke@435: // When unpacking an optimized frame the frame pointer is duke@435: // adjusted with: duke@435: int diff = (method->max_locals() - method->size_of_parameters()) * twisti@1861: Interpreter::stackElementWords; duke@435: return _fp == (fp - diff); duke@435: } duke@435: duke@435: void frame::pd_gc_epilog() { duke@435: // nothing done here now duke@435: } duke@435: sgoldman@542: bool frame::is_interpreted_frame_valid(JavaThread* thread) const { duke@435: // QQQ duke@435: #ifdef CC_INTERP duke@435: #else duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: // These are reasonable sanity checks duke@435: if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) { duke@435: return false; duke@435: } duke@435: if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) { duke@435: return false; duke@435: } duke@435: if (fp() + interpreter_frame_initial_sp_offset < sp()) { duke@435: return false; duke@435: } duke@435: // These are hacks to keep us out of trouble. duke@435: // The problem with these is that they mask other problems duke@435: if (fp() <= sp()) { // this attempts to deal with unsigned comparison above duke@435: return false; duke@435: } sgoldman@542: sgoldman@542: // do some validation of frame elements sgoldman@542: sgoldman@542: // first the method sgoldman@542: coleenp@4037: Method* m = *interpreter_frame_method_addr(); sgoldman@542: sgoldman@542: // validate the method we'd find in this potential sender coleenp@4295: if (!m->is_valid_method()) return false; sgoldman@542: sgoldman@542: // stack frames shouldn't be much larger than max_stack elements sgoldman@542: twisti@1861: if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { duke@435: return false; duke@435: } sgoldman@542: sgoldman@542: // validate bci/bcx sgoldman@542: sgoldman@542: intptr_t bcx = interpreter_frame_bcx(); sgoldman@542: if (m->validate_bci_from_bcx(bcx) < 0) { sgoldman@542: return false; sgoldman@542: } sgoldman@542: coleenp@4037: // validate ConstantPoolCache* coleenp@4037: ConstantPoolCache* cp = *interpreter_frame_cache_addr(); coleenp@5307: if (cp == NULL || !cp->is_metaspace_object()) return false; sgoldman@542: sgoldman@542: // validate locals sgoldman@542: sgoldman@542: address locals = (address) *interpreter_frame_locals_addr(); sgoldman@542: sgoldman@542: if (locals > thread->stack_base() || locals < (address) fp()) return false; sgoldman@542: sgoldman@542: // We'd have to be pretty unlucky to be mislead at this point sgoldman@542: duke@435: #endif // CC_INTERP duke@435: return true; duke@435: } duke@435: duke@435: BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) { duke@435: #ifdef CC_INTERP bobv@2036: // Needed for JVMTI. The result should always be in the bobv@2036: // interpreterState object duke@435: interpreterState istate = get_interpreterState(); duke@435: #endif // CC_INTERP duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); coleenp@4037: Method* method = interpreter_frame_method(); duke@435: BasicType type = method->result_type(); duke@435: duke@435: intptr_t* tos_addr; duke@435: if (method->is_native()) { duke@435: // Prior to calling into the runtime to report the method_exit the possible duke@435: // return value is pushed to the native stack. If the result is a jfloat/jdouble duke@435: // then ST0 is saved before EAX/EDX. See the note in generate_native_result duke@435: tos_addr = (intptr_t*)sp(); duke@435: if (type == T_FLOAT || type == T_DOUBLE) { duke@435: // QQQ seems like this code is equivalent on the two platforms duke@435: #ifdef AMD64 duke@435: // This is times two because we do a push(ltos) after pushing XMM0 duke@435: // and that takes two interpreter stack slots. twisti@1861: tos_addr += 2 * Interpreter::stackElementWords; duke@435: #else duke@435: tos_addr += 2; duke@435: #endif // AMD64 duke@435: } duke@435: } else { duke@435: tos_addr = (intptr_t*)interpreter_frame_tos_address(); duke@435: } duke@435: duke@435: switch (type) { duke@435: case T_OBJECT : duke@435: case T_ARRAY : { duke@435: oop obj; duke@435: if (method->is_native()) { duke@435: #ifdef CC_INTERP duke@435: obj = istate->_oop_temp; duke@435: #else hseigel@5784: obj = cast_to_oop(at(interpreter_frame_oop_temp_offset)); duke@435: #endif // CC_INTERP duke@435: } else { duke@435: oop* obj_p = (oop*)tos_addr; duke@435: obj = (obj_p == NULL) ? (oop)NULL : *obj_p; duke@435: } duke@435: assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check"); duke@435: *oop_result = obj; duke@435: break; duke@435: } duke@435: case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break; duke@435: case T_BYTE : value_result->b = *(jbyte*)tos_addr; break; duke@435: case T_CHAR : value_result->c = *(jchar*)tos_addr; break; duke@435: case T_SHORT : value_result->s = *(jshort*)tos_addr; break; duke@435: case T_INT : value_result->i = *(jint*)tos_addr; break; duke@435: case T_LONG : value_result->j = *(jlong*)tos_addr; break; duke@435: case T_FLOAT : { duke@435: #ifdef AMD64 duke@435: value_result->f = *(jfloat*)tos_addr; duke@435: #else duke@435: if (method->is_native()) { duke@435: jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat duke@435: value_result->f = (jfloat)d; duke@435: } else { duke@435: value_result->f = *(jfloat*)tos_addr; duke@435: } duke@435: #endif // AMD64 duke@435: break; duke@435: } duke@435: case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break; duke@435: case T_VOID : /* Nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: duke@435: return type; duke@435: } duke@435: duke@435: duke@435: intptr_t* frame::interpreter_frame_tos_at(jint offset) const { duke@435: int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); duke@435: return &interpreter_frame_tos_address()[index]; duke@435: } never@2868: bdelsart@3451: #ifndef PRODUCT never@2868: never@2868: #define DESCRIBE_FP_OFFSET(name) \ never@2897: values.describe(frame_no, fp() + frame::name##_offset, #name) never@2868: never@2868: void frame::describe_pd(FrameValues& values, int frame_no) { twisti@3969: if (is_interpreted_frame()) { never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_last_sp); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_method); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_mdx); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_cache); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_locals); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_bcx); never@2868: DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp); never@2868: } never@2868: } never@2868: #endif bdelsart@3130: bdelsart@3130: intptr_t *frame::initial_deoptimization_info() { bdelsart@3130: // used to reset the saved FP bdelsart@3130: return fp(); bdelsart@3130: } bdelsart@3433: bdelsart@3433: intptr_t* frame::real_fp() const { bdelsart@3433: if (_cb != NULL) { bdelsart@3433: // use the frame size if valid bdelsart@3433: int size = _cb->frame_size(); twisti@3969: if (size > 0) { bdelsart@3433: return unextended_sp() + size; bdelsart@3433: } bdelsart@3433: } bdelsart@3433: // else rely on fp() bdelsart@3433: assert(! is_compiled_frame(), "unknown compiled frame size"); bdelsart@3433: return fp(); bdelsart@3433: } simonis@7553: simonis@7553: #ifndef PRODUCT simonis@7553: // This is a generic constructor which is only used by pns() in debug.cpp. simonis@7553: frame::frame(void* sp, void* fp, void* pc) { simonis@7553: init((intptr_t*)sp, (intptr_t*)fp, (address)pc); simonis@7553: } simonis@7553: #endif kevinw@8877: kevinw@8877: void JavaFrameAnchor::make_walkable(JavaThread* thread) { kevinw@8877: // last frame set? kevinw@8877: if (last_Java_sp() == NULL) return; kevinw@8877: // already walkable? kevinw@8877: if (walkable()) return; kevinw@8877: assert(Thread::current() == (Thread*)thread, "not current thread"); kevinw@8877: assert(last_Java_sp() != NULL, "not called from Java code?"); kevinw@8877: assert(last_Java_pc() == NULL, "already walkable"); kevinw@8877: capture_last_Java_pc(); kevinw@8877: assert(walkable(), "something went wrong"); kevinw@8877: } kevinw@8877: kevinw@8877: void JavaFrameAnchor::capture_last_Java_pc() { kevinw@8877: assert(_last_Java_sp != NULL, "no last frame set"); kevinw@8877: assert(_last_Java_pc == NULL, "already walkable"); kevinw@8877: _last_Java_pc = (address)_last_Java_sp[-1]; kevinw@8877: }