duke@435: /* hseigel@5784: * Copyright (c) 1997, 2013, 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" kvn@5543: #include "compiler/abstractCompiler.hpp" twisti@4318: #include "compiler/disassembler.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/oopMapCache.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/markOop.hpp" coleenp@4037: #include "oops/methodData.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/oop.inline2.hpp" never@2895: #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" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/signature.hpp" stefank@2314: #include "runtime/stubCodeGenerator.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" zgu@2364: #include "utilities/decoder.hpp" zgu@2364: stefank@2314: #ifdef TARGET_ARCH_x86 stefank@2314: # include "nativeInst_x86.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_sparc stefank@2314: # include "nativeInst_sparc.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_zero stefank@2314: # include "nativeInst_zero.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_ARCH_arm bobv@2508: # include "nativeInst_arm.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_ARCH_ppc bobv@2508: # include "nativeInst_ppc.hpp" bobv@2508: #endif duke@435: duke@435: RegisterMap::RegisterMap(JavaThread *thread, bool update_map) { duke@435: _thread = thread; duke@435: _update_map = update_map; duke@435: clear(); duke@435: debug_only(_update_for_id = NULL;) duke@435: #ifndef PRODUCT duke@435: for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL; duke@435: #endif /* PRODUCT */ duke@435: } duke@435: duke@435: RegisterMap::RegisterMap(const RegisterMap* map) { duke@435: assert(map != this, "bad initialization parameter"); duke@435: assert(map != NULL, "RegisterMap must be present"); duke@435: _thread = map->thread(); duke@435: _update_map = map->update_map(); duke@435: _include_argument_oops = map->include_argument_oops(); duke@435: debug_only(_update_for_id = map->_update_for_id;) duke@435: pd_initialize_from(map); duke@435: if (update_map()) { duke@435: for(int i = 0; i < location_valid_size; i++) { duke@435: LocationValidType bits = !update_map() ? 0 : map->_location_valid[i]; duke@435: _location_valid[i] = bits; duke@435: // for whichever bits are set, pull in the corresponding map->_location duke@435: int j = i*location_valid_type_size; duke@435: while (bits != 0) { duke@435: if ((bits & 1) != 0) { duke@435: assert(0 <= j && j < reg_count, "range check"); duke@435: _location[j] = map->_location[j]; duke@435: } duke@435: bits >>= 1; duke@435: j += 1; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void RegisterMap::clear() { duke@435: set_include_argument_oops(true); duke@435: if (_update_map) { duke@435: for(int i = 0; i < location_valid_size; i++) { duke@435: _location_valid[i] = 0; duke@435: } duke@435: pd_clear(); duke@435: } else { duke@435: pd_initialize(); duke@435: } duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: void RegisterMap::print_on(outputStream* st) const { duke@435: st->print_cr("Register map"); duke@435: for(int i = 0; i < reg_count; i++) { duke@435: duke@435: VMReg r = VMRegImpl::as_VMReg(i); duke@435: intptr_t* src = (intptr_t*) location(r); duke@435: if (src != NULL) { duke@435: never@852: r->print_on(st); never@852: st->print(" [" INTPTR_FORMAT "] = ", src); duke@435: if (((uintptr_t)src & (sizeof(*src)-1)) != 0) { never@852: st->print_cr(""); duke@435: } else { never@852: st->print_cr(INTPTR_FORMAT, *src); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void RegisterMap::print() const { duke@435: print_on(tty); duke@435: } duke@435: duke@435: #endif duke@435: // This returns the pc that if you were in the debugger you'd see. Not duke@435: // the idealized value in the frame object. This undoes the magic conversion duke@435: // that happens for deoptimized frames. In addition it makes the value the duke@435: // hardware would want to see in the native frame. The only user (at this point) duke@435: // is deoptimization. It likely no one else should ever use it. duke@435: duke@435: address frame::raw_pc() const { duke@435: if (is_deoptimized_frame()) { twisti@1639: nmethod* nm = cb()->as_nmethod_or_null(); twisti@1639: if (nm->is_method_handle_return(pc())) twisti@1639: return nm->deopt_mh_handler_begin() - pc_return_offset; twisti@1639: else twisti@1639: return nm->deopt_handler_begin() - pc_return_offset; duke@435: } else { duke@435: return (pc() - pc_return_offset); duke@435: } duke@435: } duke@435: duke@435: // Change the pc in a frame object. This does not change the actual pc in duke@435: // actual frame. To do that use patch_pc. duke@435: // duke@435: void frame::set_pc(address newpc ) { duke@435: #ifdef ASSERT duke@435: if (_cb != NULL && _cb->is_nmethod()) { duke@435: assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation"); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // Unsafe to use the is_deoptimzed tester after changing pc duke@435: _deopt_state = unknown; duke@435: _pc = newpc; duke@435: _cb = CodeCache::find_blob_unsafe(_pc); duke@435: duke@435: } duke@435: duke@435: // type testers twisti@3969: bool frame::is_ignored_frame() const { twisti@3969: return false; // FIXME: some LambdaForm frames should be ignored never@2895: } duke@435: bool frame::is_deoptimized_frame() const { duke@435: assert(_deopt_state != unknown, "not answerable"); duke@435: return _deopt_state == is_deoptimized; duke@435: } duke@435: duke@435: bool frame::is_native_frame() const { duke@435: return (_cb != NULL && duke@435: _cb->is_nmethod() && duke@435: ((nmethod*)_cb)->is_native_method()); duke@435: } duke@435: duke@435: bool frame::is_java_frame() const { duke@435: if (is_interpreted_frame()) return true; duke@435: if (is_compiled_frame()) return true; duke@435: return false; duke@435: } duke@435: duke@435: duke@435: bool frame::is_compiled_frame() const { duke@435: if (_cb != NULL && duke@435: _cb->is_nmethod() && duke@435: ((nmethod*)_cb)->is_java_method()) { duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: duke@435: bool frame::is_runtime_frame() const { duke@435: return (_cb != NULL && _cb->is_runtime_stub()); duke@435: } duke@435: duke@435: bool frame::is_safepoint_blob_frame() const { duke@435: return (_cb != NULL && _cb->is_safepoint_stub()); duke@435: } duke@435: duke@435: // testers duke@435: duke@435: bool frame::is_first_java_frame() const { duke@435: RegisterMap map(JavaThread::current(), false); // No update duke@435: frame s; duke@435: for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)); duke@435: return s.is_first_frame(); duke@435: } duke@435: duke@435: duke@435: bool frame::entry_frame_is_first() const { rbackman@5419: return entry_frame_call_wrapper()->is_first_frame(); duke@435: } duke@435: rbackman@5419: JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const { rbackman@5419: JavaCallWrapper** jcw = entry_frame_call_wrapper_addr(); rbackman@5419: address addr = (address) jcw; rbackman@5419: rbackman@5419: // addr must be within the usable part of the stack rbackman@5419: if (thread->is_in_usable_stack(addr)) { rbackman@5419: return *jcw; rbackman@5419: } rbackman@5419: rbackman@5419: return NULL; rbackman@5419: } duke@435: duke@435: bool frame::should_be_deoptimized() const { duke@435: if (_deopt_state == is_deoptimized || duke@435: !is_compiled_frame() ) return false; duke@435: assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod"); duke@435: nmethod* nm = (nmethod *)_cb; duke@435: if (TraceDependencies) { duke@435: tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false"); duke@435: nm->print_value_on(tty); duke@435: tty->cr(); duke@435: } duke@435: duke@435: if( !nm->is_marked_for_deoptimization() ) duke@435: return false; duke@435: duke@435: // If at the return point, then the frame has already been popped, and duke@435: // only the return needs to be executed. Don't deoptimize here. duke@435: return !nm->is_at_poll_return(pc()); duke@435: } duke@435: duke@435: bool frame::can_be_deoptimized() const { duke@435: if (!is_compiled_frame()) return false; duke@435: nmethod* nm = (nmethod*)_cb; duke@435: duke@435: if( !nm->can_be_deoptimized() ) duke@435: return false; duke@435: duke@435: return !nm->is_at_poll_return(pc()); duke@435: } duke@435: never@2082: void frame::deoptimize(JavaThread* thread) { never@2082: // Schedule deoptimization of an nmethod activation with this frame. duke@435: assert(_cb != NULL && _cb->is_nmethod(), "must be"); duke@435: nmethod* nm = (nmethod*)_cb; duke@435: duke@435: // This is a fix for register window patching race never@2082: if (NeedsDeoptSuspend && Thread::current() != thread) { never@2082: assert(SafepointSynchronize::is_at_safepoint(), never@2082: "patching other threads for deopt may only occur at a safepoint"); duke@435: duke@435: // It is possible especially with DeoptimizeALot/DeoptimizeRandom that duke@435: // we could see the frame again and ask for it to be deoptimized since duke@435: // it might move for a long time. That is harmless and we just ignore it. duke@435: if (id() == thread->must_deopt_id()) { duke@435: assert(thread->is_deopt_suspend(), "lost suspension"); duke@435: return; duke@435: } duke@435: duke@435: // We are at a safepoint so the target thread can only be duke@435: // in 4 states: duke@435: // blocked - no problem duke@435: // blocked_trans - no problem (i.e. could have woken up from blocked duke@435: // during a safepoint). duke@435: // native - register window pc patching race duke@435: // native_trans - momentary state duke@435: // duke@435: // We could just wait out a thread in native_trans to block. duke@435: // Then we'd have all the issues that the safepoint code has as to duke@435: // whether to spin or block. It isn't worth it. Just treat it like duke@435: // native and be done with it. duke@435: // never@2082: // Examine the state of the thread at the start of safepoint since never@2082: // threads that were in native at the start of the safepoint could never@2082: // come to a halt during the safepoint, changing the current value never@2082: // of the safepoint_state. never@2082: JavaThreadState state = thread->safepoint_state()->orig_thread_state(); duke@435: if (state == _thread_in_native || state == _thread_in_native_trans) { duke@435: // Since we are at a safepoint the target thread will stop itself duke@435: // before it can return to java as long as we remain at the safepoint. duke@435: // Therefore we can put an additional request for the thread to stop duke@435: // no matter what no (like a suspend). This will cause the thread duke@435: // to notice it needs to do the deopt on its own once it leaves native. duke@435: // duke@435: // The only reason we must do this is because on machine with register duke@435: // windows we have a race with patching the return address and the duke@435: // window coming live as the thread returns to the Java code (but still duke@435: // in native mode) and then blocks. It is only this top most frame duke@435: // that is at risk. So in truth we could add an additional check to duke@435: // see if this frame is one that is at risk. duke@435: RegisterMap map(thread, false); duke@435: frame at_risk = thread->last_frame().sender(&map); duke@435: if (id() == at_risk.id()) { duke@435: thread->set_must_deopt_id(id()); duke@435: thread->set_deopt_suspend(); duke@435: return; duke@435: } duke@435: } duke@435: } // NeedsDeoptSuspend duke@435: duke@435: twisti@1639: // If the call site is a MethodHandle call site use the MH deopt twisti@1639: // handler. twisti@1639: address deopt = nm->is_method_handle_return(pc()) ? twisti@1639: nm->deopt_mh_handler_begin() : twisti@1639: nm->deopt_handler_begin(); twisti@1639: duke@435: // Save the original pc before we patch in the new one duke@435: nm->set_original_pc(this, pc()); duke@435: patch_pc(thread, deopt); twisti@1639: duke@435: #ifdef ASSERT duke@435: { duke@435: RegisterMap map(thread, false); duke@435: frame check = thread->last_frame(); duke@435: while (id() != check.id()) { duke@435: check = check.sender(&map); duke@435: } duke@435: assert(check.is_deoptimized_frame(), "missed deopt"); duke@435: } duke@435: #endif // ASSERT duke@435: } duke@435: duke@435: frame frame::java_sender() const { duke@435: RegisterMap map(JavaThread::current(), false); duke@435: frame s; duke@435: for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ; duke@435: guarantee(s.is_java_frame(), "tried to get caller of first java frame"); duke@435: return s; duke@435: } duke@435: duke@435: frame frame::real_sender(RegisterMap* map) const { duke@435: frame result = sender(map); never@2895: while (result.is_runtime_frame() || twisti@3969: result.is_ignored_frame()) { duke@435: result = result.sender(map); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: // Note: called by profiler - NOT for current thread duke@435: frame frame::profile_find_Java_sender_frame(JavaThread *thread) { duke@435: // If we don't recognize this frame, walk back up the stack until we do duke@435: RegisterMap map(thread, false); duke@435: frame first_java_frame = frame(); duke@435: duke@435: // Find the first Java frame on the stack starting with input frame duke@435: if (is_java_frame()) { duke@435: // top frame is compiled frame or deoptimized frame duke@435: first_java_frame = *this; duke@435: } else if (safe_for_sender(thread)) { duke@435: for (frame sender_frame = sender(&map); duke@435: sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame(); duke@435: sender_frame = sender_frame.sender(&map)) { duke@435: if (sender_frame.is_java_frame()) { duke@435: first_java_frame = sender_frame; duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: return first_java_frame; duke@435: } duke@435: duke@435: // Interpreter frames duke@435: duke@435: duke@435: void frame::interpreter_frame_set_locals(intptr_t* locs) { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: *interpreter_frame_locals_addr() = locs; duke@435: } duke@435: coleenp@4037: Method* frame::interpreter_frame_method() const { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); coleenp@4037: Method* m = *interpreter_frame_method_addr(); coleenp@4037: assert(m->is_method(), "not a Method*"); duke@435: return m; duke@435: } duke@435: coleenp@4037: void frame::interpreter_frame_set_method(Method* method) { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: *interpreter_frame_method_addr() = method; duke@435: } duke@435: duke@435: void frame::interpreter_frame_set_bcx(intptr_t bcx) { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: if (ProfileInterpreter) { duke@435: bool formerly_bci = is_bci(interpreter_frame_bcx()); duke@435: bool is_now_bci = is_bci(bcx); duke@435: *interpreter_frame_bcx_addr() = bcx; duke@435: duke@435: intptr_t mdx = interpreter_frame_mdx(); duke@435: duke@435: if (mdx != 0) { duke@435: if (formerly_bci) { duke@435: if (!is_now_bci) { duke@435: // The bcx was just converted from bci to bcp. duke@435: // Convert the mdx in parallel. coleenp@4037: MethodData* mdo = interpreter_frame_method()->method_data(); duke@435: assert(mdo != NULL, ""); duke@435: int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one. duke@435: address mdp = mdo->di_to_dp(mdi); duke@435: interpreter_frame_set_mdx((intptr_t)mdp); duke@435: } duke@435: } else { duke@435: if (is_now_bci) { duke@435: // The bcx was just converted from bcp to bci. duke@435: // Convert the mdx in parallel. coleenp@4037: MethodData* mdo = interpreter_frame_method()->method_data(); duke@435: assert(mdo != NULL, ""); duke@435: int mdi = mdo->dp_to_di((address)mdx); duke@435: interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0. duke@435: } duke@435: } duke@435: } duke@435: } else { duke@435: *interpreter_frame_bcx_addr() = bcx; duke@435: } duke@435: } duke@435: duke@435: jint frame::interpreter_frame_bci() const { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: intptr_t bcx = interpreter_frame_bcx(); duke@435: return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx); duke@435: } duke@435: duke@435: void frame::interpreter_frame_set_bci(jint bci) { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC"); duke@435: interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci)); duke@435: } duke@435: duke@435: address frame::interpreter_frame_bcp() const { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: intptr_t bcx = interpreter_frame_bcx(); duke@435: return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx; duke@435: } duke@435: duke@435: void frame::interpreter_frame_set_bcp(address bcp) { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC"); duke@435: interpreter_frame_set_bcx((intptr_t)bcp); duke@435: } duke@435: duke@435: void frame::interpreter_frame_set_mdx(intptr_t mdx) { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: *interpreter_frame_mdx_addr() = mdx; duke@435: } duke@435: duke@435: address frame::interpreter_frame_mdp() const { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: intptr_t bcx = interpreter_frame_bcx(); duke@435: intptr_t mdx = interpreter_frame_mdx(); duke@435: duke@435: assert(!is_bci(bcx), "should not access mdp during GC"); duke@435: return (address)mdx; duke@435: } duke@435: duke@435: void frame::interpreter_frame_set_mdp(address mdp) { duke@435: assert(is_interpreted_frame(), "interpreted frame expected"); duke@435: if (mdp == NULL) { duke@435: // Always allow the mdp to be cleared. duke@435: interpreter_frame_set_mdx((intptr_t)mdp); duke@435: } duke@435: intptr_t bcx = interpreter_frame_bcx(); duke@435: assert(!is_bci(bcx), "should not set mdp during GC"); duke@435: interpreter_frame_set_mdx((intptr_t)mdp); duke@435: } duke@435: duke@435: BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: #ifdef ASSERT duke@435: interpreter_frame_verify_monitor(current); duke@435: #endif duke@435: BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size()); duke@435: return next; duke@435: } duke@435: duke@435: BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: #ifdef ASSERT duke@435: // // This verification needs to be checked before being enabled duke@435: // interpreter_frame_verify_monitor(current); duke@435: #endif duke@435: BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size()); duke@435: return previous; duke@435: } duke@435: duke@435: // Interpreter locals and expression stack locations. duke@435: duke@435: intptr_t* frame::interpreter_frame_local_at(int index) const { duke@435: const int n = Interpreter::local_offset_in_bytes(index)/wordSize; duke@435: return &((*interpreter_frame_locals_addr())[n]); duke@435: } duke@435: duke@435: intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const { duke@435: const int i = offset * interpreter_frame_expression_stack_direction(); twisti@1861: const int n = i * Interpreter::stackElementWords; duke@435: return &(interpreter_frame_expression_stack()[n]); duke@435: } duke@435: duke@435: jint frame::interpreter_frame_expression_stack_size() const { duke@435: // Number of elements on the interpreter expression stack duke@435: // Callers should span by stackElementWords twisti@1861: int element_size = Interpreter::stackElementWords; duke@435: if (frame::interpreter_frame_expression_stack_direction() < 0) { duke@435: return (interpreter_frame_expression_stack() - duke@435: interpreter_frame_tos_address() + 1)/element_size; duke@435: } else { duke@435: return (interpreter_frame_tos_address() - duke@435: interpreter_frame_expression_stack() + 1)/element_size; duke@435: } duke@435: } duke@435: duke@435: duke@435: // (frame::interpreter_frame_sender_sp accessor is in frame_.cpp) duke@435: duke@435: const char* frame::print_name() const { duke@435: if (is_native_frame()) return "Native"; duke@435: if (is_interpreted_frame()) return "Interpreted"; duke@435: if (is_compiled_frame()) { duke@435: if (is_deoptimized_frame()) return "Deoptimized"; duke@435: return "Compiled"; duke@435: } duke@435: if (sp() == NULL) return "Empty"; duke@435: return "C"; duke@435: } duke@435: duke@435: void frame::print_value_on(outputStream* st, JavaThread *thread) const { duke@435: NOT_PRODUCT(address begin = pc()-40;) duke@435: NOT_PRODUCT(address end = NULL;) duke@435: duke@435: st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp()); duke@435: if (sp() != NULL) kvn@5543: st->print(", fp=" INTPTR_FORMAT ", real_fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), real_fp(), pc()); duke@435: duke@435: if (StubRoutines::contains(pc())) { duke@435: st->print_cr(")"); duke@435: st->print("("); duke@435: StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); duke@435: st->print("~Stub::%s", desc->name()); duke@435: NOT_PRODUCT(begin = desc->begin(); end = desc->end();) duke@435: } else if (Interpreter::contains(pc())) { duke@435: st->print_cr(")"); duke@435: st->print("("); duke@435: InterpreterCodelet* desc = Interpreter::codelet_containing(pc()); duke@435: if (desc != NULL) { duke@435: st->print("~"); never@3499: desc->print_on(st); duke@435: NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();) duke@435: } else { duke@435: st->print("~interpreter"); duke@435: } duke@435: } duke@435: st->print_cr(")"); duke@435: duke@435: if (_cb != NULL) { duke@435: st->print(" "); duke@435: _cb->print_value_on(st); duke@435: st->cr(); duke@435: #ifndef PRODUCT duke@435: if (end == NULL) { twisti@2103: begin = _cb->code_begin(); twisti@2103: end = _cb->code_end(); duke@435: } duke@435: #endif duke@435: } duke@435: NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);) duke@435: } duke@435: duke@435: duke@435: void frame::print_on(outputStream* st) const { duke@435: print_value_on(st,NULL); duke@435: if (is_interpreted_frame()) { duke@435: interpreter_frame_print_on(st); duke@435: } duke@435: } duke@435: duke@435: duke@435: void frame::interpreter_frame_print_on(outputStream* st) const { duke@435: #ifndef PRODUCT duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: jint i; duke@435: for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) { duke@435: intptr_t x = *interpreter_frame_local_at(i); duke@435: st->print(" - local [" INTPTR_FORMAT "]", x); duke@435: st->fill_to(23); duke@435: st->print_cr("; #%d", i); duke@435: } duke@435: for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) { duke@435: intptr_t x = *interpreter_frame_expression_stack_at(i); duke@435: st->print(" - stack [" INTPTR_FORMAT "]", x); duke@435: st->fill_to(23); duke@435: st->print_cr("; #%d", i); duke@435: } duke@435: // locks for synchronization duke@435: for (BasicObjectLock* current = interpreter_frame_monitor_end(); duke@435: current < interpreter_frame_monitor_begin(); duke@435: current = next_monitor_in_interpreter_frame(current)) { kvn@1690: st->print(" - obj ["); duke@435: current->obj()->print_value_on(st); kvn@1690: st->print_cr("]"); kvn@1690: st->print(" - lock ["); duke@435: current->lock()->print_on(st); kvn@1690: st->print_cr("]"); duke@435: } duke@435: // monitor duke@435: st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin()); duke@435: // bcp duke@435: st->print(" - bcp [" INTPTR_FORMAT "]", interpreter_frame_bcp()); duke@435: st->fill_to(23); duke@435: st->print_cr("; @%d", interpreter_frame_bci()); duke@435: // locals duke@435: st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0)); duke@435: // method duke@435: st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method()); duke@435: st->fill_to(23); duke@435: st->print("; "); duke@435: interpreter_frame_method()->print_name(st); duke@435: st->cr(); duke@435: #endif duke@435: } duke@435: duke@435: // Return whether the frame is in the VM or os indicating a Hotspot problem. duke@435: // Otherwise, it's likely a bug in the native library that the Java code calls, duke@435: // hopefully indicating where to submit bugs. iklam@5667: void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) { duke@435: // C/C++ frame duke@435: bool in_vm = os::address_is_in_vm(pc); duke@435: st->print(in_vm ? "V" : "C"); duke@435: duke@435: int offset; duke@435: bool found; duke@435: duke@435: // libname duke@435: found = os::dll_address_to_library_name(pc, buf, buflen, &offset); duke@435: if (found) { duke@435: // skip directory names duke@435: const char *p1, *p2; duke@435: p1 = buf; duke@435: int len = (int)strlen(os::file_separator()); duke@435: while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len; duke@435: st->print(" [%s+0x%x]", p1, offset); duke@435: } else { duke@435: st->print(" " PTR_FORMAT, pc); duke@435: } duke@435: duke@435: // function name - os::dll_address_to_function_name() may return confusing duke@435: // names if pc is within jvm.dll or libjvm.so, because JVM only has duke@435: // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this duke@435: // only for native libraries. zgu@2364: if (!in_vm || Decoder::can_decode_C_frame_in_vm()) { duke@435: found = os::dll_address_to_function_name(pc, buf, buflen, &offset); duke@435: duke@435: if (found) { duke@435: st->print(" %s+0x%x", buf, offset); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // frame::print_on_error() is called by fatal error handler. Notice that we may duke@435: // crash inside this function if stack frame is corrupted. The fatal error duke@435: // handler can catch and handle the crash. Here we assume the frame is valid. duke@435: // duke@435: // First letter indicates type of the frame: duke@435: // J: Java frame (compiled) duke@435: // j: Java frame (interpreted) duke@435: // V: VM frame (C/C++) duke@435: // v: Other frames running VM generated code (e.g. stubs, adapters, etc.) duke@435: // C: C/C++ frame duke@435: // duke@435: // We don't need detailed frame type as that in frame::print_name(). "C" duke@435: // suggests the problem is in user lib; everything else is likely a VM bug. duke@435: duke@435: void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const { duke@435: if (_cb != NULL) { duke@435: if (Interpreter::contains(pc())) { coleenp@4037: Method* m = this->interpreter_frame_method(); duke@435: if (m != NULL) { duke@435: m->name_and_sig_as_C_string(buf, buflen); duke@435: st->print("j %s", buf); duke@435: st->print("+%d", this->interpreter_frame_bci()); duke@435: } else { duke@435: st->print("j " PTR_FORMAT, pc()); duke@435: } duke@435: } else if (StubRoutines::contains(pc())) { duke@435: StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); duke@435: if (desc != NULL) { duke@435: st->print("v ~StubRoutines::%s", desc->name()); duke@435: } else { duke@435: st->print("v ~StubRoutines::" PTR_FORMAT, pc()); duke@435: } duke@435: } else if (_cb->is_buffer_blob()) { duke@435: st->print("v ~BufferBlob::%s", ((BufferBlob *)_cb)->name()); duke@435: } else if (_cb->is_nmethod()) { kvn@5543: nmethod* nm = (nmethod*)_cb; kvn@5543: Method* m = nm->method(); duke@435: if (m != NULL) { duke@435: m->name_and_sig_as_C_string(buf, buflen); kvn@5543: st->print("J %d%s %s %s (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]", kvn@5543: nm->compile_id(), (nm->is_osr_method() ? "%" : ""), kvn@5543: ((nm->compiler() != NULL) ? nm->compiler()->name() : ""), kvn@5543: buf, m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin()); duke@435: } else { duke@435: st->print("J " PTR_FORMAT, pc()); duke@435: } duke@435: } else if (_cb->is_runtime_stub()) { duke@435: st->print("v ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name()); duke@435: } else if (_cb->is_deoptimization_stub()) { duke@435: st->print("v ~DeoptimizationBlob"); duke@435: } else if (_cb->is_exception_stub()) { duke@435: st->print("v ~ExceptionBlob"); duke@435: } else if (_cb->is_safepoint_stub()) { duke@435: st->print("v ~SafepointBlob"); duke@435: } else { duke@435: st->print("v blob " PTR_FORMAT, pc()); duke@435: } duke@435: } else { duke@435: print_C_frame(st, buf, buflen, pc()); duke@435: } duke@435: } duke@435: duke@435: duke@435: /* duke@435: The interpreter_frame_expression_stack_at method in the case of SPARC needs the duke@435: max_stack value of the method in order to compute the expression stack address. coleenp@4037: It uses the Method* in order to get the max_stack value but during GC this coleenp@4037: Method* value saved on the frame is changed by reverse_and_push and hence cannot duke@435: be used. So we save the max_stack value in the FrameClosure object and pass it duke@435: down to the interpreter_frame_expression_stack_at method duke@435: */ duke@435: class InterpreterFrameClosure : public OffsetClosure { duke@435: private: duke@435: frame* _fr; duke@435: OopClosure* _f; duke@435: int _max_locals; duke@435: int _max_stack; duke@435: duke@435: public: duke@435: InterpreterFrameClosure(frame* fr, int max_locals, int max_stack, duke@435: OopClosure* f) { duke@435: _fr = fr; duke@435: _max_locals = max_locals; duke@435: _max_stack = max_stack; duke@435: _f = f; duke@435: } duke@435: duke@435: void offset_do(int offset) { duke@435: oop* addr; duke@435: if (offset < _max_locals) { duke@435: addr = (oop*) _fr->interpreter_frame_local_at(offset); duke@435: assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame"); duke@435: _f->do_oop(addr); duke@435: } else { duke@435: addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals)); duke@435: // In case of exceptions, the expression stack is invalid and the esp will be reset to express duke@435: // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel). duke@435: bool in_stack; duke@435: if (frame::interpreter_frame_expression_stack_direction() > 0) { duke@435: in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address(); duke@435: } else { duke@435: in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address(); duke@435: } duke@435: if (in_stack) { duke@435: _f->do_oop(addr); duke@435: } duke@435: } duke@435: } duke@435: duke@435: int max_locals() { return _max_locals; } duke@435: frame* fr() { return _fr; } duke@435: }; duke@435: duke@435: duke@435: class InterpretedArgumentOopFinder: public SignatureInfo { duke@435: private: twisti@1573: OopClosure* _f; // Closure to invoke twisti@1573: int _offset; // TOS-relative offset, decremented with each argument twisti@1573: bool _has_receiver; // true if the callee has a receiver duke@435: frame* _fr; duke@435: duke@435: void set(int size, BasicType type) { duke@435: _offset -= size; duke@435: if (type == T_OBJECT || type == T_ARRAY) oop_offset_do(); duke@435: } duke@435: duke@435: void oop_offset_do() { duke@435: oop* addr; duke@435: addr = (oop*)_fr->interpreter_frame_tos_at(_offset); duke@435: _f->do_oop(addr); duke@435: } duke@435: duke@435: public: coleenp@2497: InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) { duke@435: // compute size of arguments twisti@1573: int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0); duke@435: assert(!fr->is_interpreted_frame() || duke@435: args_size <= fr->interpreter_frame_expression_stack_size(), duke@435: "args cannot be on stack anymore"); duke@435: // initialize InterpretedArgumentOopFinder duke@435: _f = f; duke@435: _fr = fr; duke@435: _offset = args_size; duke@435: } duke@435: duke@435: void oops_do() { twisti@1573: if (_has_receiver) { duke@435: --_offset; duke@435: oop_offset_do(); duke@435: } duke@435: iterate_parameters(); duke@435: } duke@435: }; duke@435: duke@435: duke@435: // Entry frame has following form (n arguments) duke@435: // +-----------+ duke@435: // sp -> | last arg | duke@435: // +-----------+ duke@435: // : ::: : duke@435: // +-----------+ duke@435: // (sp+n)->| first arg| duke@435: // +-----------+ duke@435: duke@435: duke@435: duke@435: // visits and GC's all the arguments in entry frame duke@435: class EntryFrameOopFinder: public SignatureInfo { duke@435: private: duke@435: bool _is_static; duke@435: int _offset; duke@435: frame* _fr; duke@435: OopClosure* _f; duke@435: duke@435: void set(int size, BasicType type) { duke@435: assert (_offset >= 0, "illegal offset"); duke@435: if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset); duke@435: _offset -= size; duke@435: } duke@435: duke@435: void oop_at_offset_do(int offset) { jcoomes@1844: assert (offset >= 0, "illegal offset"); duke@435: oop* addr = (oop*) _fr->entry_frame_argument_at(offset); duke@435: _f->do_oop(addr); duke@435: } duke@435: duke@435: public: coleenp@2497: EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) { duke@435: _f = NULL; // will be set later duke@435: _fr = frame; duke@435: _is_static = is_static; duke@435: _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0 duke@435: } duke@435: duke@435: void arguments_do(OopClosure* f) { duke@435: _f = f; duke@435: if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver duke@435: iterate_parameters(); duke@435: } duke@435: duke@435: }; duke@435: coleenp@2497: oop* frame::interpreter_callee_receiver_addr(Symbol* signature) { duke@435: ArgumentSizeComputer asc(signature); duke@435: int size = asc.size(); duke@435: return (oop *)interpreter_frame_tos_at(size); duke@435: } duke@435: duke@435: stefank@4298: void frame::oops_interpreted_do(OopClosure* f, CLDToOopClosure* cld_f, stefank@4298: const RegisterMap* map, bool query_oop_map_cache) { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: assert(map != NULL, "map must be set"); duke@435: Thread *thread = Thread::current(); duke@435: methodHandle m (thread, interpreter_frame_method()); duke@435: jint bci = interpreter_frame_bci(); duke@435: coleenp@4037: assert(!Universe::heap()->is_in(m()), coleenp@4037: "must be valid oop"); duke@435: assert(m->is_method(), "checking frame value"); coleenp@4037: assert((m->is_native() && bci == 0) || coleenp@4037: (!m->is_native() && bci >= 0 && bci < m->code_size()), coleenp@4037: "invalid bci value"); duke@435: duke@435: // Handle the monitor elements in the activation duke@435: for ( duke@435: BasicObjectLock* current = interpreter_frame_monitor_end(); duke@435: current < interpreter_frame_monitor_begin(); duke@435: current = next_monitor_in_interpreter_frame(current) duke@435: ) { duke@435: #ifdef ASSERT duke@435: interpreter_frame_verify_monitor(current); duke@435: #endif duke@435: current->oops_do(f); duke@435: } duke@435: duke@435: // process fixed part stefank@4298: if (cld_f != NULL) { stefank@4298: // The method pointer in the frame might be the only path to the method's stefank@4298: // klass, and the klass needs to be kept alive while executing. The GCs stefank@4298: // don't trace through method pointers, so typically in similar situations stefank@4298: // the mirror or the class loader of the klass are installed as a GC root. stefank@4298: // To minimze the overhead of doing that here, we ask the GC to pass down a stefank@4298: // closure that knows how to keep klasses alive given a ClassLoaderData. stefank@4298: cld_f->do_cld(m->method_holder()->class_loader_data()); stefank@4298: } stefank@4298: twisti@2263: #if !defined(PPC) || defined(ZERO) duke@435: if (m->is_native()) { duke@435: #ifdef CC_INTERP coleenp@4037: interpreterState istate = get_interpreterState(); duke@435: f->do_oop((oop*)&istate->_oop_temp); duke@435: #else duke@435: f->do_oop((oop*)( fp() + interpreter_frame_oop_temp_offset )); duke@435: #endif /* CC_INTERP */ duke@435: } bobv@2036: #else // PPC bobv@2036: if (m->is_native() && m->is_static()) { bobv@2036: f->do_oop(interpreter_frame_mirror_addr()); bobv@2036: } bobv@2036: #endif // PPC duke@435: duke@435: int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); duke@435: coleenp@2497: Symbol* signature = NULL; twisti@1573: bool has_receiver = false; duke@435: duke@435: // Process a callee's arguments if we are at a call site duke@435: // (i.e., if we are at an invoke bytecode) duke@435: // This is used sometimes for calling into the VM, not for another duke@435: // interpreted or compiled frame. duke@435: if (!m->is_native()) { never@2462: Bytecode_invoke call = Bytecode_invoke_check(m, bci); never@2462: if (call.is_valid()) { coleenp@2497: signature = call.signature(); never@2462: has_receiver = call.has_receiver(); duke@435: if (map->include_argument_oops() && duke@435: interpreter_frame_expression_stack_size() > 0) { duke@435: ResourceMark rm(thread); // is this right ??? duke@435: // we are at a call site & the expression stack is not empty duke@435: // => process callee's arguments duke@435: // duke@435: // Note: The expression stack can be empty if an exception twisti@1040: // occurred during method resolution/execution. In all duke@435: // cases we empty the expression stack completely be- duke@435: // fore handling the exception (the exception handling duke@435: // code in the interpreter calls a blocking runtime duke@435: // routine which can cause this code to be executed). duke@435: // (was bug gri 7/27/98) twisti@1573: oops_interpreted_arguments_do(signature, has_receiver, f); duke@435: } duke@435: } duke@435: } duke@435: twisti@1861: InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f); twisti@1861: twisti@1861: // process locals & expression stack twisti@1861: InterpreterOopMap mask; twisti@1861: if (query_oop_map_cache) { twisti@1861: m->mask_for(bci, &mask); duke@435: } else { twisti@1861: OopMapCache::compute_one_oop_map(m, bci, &mask); duke@435: } twisti@1861: mask.iterate_oop(&blk); duke@435: } duke@435: duke@435: coleenp@2497: void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) { twisti@1573: InterpretedArgumentOopFinder finder(signature, has_receiver, this, f); duke@435: finder.oops_do(); duke@435: } duke@435: jrose@1424: void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) { duke@435: assert(_cb != NULL, "sanity check"); duke@435: if (_cb->oop_maps() != NULL) { duke@435: OopMapSet::oops_do(this, reg_map, f); duke@435: duke@435: // Preserve potential arguments for a callee. We handle this by dispatching duke@435: // on the codeblob. For c2i, we do duke@435: if (reg_map->include_argument_oops()) { duke@435: _cb->preserve_callee_argument_oops(*this, reg_map, f); duke@435: } duke@435: } duke@435: // In cases where perm gen is collected, GC will want to mark duke@435: // oops referenced from nmethods active on thread stacks so as to duke@435: // prevent them from being collected. However, this visit should be duke@435: // restricted to certain phases of the collection only. The jrose@1424: // closure decides how it wants nmethods to be traced. jrose@1424: if (cf != NULL) jrose@1424: cf->do_code_blob(_cb); duke@435: } duke@435: duke@435: class CompiledArgumentOopFinder: public SignatureInfo { duke@435: protected: duke@435: OopClosure* _f; twisti@1573: int _offset; // the current offset, incremented with each argument twisti@1573: bool _has_receiver; // true if the callee has a receiver roland@5222: bool _has_appendix; // true if the call has an appendix duke@435: frame _fr; duke@435: RegisterMap* _reg_map; duke@435: int _arg_size; duke@435: VMRegPair* _regs; // VMReg list of arguments duke@435: duke@435: void set(int size, BasicType type) { duke@435: if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset(); duke@435: _offset += size; duke@435: } duke@435: duke@435: virtual void handle_oop_offset() { duke@435: // Extract low order register number from register array. duke@435: // In LP64-land, the high-order bits are valid but unhelpful. duke@435: VMReg reg = _regs[_offset].first(); duke@435: oop *loc = _fr.oopmapreg_to_location(reg, _reg_map); duke@435: _f->do_oop(loc); duke@435: } duke@435: duke@435: public: roland@5222: CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map) duke@435: : SignatureInfo(signature) { duke@435: duke@435: // initialize CompiledArgumentOopFinder duke@435: _f = f; duke@435: _offset = 0; twisti@1573: _has_receiver = has_receiver; roland@5222: _has_appendix = has_appendix; duke@435: _fr = fr; duke@435: _reg_map = (RegisterMap*)reg_map; roland@5222: _arg_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0); duke@435: duke@435: int arg_size; roland@5222: _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size); duke@435: assert(arg_size == _arg_size, "wrong arg size"); duke@435: } duke@435: duke@435: void oops_do() { twisti@1573: if (_has_receiver) { duke@435: handle_oop_offset(); duke@435: _offset++; duke@435: } duke@435: iterate_parameters(); roland@5222: if (_has_appendix) { roland@5222: handle_oop_offset(); roland@5222: _offset++; roland@5222: } duke@435: } duke@435: }; duke@435: roland@5222: void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f) { duke@435: ResourceMark rm; roland@5222: CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map); duke@435: finder.oops_do(); duke@435: } duke@435: duke@435: duke@435: // Get receiver out of callers frame, i.e. find parameter 0 in callers duke@435: // frame. Consult ADLC for where parameter 0 is to be found. Then duke@435: // check local reg_map for it being a callee-save register or argument duke@435: // register, both of which are saved in the local frame. If not found duke@435: // there, it must be an in-stack argument of the caller. duke@435: // Note: caller.sp() points to callee-arguments duke@435: oop frame::retrieve_receiver(RegisterMap* reg_map) { duke@435: frame caller = *this; duke@435: duke@435: // First consult the ADLC on where it puts parameter 0 for this signature. duke@435: VMReg reg = SharedRuntime::name_for_receiver(); morris@4690: oop* oop_adr = caller.oopmapreg_to_location(reg, reg_map); morris@4690: if (oop_adr == NULL) { morris@4690: guarantee(oop_adr != NULL, "bad register save location"); morris@4690: return NULL; morris@4690: } morris@4690: oop r = *oop_adr; hseigel@5784: assert(Universe::heap()->is_in_or_null(r), err_msg("bad receiver: " INTPTR_FORMAT " (" INTX_FORMAT ")", (void *) r, (void *) r)); duke@435: return r; duke@435: } duke@435: duke@435: duke@435: oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const { duke@435: if(reg->is_reg()) { duke@435: // If it is passed in a register, it got spilled in the stub frame. duke@435: return (oop *)reg_map->location(reg); duke@435: } else { coleenp@548: int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size; coleenp@548: return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes); duke@435: } duke@435: } duke@435: kamg@2361: BasicLock* frame::get_native_monitor() { kamg@2361: nmethod* nm = (nmethod*)_cb; kamg@2361: assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(), kamg@2361: "Should not call this unless it's a native nmethod"); kamg@2361: int byte_offset = in_bytes(nm->native_basic_lock_sp_offset()); duke@435: assert(byte_offset >= 0, "should not see invalid offset"); duke@435: return (BasicLock*) &sp()[byte_offset / wordSize]; duke@435: } duke@435: kamg@2361: oop frame::get_native_receiver() { kamg@2361: nmethod* nm = (nmethod*)_cb; kamg@2361: assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(), kamg@2361: "Should not call this unless it's a native nmethod"); kamg@2361: int byte_offset = in_bytes(nm->native_receiver_sp_offset()); duke@435: assert(byte_offset >= 0, "should not see invalid offset"); duke@435: oop owner = ((oop*) sp())[byte_offset / wordSize]; duke@435: assert( Universe::heap()->is_in(owner), "bad receiver" ); duke@435: return owner; duke@435: } duke@435: duke@435: void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) { duke@435: assert(map != NULL, "map must be set"); duke@435: if (map->include_argument_oops()) { duke@435: // must collect argument oops, as nobody else is doing it duke@435: Thread *thread = Thread::current(); duke@435: methodHandle m (thread, entry_frame_call_wrapper()->callee_method()); coleenp@2497: EntryFrameOopFinder finder(this, m->signature(), m->is_static()); duke@435: finder.arguments_do(f); duke@435: } duke@435: // Traverse the Handle Block saved in the entry frame duke@435: entry_frame_call_wrapper()->oops_do(f); duke@435: } duke@435: duke@435: stefank@4298: void frame::oops_do_internal(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) { minqi@1554: #ifndef PRODUCT minqi@1554: // simulate GC crash here to dump java thread in error report minqi@1554: if (CrashGCForDumpingJavaThread) { minqi@1554: char *t = NULL; minqi@1554: *t = 'c'; minqi@1554: } minqi@1554: #endif minqi@1554: if (is_interpreted_frame()) { stefank@4298: oops_interpreted_do(f, cld_f, map, use_interpreter_oop_map_cache); minqi@1554: } else if (is_entry_frame()) { minqi@1554: oops_entry_do(f, map); minqi@1554: } else if (CodeCache::contains(pc())) { minqi@1554: oops_code_blob_do(f, cf, map); twisti@2047: #ifdef SHARK twisti@2047: } else if (is_fake_stub_frame()) { twisti@2047: // nothing to do twisti@2047: #endif // SHARK duke@435: } else { duke@435: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: jrose@1424: void frame::nmethods_do(CodeBlobClosure* cf) { duke@435: if (_cb != NULL && _cb->is_nmethod()) { jrose@1424: cf->do_code_blob(_cb); duke@435: } duke@435: } duke@435: duke@435: coleenp@4037: // call f() on the interpreted Method*s in the stack. coleenp@4037: // Have to walk the entire code cache for the compiled frames Yuck. coleenp@4037: void frame::metadata_do(void f(Metadata*)) { coleenp@4037: if (_cb != NULL && Interpreter::contains(pc())) { coleenp@4037: Method* m = this->interpreter_frame_method(); coleenp@4037: assert(m != NULL, "huh?"); coleenp@4037: f(m); coleenp@4037: } coleenp@4037: } coleenp@4037: duke@435: void frame::gc_prologue() { duke@435: if (is_interpreted_frame()) { coleenp@4037: // set bcx to bci to become Method* position independent during GC duke@435: interpreter_frame_set_bcx(interpreter_frame_bci()); duke@435: } duke@435: } duke@435: duke@435: duke@435: void frame::gc_epilogue() { duke@435: if (is_interpreted_frame()) { duke@435: // set bcx back to bcp for interpreter duke@435: interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp()); duke@435: } duke@435: // call processor specific epilog function duke@435: pd_gc_epilog(); duke@435: } duke@435: duke@435: duke@435: # ifdef ENABLE_ZAP_DEAD_LOCALS duke@435: duke@435: void frame::CheckValueClosure::do_oop(oop* p) { duke@435: if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) { duke@435: warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); duke@435: } duke@435: } duke@435: frame::CheckValueClosure frame::_check_value; duke@435: duke@435: duke@435: void frame::CheckOopClosure::do_oop(oop* p) { duke@435: if (*p != NULL && !(*p)->is_oop()) { duke@435: warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); duke@435: } duke@435: } duke@435: frame::CheckOopClosure frame::_check_oop; duke@435: duke@435: void frame::check_derived_oop(oop* base, oop* derived) { duke@435: _check_oop.do_oop(base); duke@435: } duke@435: duke@435: duke@435: void frame::ZapDeadClosure::do_oop(oop* p) { duke@435: if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p); hseigel@5784: *p = cast_to_oop(0xbabebabe); duke@435: } duke@435: frame::ZapDeadClosure frame::_zap_dead; duke@435: duke@435: void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) { duke@435: assert(thread == Thread::current(), "need to synchronize to do this to another thread"); duke@435: // Tracing - part 1 duke@435: if (TraceZapDeadLocals) { duke@435: ResourceMark rm(thread); duke@435: tty->print_cr("--------------------------------------------------------------------------------"); duke@435: tty->print("Zapping dead locals in "); duke@435: print_on(tty); duke@435: tty->cr(); duke@435: } duke@435: // Zapping duke@435: if (is_entry_frame ()) zap_dead_entry_locals (thread, map); duke@435: else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map); duke@435: else if (is_compiled_frame()) zap_dead_compiled_locals (thread, map); duke@435: duke@435: else duke@435: // could be is_runtime_frame duke@435: // so remove error: ShouldNotReachHere(); duke@435: ; duke@435: // Tracing - part 2 duke@435: if (TraceZapDeadLocals) { duke@435: tty->cr(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) { duke@435: // get current interpreter 'pc' duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); coleenp@4037: Method* m = interpreter_frame_method(); duke@435: int bci = interpreter_frame_bci(); duke@435: duke@435: int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); duke@435: twisti@1861: // process dynamic part twisti@1861: InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(), twisti@1861: &_check_value); twisti@1861: InterpreterFrameClosure oop_blk(this, max_locals, m->max_stack(), twisti@1861: &_check_oop ); twisti@1861: InterpreterFrameClosure dead_blk(this, max_locals, m->max_stack(), twisti@1861: &_zap_dead ); duke@435: twisti@1861: // get frame map twisti@1861: InterpreterOopMap mask; twisti@1861: m->mask_for(bci, &mask); twisti@1861: mask.iterate_all( &oop_blk, &value_blk, &dead_blk); duke@435: } duke@435: duke@435: duke@435: void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) { duke@435: duke@435: ResourceMark rm(thread); duke@435: assert(_cb != NULL, "sanity check"); duke@435: if (_cb->oop_maps() != NULL) { coleenp@548: OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value); duke@435: } duke@435: } duke@435: duke@435: duke@435: void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) { duke@435: if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented"); duke@435: } duke@435: duke@435: duke@435: void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) { duke@435: if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented"); duke@435: } duke@435: duke@435: # endif // ENABLE_ZAP_DEAD_LOCALS duke@435: duke@435: void frame::verify(const RegisterMap* map) { duke@435: // for now make sure receiver type is correct duke@435: if (is_interpreted_frame()) { coleenp@4037: Method* method = interpreter_frame_method(); duke@435: guarantee(method->is_method(), "method is wrong in frame::verify"); duke@435: if (!method->is_static()) { duke@435: // fetch the receiver duke@435: oop* p = (oop*) interpreter_frame_local_at(0); duke@435: // make sure we have the right receiver type duke@435: } duke@435: } duke@435: COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");) stefank@4298: oops_do_internal(&VerifyOopClosure::verify_oop, NULL, NULL, (RegisterMap*)map, false); duke@435: } duke@435: duke@435: duke@435: #ifdef ASSERT duke@435: bool frame::verify_return_pc(address x) { duke@435: if (StubRoutines::returns_to_call_stub(x)) { duke@435: return true; duke@435: } duke@435: if (CodeCache::contains(x)) { duke@435: return true; duke@435: } duke@435: if (Interpreter::contains(x)) { duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: #endif duke@435: duke@435: #ifdef ASSERT duke@435: void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const { duke@435: assert(is_interpreted_frame(), "Not an interpreted frame"); duke@435: // verify that the value is in the right part of the frame duke@435: address low_mark = (address) interpreter_frame_monitor_end(); duke@435: address high_mark = (address) interpreter_frame_monitor_begin(); duke@435: address current = (address) value; duke@435: duke@435: const int monitor_size = frame::interpreter_frame_monitor_size(); duke@435: guarantee((high_mark - current) % monitor_size == 0 , "Misaligned top of BasicObjectLock*"); duke@435: guarantee( high_mark > current , "Current BasicObjectLock* higher than high_mark"); duke@435: duke@435: guarantee((current - low_mark) % monitor_size == 0 , "Misaligned bottom of BasicObjectLock*"); duke@435: guarantee( current >= low_mark , "Current BasicObjectLock* below than low_mark"); duke@435: } bdelsart@3451: #endif never@2868: bdelsart@3451: #ifndef PRODUCT never@2868: void frame::describe(FrameValues& values, int frame_no) { bdelsart@3445: // boundaries: sp and the 'real' frame pointer bdelsart@3445: values.describe(-1, sp(), err_msg("sp for #%d", frame_no), 1); bdelsart@3445: intptr_t* frame_pointer = real_fp(); // Note: may differ from fp() bdelsart@3445: bdelsart@3445: // print frame info at the highest boundary bdelsart@3445: intptr_t* info_address = MAX2(sp(), frame_pointer); bdelsart@3445: bdelsart@3445: if (info_address != frame_pointer) { bdelsart@3445: // print frame_pointer explicitly if not marked by the frame info bdelsart@3445: values.describe(-1, frame_pointer, err_msg("frame pointer for #%d", frame_no), 1); bdelsart@3445: } bdelsart@3445: never@2868: if (is_entry_frame() || is_compiled_frame() || is_interpreted_frame() || is_native_frame()) { never@2868: // Label values common to most frames never@2868: values.describe(-1, unextended_sp(), err_msg("unextended_sp for #%d", frame_no)); never@2868: } bdelsart@3445: never@2868: if (is_interpreted_frame()) { coleenp@4037: Method* m = interpreter_frame_method(); never@2868: int bci = interpreter_frame_bci(); never@2868: never@2868: // Label the method and current bci bdelsart@3445: values.describe(-1, info_address, never@2868: FormatBuffer<1024>("#%d method %s @ %d", frame_no, m->name_and_sig_as_C_string(), bci), 2); bdelsart@3445: values.describe(-1, info_address, never@2868: err_msg("- %d locals %d max stack", m->max_locals(), m->max_stack()), 1); never@2868: if (m->max_locals() > 0) { never@2868: intptr_t* l0 = interpreter_frame_local_at(0); never@2868: intptr_t* ln = interpreter_frame_local_at(m->max_locals() - 1); never@2868: values.describe(-1, MAX2(l0, ln), err_msg("locals for #%d", frame_no), 1); never@2868: // Report each local and mark as owned by this frame never@2868: for (int l = 0; l < m->max_locals(); l++) { never@2868: intptr_t* l0 = interpreter_frame_local_at(l); never@2868: values.describe(frame_no, l0, err_msg("local %d", l)); never@2868: } never@2868: } never@2868: never@2868: // Compute the actual expression stack size never@2868: InterpreterOopMap mask; never@2868: OopMapCache::compute_one_oop_map(m, bci, &mask); never@2868: intptr_t* tos = NULL; never@2868: // Report each stack element and mark as owned by this frame never@2868: for (int e = 0; e < mask.expression_stack_size(); e++) { never@2868: tos = MAX2(tos, interpreter_frame_expression_stack_at(e)); never@2868: values.describe(frame_no, interpreter_frame_expression_stack_at(e), never@2868: err_msg("stack %d", e)); never@2868: } never@2868: if (tos != NULL) { never@2868: values.describe(-1, tos, err_msg("expression stack for #%d", frame_no), 1); never@2868: } never@2868: if (interpreter_frame_monitor_begin() != interpreter_frame_monitor_end()) { never@2868: values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_begin(), "monitors begin"); never@2868: values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_end(), "monitors end"); never@2868: } never@2868: } else if (is_entry_frame()) { never@2868: // For now just label the frame bdelsart@3445: values.describe(-1, info_address, err_msg("#%d entry frame", frame_no), 2); never@2868: } else if (is_compiled_frame()) { never@2868: // For now just label the frame never@2868: nmethod* nm = cb()->as_nmethod_or_null(); bdelsart@3445: values.describe(-1, info_address, never@2868: FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for method %s%s", frame_no, never@2868: nm, nm->method()->name_and_sig_as_C_string(), bdelsart@3445: (_deopt_state == is_deoptimized) ? bdelsart@3445: " (deoptimized)" : bdelsart@3445: ((_deopt_state == unknown) ? " (state unknown)" : "")), bdelsart@3445: 2); never@2868: } else if (is_native_frame()) { never@2868: // For now just label the frame never@2868: nmethod* nm = cb()->as_nmethod_or_null(); bdelsart@3445: values.describe(-1, info_address, never@2868: FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for native method %s", frame_no, never@2868: nm, nm->method()->name_and_sig_as_C_string()), 2); bdelsart@3445: } else { bdelsart@3445: // provide default info if not handled before bdelsart@3445: char *info = (char *) "special frame"; bdelsart@3445: if ((_cb != NULL) && bdelsart@3445: (_cb->name() != NULL)) { bdelsart@3445: info = (char *)_cb->name(); bdelsart@3445: } bdelsart@3445: values.describe(-1, info_address, err_msg("#%d <%s>", frame_no, info), 2); never@2868: } bdelsart@3445: bdelsart@3445: // platform dependent additional data never@2868: describe_pd(values, frame_no); never@2868: } never@2868: duke@435: #endif duke@435: duke@435: duke@435: //----------------------------------------------------------------------------------- duke@435: // StackFrameStream implementation duke@435: duke@435: StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) { duke@435: assert(thread->has_last_Java_frame(), "sanity check"); duke@435: _fr = thread->last_frame(); duke@435: _is_done = false; duke@435: } never@2868: never@2868: bdelsart@3451: #ifndef PRODUCT never@2868: never@2868: void FrameValues::describe(int owner, intptr_t* location, const char* description, int priority) { never@2868: FrameValue fv; never@2868: fv.location = location; never@2868: fv.owner = owner; never@2868: fv.priority = priority; never@2868: fv.description = NEW_RESOURCE_ARRAY(char, strlen(description) + 1); never@2868: strcpy(fv.description, description); never@2868: _values.append(fv); never@2868: } never@2868: never@2868: bdelsart@3451: #ifdef ASSERT never@2897: void FrameValues::validate() { never@2868: _values.sort(compare); never@2868: bool error = false; never@2868: FrameValue prev; never@2868: prev.owner = -1; never@2868: for (int i = _values.length() - 1; i >= 0; i--) { never@2868: FrameValue fv = _values.at(i); never@2868: if (fv.owner == -1) continue; never@2868: if (prev.owner == -1) { never@2868: prev = fv; never@2868: continue; never@2868: } never@2868: if (prev.location == fv.location) { never@2868: if (fv.owner != prev.owner) { never@2868: tty->print_cr("overlapping storage"); never@2868: tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", prev.location, *prev.location, prev.description); never@2868: tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description); never@2868: error = true; never@2868: } never@2868: } else { never@2868: prev = fv; never@2868: } never@2868: } never@2897: assert(!error, "invalid layout"); never@2868: } bdelsart@3451: #endif // ASSERT never@2868: twisti@3238: void FrameValues::print(JavaThread* thread) { never@2868: _values.sort(compare); never@2901: never@2901: // Sometimes values like the fp can be invalid values if the never@2901: // register map wasn't updated during the walk. Trim out values never@2901: // that aren't actually in the stack of the thread. never@2901: int min_index = 0; never@2901: int max_index = _values.length() - 1; never@2901: intptr_t* v0 = _values.at(min_index).location; never@2901: intptr_t* v1 = _values.at(max_index).location; twisti@3238: twisti@3238: if (thread == Thread::current()) { twisti@3238: while (!thread->is_in_stack((address)v0)) { twisti@3238: v0 = _values.at(++min_index).location; twisti@3238: } twisti@3238: while (!thread->is_in_stack((address)v1)) { twisti@3238: v1 = _values.at(--max_index).location; twisti@3238: } twisti@3238: } else { twisti@3238: while (!thread->on_local_stack((address)v0)) { twisti@3238: v0 = _values.at(++min_index).location; twisti@3238: } twisti@3238: while (!thread->on_local_stack((address)v1)) { twisti@3238: v1 = _values.at(--max_index).location; twisti@3238: } never@2901: } never@2868: intptr_t* min = MIN2(v0, v1); never@2868: intptr_t* max = MAX2(v0, v1); never@2868: intptr_t* cur = max; never@2868: intptr_t* last = NULL; never@2901: for (int i = max_index; i >= min_index; i--) { never@2868: FrameValue fv = _values.at(i); never@2868: while (cur > fv.location) { never@2868: tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT, cur, *cur); never@2868: cur--; never@2868: } never@2868: if (last == fv.location) { never@2868: const char* spacer = " " LP64_ONLY(" "); never@2868: tty->print_cr(" %s %s %s", spacer, spacer, fv.description); never@2868: } else { never@2868: tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description); never@2868: last = fv.location; never@2868: cur--; never@2868: } never@2868: } never@2868: } never@2868: bdelsart@3451: #endif // ndef PRODUCT