frame.cpp revision 1138:dd57230ba8fe
1/* 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 * 23 */ 24 25# include "incls/_precompiled.incl" 26# include "incls/_frame.cpp.incl" 27 28RegisterMap::RegisterMap(JavaThread *thread, bool update_map) { 29 _thread = thread; 30 _update_map = update_map; 31 clear(); 32 debug_only(_update_for_id = NULL;) 33#ifndef PRODUCT 34 for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL; 35#endif /* PRODUCT */ 36} 37 38RegisterMap::RegisterMap(const RegisterMap* map) { 39 assert(map != this, "bad initialization parameter"); 40 assert(map != NULL, "RegisterMap must be present"); 41 _thread = map->thread(); 42 _update_map = map->update_map(); 43 _include_argument_oops = map->include_argument_oops(); 44 debug_only(_update_for_id = map->_update_for_id;) 45 pd_initialize_from(map); 46 if (update_map()) { 47 for(int i = 0; i < location_valid_size; i++) { 48 LocationValidType bits = !update_map() ? 0 : map->_location_valid[i]; 49 _location_valid[i] = bits; 50 // for whichever bits are set, pull in the corresponding map->_location 51 int j = i*location_valid_type_size; 52 while (bits != 0) { 53 if ((bits & 1) != 0) { 54 assert(0 <= j && j < reg_count, "range check"); 55 _location[j] = map->_location[j]; 56 } 57 bits >>= 1; 58 j += 1; 59 } 60 } 61 } 62} 63 64void RegisterMap::clear() { 65 set_include_argument_oops(true); 66 if (_update_map) { 67 for(int i = 0; i < location_valid_size; i++) { 68 _location_valid[i] = 0; 69 } 70 pd_clear(); 71 } else { 72 pd_initialize(); 73 } 74} 75 76#ifndef PRODUCT 77 78void RegisterMap::print_on(outputStream* st) const { 79 st->print_cr("Register map"); 80 for(int i = 0; i < reg_count; i++) { 81 82 VMReg r = VMRegImpl::as_VMReg(i); 83 intptr_t* src = (intptr_t*) location(r); 84 if (src != NULL) { 85 86 r->print_on(st); 87 st->print(" [" INTPTR_FORMAT "] = ", src); 88 if (((uintptr_t)src & (sizeof(*src)-1)) != 0) { 89 st->print_cr("<misaligned>"); 90 } else { 91 st->print_cr(INTPTR_FORMAT, *src); 92 } 93 } 94 } 95} 96 97void RegisterMap::print() const { 98 print_on(tty); 99} 100 101#endif 102// This returns the pc that if you were in the debugger you'd see. Not 103// the idealized value in the frame object. This undoes the magic conversion 104// that happens for deoptimized frames. In addition it makes the value the 105// hardware would want to see in the native frame. The only user (at this point) 106// is deoptimization. It likely no one else should ever use it. 107 108address frame::raw_pc() const { 109 if (is_deoptimized_frame()) { 110 return ((nmethod*) cb())->deopt_handler_begin() - pc_return_offset; 111 } else { 112 return (pc() - pc_return_offset); 113 } 114} 115 116// Change the pc in a frame object. This does not change the actual pc in 117// actual frame. To do that use patch_pc. 118// 119void frame::set_pc(address newpc ) { 120#ifdef ASSERT 121 if (_cb != NULL && _cb->is_nmethod()) { 122 assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation"); 123 } 124#endif // ASSERT 125 126 // Unsafe to use the is_deoptimzed tester after changing pc 127 _deopt_state = unknown; 128 _pc = newpc; 129 _cb = CodeCache::find_blob_unsafe(_pc); 130 131} 132 133// type testers 134bool frame::is_deoptimized_frame() const { 135 assert(_deopt_state != unknown, "not answerable"); 136 return _deopt_state == is_deoptimized; 137} 138 139bool frame::is_native_frame() const { 140 return (_cb != NULL && 141 _cb->is_nmethod() && 142 ((nmethod*)_cb)->is_native_method()); 143} 144 145bool frame::is_java_frame() const { 146 if (is_interpreted_frame()) return true; 147 if (is_compiled_frame()) return true; 148 return false; 149} 150 151 152bool frame::is_compiled_frame() const { 153 if (_cb != NULL && 154 _cb->is_nmethod() && 155 ((nmethod*)_cb)->is_java_method()) { 156 return true; 157 } 158 return false; 159} 160 161 162bool frame::is_runtime_frame() const { 163 return (_cb != NULL && _cb->is_runtime_stub()); 164} 165 166bool frame::is_safepoint_blob_frame() const { 167 return (_cb != NULL && _cb->is_safepoint_stub()); 168} 169 170// testers 171 172bool frame::is_first_java_frame() const { 173 RegisterMap map(JavaThread::current(), false); // No update 174 frame s; 175 for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)); 176 return s.is_first_frame(); 177} 178 179 180bool frame::entry_frame_is_first() const { 181 return entry_frame_call_wrapper()->anchor()->last_Java_sp() == NULL; 182} 183 184 185bool frame::should_be_deoptimized() const { 186 if (_deopt_state == is_deoptimized || 187 !is_compiled_frame() ) return false; 188 assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod"); 189 nmethod* nm = (nmethod *)_cb; 190 if (TraceDependencies) { 191 tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false"); 192 nm->print_value_on(tty); 193 tty->cr(); 194 } 195 196 if( !nm->is_marked_for_deoptimization() ) 197 return false; 198 199 // If at the return point, then the frame has already been popped, and 200 // only the return needs to be executed. Don't deoptimize here. 201 return !nm->is_at_poll_return(pc()); 202} 203 204bool frame::can_be_deoptimized() const { 205 if (!is_compiled_frame()) return false; 206 nmethod* nm = (nmethod*)_cb; 207 208 if( !nm->can_be_deoptimized() ) 209 return false; 210 211 return !nm->is_at_poll_return(pc()); 212} 213 214void frame::deoptimize(JavaThread* thread, bool thread_is_known_safe) { 215// Schedule deoptimization of an nmethod activation with this frame. 216 217 // Store the original pc before an patch (or request to self-deopt) 218 // in the published location of the frame. 219 220 assert(_cb != NULL && _cb->is_nmethod(), "must be"); 221 nmethod* nm = (nmethod*)_cb; 222 223 // This is a fix for register window patching race 224 if (NeedsDeoptSuspend && !thread_is_known_safe) { 225 226 // It is possible especially with DeoptimizeALot/DeoptimizeRandom that 227 // we could see the frame again and ask for it to be deoptimized since 228 // it might move for a long time. That is harmless and we just ignore it. 229 if (id() == thread->must_deopt_id()) { 230 assert(thread->is_deopt_suspend(), "lost suspension"); 231 return; 232 } 233 234 // We are at a safepoint so the target thread can only be 235 // in 4 states: 236 // blocked - no problem 237 // blocked_trans - no problem (i.e. could have woken up from blocked 238 // during a safepoint). 239 // native - register window pc patching race 240 // native_trans - momentary state 241 // 242 // We could just wait out a thread in native_trans to block. 243 // Then we'd have all the issues that the safepoint code has as to 244 // whether to spin or block. It isn't worth it. Just treat it like 245 // native and be done with it. 246 // 247 JavaThreadState state = thread->thread_state(); 248 if (state == _thread_in_native || state == _thread_in_native_trans) { 249 // Since we are at a safepoint the target thread will stop itself 250 // before it can return to java as long as we remain at the safepoint. 251 // Therefore we can put an additional request for the thread to stop 252 // no matter what no (like a suspend). This will cause the thread 253 // to notice it needs to do the deopt on its own once it leaves native. 254 // 255 // The only reason we must do this is because on machine with register 256 // windows we have a race with patching the return address and the 257 // window coming live as the thread returns to the Java code (but still 258 // in native mode) and then blocks. It is only this top most frame 259 // that is at risk. So in truth we could add an additional check to 260 // see if this frame is one that is at risk. 261 RegisterMap map(thread, false); 262 frame at_risk = thread->last_frame().sender(&map); 263 if (id() == at_risk.id()) { 264 thread->set_must_deopt_id(id()); 265 thread->set_deopt_suspend(); 266 return; 267 } 268 } 269 } // NeedsDeoptSuspend 270 271 272 address deopt = nm->deopt_handler_begin(); 273 // Save the original pc before we patch in the new one 274 nm->set_original_pc(this, pc()); 275 patch_pc(thread, deopt); 276#ifdef ASSERT 277 { 278 RegisterMap map(thread, false); 279 frame check = thread->last_frame(); 280 while (id() != check.id()) { 281 check = check.sender(&map); 282 } 283 assert(check.is_deoptimized_frame(), "missed deopt"); 284 } 285#endif // ASSERT 286} 287 288frame frame::java_sender() const { 289 RegisterMap map(JavaThread::current(), false); 290 frame s; 291 for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ; 292 guarantee(s.is_java_frame(), "tried to get caller of first java frame"); 293 return s; 294} 295 296frame frame::real_sender(RegisterMap* map) const { 297 frame result = sender(map); 298 while (result.is_runtime_frame()) { 299 result = result.sender(map); 300 } 301 return result; 302} 303 304// Note: called by profiler - NOT for current thread 305frame frame::profile_find_Java_sender_frame(JavaThread *thread) { 306// If we don't recognize this frame, walk back up the stack until we do 307 RegisterMap map(thread, false); 308 frame first_java_frame = frame(); 309 310 // Find the first Java frame on the stack starting with input frame 311 if (is_java_frame()) { 312 // top frame is compiled frame or deoptimized frame 313 first_java_frame = *this; 314 } else if (safe_for_sender(thread)) { 315 for (frame sender_frame = sender(&map); 316 sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame(); 317 sender_frame = sender_frame.sender(&map)) { 318 if (sender_frame.is_java_frame()) { 319 first_java_frame = sender_frame; 320 break; 321 } 322 } 323 } 324 return first_java_frame; 325} 326 327// Interpreter frames 328 329 330void frame::interpreter_frame_set_locals(intptr_t* locs) { 331 assert(is_interpreted_frame(), "Not an interpreted frame"); 332 *interpreter_frame_locals_addr() = locs; 333} 334 335methodOop frame::interpreter_frame_method() const { 336 assert(is_interpreted_frame(), "interpreted frame expected"); 337 methodOop m = *interpreter_frame_method_addr(); 338 assert(m->is_perm(), "bad methodOop in interpreter frame"); 339 assert(m->is_method(), "not a methodOop"); 340 return m; 341} 342 343void frame::interpreter_frame_set_method(methodOop method) { 344 assert(is_interpreted_frame(), "interpreted frame expected"); 345 *interpreter_frame_method_addr() = method; 346} 347 348void frame::interpreter_frame_set_bcx(intptr_t bcx) { 349 assert(is_interpreted_frame(), "Not an interpreted frame"); 350 if (ProfileInterpreter) { 351 bool formerly_bci = is_bci(interpreter_frame_bcx()); 352 bool is_now_bci = is_bci(bcx); 353 *interpreter_frame_bcx_addr() = bcx; 354 355 intptr_t mdx = interpreter_frame_mdx(); 356 357 if (mdx != 0) { 358 if (formerly_bci) { 359 if (!is_now_bci) { 360 // The bcx was just converted from bci to bcp. 361 // Convert the mdx in parallel. 362 methodDataOop mdo = interpreter_frame_method()->method_data(); 363 assert(mdo != NULL, ""); 364 int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one. 365 address mdp = mdo->di_to_dp(mdi); 366 interpreter_frame_set_mdx((intptr_t)mdp); 367 } 368 } else { 369 if (is_now_bci) { 370 // The bcx was just converted from bcp to bci. 371 // Convert the mdx in parallel. 372 methodDataOop mdo = interpreter_frame_method()->method_data(); 373 assert(mdo != NULL, ""); 374 int mdi = mdo->dp_to_di((address)mdx); 375 interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0. 376 } 377 } 378 } 379 } else { 380 *interpreter_frame_bcx_addr() = bcx; 381 } 382} 383 384jint frame::interpreter_frame_bci() const { 385 assert(is_interpreted_frame(), "interpreted frame expected"); 386 intptr_t bcx = interpreter_frame_bcx(); 387 return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx); 388} 389 390void frame::interpreter_frame_set_bci(jint bci) { 391 assert(is_interpreted_frame(), "interpreted frame expected"); 392 assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC"); 393 interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci)); 394} 395 396address frame::interpreter_frame_bcp() const { 397 assert(is_interpreted_frame(), "interpreted frame expected"); 398 intptr_t bcx = interpreter_frame_bcx(); 399 return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx; 400} 401 402void frame::interpreter_frame_set_bcp(address bcp) { 403 assert(is_interpreted_frame(), "interpreted frame expected"); 404 assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC"); 405 interpreter_frame_set_bcx((intptr_t)bcp); 406} 407 408void frame::interpreter_frame_set_mdx(intptr_t mdx) { 409 assert(is_interpreted_frame(), "Not an interpreted frame"); 410 assert(ProfileInterpreter, "must be profiling interpreter"); 411 *interpreter_frame_mdx_addr() = mdx; 412} 413 414address frame::interpreter_frame_mdp() const { 415 assert(ProfileInterpreter, "must be profiling interpreter"); 416 assert(is_interpreted_frame(), "interpreted frame expected"); 417 intptr_t bcx = interpreter_frame_bcx(); 418 intptr_t mdx = interpreter_frame_mdx(); 419 420 assert(!is_bci(bcx), "should not access mdp during GC"); 421 return (address)mdx; 422} 423 424void frame::interpreter_frame_set_mdp(address mdp) { 425 assert(is_interpreted_frame(), "interpreted frame expected"); 426 if (mdp == NULL) { 427 // Always allow the mdp to be cleared. 428 interpreter_frame_set_mdx((intptr_t)mdp); 429 } 430 intptr_t bcx = interpreter_frame_bcx(); 431 assert(!is_bci(bcx), "should not set mdp during GC"); 432 interpreter_frame_set_mdx((intptr_t)mdp); 433} 434 435BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const { 436 assert(is_interpreted_frame(), "Not an interpreted frame"); 437#ifdef ASSERT 438 interpreter_frame_verify_monitor(current); 439#endif 440 BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size()); 441 return next; 442} 443 444BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const { 445 assert(is_interpreted_frame(), "Not an interpreted frame"); 446#ifdef ASSERT 447// // This verification needs to be checked before being enabled 448// interpreter_frame_verify_monitor(current); 449#endif 450 BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size()); 451 return previous; 452} 453 454// Interpreter locals and expression stack locations. 455 456intptr_t* frame::interpreter_frame_local_at(int index) const { 457 const int n = Interpreter::local_offset_in_bytes(index)/wordSize; 458 return &((*interpreter_frame_locals_addr())[n]); 459} 460 461frame::Tag frame::interpreter_frame_local_tag(int index) const { 462 const int n = Interpreter::local_tag_offset_in_bytes(index)/wordSize; 463 return (Tag)(*interpreter_frame_locals_addr()) [n]; 464} 465 466void frame::interpreter_frame_set_local_tag(int index, Tag tag) const { 467 const int n = Interpreter::local_tag_offset_in_bytes(index)/wordSize; 468 (*interpreter_frame_locals_addr())[n] = (intptr_t)tag; 469} 470 471intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const { 472 const int i = offset * interpreter_frame_expression_stack_direction(); 473 const int n = ((i * Interpreter::stackElementSize()) + 474 Interpreter::value_offset_in_bytes())/wordSize; 475 return &(interpreter_frame_expression_stack()[n]); 476} 477 478frame::Tag frame::interpreter_frame_expression_stack_tag(jint offset) const { 479 const int i = offset * interpreter_frame_expression_stack_direction(); 480 const int n = ((i * Interpreter::stackElementSize()) + 481 Interpreter::tag_offset_in_bytes())/wordSize; 482 return (Tag)(interpreter_frame_expression_stack()[n]); 483} 484 485void frame::interpreter_frame_set_expression_stack_tag(jint offset, 486 Tag tag) const { 487 const int i = offset * interpreter_frame_expression_stack_direction(); 488 const int n = ((i * Interpreter::stackElementSize()) + 489 Interpreter::tag_offset_in_bytes())/wordSize; 490 interpreter_frame_expression_stack()[n] = (intptr_t)tag; 491} 492 493jint frame::interpreter_frame_expression_stack_size() const { 494 // Number of elements on the interpreter expression stack 495 // Callers should span by stackElementWords 496 int element_size = Interpreter::stackElementWords(); 497 if (frame::interpreter_frame_expression_stack_direction() < 0) { 498 return (interpreter_frame_expression_stack() - 499 interpreter_frame_tos_address() + 1)/element_size; 500 } else { 501 return (interpreter_frame_tos_address() - 502 interpreter_frame_expression_stack() + 1)/element_size; 503 } 504} 505 506 507// (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp) 508 509const char* frame::print_name() const { 510 if (is_native_frame()) return "Native"; 511 if (is_interpreted_frame()) return "Interpreted"; 512 if (is_compiled_frame()) { 513 if (is_deoptimized_frame()) return "Deoptimized"; 514 return "Compiled"; 515 } 516 if (sp() == NULL) return "Empty"; 517 return "C"; 518} 519 520void frame::print_value_on(outputStream* st, JavaThread *thread) const { 521 NOT_PRODUCT(address begin = pc()-40;) 522 NOT_PRODUCT(address end = NULL;) 523 524 st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp()); 525 if (sp() != NULL) 526 st->print(", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), pc()); 527 528 if (StubRoutines::contains(pc())) { 529 st->print_cr(")"); 530 st->print("("); 531 StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); 532 st->print("~Stub::%s", desc->name()); 533 NOT_PRODUCT(begin = desc->begin(); end = desc->end();) 534 } else if (Interpreter::contains(pc())) { 535 st->print_cr(")"); 536 st->print("("); 537 InterpreterCodelet* desc = Interpreter::codelet_containing(pc()); 538 if (desc != NULL) { 539 st->print("~"); 540 desc->print(); 541 NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();) 542 } else { 543 st->print("~interpreter"); 544 } 545 } 546 st->print_cr(")"); 547 548 if (_cb != NULL) { 549 st->print(" "); 550 _cb->print_value_on(st); 551 st->cr(); 552#ifndef PRODUCT 553 if (end == NULL) { 554 begin = _cb->instructions_begin(); 555 end = _cb->instructions_end(); 556 } 557#endif 558 } 559 NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);) 560} 561 562 563void frame::print_on(outputStream* st) const { 564 print_value_on(st,NULL); 565 if (is_interpreted_frame()) { 566 interpreter_frame_print_on(st); 567 } 568} 569 570 571void frame::interpreter_frame_print_on(outputStream* st) const { 572#ifndef PRODUCT 573 assert(is_interpreted_frame(), "Not an interpreted frame"); 574 jint i; 575 for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) { 576 intptr_t x = *interpreter_frame_local_at(i); 577 st->print(" - local [" INTPTR_FORMAT "]", x); 578 if (TaggedStackInterpreter) { 579 Tag x = interpreter_frame_local_tag(i); 580 st->print(" - local tag [" INTPTR_FORMAT "]", x); 581 } 582 st->fill_to(23); 583 st->print_cr("; #%d", i); 584 } 585 for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) { 586 intptr_t x = *interpreter_frame_expression_stack_at(i); 587 st->print(" - stack [" INTPTR_FORMAT "]", x); 588 if (TaggedStackInterpreter) { 589 Tag x = interpreter_frame_expression_stack_tag(i); 590 st->print(" - stack tag [" INTPTR_FORMAT "]", x); 591 } 592 st->fill_to(23); 593 st->print_cr("; #%d", i); 594 } 595 // locks for synchronization 596 for (BasicObjectLock* current = interpreter_frame_monitor_end(); 597 current < interpreter_frame_monitor_begin(); 598 current = next_monitor_in_interpreter_frame(current)) { 599 st->print_cr(" [ - obj "); 600 current->obj()->print_value_on(st); 601 st->cr(); 602 st->print_cr(" - lock "); 603 current->lock()->print_on(st); 604 st->cr(); 605 } 606 // monitor 607 st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin()); 608 // bcp 609 st->print(" - bcp [" INTPTR_FORMAT "]", interpreter_frame_bcp()); 610 st->fill_to(23); 611 st->print_cr("; @%d", interpreter_frame_bci()); 612 // locals 613 st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0)); 614 // method 615 st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method()); 616 st->fill_to(23); 617 st->print("; "); 618 interpreter_frame_method()->print_name(st); 619 st->cr(); 620#endif 621} 622 623// Return whether the frame is in the VM or os indicating a Hotspot problem. 624// Otherwise, it's likely a bug in the native library that the Java code calls, 625// hopefully indicating where to submit bugs. 626static void print_C_frame(outputStream* st, char* buf, int buflen, address pc) { 627 // C/C++ frame 628 bool in_vm = os::address_is_in_vm(pc); 629 st->print(in_vm ? "V" : "C"); 630 631 int offset; 632 bool found; 633 634 // libname 635 found = os::dll_address_to_library_name(pc, buf, buflen, &offset); 636 if (found) { 637 // skip directory names 638 const char *p1, *p2; 639 p1 = buf; 640 int len = (int)strlen(os::file_separator()); 641 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len; 642 st->print(" [%s+0x%x]", p1, offset); 643 } else { 644 st->print(" " PTR_FORMAT, pc); 645 } 646 647 // function name - os::dll_address_to_function_name() may return confusing 648 // names if pc is within jvm.dll or libjvm.so, because JVM only has 649 // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this 650 // only for native libraries. 651 if (!in_vm) { 652 found = os::dll_address_to_function_name(pc, buf, buflen, &offset); 653 654 if (found) { 655 st->print(" %s+0x%x", buf, offset); 656 } 657 } 658} 659 660// frame::print_on_error() is called by fatal error handler. Notice that we may 661// crash inside this function if stack frame is corrupted. The fatal error 662// handler can catch and handle the crash. Here we assume the frame is valid. 663// 664// First letter indicates type of the frame: 665// J: Java frame (compiled) 666// j: Java frame (interpreted) 667// V: VM frame (C/C++) 668// v: Other frames running VM generated code (e.g. stubs, adapters, etc.) 669// C: C/C++ frame 670// 671// We don't need detailed frame type as that in frame::print_name(). "C" 672// suggests the problem is in user lib; everything else is likely a VM bug. 673 674void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const { 675 if (_cb != NULL) { 676 if (Interpreter::contains(pc())) { 677 methodOop m = this->interpreter_frame_method(); 678 if (m != NULL) { 679 m->name_and_sig_as_C_string(buf, buflen); 680 st->print("j %s", buf); 681 st->print("+%d", this->interpreter_frame_bci()); 682 } else { 683 st->print("j " PTR_FORMAT, pc()); 684 } 685 } else if (StubRoutines::contains(pc())) { 686 StubCodeDesc* desc = StubCodeDesc::desc_for(pc()); 687 if (desc != NULL) { 688 st->print("v ~StubRoutines::%s", desc->name()); 689 } else { 690 st->print("v ~StubRoutines::" PTR_FORMAT, pc()); 691 } 692 } else if (_cb->is_buffer_blob()) { 693 st->print("v ~BufferBlob::%s", ((BufferBlob *)_cb)->name()); 694 } else if (_cb->is_nmethod()) { 695 methodOop m = ((nmethod *)_cb)->method(); 696 if (m != NULL) { 697 m->name_and_sig_as_C_string(buf, buflen); 698 st->print("J %s", buf); 699 } else { 700 st->print("J " PTR_FORMAT, pc()); 701 } 702 } else if (_cb->is_runtime_stub()) { 703 st->print("v ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name()); 704 } else if (_cb->is_deoptimization_stub()) { 705 st->print("v ~DeoptimizationBlob"); 706 } else if (_cb->is_exception_stub()) { 707 st->print("v ~ExceptionBlob"); 708 } else if (_cb->is_safepoint_stub()) { 709 st->print("v ~SafepointBlob"); 710 } else { 711 st->print("v blob " PTR_FORMAT, pc()); 712 } 713 } else { 714 print_C_frame(st, buf, buflen, pc()); 715 } 716} 717 718 719/* 720 The interpreter_frame_expression_stack_at method in the case of SPARC needs the 721 max_stack value of the method in order to compute the expression stack address. 722 It uses the methodOop in order to get the max_stack value but during GC this 723 methodOop value saved on the frame is changed by reverse_and_push and hence cannot 724 be used. So we save the max_stack value in the FrameClosure object and pass it 725 down to the interpreter_frame_expression_stack_at method 726*/ 727class InterpreterFrameClosure : public OffsetClosure { 728 private: 729 frame* _fr; 730 OopClosure* _f; 731 int _max_locals; 732 int _max_stack; 733 734 public: 735 InterpreterFrameClosure(frame* fr, int max_locals, int max_stack, 736 OopClosure* f) { 737 _fr = fr; 738 _max_locals = max_locals; 739 _max_stack = max_stack; 740 _f = f; 741 } 742 743 void offset_do(int offset) { 744 oop* addr; 745 if (offset < _max_locals) { 746 addr = (oop*) _fr->interpreter_frame_local_at(offset); 747 assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame"); 748 _f->do_oop(addr); 749 } else { 750 addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals)); 751 // In case of exceptions, the expression stack is invalid and the esp will be reset to express 752 // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel). 753 bool in_stack; 754 if (frame::interpreter_frame_expression_stack_direction() > 0) { 755 in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address(); 756 } else { 757 in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address(); 758 } 759 if (in_stack) { 760 _f->do_oop(addr); 761 } 762 } 763 } 764 765 int max_locals() { return _max_locals; } 766 frame* fr() { return _fr; } 767}; 768 769 770class InterpretedArgumentOopFinder: public SignatureInfo { 771 private: 772 OopClosure* _f; // Closure to invoke 773 int _offset; // TOS-relative offset, decremented with each argument 774 bool _has_receiver; // true if the callee has a receiver 775 frame* _fr; 776 777 void set(int size, BasicType type) { 778 _offset -= size; 779 if (type == T_OBJECT || type == T_ARRAY) oop_offset_do(); 780 } 781 782 void oop_offset_do() { 783 oop* addr; 784 addr = (oop*)_fr->interpreter_frame_tos_at(_offset); 785 _f->do_oop(addr); 786 } 787 788 public: 789 InterpretedArgumentOopFinder(symbolHandle signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) { 790 // compute size of arguments 791 int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0); 792 assert(!fr->is_interpreted_frame() || 793 args_size <= fr->interpreter_frame_expression_stack_size(), 794 "args cannot be on stack anymore"); 795 // initialize InterpretedArgumentOopFinder 796 _f = f; 797 _fr = fr; 798 _offset = args_size; 799 } 800 801 void oops_do() { 802 if (_has_receiver) { 803 --_offset; 804 oop_offset_do(); 805 } 806 iterate_parameters(); 807 } 808}; 809 810 811// Entry frame has following form (n arguments) 812// +-----------+ 813// sp -> | last arg | 814// +-----------+ 815// : ::: : 816// +-----------+ 817// (sp+n)->| first arg| 818// +-----------+ 819 820 821 822// visits and GC's all the arguments in entry frame 823class EntryFrameOopFinder: public SignatureInfo { 824 private: 825 bool _is_static; 826 int _offset; 827 frame* _fr; 828 OopClosure* _f; 829 830 void set(int size, BasicType type) { 831 assert (_offset >= 0, "illegal offset"); 832 if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset); 833 _offset -= size; 834 } 835 836 void oop_at_offset_do(int offset) { 837 assert (offset >= 0, "illegal offset") 838 oop* addr = (oop*) _fr->entry_frame_argument_at(offset); 839 _f->do_oop(addr); 840 } 841 842 public: 843 EntryFrameOopFinder(frame* frame, symbolHandle signature, bool is_static) : SignatureInfo(signature) { 844 _f = NULL; // will be set later 845 _fr = frame; 846 _is_static = is_static; 847 _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0 848 } 849 850 void arguments_do(OopClosure* f) { 851 _f = f; 852 if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver 853 iterate_parameters(); 854 } 855 856}; 857 858oop* frame::interpreter_callee_receiver_addr(symbolHandle signature) { 859 ArgumentSizeComputer asc(signature); 860 int size = asc.size(); 861 return (oop *)interpreter_frame_tos_at(size); 862} 863 864 865void frame::oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) { 866 assert(is_interpreted_frame(), "Not an interpreted frame"); 867 assert(map != NULL, "map must be set"); 868 Thread *thread = Thread::current(); 869 methodHandle m (thread, interpreter_frame_method()); 870 jint bci = interpreter_frame_bci(); 871 872 assert(Universe::heap()->is_in(m()), "must be valid oop"); 873 assert(m->is_method(), "checking frame value"); 874 assert((m->is_native() && bci == 0) || (!m->is_native() && bci >= 0 && bci < m->code_size()), "invalid bci value"); 875 876 // Handle the monitor elements in the activation 877 for ( 878 BasicObjectLock* current = interpreter_frame_monitor_end(); 879 current < interpreter_frame_monitor_begin(); 880 current = next_monitor_in_interpreter_frame(current) 881 ) { 882#ifdef ASSERT 883 interpreter_frame_verify_monitor(current); 884#endif 885 current->oops_do(f); 886 } 887 888 // process fixed part 889 f->do_oop((oop*)interpreter_frame_method_addr()); 890 f->do_oop((oop*)interpreter_frame_cache_addr()); 891 892 // Hmm what about the mdp? 893#ifdef CC_INTERP 894 // Interpreter frame in the midst of a call have a methodOop within the 895 // object. 896 interpreterState istate = get_interpreterState(); 897 if (istate->msg() == BytecodeInterpreter::call_method) { 898 f->do_oop((oop*)&istate->_result._to_call._callee); 899 } 900 901#endif /* CC_INTERP */ 902 903 if (m->is_native()) { 904#ifdef CC_INTERP 905 f->do_oop((oop*)&istate->_oop_temp); 906#else 907 f->do_oop((oop*)( fp() + interpreter_frame_oop_temp_offset )); 908#endif /* CC_INTERP */ 909 } 910 911 int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); 912 913 symbolHandle signature; 914 bool has_receiver = false; 915 916 // Process a callee's arguments if we are at a call site 917 // (i.e., if we are at an invoke bytecode) 918 // This is used sometimes for calling into the VM, not for another 919 // interpreted or compiled frame. 920 if (!m->is_native()) { 921 Bytecode_invoke *call = Bytecode_invoke_at_check(m, bci); 922 if (call != NULL) { 923 signature = symbolHandle(thread, call->signature()); 924 has_receiver = call->has_receiver(); 925 if (map->include_argument_oops() && 926 interpreter_frame_expression_stack_size() > 0) { 927 ResourceMark rm(thread); // is this right ??? 928 // we are at a call site & the expression stack is not empty 929 // => process callee's arguments 930 // 931 // Note: The expression stack can be empty if an exception 932 // occurred during method resolution/execution. In all 933 // cases we empty the expression stack completely be- 934 // fore handling the exception (the exception handling 935 // code in the interpreter calls a blocking runtime 936 // routine which can cause this code to be executed). 937 // (was bug gri 7/27/98) 938 oops_interpreted_arguments_do(signature, has_receiver, f); 939 } 940 } 941 } 942 943 if (TaggedStackInterpreter) { 944 // process locals & expression stack 945 InterpreterOopMap *mask = NULL; 946#ifdef ASSERT 947 InterpreterOopMap oopmap_mask; 948 OopMapCache::compute_one_oop_map(m, bci, &oopmap_mask); 949 mask = &oopmap_mask; 950#endif // ASSERT 951 oops_interpreted_locals_do(f, max_locals, mask); 952 oops_interpreted_expressions_do(f, signature, has_receiver, 953 m->max_stack(), 954 max_locals, mask); 955 } else { 956 InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f); 957 958 // process locals & expression stack 959 InterpreterOopMap mask; 960 if (query_oop_map_cache) { 961 m->mask_for(bci, &mask); 962 } else { 963 OopMapCache::compute_one_oop_map(m, bci, &mask); 964 } 965 mask.iterate_oop(&blk); 966 } 967} 968 969 970void frame::oops_interpreted_locals_do(OopClosure *f, 971 int max_locals, 972 InterpreterOopMap *mask) { 973 // Process locals then interpreter expression stack 974 for (int i = 0; i < max_locals; i++ ) { 975 Tag tag = interpreter_frame_local_tag(i); 976 if (tag == TagReference) { 977 oop* addr = (oop*) interpreter_frame_local_at(i); 978 assert((intptr_t*)addr >= sp(), "must be inside the frame"); 979 f->do_oop(addr); 980#ifdef ASSERT 981 } else { 982 assert(tag == TagValue, "bad tag value for locals"); 983 oop* p = (oop*) interpreter_frame_local_at(i); 984 // Not always true - too bad. May have dead oops without tags in locals. 985 // assert(*p == NULL || !(*p)->is_oop(), "oop not tagged on interpreter locals"); 986 assert(*p == NULL || !mask->is_oop(i), "local oop map mismatch"); 987#endif // ASSERT 988 } 989 } 990} 991 992void frame::oops_interpreted_expressions_do(OopClosure *f, 993 symbolHandle signature, 994 bool has_receiver, 995 int max_stack, 996 int max_locals, 997 InterpreterOopMap *mask) { 998 // There is no stack no matter what the esp is pointing to (native methods 999 // might look like expression stack is nonempty). 1000 if (max_stack == 0) return; 1001 1002 // Point the top of the expression stack above arguments to a call so 1003 // arguments aren't gc'ed as both stack values for callee and callee 1004 // arguments in callee's locals. 1005 int args_size = 0; 1006 if (!signature.is_null()) { 1007 args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0); 1008 } 1009 1010 intptr_t *tos_addr = interpreter_frame_tos_at(args_size); 1011 assert(args_size != 0 || tos_addr == interpreter_frame_tos_address(), "these are same"); 1012 intptr_t *frst_expr = interpreter_frame_expression_stack_at(0); 1013 // In case of exceptions, the expression stack is invalid and the esp 1014 // will be reset to express this condition. Therefore, we call f only 1015 // if addr is 'inside' the stack (i.e., addr >= esp for Intel). 1016 bool in_stack; 1017 if (interpreter_frame_expression_stack_direction() > 0) { 1018 in_stack = (intptr_t*)frst_expr <= tos_addr; 1019 } else { 1020 in_stack = (intptr_t*)frst_expr >= tos_addr; 1021 } 1022 if (!in_stack) return; 1023 1024 jint stack_size = interpreter_frame_expression_stack_size() - args_size; 1025 for (int j = 0; j < stack_size; j++) { 1026 Tag tag = interpreter_frame_expression_stack_tag(j); 1027 if (tag == TagReference) { 1028 oop *addr = (oop*) interpreter_frame_expression_stack_at(j); 1029 f->do_oop(addr); 1030#ifdef ASSERT 1031 } else { 1032 assert(tag == TagValue, "bad tag value for stack element"); 1033 oop *p = (oop*) interpreter_frame_expression_stack_at((j)); 1034 assert(*p == NULL || !mask->is_oop(j+max_locals), "stack oop map mismatch"); 1035#endif // ASSERT 1036 } 1037 } 1038} 1039 1040void frame::oops_interpreted_arguments_do(symbolHandle signature, bool has_receiver, OopClosure* f) { 1041 InterpretedArgumentOopFinder finder(signature, has_receiver, this, f); 1042 finder.oops_do(); 1043} 1044 1045void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) { 1046 assert(_cb != NULL, "sanity check"); 1047 if (_cb->oop_maps() != NULL) { 1048 OopMapSet::oops_do(this, reg_map, f); 1049 1050 // Preserve potential arguments for a callee. We handle this by dispatching 1051 // on the codeblob. For c2i, we do 1052 if (reg_map->include_argument_oops()) { 1053 _cb->preserve_callee_argument_oops(*this, reg_map, f); 1054 } 1055 } 1056 // In cases where perm gen is collected, GC will want to mark 1057 // oops referenced from nmethods active on thread stacks so as to 1058 // prevent them from being collected. However, this visit should be 1059 // restricted to certain phases of the collection only. The 1060 // closure decides how it wants nmethods to be traced. 1061 if (cf != NULL) 1062 cf->do_code_blob(_cb); 1063} 1064 1065class CompiledArgumentOopFinder: public SignatureInfo { 1066 protected: 1067 OopClosure* _f; 1068 int _offset; // the current offset, incremented with each argument 1069 bool _has_receiver; // true if the callee has a receiver 1070 frame _fr; 1071 RegisterMap* _reg_map; 1072 int _arg_size; 1073 VMRegPair* _regs; // VMReg list of arguments 1074 1075 void set(int size, BasicType type) { 1076 if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset(); 1077 _offset += size; 1078 } 1079 1080 virtual void handle_oop_offset() { 1081 // Extract low order register number from register array. 1082 // In LP64-land, the high-order bits are valid but unhelpful. 1083 VMReg reg = _regs[_offset].first(); 1084 oop *loc = _fr.oopmapreg_to_location(reg, _reg_map); 1085 _f->do_oop(loc); 1086 } 1087 1088 public: 1089 CompiledArgumentOopFinder(symbolHandle signature, bool has_receiver, OopClosure* f, frame fr, const RegisterMap* reg_map) 1090 : SignatureInfo(signature) { 1091 1092 // initialize CompiledArgumentOopFinder 1093 _f = f; 1094 _offset = 0; 1095 _has_receiver = has_receiver; 1096 _fr = fr; 1097 _reg_map = (RegisterMap*)reg_map; 1098 _arg_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0); 1099 1100 int arg_size; 1101 _regs = SharedRuntime::find_callee_arguments(signature(), has_receiver, &arg_size); 1102 assert(arg_size == _arg_size, "wrong arg size"); 1103 } 1104 1105 void oops_do() { 1106 if (_has_receiver) { 1107 handle_oop_offset(); 1108 _offset++; 1109 } 1110 iterate_parameters(); 1111 } 1112}; 1113 1114void frame::oops_compiled_arguments_do(symbolHandle signature, bool has_receiver, const RegisterMap* reg_map, OopClosure* f) { 1115 ResourceMark rm; 1116 CompiledArgumentOopFinder finder(signature, has_receiver, f, *this, reg_map); 1117 finder.oops_do(); 1118} 1119 1120 1121// Get receiver out of callers frame, i.e. find parameter 0 in callers 1122// frame. Consult ADLC for where parameter 0 is to be found. Then 1123// check local reg_map for it being a callee-save register or argument 1124// register, both of which are saved in the local frame. If not found 1125// there, it must be an in-stack argument of the caller. 1126// Note: caller.sp() points to callee-arguments 1127oop frame::retrieve_receiver(RegisterMap* reg_map) { 1128 frame caller = *this; 1129 1130 // First consult the ADLC on where it puts parameter 0 for this signature. 1131 VMReg reg = SharedRuntime::name_for_receiver(); 1132 oop r = *caller.oopmapreg_to_location(reg, reg_map); 1133 assert( Universe::heap()->is_in_or_null(r), "bad receiver" ); 1134 return r; 1135} 1136 1137 1138oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const { 1139 if(reg->is_reg()) { 1140 // If it is passed in a register, it got spilled in the stub frame. 1141 return (oop *)reg_map->location(reg); 1142 } else { 1143 int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size; 1144 return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes); 1145 } 1146} 1147 1148BasicLock* frame::compiled_synchronized_native_monitor(nmethod* nm) { 1149 if (nm == NULL) { 1150 assert(_cb != NULL && _cb->is_nmethod() && 1151 nm->method()->is_native() && 1152 nm->method()->is_synchronized(), 1153 "should not call this otherwise"); 1154 nm = (nmethod*) _cb; 1155 } 1156 int byte_offset = in_bytes(nm->compiled_synchronized_native_basic_lock_sp_offset()); 1157 assert(byte_offset >= 0, "should not see invalid offset"); 1158 return (BasicLock*) &sp()[byte_offset / wordSize]; 1159} 1160 1161oop frame::compiled_synchronized_native_monitor_owner(nmethod* nm) { 1162 if (nm == NULL) { 1163 assert(_cb != NULL && _cb->is_nmethod() && 1164 nm->method()->is_native() && 1165 nm->method()->is_synchronized(), 1166 "should not call this otherwise"); 1167 nm = (nmethod*) _cb; 1168 } 1169 int byte_offset = in_bytes(nm->compiled_synchronized_native_basic_lock_owner_sp_offset()); 1170 assert(byte_offset >= 0, "should not see invalid offset"); 1171 oop owner = ((oop*) sp())[byte_offset / wordSize]; 1172 assert( Universe::heap()->is_in(owner), "bad receiver" ); 1173 return owner; 1174} 1175 1176void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) { 1177 assert(map != NULL, "map must be set"); 1178 if (map->include_argument_oops()) { 1179 // must collect argument oops, as nobody else is doing it 1180 Thread *thread = Thread::current(); 1181 methodHandle m (thread, entry_frame_call_wrapper()->callee_method()); 1182 symbolHandle signature (thread, m->signature()); 1183 EntryFrameOopFinder finder(this, signature, m->is_static()); 1184 finder.arguments_do(f); 1185 } 1186 // Traverse the Handle Block saved in the entry frame 1187 entry_frame_call_wrapper()->oops_do(f); 1188} 1189 1190 1191void frame::oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) { 1192 if (is_interpreted_frame()) { oops_interpreted_do(f, map, use_interpreter_oop_map_cache); 1193 } else if (is_entry_frame()) { oops_entry_do (f, map); 1194 } else if (CodeCache::contains(pc())) { oops_code_blob_do (f, cf, map); 1195 } else { 1196 ShouldNotReachHere(); 1197 } 1198} 1199 1200void frame::nmethods_do(CodeBlobClosure* cf) { 1201 if (_cb != NULL && _cb->is_nmethod()) { 1202 cf->do_code_blob(_cb); 1203 } 1204} 1205 1206 1207void frame::gc_prologue() { 1208 if (is_interpreted_frame()) { 1209 // set bcx to bci to become methodOop position independent during GC 1210 interpreter_frame_set_bcx(interpreter_frame_bci()); 1211 } 1212} 1213 1214 1215void frame::gc_epilogue() { 1216 if (is_interpreted_frame()) { 1217 // set bcx back to bcp for interpreter 1218 interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp()); 1219 } 1220 // call processor specific epilog function 1221 pd_gc_epilog(); 1222} 1223 1224 1225# ifdef ENABLE_ZAP_DEAD_LOCALS 1226 1227void frame::CheckValueClosure::do_oop(oop* p) { 1228 if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) { 1229 warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); 1230 } 1231} 1232frame::CheckValueClosure frame::_check_value; 1233 1234 1235void frame::CheckOopClosure::do_oop(oop* p) { 1236 if (*p != NULL && !(*p)->is_oop()) { 1237 warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current()); 1238 } 1239} 1240frame::CheckOopClosure frame::_check_oop; 1241 1242void frame::check_derived_oop(oop* base, oop* derived) { 1243 _check_oop.do_oop(base); 1244} 1245 1246 1247void frame::ZapDeadClosure::do_oop(oop* p) { 1248 if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p); 1249 // Need cast because on _LP64 the conversion to oop is ambiguous. Constant 1250 // can be either long or int. 1251 *p = (oop)(int)0xbabebabe; 1252} 1253frame::ZapDeadClosure frame::_zap_dead; 1254 1255void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) { 1256 assert(thread == Thread::current(), "need to synchronize to do this to another thread"); 1257 // Tracing - part 1 1258 if (TraceZapDeadLocals) { 1259 ResourceMark rm(thread); 1260 tty->print_cr("--------------------------------------------------------------------------------"); 1261 tty->print("Zapping dead locals in "); 1262 print_on(tty); 1263 tty->cr(); 1264 } 1265 // Zapping 1266 if (is_entry_frame ()) zap_dead_entry_locals (thread, map); 1267 else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map); 1268 else if (is_compiled_frame()) zap_dead_compiled_locals (thread, map); 1269 1270 else 1271 // could be is_runtime_frame 1272 // so remove error: ShouldNotReachHere(); 1273 ; 1274 // Tracing - part 2 1275 if (TraceZapDeadLocals) { 1276 tty->cr(); 1277 } 1278} 1279 1280 1281void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) { 1282 // get current interpreter 'pc' 1283 assert(is_interpreted_frame(), "Not an interpreted frame"); 1284 methodOop m = interpreter_frame_method(); 1285 int bci = interpreter_frame_bci(); 1286 1287 int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals(); 1288 1289 if (TaggedStackInterpreter) { 1290 InterpreterOopMap *mask = NULL; 1291#ifdef ASSERT 1292 InterpreterOopMap oopmap_mask; 1293 methodHandle method(thread, m); 1294 OopMapCache::compute_one_oop_map(method, bci, &oopmap_mask); 1295 mask = &oopmap_mask; 1296#endif // ASSERT 1297 oops_interpreted_locals_do(&_check_oop, max_locals, mask); 1298 } else { 1299 // process dynamic part 1300 InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(), 1301 &_check_value); 1302 InterpreterFrameClosure oop_blk(this, max_locals, m->max_stack(), 1303 &_check_oop ); 1304 InterpreterFrameClosure dead_blk(this, max_locals, m->max_stack(), 1305 &_zap_dead ); 1306 1307 // get frame map 1308 InterpreterOopMap mask; 1309 m->mask_for(bci, &mask); 1310 mask.iterate_all( &oop_blk, &value_blk, &dead_blk); 1311 } 1312} 1313 1314 1315void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) { 1316 1317 ResourceMark rm(thread); 1318 assert(_cb != NULL, "sanity check"); 1319 if (_cb->oop_maps() != NULL) { 1320 OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value); 1321 } 1322} 1323 1324 1325void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) { 1326 if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented"); 1327} 1328 1329 1330void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) { 1331 if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented"); 1332} 1333 1334# endif // ENABLE_ZAP_DEAD_LOCALS 1335 1336void frame::verify(const RegisterMap* map) { 1337 // for now make sure receiver type is correct 1338 if (is_interpreted_frame()) { 1339 methodOop method = interpreter_frame_method(); 1340 guarantee(method->is_method(), "method is wrong in frame::verify"); 1341 if (!method->is_static()) { 1342 // fetch the receiver 1343 oop* p = (oop*) interpreter_frame_local_at(0); 1344 // make sure we have the right receiver type 1345 } 1346 } 1347 COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");) 1348 oops_do_internal(&VerifyOopClosure::verify_oop, NULL, (RegisterMap*)map, false); 1349} 1350 1351 1352#ifdef ASSERT 1353bool frame::verify_return_pc(address x) { 1354 if (StubRoutines::returns_to_call_stub(x)) { 1355 return true; 1356 } 1357 if (CodeCache::contains(x)) { 1358 return true; 1359 } 1360 if (Interpreter::contains(x)) { 1361 return true; 1362 } 1363 return false; 1364} 1365#endif 1366 1367 1368#ifdef ASSERT 1369void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const { 1370 assert(is_interpreted_frame(), "Not an interpreted frame"); 1371 // verify that the value is in the right part of the frame 1372 address low_mark = (address) interpreter_frame_monitor_end(); 1373 address high_mark = (address) interpreter_frame_monitor_begin(); 1374 address current = (address) value; 1375 1376 const int monitor_size = frame::interpreter_frame_monitor_size(); 1377 guarantee((high_mark - current) % monitor_size == 0 , "Misaligned top of BasicObjectLock*"); 1378 guarantee( high_mark > current , "Current BasicObjectLock* higher than high_mark"); 1379 1380 guarantee((current - low_mark) % monitor_size == 0 , "Misaligned bottom of BasicObjectLock*"); 1381 guarantee( current >= low_mark , "Current BasicObjectLock* below than low_mark"); 1382} 1383#endif 1384 1385 1386//----------------------------------------------------------------------------------- 1387// StackFrameStream implementation 1388 1389StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) { 1390 assert(thread->has_last_Java_frame(), "sanity check"); 1391 _fr = thread->last_frame(); 1392 _is_done = false; 1393} 1394