frame.cpp revision 1930:54f5dd2aa1d9
192108Sphk/* 292108Sphk * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 392108Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 492108Sphk * 592108Sphk * This code is free software; you can redistribute it and/or modify it 692108Sphk * under the terms of the GNU General Public License version 2 only, as 792108Sphk * published by the Free Software Foundation. 892108Sphk * 992108Sphk * This code is distributed in the hope that it will be useful, but WITHOUT 1092108Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1192108Sphk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1292108Sphk * version 2 for more details (a copy is included in the LICENSE file that 1392108Sphk * accompanied this code). 1492108Sphk * 1592108Sphk * You should have received a copy of the GNU General Public License version 1692108Sphk * 2 along with this work; if not, write to the Free Software Foundation, 1792108Sphk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1892108Sphk * 1992108Sphk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2092108Sphk * or visit www.oracle.com if you need additional information or have any 2192108Sphk * questions. 2292108Sphk * 2392108Sphk */ 2492108Sphk 2592108Sphk#include "precompiled.hpp" 2692108Sphk#include "gc_interface/collectedHeap.inline.hpp" 2792108Sphk#include "interpreter/interpreter.hpp" 2892108Sphk#include "interpreter/oopMapCache.hpp" 2992108Sphk#include "memory/resourceArea.hpp" 3092108Sphk#include "memory/universe.inline.hpp" 3192108Sphk#include "oops/markOop.hpp" 3292108Sphk#include "oops/methodDataOop.hpp" 3392108Sphk#include "oops/methodOop.hpp" 3492108Sphk#include "oops/oop.inline.hpp" 3592108Sphk#include "oops/oop.inline2.hpp" 3692108Sphk#include "runtime/frame.inline.hpp" 3792108Sphk#include "runtime/handles.inline.hpp" 3892108Sphk#include "runtime/javaCalls.hpp" 3992108Sphk#include "runtime/monitorChunk.hpp" 4092108Sphk#include "runtime/sharedRuntime.hpp" 4192108Sphk#include "runtime/signature.hpp" 4292108Sphk#include "runtime/stubCodeGenerator.hpp" 4392108Sphk#include "runtime/stubRoutines.hpp" 4492108Sphk#include "utilities/decoder.hpp" 4592108Sphk 4692108Sphk#ifdef TARGET_ARCH_x86 4792108Sphk# include "nativeInst_x86.hpp" 4892108Sphk#endif 4992108Sphk#ifdef TARGET_ARCH_sparc 5092108Sphk# include "nativeInst_sparc.hpp" 5192108Sphk#endif 5292108Sphk#ifdef TARGET_ARCH_zero 5392108Sphk# include "nativeInst_zero.hpp" 5492108Sphk#endif 5593776Sphk 5693776SphkRegisterMap::RegisterMap(JavaThread *thread, bool update_map) { 5793776Sphk _thread = thread; 5893776Sphk _update_map = update_map; 5995321Sphk clear(); 60114493Sphk debug_only(_update_for_id = NULL;) 6192108Sphk#ifndef PRODUCT 6292108Sphk for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL; 6392108Sphk#endif /* PRODUCT */ 64111119Simp} 65111119Simp 66104057SphkRegisterMap::RegisterMap(const RegisterMap* map) { 67111119Simp assert(map != this, "bad initialization parameter"); 6892108Sphk assert(map != NULL, "RegisterMap must be present"); 6992108Sphk _thread = map->thread(); 7092108Sphk _update_map = map->update_map(); 7192108Sphk _include_argument_oops = map->include_argument_oops(); 72114493Sphk debug_only(_update_for_id = map->_update_for_id;) 73114493Sphk pd_initialize_from(map); 74114493Sphk if (update_map()) { 75114493Sphk for(int i = 0; i < location_valid_size; i++) { 76114493Sphk LocationValidType bits = !update_map() ? 0 : map->_location_valid[i]; 77114493Sphk _location_valid[i] = bits; 78114493Sphk // for whichever bits are set, pull in the corresponding map->_location 79114493Sphk int j = i*location_valid_type_size; 80114493Sphk while (bits != 0) { 81114493Sphk if ((bits & 1) != 0) { 82114493Sphk assert(0 <= j && j < reg_count, "range check"); 8393776Sphk _location[j] = map->_location[j]; 8492108Sphk } 8592108Sphk bits >>= 1; 86107953Sphk j += 1; 87107953Sphk } 8892108Sphk } 8992108Sphk } 9092108Sphk} 9192108Sphk 9292108Sphkvoid RegisterMap::clear() { 9392108Sphk set_include_argument_oops(true); 9492108Sphk if (_update_map) { 9592108Sphk for(int i = 0; i < location_valid_size; i++) { 9692108Sphk _location_valid[i] = 0; 9792108Sphk } 9892108Sphk pd_clear(); 99107953Sphk } else { 100107953Sphk pd_initialize(); 10192108Sphk } 10292108Sphk} 103107953Sphk 10492108Sphk#ifndef PRODUCT 10592108Sphk 10692108Sphkvoid RegisterMap::print_on(outputStream* st) const { 10792108Sphk st->print_cr("Register map"); 10892108Sphk for(int i = 0; i < reg_count; i++) { 10992108Sphk 11092108Sphk VMReg r = VMRegImpl::as_VMReg(i); 11192108Sphk intptr_t* src = (intptr_t*) location(r); 11292108Sphk if (src != NULL) { 11392108Sphk 11492108Sphk r->print_on(st); 11592108Sphk st->print(" [" INTPTR_FORMAT "] = ", src); 11692108Sphk if (((uintptr_t)src & (sizeof(*src)-1)) != 0) { 11792108Sphk st->print_cr("<misaligned>"); 11892108Sphk } else { 11992108Sphk st->print_cr(INTPTR_FORMAT, *src); 12092108Sphk } 12192108Sphk } 12292108Sphk } 12392108Sphk} 12492108Sphk 12592108Sphkvoid RegisterMap::print() const { 126113713Sphk print_on(tty); 127113713Sphk} 128113713Sphk 129113713Sphk#endif 130113713Sphk// This returns the pc that if you were in the debugger you'd see. Not 131113713Sphk// the idealized value in the frame object. This undoes the magic conversion 132113713Sphk// that happens for deoptimized frames. In addition it makes the value the 133107522Sphk// hardware would want to see in the native frame. The only user (at this point) 134107522Sphk// is deoptimization. It likely no one else should ever use it. 135107522Sphk 136107522Sphkaddress frame::raw_pc() const { 137107522Sphk if (is_deoptimized_frame()) { 138107522Sphk nmethod* nm = cb()->as_nmethod_or_null(); 139107522Sphk if (nm->is_method_handle_return(pc())) 140107522Sphk return nm->deopt_mh_handler_begin() - pc_return_offset; 141107953Sphk else 142107522Sphk return nm->deopt_handler_begin() - pc_return_offset; 143113713Sphk } else { 144113713Sphk return (pc() - pc_return_offset); 145113713Sphk } 146113713Sphk} 147107522Sphk 148107522Sphk// Change the pc in a frame object. This does not change the actual pc in 149107522Sphk// actual frame. To do that use patch_pc. 150107522Sphk// 151107953Sphkvoid frame::set_pc(address newpc ) { 152107953Sphk#ifdef ASSERT 153107522Sphk if (_cb != NULL && _cb->is_nmethod()) { 154107522Sphk assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation"); 155107522Sphk } 156107522Sphk#endif // ASSERT 157107522Sphk 158107522Sphk // Unsafe to use the is_deoptimzed tester after changing pc 159107522Sphk _deopt_state = unknown; 160107522Sphk _pc = newpc; 161107522Sphk _cb = CodeCache::find_blob_unsafe(_pc); 162107522Sphk 163107522Sphk} 164107522Sphk 165107522Sphk// type testers 166107522Sphkbool frame::is_deoptimized_frame() const { 16793776Sphk assert(_deopt_state != unknown, "not answerable"); 16892108Sphk return _deopt_state == is_deoptimized; 16992108Sphk} 17092108Sphk 17192108Sphkbool frame::is_native_frame() const { 17292108Sphk return (_cb != NULL && 17392108Sphk _cb->is_nmethod() && 17492108Sphk ((nmethod*)_cb)->is_native_method()); 175113712Sphk} 176113713Sphk 177107953Sphkbool frame::is_java_frame() const { 178107522Sphk if (is_interpreted_frame()) return true; 17994287Sphk if (is_compiled_frame()) return true; 18092108Sphk return false; 18192108Sphk} 18292108Sphk 18392108Sphk 18492108Sphkbool frame::is_compiled_frame() const { 185107953Sphk if (_cb != NULL && 186107953Sphk _cb->is_nmethod() && 18792108Sphk ((nmethod*)_cb)->is_java_method()) { 18892108Sphk return true; 18992108Sphk } 19092108Sphk return false; 19192108Sphk} 192104195Sphk 19392108Sphk 19492108Sphkbool frame::is_runtime_frame() const { 195107522Sphk return (_cb != NULL && _cb->is_runtime_stub()); 196107522Sphk} 197107522Sphk 198107522Sphkbool frame::is_safepoint_blob_frame() const { 199107832Sphk return (_cb != NULL && _cb->is_safepoint_stub()); 200113712Sphk} 201113713Sphk 202113713Sphk// testers 203107522Sphk 204113713Sphkbool frame::is_first_java_frame() const { 205107522Sphk RegisterMap map(JavaThread::current(), false); // No update 206113713Sphk frame s; 207113713Sphk for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)); 208113713Sphk return s.is_first_frame(); 209113713Sphk} 210113713Sphk 211113713Sphk 212113713Sphkbool frame::entry_frame_is_first() const { 213113713Sphk return entry_frame_call_wrapper()->anchor()->last_Java_sp() == NULL; 214113713Sphk} 215113713Sphk 216113713Sphk 217107522Sphkbool frame::should_be_deoptimized() const { 218113713Sphk if (_deopt_state == is_deoptimized || 219113713Sphk !is_compiled_frame() ) return false; 220113713Sphk assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod"); 221113713Sphk nmethod* nm = (nmethod *)_cb; 222107522Sphk if (TraceDependencies) { 223113713Sphk tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false"); 224113937Sphk nm->print_value_on(tty); 225113937Sphk tty->cr(); 226113713Sphk } 227113713Sphk 228113713Sphk if( !nm->is_marked_for_deoptimization() ) 229107522Sphk return false; 230107522Sphk 231107522Sphk // If at the return point, then the frame has already been popped, and 23292108Sphk // only the return needs to be executed. Don't deoptimize here. 233104057Sphk return !nm->is_at_poll_return(pc()); 234104195Sphk} 235104057Sphk 236104057Sphkbool frame::can_be_deoptimized() const { 23792108Sphk if (!is_compiled_frame()) return false; 23892108Sphk nmethod* nm = (nmethod*)_cb; 23992108Sphk 24092108Sphk if( !nm->can_be_deoptimized() ) 24192108Sphk return false; 24292108Sphk 24392108Sphk return !nm->is_at_poll_return(pc()); 24494287Sphk} 245113878Sphk 24694287Sphkvoid frame::deoptimize(JavaThread* thread) { 24795038Sphk // Schedule deoptimization of an nmethod activation with this frame. 24895038Sphk assert(_cb != NULL && _cb->is_nmethod(), "must be"); 24995038Sphk nmethod* nm = (nmethod*)_cb; 25095038Sphk 251107953Sphk // This is a fix for register window patching race 252107953Sphk if (NeedsDeoptSuspend && Thread::current() != thread) { 253107953Sphk assert(SafepointSynchronize::is_at_safepoint(), 25495038Sphk "patching other threads for deopt may only occur at a safepoint"); 25595038Sphk 25692108Sphk // It is possible especially with DeoptimizeALot/DeoptimizeRandom that 257104081Sphk // we could see the frame again and ask for it to be deoptimized since 258104195Sphk // it might move for a long time. That is harmless and we just ignore it. 259104081Sphk if (id() == thread->must_deopt_id()) { 260104081Sphk assert(thread->is_deopt_suspend(), "lost suspension"); 26192108Sphk return; 26292108Sphk } 26392108Sphk 26492108Sphk // We are at a safepoint so the target thread can only be 265104195Sphk // in 4 states: 26692108Sphk // blocked - no problem 26792108Sphk // blocked_trans - no problem (i.e. could have woken up from blocked 26892108Sphk // during a safepoint). 26992108Sphk // native - register window pc patching race 27092108Sphk // native_trans - momentary state 271107953Sphk // 27292108Sphk // We could just wait out a thread in native_trans to block. 27392108Sphk // Then we'd have all the issues that the safepoint code has as to 27492108Sphk // whether to spin or block. It isn't worth it. Just treat it like 27592108Sphk // native and be done with it. 276106101Sphk // 277106101Sphk // Examine the state of the thread at the start of safepoint since 278106101Sphk // threads that were in native at the start of the safepoint could 279106101Sphk // come to a halt during the safepoint, changing the current value 280106101Sphk // of the safepoint_state. 281106101Sphk JavaThreadState state = thread->safepoint_state()->orig_thread_state(); 28292108Sphk if (state == _thread_in_native || state == _thread_in_native_trans) { 28392108Sphk // Since we are at a safepoint the target thread will stop itself 284105540Sphk // before it can return to java as long as we remain at the safepoint. 285105540Sphk // Therefore we can put an additional request for the thread to stop 286105540Sphk // no matter what no (like a suspend). This will cause the thread 287105540Sphk // to notice it needs to do the deopt on its own once it leaves native. 288105540Sphk // 289105540Sphk // The only reason we must do this is because on machine with register 290105540Sphk // windows we have a race with patching the return address and the 291105540Sphk // window coming live as the thread returns to the Java code (but still 29292108Sphk // in native mode) and then blocks. It is only this top most frame 29392108Sphk // that is at risk. So in truth we could add an additional check to 29492108Sphk // see if this frame is one that is at risk. 295104064Sphk RegisterMap map(thread, false); 296107953Sphk frame at_risk = thread->last_frame().sender(&map); 297104064Sphk if (id() == at_risk.id()) { 298110710Sphk thread->set_must_deopt_id(id()); 299104064Sphk thread->set_deopt_suspend(); 300104064Sphk return; 301104064Sphk } 302104064Sphk } 303104064Sphk } // NeedsDeoptSuspend 304104064Sphk 305104195Sphk 306107953Sphk // If the call site is a MethodHandle call site use the MH deopt 307104064Sphk // handler. 308104064Sphk address deopt = nm->is_method_handle_return(pc()) ? 309104064Sphk nm->deopt_mh_handler_begin() : 310107953Sphk nm->deopt_handler_begin(); 311104064Sphk 312107953Sphk // Save the original pc before we patch in the new one 313104064Sphk nm->set_original_pc(this, pc()); 314104064Sphk patch_pc(thread, deopt); 315104064Sphk 316104064Sphk#ifdef ASSERT 317104064Sphk { 318104064Sphk RegisterMap map(thread, false); 319104064Sphk frame check = thread->last_frame(); 320104064Sphk while (id() != check.id()) { 321104064Sphk check = check.sender(&map); 322104064Sphk } 323104064Sphk assert(check.is_deoptimized_frame(), "missed deopt"); 324104064Sphk } 325104064Sphk#endif // ASSERT 326104064Sphk} 327104064Sphk 328104064Sphkframe frame::java_sender() const { 329105542Sphk RegisterMap map(JavaThread::current(), false); 330105957Sphk frame s; 331105957Sphk for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ; 332105957Sphk guarantee(s.is_java_frame(), "tried to get caller of first java frame"); 333105957Sphk return s; 334105957Sphk} 335104064Sphk 336104064Sphkframe frame::real_sender(RegisterMap* map) const { 337104064Sphk frame result = sender(map); 338104064Sphk while (result.is_runtime_frame()) { 339104064Sphk result = result.sender(map); 340105957Sphk } 341105957Sphk return result; 342105957Sphk} 343105957Sphk 344105957Sphk// Note: called by profiler - NOT for current thread 345107116Sphkframe frame::profile_find_Java_sender_frame(JavaThread *thread) { 346105957Sphk// If we don't recognize this frame, walk back up the stack until we do 347105957Sphk RegisterMap map(thread, false); 348104064Sphk frame first_java_frame = frame(); 349104064Sphk 350104064Sphk // Find the first Java frame on the stack starting with input frame 351104064Sphk if (is_java_frame()) { 352104064Sphk // top frame is compiled frame or deoptimized frame 353110710Sphk first_java_frame = *this; 354110710Sphk } else if (safe_for_sender(thread)) { 355110713Sphk for (frame sender_frame = sender(&map); 356110713Sphk sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame(); 357110713Sphk sender_frame = sender_frame.sender(&map)) { 358110713Sphk if (sender_frame.is_java_frame()) { 359105957Sphk first_java_frame = sender_frame; 360105957Sphk break; 361105957Sphk } 362105957Sphk } 363107953Sphk } 364105542Sphk return first_java_frame; 365105542Sphk} 366104064Sphk 367104064Sphk// Interpreter frames 368104064Sphk 369104064Sphk 370104064Sphkvoid frame::interpreter_frame_set_locals(intptr_t* locs) { 371104064Sphk assert(is_interpreted_frame(), "Not an interpreted frame"); 372104064Sphk *interpreter_frame_locals_addr() = locs; 373113713Sphk} 374113713Sphk 375113713SphkmethodOop frame::interpreter_frame_method() const { 376113713Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 377113713Sphk methodOop m = *interpreter_frame_method_addr(); 378113713Sphk assert(m->is_perm(), "bad methodOop in interpreter frame"); 379113713Sphk assert(m->is_method(), "not a methodOop"); 380113713Sphk return m; 381113713Sphk} 382113713Sphk 383113713Sphkvoid frame::interpreter_frame_set_method(methodOop method) { 384113713Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 385113713Sphk *interpreter_frame_method_addr() = method; 386107522Sphk} 387113713Sphk 388107522Sphkvoid frame::interpreter_frame_set_bcx(intptr_t bcx) { 389107522Sphk assert(is_interpreted_frame(), "Not an interpreted frame"); 390113712Sphk if (ProfileInterpreter) { 391107522Sphk bool formerly_bci = is_bci(interpreter_frame_bcx()); 392113713Sphk bool is_now_bci = is_bci(bcx); 393113713Sphk *interpreter_frame_bcx_addr() = bcx; 394107522Sphk 395107522Sphk intptr_t mdx = interpreter_frame_mdx(); 396113712Sphk 397113712Sphk if (mdx != 0) { 398111119Simp if (formerly_bci) { 399113712Sphk if (!is_now_bci) { 400113712Sphk // The bcx was just converted from bci to bcp. 401113712Sphk // Convert the mdx in parallel. 402113712Sphk methodDataOop mdo = interpreter_frame_method()->method_data(); 403107522Sphk assert(mdo != NULL, ""); 404107522Sphk int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one. 405113712Sphk address mdp = mdo->di_to_dp(mdi); 406107522Sphk interpreter_frame_set_mdx((intptr_t)mdp); 407107953Sphk } 408107953Sphk } else { 409113878Sphk if (is_now_bci) { 410113878Sphk // The bcx was just converted from bcp to bci. 411113878Sphk // Convert the mdx in parallel. 412113713Sphk methodDataOop mdo = interpreter_frame_method()->method_data(); 413113713Sphk assert(mdo != NULL, ""); 414113713Sphk int mdi = mdo->dp_to_di((address)mdx); 415107522Sphk interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0. 416107522Sphk } 417107522Sphk } 418114504Sphk } 419114504Sphk } else { 420114504Sphk *interpreter_frame_bcx_addr() = bcx; 421114504Sphk } 422114504Sphk} 423114504Sphk 424114504Sphkjint frame::interpreter_frame_bci() const { 425114504Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 426114504Sphk intptr_t bcx = interpreter_frame_bcx(); 427114504Sphk return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx); 428114504Sphk} 429114504Sphk 430114504Sphkvoid frame::interpreter_frame_set_bci(jint bci) { 431114504Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 432114504Sphk assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC"); 43392108Sphk interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci)); 434107522Sphk} 43592108Sphk 43692108Sphkaddress frame::interpreter_frame_bcp() const { 43792108Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 43892108Sphk intptr_t bcx = interpreter_frame_bcx(); 43992108Sphk return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx; 440113390Sphk} 44192108Sphk 44292108Sphkvoid frame::interpreter_frame_set_bcp(address bcp) { 44392108Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 44492108Sphk assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC"); 445114493Sphk interpreter_frame_set_bcx((intptr_t)bcp); 44692108Sphk} 44793776Sphk 44893776Sphkvoid frame::interpreter_frame_set_mdx(intptr_t mdx) { 44992108Sphk assert(is_interpreted_frame(), "Not an interpreted frame"); 45092108Sphk assert(ProfileInterpreter, "must be profiling interpreter"); 451114504Sphk *interpreter_frame_mdx_addr() = mdx; 45292108Sphk} 45392108Sphk 454105551Sphkaddress frame::interpreter_frame_mdp() const { 455105551Sphk assert(ProfileInterpreter, "must be profiling interpreter"); 456105551Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 45792108Sphk intptr_t bcx = interpreter_frame_bcx(); 458114504Sphk intptr_t mdx = interpreter_frame_mdx(); 45992108Sphk 46092108Sphk assert(!is_bci(bcx), "should not access mdp during GC"); 46192108Sphk return (address)mdx; 46292108Sphk} 46392108Sphk 46492108Sphkvoid frame::interpreter_frame_set_mdp(address mdp) { 46592108Sphk assert(is_interpreted_frame(), "interpreted frame expected"); 46693776Sphk if (mdp == NULL) { 46793250Sphk // Always allow the mdp to be cleared. 46892108Sphk interpreter_frame_set_mdx((intptr_t)mdp); 46992108Sphk } 47092108Sphk intptr_t bcx = interpreter_frame_bcx(); 47192108Sphk assert(!is_bci(bcx), "should not set mdp during GC"); 47292108Sphk interpreter_frame_set_mdx((intptr_t)mdp); 47392108Sphk} 47492108Sphk 475107522SphkBasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const { 476114504Sphk assert(is_interpreted_frame(), "Not an interpreted frame"); 477114504Sphk#ifdef ASSERT 47892108Sphk interpreter_frame_verify_monitor(current); 479#endif 480 BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size()); 481 return next; 482} 483 484BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const { 485 assert(is_interpreted_frame(), "Not an interpreted frame"); 486#ifdef ASSERT 487// // This verification needs to be checked before being enabled 488// interpreter_frame_verify_monitor(current); 489#endif 490 BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size()); 491 return previous; 492} 493 494// Interpreter locals and expression stack locations. 495 496intptr_t* frame::interpreter_frame_local_at(int index) const { 497 const int n = Interpreter::local_offset_in_bytes(index)/wordSize; 498 return &((*interpreter_frame_locals_addr())[n]); 499} 500 501intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const { 502 const int i = offset * interpreter_frame_expression_stack_direction(); 503 const int n = i * Interpreter::stackElementWords; 504 return &(interpreter_frame_expression_stack()[n]); 505} 506 507jint frame::interpreter_frame_expression_stack_size() const { 508 // Number of elements on the interpreter expression stack 509 // Callers should span by stackElementWords 510 int element_size = Interpreter::stackElementWords; 511 if (frame::interpreter_frame_expression_stack_direction() < 0) { 512 return (interpreter_frame_expression_stack() - 513 interpreter_frame_tos_address() + 1)/element_size; 514 } else { 515 return (interpreter_frame_tos_address() - 516 interpreter_frame_expression_stack() + 1)/element_size; 517 } 518} 519 520 521// (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp) 522 523const char* frame::print_name() const { 524 if (is_native_frame()) return "Native"; 525 if (is_interpreted_frame()) return "Interpreted"; 526 if (is_compiled_frame()) { 527 if (is_deoptimized_frame()) return "Deoptimized"; 528 return "Compiled"; 529 } 530 if (sp() == NULL) return "Empty"; 531 return "C"; 532} 533 534void frame::print_value_on(outputStream* st, JavaThread *thread) const { 535 NOT_PRODUCT(address begin = pc()-40;) 536 NOT_PRODUCT(address end = NULL;) 537 538 st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp()); 539 if (sp() != NULL) 540 st->print(", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), pc()); 541 542 if (StubRoutines::contains(pc())) { 543 st->print_cr(")"); 544 st->print("("); 545 StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); 546 st->print("~Stub::%s", desc->name()); 547 NOT_PRODUCT(begin = desc->begin(); end = desc->end();) 548 } else if (Interpreter::contains(pc())) { 549 st->print_cr(")"); 550 st->print("("); 551 InterpreterCodelet* desc = Interpreter::codelet_containing(pc()); 552 if (desc != NULL) { 553 st->print("~"); 554 desc->print(); 555 NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();) 556 } else { 557 st->print("~interpreter"); 558 } 559 } 560 st->print_cr(")"); 561 562 if (_cb != NULL) { 563 st->print(" "); 564 _cb->print_value_on(st); 565 st->cr(); 566#ifndef PRODUCT 567 if (end == NULL) { 568 begin = _cb->code_begin(); 569 end = _cb->code_end(); 570 } 571#endif 572 } 573 NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);) 574} 575 576 577void frame::print_on(outputStream* st) const { 578 print_value_on(st,NULL); 579 if (is_interpreted_frame()) { 580 interpreter_frame_print_on(st); 581 } 582} 583 584 585void frame::interpreter_frame_print_on(outputStream* st) const { 586#ifndef PRODUCT 587 assert(is_interpreted_frame(), "Not an interpreted frame"); 588 jint i; 589 for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) { 590 intptr_t x = *interpreter_frame_local_at(i); 591 st->print(" - local [" INTPTR_FORMAT "]", x); 592 st->fill_to(23); 593 st->print_cr("; #%d", i); 594 } 595 for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) { 596 intptr_t x = *interpreter_frame_expression_stack_at(i); 597 st->print(" - stack [" INTPTR_FORMAT "]", x); 598 st->fill_to(23); 599 st->print_cr("; #%d", i); 600 } 601 // locks for synchronization 602 for (BasicObjectLock* current = interpreter_frame_monitor_end(); 603 current < interpreter_frame_monitor_begin(); 604 current = next_monitor_in_interpreter_frame(current)) { 605 st->print(" - obj ["); 606 current->obj()->print_value_on(st); 607 st->print_cr("]"); 608 st->print(" - lock ["); 609 current->lock()->print_on(st); 610 st->print_cr("]"); 611 } 612 // monitor 613 st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin()); 614 // bcp 615 st->print(" - bcp [" INTPTR_FORMAT "]", interpreter_frame_bcp()); 616 st->fill_to(23); 617 st->print_cr("; @%d", interpreter_frame_bci()); 618 // locals 619 st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0)); 620 // method 621 st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method()); 622 st->fill_to(23); 623 st->print("; "); 624 interpreter_frame_method()->print_name(st); 625 st->cr(); 626#endif 627} 628 629// Return whether the frame is in the VM or os indicating a Hotspot problem. 630// Otherwise, it's likely a bug in the native library that the Java code calls, 631// hopefully indicating where to submit bugs. 632static void print_C_frame(outputStream* st, char* buf, int buflen, address pc) { 633 // C/C++ frame 634 bool in_vm = os::address_is_in_vm(pc); 635 st->print(in_vm ? "V" : "C"); 636 637 int offset; 638 bool found; 639 640 // libname 641 found = os::dll_address_to_library_name(pc, buf, buflen, &offset); 642 if (found) { 643 // skip directory names 644 const char *p1, *p2; 645 p1 = buf; 646 int len = (int)strlen(os::file_separator()); 647 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len; 648 st->print(" [%s+0x%x]", p1, offset); 649 } else { 650 st->print(" " PTR_FORMAT, pc); 651 } 652 653 // function name - os::dll_address_to_function_name() may return confusing 654 // names if pc is within jvm.dll or libjvm.so, because JVM only has 655 // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this 656 // only for native libraries. 657 if (!in_vm || Decoder::can_decode_C_frame_in_vm()) { 658 found = os::dll_address_to_function_name(pc, buf, buflen, &offset); 659 660 if (found) { 661 st->print(" %s+0x%x", buf, offset); 662 } 663 } 664} 665 666// frame::print_on_error() is called by fatal error handler. Notice that we may 667// crash inside this function if stack frame is corrupted. The fatal error 668// handler can catch and handle the crash. Here we assume the frame is valid. 669// 670// First letter indicates type of the frame: 671// J: Java frame (compiled) 672// j: Java frame (interpreted) 673// V: VM frame (C/C++) 674// v: Other frames running VM generated code (e.g. stubs, adapters, etc.) 675// C: C/C++ frame 676// 677// We don't need detailed frame type as that in frame::print_name(). "C" 678// suggests the problem is in user lib; everything else is likely a VM bug. 679 680void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const { 681 if (_cb != NULL) { 682 if (Interpreter::contains(pc())) { 683 methodOop m = this->interpreter_frame_method(); 684 if (m != NULL) { 685 m->name_and_sig_as_C_string(buf, buflen); 686 st->print("j %s", buf); 687 st->print("+%d", this->interpreter_frame_bci()); 688 } else { 689 st->print("j " PTR_FORMAT, pc()); 690 } 691 } else if (StubRoutines::contains(pc())) { 692 StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); 693 if (desc != NULL) { 694 st->print("v ~StubRoutines::%s", desc->name()); 695 } else { 696 st->print("v ~StubRoutines::" PTR_FORMAT, pc()); 697 } 698 } else if (_cb->is_buffer_blob()) { 699 st->print("v ~BufferBlob::%s", ((BufferBlob *)_cb)->name()); 700 } else if (_cb->is_nmethod()) { 701 methodOop m = ((nmethod *)_cb)->method(); 702 if (m != NULL) { 703 m->name_and_sig_as_C_string(buf, buflen); 704 st->print("J %s", buf); 705 } else { 706 st->print("J " PTR_FORMAT, pc()); 707 } 708 } else if (_cb->is_runtime_stub()) { 709 st->print("v ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name()); 710 } else if (_cb->is_deoptimization_stub()) { 711 st->print("v ~DeoptimizationBlob"); 712 } else if (_cb->is_exception_stub()) { 713 st->print("v ~ExceptionBlob"); 714 } else if (_cb->is_safepoint_stub()) { 715 st->print("v ~SafepointBlob"); 716 } else { 717 st->print("v blob " PTR_FORMAT, pc()); 718 } 719 } else { 720 print_C_frame(st, buf, buflen, pc()); 721 } 722} 723 724 725/* 726 The interpreter_frame_expression_stack_at method in the case of SPARC needs the 727 max_stack value of the method in order to compute the expression stack address. 728 It uses the methodOop in order to get the max_stack value but during GC this 729 methodOop value saved on the frame is changed by reverse_and_push and hence cannot 730 be used. So we save the max_stack value in the FrameClosure object and pass it 731 down to the interpreter_frame_expression_stack_at method 732*/ 733class InterpreterFrameClosure : public OffsetClosure { 734 private: 735 frame* _fr; 736 OopClosure* _f; 737 int _max_locals; 738 int _max_stack; 739 740 public: 741 InterpreterFrameClosure(frame* fr, int max_locals, int max_stack, 742 OopClosure* f) { 743 _fr = fr; 744 _max_locals = max_locals; 745 _max_stack = max_stack; 746 _f = f; 747 } 748 749 void offset_do(int offset) { 750 oop* addr; 751 if (offset < _max_locals) { 752 addr = (oop*) _fr->interpreter_frame_local_at(offset); 753 assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame"); 754 _f->do_oop(addr); 755 } else { 756 addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals)); 757 // In case of exceptions, the expression stack is invalid and the esp will be reset to express 758 // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel). 759 bool in_stack; 760 if (frame::interpreter_frame_expression_stack_direction() > 0) { 761 in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address(); 762 } else { 763 in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address(); 764 } 765 if (in_stack) { 766 _f->do_oop(addr); 767 } 768 } 769 } 770 771 int max_locals() { return _max_locals; } 772 frame* fr() { return _fr; } 773}; 774 775 776class InterpretedArgumentOopFinder: public SignatureInfo { 777 private: 778 OopClosure* _f; // Closure to invoke 779 int _offset; // TOS-relative offset, decremented with each argument 780 bool _has_receiver; // true if the callee has a receiver 781 frame* _fr; 782 783 void set(int size, BasicType type) { 784 _offset -= size; 785 if (type == T_OBJECT || type == T_ARRAY) oop_offset_do(); 786 } 787 788 void oop_offset_do() { 789 oop* addr; 790 addr = (oop*)_fr->interpreter_frame_tos_at(_offset); 791 _f->do_oop(addr); 792 } 793 794 public: 795 InterpretedArgumentOopFinder(symbolHandle signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) { 796 // compute size of arguments 797 int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0); 798 assert(!fr->is_interpreted_frame() || 799 args_size <= fr->interpreter_frame_expression_stack_size(), 800 "args cannot be on stack anymore"); 801 // initialize InterpretedArgumentOopFinder 802 _f = f; 803 _fr = fr; 804 _offset = args_size; 805 } 806 807 void oops_do() { 808 if (_has_receiver) { 809 --_offset; 810 oop_offset_do(); 811 } 812 iterate_parameters(); 813 } 814}; 815 816 817// Entry frame has following form (n arguments) 818// +-----------+ 819// sp -> | last arg | 820// +-----------+ 821// : ::: : 822// +-----------+ 823// (sp+n)->| first arg| 824// +-----------+ 825 826 827 828// visits and GC's all the arguments in entry frame 829class EntryFrameOopFinder: public SignatureInfo { 830 private: 831 bool _is_static; 832 int _offset; 833 frame* _fr; 834 OopClosure* _f; 835 836 void set(int size, BasicType type) { 837 assert (_offset >= 0, "illegal offset"); 838 if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset); 839 _offset -= size; 840 } 841 842 void oop_at_offset_do(int offset) { 843 assert (offset >= 0, "illegal offset"); 844 oop* addr = (oop*) _fr->entry_frame_argument_at(offset); 845 _f->do_oop(addr); 846 } 847 848 public: 849 EntryFrameOopFinder(frame* frame, symbolHandle signature, bool is_static) : SignatureInfo(signature) { 850 _f = NULL; // will be set later 851 _fr = frame; 852 _is_static = is_static; 853 _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0 854 } 855 856 void arguments_do(OopClosure* f) { 857 _f = f; 858 if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver 859 iterate_parameters(); 860 } 861 862}; 863 864oop* frame::interpreter_callee_receiver_addr(symbolHandle signature) { 865 ArgumentSizeComputer asc(signature); 866 int size = asc.size(); 867 return (oop *)interpreter_frame_tos_at(size); 868} 869 870 871void frame::oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) { 872 assert(is_interpreted_frame(), "Not an interpreted frame"); 873 assert(map != NULL, "map must be set"); 874 Thread *thread = Thread::current(); 875 methodHandle m (thread, interpreter_frame_method()); 876 jint bci = interpreter_frame_bci(); 877 878 assert(Universe::heap()->is_in(m()), "must be valid oop"); 879 assert(m->is_method(), "checking frame value"); 880 assert((m->is_native() && bci == 0) || (!m->is_native() && bci >= 0 && bci < m->code_size()), "invalid bci value"); 881 882 // Handle the monitor elements in the activation 883 for ( 884 BasicObjectLock* current = interpreter_frame_monitor_end(); 885 current < interpreter_frame_monitor_begin(); 886 current = next_monitor_in_interpreter_frame(current) 887 ) { 888#ifdef ASSERT 889 interpreter_frame_verify_monitor(current); 890#endif 891 current->oops_do(f); 892 } 893 894 // process fixed part 895 f->do_oop((oop*)interpreter_frame_method_addr()); 896 f->do_oop((oop*)interpreter_frame_cache_addr()); 897 898 // Hmm what about the mdp? 899#ifdef CC_INTERP 900 // Interpreter frame in the midst of a call have a methodOop within the 901 // object. 902 interpreterState istate = get_interpreterState(); 903 if (istate->msg() == BytecodeInterpreter::call_method) { 904 f->do_oop((oop*)&istate->_result._to_call._callee); 905 } 906 907#endif /* CC_INTERP */ 908 909#if !defined(PPC) || defined(ZERO) 910 if (m->is_native()) { 911#ifdef CC_INTERP 912 f->do_oop((oop*)&istate->_oop_temp); 913#else 914 f->do_oop((oop*)( fp() + interpreter_frame_oop_temp_offset )); 915#endif /* CC_INTERP */ 916 } 917#else // PPC 918 if (m->is_native() && m->is_static()) { 919 f->do_oop(interpreter_frame_mirror_addr()); 920 } 921#endif // PPC 922 923 int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); 924 925 symbolHandle signature; 926 bool has_receiver = false; 927 928 // Process a callee's arguments if we are at a call site 929 // (i.e., if we are at an invoke bytecode) 930 // This is used sometimes for calling into the VM, not for another 931 // interpreted or compiled frame. 932 if (!m->is_native()) { 933 Bytecode_invoke *call = Bytecode_invoke_at_check(m, bci); 934 if (call != NULL) { 935 signature = symbolHandle(thread, call->signature()); 936 has_receiver = call->has_receiver(); 937 if (map->include_argument_oops() && 938 interpreter_frame_expression_stack_size() > 0) { 939 ResourceMark rm(thread); // is this right ??? 940 // we are at a call site & the expression stack is not empty 941 // => process callee's arguments 942 // 943 // Note: The expression stack can be empty if an exception 944 // occurred during method resolution/execution. In all 945 // cases we empty the expression stack completely be- 946 // fore handling the exception (the exception handling 947 // code in the interpreter calls a blocking runtime 948 // routine which can cause this code to be executed). 949 // (was bug gri 7/27/98) 950 oops_interpreted_arguments_do(signature, has_receiver, f); 951 } 952 } 953 } 954 955 InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f); 956 957 // process locals & expression stack 958 InterpreterOopMap mask; 959 if (query_oop_map_cache) { 960 m->mask_for(bci, &mask); 961 } else { 962 OopMapCache::compute_one_oop_map(m, bci, &mask); 963 } 964 mask.iterate_oop(&blk); 965} 966 967 968void frame::oops_interpreted_arguments_do(symbolHandle signature, bool has_receiver, OopClosure* f) { 969 InterpretedArgumentOopFinder finder(signature, has_receiver, this, f); 970 finder.oops_do(); 971} 972 973void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) { 974 assert(_cb != NULL, "sanity check"); 975 if (_cb->oop_maps() != NULL) { 976 OopMapSet::oops_do(this, reg_map, f); 977 978 // Preserve potential arguments for a callee. We handle this by dispatching 979 // on the codeblob. For c2i, we do 980 if (reg_map->include_argument_oops()) { 981 _cb->preserve_callee_argument_oops(*this, reg_map, f); 982 } 983 } 984 // In cases where perm gen is collected, GC will want to mark 985 // oops referenced from nmethods active on thread stacks so as to 986 // prevent them from being collected. However, this visit should be 987 // restricted to certain phases of the collection only. The 988 // closure decides how it wants nmethods to be traced. 989 if (cf != NULL) 990 cf->do_code_blob(_cb); 991} 992 993class CompiledArgumentOopFinder: public SignatureInfo { 994 protected: 995 OopClosure* _f; 996 int _offset; // the current offset, incremented with each argument 997 bool _has_receiver; // true if the callee has a receiver 998 frame _fr; 999 RegisterMap* _reg_map; 1000 int _arg_size; 1001 VMRegPair* _regs; // VMReg list of arguments 1002 1003 void set(int size, BasicType type) { 1004 if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset(); 1005 _offset += size; 1006 } 1007 1008 virtual void handle_oop_offset() { 1009 // Extract low order register number from register array. 1010 // In LP64-land, the high-order bits are valid but unhelpful. 1011 VMReg reg = _regs[_offset].first(); 1012 oop *loc = _fr.oopmapreg_to_location(reg, _reg_map); 1013 _f->do_oop(loc); 1014 } 1015 1016 public: 1017 CompiledArgumentOopFinder(symbolHandle signature, bool has_receiver, OopClosure* f, frame fr, const RegisterMap* reg_map) 1018 : SignatureInfo(signature) { 1019 1020 // initialize CompiledArgumentOopFinder 1021 _f = f; 1022 _offset = 0; 1023 _has_receiver = has_receiver; 1024 _fr = fr; 1025 _reg_map = (RegisterMap*)reg_map; 1026 _arg_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0); 1027 1028 int arg_size; 1029 _regs = SharedRuntime::find_callee_arguments(signature(), has_receiver, &arg_size); 1030 assert(arg_size == _arg_size, "wrong arg size"); 1031 } 1032 1033 void oops_do() { 1034 if (_has_receiver) { 1035 handle_oop_offset(); 1036 _offset++; 1037 } 1038 iterate_parameters(); 1039 } 1040}; 1041 1042void frame::oops_compiled_arguments_do(symbolHandle signature, bool has_receiver, const RegisterMap* reg_map, OopClosure* f) { 1043 ResourceMark rm; 1044 CompiledArgumentOopFinder finder(signature, has_receiver, f, *this, reg_map); 1045 finder.oops_do(); 1046} 1047 1048 1049// Get receiver out of callers frame, i.e. find parameter 0 in callers 1050// frame. Consult ADLC for where parameter 0 is to be found. Then 1051// check local reg_map for it being a callee-save register or argument 1052// register, both of which are saved in the local frame. If not found 1053// there, it must be an in-stack argument of the caller. 1054// Note: caller.sp() points to callee-arguments 1055oop frame::retrieve_receiver(RegisterMap* reg_map) { 1056 frame caller = *this; 1057 1058 // First consult the ADLC on where it puts parameter 0 for this signature. 1059 VMReg reg = SharedRuntime::name_for_receiver(); 1060 oop r = *caller.oopmapreg_to_location(reg, reg_map); 1061 assert( Universe::heap()->is_in_or_null(r), "bad receiver" ); 1062 return r; 1063} 1064 1065 1066oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const { 1067 if(reg->is_reg()) { 1068 // If it is passed in a register, it got spilled in the stub frame. 1069 return (oop *)reg_map->location(reg); 1070 } else { 1071 int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size; 1072 return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes); 1073 } 1074} 1075 1076BasicLock* frame::get_native_monitor() { 1077 nmethod* nm = (nmethod*)_cb; 1078 assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(), 1079 "Should not call this unless it's a native nmethod"); 1080 int byte_offset = in_bytes(nm->native_basic_lock_sp_offset()); 1081 assert(byte_offset >= 0, "should not see invalid offset"); 1082 return (BasicLock*) &sp()[byte_offset / wordSize]; 1083} 1084 1085oop frame::get_native_receiver() { 1086 nmethod* nm = (nmethod*)_cb; 1087 assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(), 1088 "Should not call this unless it's a native nmethod"); 1089 int byte_offset = in_bytes(nm->native_receiver_sp_offset()); 1090 assert(byte_offset >= 0, "should not see invalid offset"); 1091 oop owner = ((oop*) sp())[byte_offset / wordSize]; 1092 assert( Universe::heap()->is_in(owner), "bad receiver" ); 1093 return owner; 1094} 1095 1096void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) { 1097 assert(map != NULL, "map must be set"); 1098 if (map->include_argument_oops()) { 1099 // must collect argument oops, as nobody else is doing it 1100 Thread *thread = Thread::current(); 1101 methodHandle m (thread, entry_frame_call_wrapper()->callee_method()); 1102 symbolHandle signature (thread, m->signature()); 1103 EntryFrameOopFinder finder(this, signature, m->is_static()); 1104 finder.arguments_do(f); 1105 } 1106 // Traverse the Handle Block saved in the entry frame 1107 entry_frame_call_wrapper()->oops_do(f); 1108} 1109 1110 1111void frame::oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) { 1112#ifndef PRODUCT 1113 // simulate GC crash here to dump java thread in error report 1114 if (CrashGCForDumpingJavaThread) { 1115 char *t = NULL; 1116 *t = 'c'; 1117 } 1118#endif 1119 if (is_interpreted_frame()) { 1120 oops_interpreted_do(f, map, use_interpreter_oop_map_cache); 1121 } else if (is_entry_frame()) { 1122 oops_entry_do(f, map); 1123 } else if (CodeCache::contains(pc())) { 1124 oops_code_blob_do(f, cf, map); 1125#ifdef SHARK 1126 } else if (is_fake_stub_frame()) { 1127 // nothing to do 1128#endif // SHARK 1129 } else { 1130 ShouldNotReachHere(); 1131 } 1132} 1133 1134void frame::nmethods_do(CodeBlobClosure* cf) { 1135 if (_cb != NULL && _cb->is_nmethod()) { 1136 cf->do_code_blob(_cb); 1137 } 1138} 1139 1140 1141void frame::gc_prologue() { 1142 if (is_interpreted_frame()) { 1143 // set bcx to bci to become methodOop position independent during GC 1144 interpreter_frame_set_bcx(interpreter_frame_bci()); 1145 } 1146} 1147 1148 1149void frame::gc_epilogue() { 1150 if (is_interpreted_frame()) { 1151 // set bcx back to bcp for interpreter 1152 interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp()); 1153 } 1154 // call processor specific epilog function 1155 pd_gc_epilog(); 1156} 1157 1158 1159# ifdef ENABLE_ZAP_DEAD_LOCALS 1160 1161void frame::CheckValueClosure::do_oop(oop* p) { 1162 if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) { 1163 warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); 1164 } 1165} 1166frame::CheckValueClosure frame::_check_value; 1167 1168 1169void frame::CheckOopClosure::do_oop(oop* p) { 1170 if (*p != NULL && !(*p)->is_oop()) { 1171 warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); 1172 } 1173} 1174frame::CheckOopClosure frame::_check_oop; 1175 1176void frame::check_derived_oop(oop* base, oop* derived) { 1177 _check_oop.do_oop(base); 1178} 1179 1180 1181void frame::ZapDeadClosure::do_oop(oop* p) { 1182 if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p); 1183 // Need cast because on _LP64 the conversion to oop is ambiguous. Constant 1184 // can be either long or int. 1185 *p = (oop)(int)0xbabebabe; 1186} 1187frame::ZapDeadClosure frame::_zap_dead; 1188 1189void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) { 1190 assert(thread == Thread::current(), "need to synchronize to do this to another thread"); 1191 // Tracing - part 1 1192 if (TraceZapDeadLocals) { 1193 ResourceMark rm(thread); 1194 tty->print_cr("--------------------------------------------------------------------------------"); 1195 tty->print("Zapping dead locals in "); 1196 print_on(tty); 1197 tty->cr(); 1198 } 1199 // Zapping 1200 if (is_entry_frame ()) zap_dead_entry_locals (thread, map); 1201 else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map); 1202 else if (is_compiled_frame()) zap_dead_compiled_locals (thread, map); 1203 1204 else 1205 // could be is_runtime_frame 1206 // so remove error: ShouldNotReachHere(); 1207 ; 1208 // Tracing - part 2 1209 if (TraceZapDeadLocals) { 1210 tty->cr(); 1211 } 1212} 1213 1214 1215void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) { 1216 // get current interpreter 'pc' 1217 assert(is_interpreted_frame(), "Not an interpreted frame"); 1218 methodOop m = interpreter_frame_method(); 1219 int bci = interpreter_frame_bci(); 1220 1221 int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); 1222 1223 // process dynamic part 1224 InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(), 1225 &_check_value); 1226 InterpreterFrameClosure oop_blk(this, max_locals, m->max_stack(), 1227 &_check_oop ); 1228 InterpreterFrameClosure dead_blk(this, max_locals, m->max_stack(), 1229 &_zap_dead ); 1230 1231 // get frame map 1232 InterpreterOopMap mask; 1233 m->mask_for(bci, &mask); 1234 mask.iterate_all( &oop_blk, &value_blk, &dead_blk); 1235} 1236 1237 1238void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) { 1239 1240 ResourceMark rm(thread); 1241 assert(_cb != NULL, "sanity check"); 1242 if (_cb->oop_maps() != NULL) { 1243 OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value); 1244 } 1245} 1246 1247 1248void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) { 1249 if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented"); 1250} 1251 1252 1253void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) { 1254 if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented"); 1255} 1256 1257# endif // ENABLE_ZAP_DEAD_LOCALS 1258 1259void frame::verify(const RegisterMap* map) { 1260 // for now make sure receiver type is correct 1261 if (is_interpreted_frame()) { 1262 methodOop method = interpreter_frame_method(); 1263 guarantee(method->is_method(), "method is wrong in frame::verify"); 1264 if (!method->is_static()) { 1265 // fetch the receiver 1266 oop* p = (oop*) interpreter_frame_local_at(0); 1267 // make sure we have the right receiver type 1268 } 1269 } 1270 COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");) 1271 oops_do_internal(&VerifyOopClosure::verify_oop, NULL, (RegisterMap*)map, false); 1272} 1273 1274 1275#ifdef ASSERT 1276bool frame::verify_return_pc(address x) { 1277 if (StubRoutines::returns_to_call_stub(x)) { 1278 return true; 1279 } 1280 if (CodeCache::contains(x)) { 1281 return true; 1282 } 1283 if (Interpreter::contains(x)) { 1284 return true; 1285 } 1286 return false; 1287} 1288#endif 1289 1290 1291#ifdef ASSERT 1292void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const { 1293 assert(is_interpreted_frame(), "Not an interpreted frame"); 1294 // verify that the value is in the right part of the frame 1295 address low_mark = (address) interpreter_frame_monitor_end(); 1296 address high_mark = (address) interpreter_frame_monitor_begin(); 1297 address current = (address) value; 1298 1299 const int monitor_size = frame::interpreter_frame_monitor_size(); 1300 guarantee((high_mark - current) % monitor_size == 0 , "Misaligned top of BasicObjectLock*"); 1301 guarantee( high_mark > current , "Current BasicObjectLock* higher than high_mark"); 1302 1303 guarantee((current - low_mark) % monitor_size == 0 , "Misaligned bottom of BasicObjectLock*"); 1304 guarantee( current >= low_mark , "Current BasicObjectLock* below than low_mark"); 1305} 1306#endif 1307 1308 1309//----------------------------------------------------------------------------------- 1310// StackFrameStream implementation 1311 1312StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) { 1313 assert(thread->has_last_Java_frame(), "sanity check"); 1314 _fr = thread->last_frame(); 1315 _is_done = false; 1316} 1317