131 return false; 132 } 133 134 sender_pc = (address) this->fp()[return_addr_offset]; 135 sender_sp = (intptr_t*) addr_at(sender_sp_offset); 136 137 } else { 138 // must be some sort of compiled/runtime frame 139 // fp does not have to be safe (although it could be check for c1?) 140 141 // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc 142 if (_cb->frame_size() <= 0) { 143 return false; 144 } 145 146 sender_sp = _unextended_sp + _cb->frame_size(); 147 // On Intel the return_address is always the word on the stack 148 sender_pc = (address) *(sender_sp-1); 149 } 150 151 152 // If the potential sender is the interpreter then we can do some more checking 153 if (Interpreter::contains(sender_pc)) { 154 155 // ebp is always saved in a recognizable place in any code we generate. However 156 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp 157 // is really a frame pointer. 158 159 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); 160 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); 161 162 if (!saved_fp_safe) { 163 return false; 164 } 165 166 // construct the potential sender 167 168 frame sender(sender_sp, saved_fp, sender_pc); 169 170 return sender.is_interpreted_frame_valid(thread); 171 172 } 173 174 // We must always be able to find a recognizable pc 175 CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); 176 if (sender_pc == NULL || sender_blob == NULL) { 177 return false; 178 } 179 180 // Could be a zombie method 181 if (sender_blob->is_zombie() || sender_blob->is_unloaded()) { 182 return false; 183 } 184 185 // Could just be some random pointer within the codeBlob 186 if (!sender_blob->code_contains(sender_pc)) { 187 return false; 188 } 189 190 // We should never be able to see an adapter if the current frame is something from code cache 191 if (sender_blob->is_adapter_blob()) { 192 return false; 193 } 194 195 // Could be the call_stub 196 if (StubRoutines::returns_to_call_stub(sender_pc)) { 197 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); 198 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); 199 200 if (!saved_fp_safe) { 201 return false; 202 } 203 204 // construct the potential sender 205 206 frame sender(sender_sp, saved_fp, sender_pc); 207 208 // Validate the JavaCallWrapper an entry frame must have 209 address jcw = (address)sender.entry_frame_call_wrapper(); 210 211 bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp()); 212 213 return jcw_safe; 214 } 215 216 if (sender_blob->is_nmethod()) { 217 nmethod* nm = sender_blob->as_nmethod_or_null(); 218 if (nm != NULL) { 219 if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) || 220 nm->method()->is_method_handle_intrinsic()) { 221 return false; 222 } 223 } 224 } 225 226 // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size 257 } 258 259 // Will the pc we fetch be non-zero (which we'll find at the oldest frame) 260 261 if ( (address) this->fp()[return_addr_offset] == NULL) return false; 262 263 264 // could try and do some more potential verification of native frame if we could think of some... 265 266 return true; 267 268 } 269 270 271 void frame::patch_pc(Thread* thread, address pc) { 272 address* pc_addr = &(((address*) sp())[-1]); 273 if (TracePcPatching) { 274 tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]", 275 pc_addr, *pc_addr, pc); 276 } 277 // Either the return address is the original one or we are going to 278 // patch in the same address that's already there. 279 assert(_pc == *pc_addr || pc == *pc_addr, "must be"); 280 *pc_addr = pc; 281 _cb = CodeCache::find_blob(pc); 282 address original_pc = nmethod::get_deopt_original_pc(this); 283 if (original_pc != NULL) { 284 assert(original_pc == _pc, "expected original PC to be stored before patching"); 285 _deopt_state = is_deoptimized; 286 // leave _pc as is 287 } else { 288 _deopt_state = not_deoptimized; 289 _pc = pc; 290 } 291 } 292 293 bool frame::is_interpreted_frame() const { 294 return Interpreter::contains(pc()); 295 } 296 356 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { 357 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value; 358 } 359 360 // Used by template based interpreter deoptimization 361 void frame::interpreter_frame_set_last_sp(intptr_t* sp) { 362 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp; 363 } 364 #endif // CC_INTERP 365 366 frame frame::sender_for_entry_frame(RegisterMap* map) const { 367 assert(map != NULL, "map must be set"); 368 // Java frame called from C; skip all C frames and return top C 369 // frame of that chunk as the sender 370 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 371 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 372 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); 373 map->clear(); 374 assert(map->include_argument_oops(), "should be set by clear"); 375 if (jfa->last_Java_pc() != NULL ) { 376 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); 377 return fr; 378 } 379 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp()); 380 return fr; 381 } 382 383 //------------------------------------------------------------------------------ 384 // frame::verify_deopt_original_pc 385 // 386 // Verifies the calculated original PC of a deoptimization PC for the 387 // given unextended SP. 388 #ifdef ASSERT 389 void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp) { 390 frame fr; 391 392 // This is ugly but it's better than to change {get,set}_original_pc 393 // to take an SP value as argument. And it's only a debugging 394 // method anyway. 395 fr._unextended_sp = unextended_sp; 396 397 address original_pc = nm->get_original_pc(&fr); 398 assert(nm->insts_contains(original_pc), "original PC must be in nmethod"); 399 } 439 #endif // AMD64 440 } 441 442 443 //------------------------------------------------------------------------------ 444 // frame::sender_for_interpreter_frame 445 frame frame::sender_for_interpreter_frame(RegisterMap* map) const { 446 // SP is the raw SP from the sender after adapter or interpreter 447 // extension. 448 intptr_t* sender_sp = this->sender_sp(); 449 450 // This is the sp before any possible extension (adapter/locals). 451 intptr_t* unextended_sp = interpreter_frame_sender_sp(); 452 453 #ifdef COMPILER2 454 if (map->update_map()) { 455 update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset)); 456 } 457 #endif // COMPILER2 458 459 return frame(sender_sp, unextended_sp, link(), sender_pc()); 460 } 461 462 463 //------------------------------------------------------------------------------ 464 // frame::sender_for_compiled_frame 465 frame frame::sender_for_compiled_frame(RegisterMap* map) const { 466 assert(map != NULL, "map must be set"); 467 468 // frame owned by optimizing compiler 469 assert(_cb->frame_size() >= 0, "must have non-zero frame size"); 470 intptr_t* sender_sp = unextended_sp() + _cb->frame_size(); 471 intptr_t* unextended_sp = sender_sp; 472 473 // On Intel the return_address is always the word on the stack 474 address sender_pc = (address) *(sender_sp-1); 475 476 // This is the saved value of EBP which may or may not really be an FP. 477 // It is only an FP if the sender is an interpreter frame (or C1?). 478 intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset); 479 480 if (map->update_map()) { 481 // Tell GC to use argument oopmaps for some runtime stubs that need it. 482 // For C1, the runtime stub might not have oop maps, so set this flag 483 // outside of update_register_map. 484 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); 485 if (_cb->oop_maps() != NULL) { 486 OopMapSet::update_register_map(this, map); 487 } 488 489 // Since the prolog does the save and restore of EBP there is no oopmap 490 // for it so we must fill in its location as if there was an oopmap entry 491 // since if our caller was compiled code there could be live jvm state in it. 492 update_map_with_saved_link(map, saved_fp_addr); 493 } 494 495 assert(sender_sp != sp(), "must have changed"); 496 return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc); 497 } 498 499 500 //------------------------------------------------------------------------------ 501 // frame::sender 502 frame frame::sender(RegisterMap* map) const { 503 // Default is we done have to follow them. The sender_for_xxx will 504 // update it accordingly 505 map->set_include_argument_oops(false); 506 507 if (is_entry_frame()) return sender_for_entry_frame(map); 508 if (is_interpreted_frame()) return sender_for_interpreter_frame(map); 509 assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); 510 511 if (_cb != NULL) { 512 return sender_for_compiled_frame(map); 513 } 514 // Must be native-compiled frame, i.e. the marshaling code for native 515 // methods that exists in the core system. 516 return frame(sender_sp(), link(), sender_pc()); 517 } 518 519 520 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) { 521 assert(is_interpreted_frame(), "must be interpreter frame"); 522 Method* method = interpreter_frame_method(); 523 // When unpacking an optimized frame the frame pointer is 524 // adjusted with: 525 int diff = (method->max_locals() - method->size_of_parameters()) * 526 Interpreter::stackElementWords; 527 return _fp == (fp - diff); 528 } 529 530 void frame::pd_gc_epilog() { 531 // nothing done here now 532 } 533 534 bool frame::is_interpreted_frame_valid(JavaThread* thread) const { 535 // QQQ 536 #ifdef CC_INTERP 693 intptr_t *frame::initial_deoptimization_info() { 694 // used to reset the saved FP 695 return fp(); 696 } 697 698 intptr_t* frame::real_fp() const { 699 if (_cb != NULL) { 700 // use the frame size if valid 701 int size = _cb->frame_size(); 702 if (size > 0) { 703 return unextended_sp() + size; 704 } 705 } 706 // else rely on fp() 707 assert(! is_compiled_frame(), "unknown compiled frame size"); 708 return fp(); 709 } 710 711 #ifndef PRODUCT 712 // This is a generic constructor which is only used by pns() in debug.cpp. 713 frame::frame(void* sp, void* fp, void* pc) { 714 init((intptr_t*)sp, (intptr_t*)fp, (address)pc); 715 } 716 #endif | 131 return false; 132 } 133 134 sender_pc = (address) this->fp()[return_addr_offset]; 135 sender_sp = (intptr_t*) addr_at(sender_sp_offset); 136 137 } else { 138 // must be some sort of compiled/runtime frame 139 // fp does not have to be safe (although it could be check for c1?) 140 141 // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc 142 if (_cb->frame_size() <= 0) { 143 return false; 144 } 145 146 sender_sp = _unextended_sp + _cb->frame_size(); 147 // On Intel the return_address is always the word on the stack 148 sender_pc = (address) *(sender_sp-1); 149 } 150 151 if (SharedRuntime::is_memento_stack_trace_return_handler(sender_pc)) { 152 sender_pc = thread->memento_original_return_address(); 153 } 154 155 156 // If the potential sender is the interpreter then we can do some more checking 157 if (Interpreter::contains(sender_pc)) { 158 159 // ebp is always saved in a recognizable place in any code we generate. However 160 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp 161 // is really a frame pointer. 162 163 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); 164 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); 165 166 if (!saved_fp_safe) { 167 return false; 168 } 169 170 // construct the potential sender 171 172 frame sender(thread, sender_sp, saved_fp, sender_pc); 173 174 return sender.is_interpreted_frame_valid(thread); 175 176 } 177 178 // We must always be able to find a recognizable pc 179 CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); 180 if (sender_pc == NULL || sender_blob == NULL) { 181 return false; 182 } 183 184 // Could be a zombie method 185 if (sender_blob->is_zombie() || sender_blob->is_unloaded()) { 186 return false; 187 } 188 189 // Could just be some random pointer within the codeBlob 190 if (!sender_blob->code_contains(sender_pc)) { 191 return false; 192 } 193 194 // We should never be able to see an adapter if the current frame is something from code cache 195 if (sender_blob->is_adapter_blob()) { 196 return false; 197 } 198 199 // Could be the call_stub 200 if (StubRoutines::returns_to_call_stub(sender_pc)) { 201 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); 202 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); 203 204 if (!saved_fp_safe) { 205 return false; 206 } 207 208 // construct the potential sender 209 210 frame sender(thread, sender_sp, saved_fp, sender_pc); 211 212 // Validate the JavaCallWrapper an entry frame must have 213 address jcw = (address)sender.entry_frame_call_wrapper(); 214 215 bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp()); 216 217 return jcw_safe; 218 } 219 220 if (sender_blob->is_nmethod()) { 221 nmethod* nm = sender_blob->as_nmethod_or_null(); 222 if (nm != NULL) { 223 if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) || 224 nm->method()->is_method_handle_intrinsic()) { 225 return false; 226 } 227 } 228 } 229 230 // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size 261 } 262 263 // Will the pc we fetch be non-zero (which we'll find at the oldest frame) 264 265 if ( (address) this->fp()[return_addr_offset] == NULL) return false; 266 267 268 // could try and do some more potential verification of native frame if we could think of some... 269 270 return true; 271 272 } 273 274 275 void frame::patch_pc(Thread* thread, address pc) { 276 address* pc_addr = &(((address*) sp())[-1]); 277 if (TracePcPatching) { 278 tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]", 279 pc_addr, *pc_addr, pc); 280 } 281 assert(!SharedRuntime::is_memento_stack_trace_return_handler(pc), "new return address must not be memento return handler"); 282 if (SharedRuntime::is_memento_stack_trace_return_handler(*pc_addr)) { 283 pc_addr = &(thread->memento_original_return_address()); 284 assert(*pc_addr != NULL, "memento original return address must be set"); 285 } 286 // Either the return address is the original one or we are going to 287 // patch in the same address that's already there. 288 assert(_pc == *pc_addr || pc == *pc_addr, "must be"); 289 *pc_addr = pc; 290 _cb = CodeCache::find_blob(pc); 291 address original_pc = nmethod::get_deopt_original_pc(this); 292 if (original_pc != NULL) { 293 assert(original_pc == _pc, "expected original PC to be stored before patching"); 294 _deopt_state = is_deoptimized; 295 // leave _pc as is 296 } else { 297 _deopt_state = not_deoptimized; 298 _pc = pc; 299 } 300 } 301 302 bool frame::is_interpreted_frame() const { 303 return Interpreter::contains(pc()); 304 } 305 365 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { 366 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value; 367 } 368 369 // Used by template based interpreter deoptimization 370 void frame::interpreter_frame_set_last_sp(intptr_t* sp) { 371 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp; 372 } 373 #endif // CC_INTERP 374 375 frame frame::sender_for_entry_frame(RegisterMap* map) const { 376 assert(map != NULL, "map must be set"); 377 // Java frame called from C; skip all C frames and return top C 378 // frame of that chunk as the sender 379 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 380 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 381 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); 382 map->clear(); 383 assert(map->include_argument_oops(), "should be set by clear"); 384 if (jfa->last_Java_pc() != NULL ) { 385 frame fr(map->thread(), jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); 386 return fr; 387 } 388 frame fr(map->thread(), jfa->last_Java_sp(), jfa->last_Java_fp()); 389 return fr; 390 } 391 392 //------------------------------------------------------------------------------ 393 // frame::verify_deopt_original_pc 394 // 395 // Verifies the calculated original PC of a deoptimization PC for the 396 // given unextended SP. 397 #ifdef ASSERT 398 void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp) { 399 frame fr; 400 401 // This is ugly but it's better than to change {get,set}_original_pc 402 // to take an SP value as argument. And it's only a debugging 403 // method anyway. 404 fr._unextended_sp = unextended_sp; 405 406 address original_pc = nm->get_original_pc(&fr); 407 assert(nm->insts_contains(original_pc), "original PC must be in nmethod"); 408 } 448 #endif // AMD64 449 } 450 451 452 //------------------------------------------------------------------------------ 453 // frame::sender_for_interpreter_frame 454 frame frame::sender_for_interpreter_frame(RegisterMap* map) const { 455 // SP is the raw SP from the sender after adapter or interpreter 456 // extension. 457 intptr_t* sender_sp = this->sender_sp(); 458 459 // This is the sp before any possible extension (adapter/locals). 460 intptr_t* unextended_sp = interpreter_frame_sender_sp(); 461 462 #ifdef COMPILER2 463 if (map->update_map()) { 464 update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset)); 465 } 466 #endif // COMPILER2 467 468 return frame(map->thread(), sender_sp, unextended_sp, link(), sender_pc()); 469 } 470 471 472 //------------------------------------------------------------------------------ 473 // frame::sender_for_compiled_frame 474 frame frame::sender_for_compiled_frame(RegisterMap* map) const { 475 assert(map != NULL, "map must be set"); 476 477 // frame owned by optimizing compiler 478 assert(_cb->frame_size() >= 0, "must have non-zero frame size"); 479 intptr_t* sender_sp = unextended_sp() + _cb->frame_size(); 480 intptr_t* unextended_sp = sender_sp; 481 482 // On Intel the return_address is always the word on the stack 483 address sender_pc = (address) *(sender_sp-1); 484 485 // This is the saved value of EBP which may or may not really be an FP. 486 // It is only an FP if the sender is an interpreter frame (or C1?). 487 intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset); 488 489 if (map->update_map()) { 490 // Tell GC to use argument oopmaps for some runtime stubs that need it. 491 // For C1, the runtime stub might not have oop maps, so set this flag 492 // outside of update_register_map. 493 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); 494 if (_cb->oop_maps() != NULL) { 495 OopMapSet::update_register_map(this, map); 496 } 497 498 // Since the prolog does the save and restore of EBP there is no oopmap 499 // for it so we must fill in its location as if there was an oopmap entry 500 // since if our caller was compiled code there could be live jvm state in it. 501 update_map_with_saved_link(map, saved_fp_addr); 502 } 503 504 assert(sender_sp != sp(), "must have changed"); 505 return frame(map->thread(), sender_sp, unextended_sp, *saved_fp_addr, sender_pc); 506 } 507 508 509 //------------------------------------------------------------------------------ 510 // frame::sender 511 frame frame::sender(RegisterMap* map) const { 512 // Default is we done have to follow them. The sender_for_xxx will 513 // update it accordingly 514 map->set_include_argument_oops(false); 515 516 if (is_entry_frame()) return sender_for_entry_frame(map); 517 if (is_interpreted_frame()) return sender_for_interpreter_frame(map); 518 assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); 519 520 if (_cb != NULL) { 521 return sender_for_compiled_frame(map); 522 } 523 // Must be native-compiled frame, i.e. the marshaling code for native 524 // methods that exists in the core system. 525 return frame(map->thread(), sender_sp(), link(), sender_pc()); 526 } 527 528 529 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) { 530 assert(is_interpreted_frame(), "must be interpreter frame"); 531 Method* method = interpreter_frame_method(); 532 // When unpacking an optimized frame the frame pointer is 533 // adjusted with: 534 int diff = (method->max_locals() - method->size_of_parameters()) * 535 Interpreter::stackElementWords; 536 return _fp == (fp - diff); 537 } 538 539 void frame::pd_gc_epilog() { 540 // nothing done here now 541 } 542 543 bool frame::is_interpreted_frame_valid(JavaThread* thread) const { 544 // QQQ 545 #ifdef CC_INTERP 702 intptr_t *frame::initial_deoptimization_info() { 703 // used to reset the saved FP 704 return fp(); 705 } 706 707 intptr_t* frame::real_fp() const { 708 if (_cb != NULL) { 709 // use the frame size if valid 710 int size = _cb->frame_size(); 711 if (size > 0) { 712 return unextended_sp() + size; 713 } 714 } 715 // else rely on fp() 716 assert(! is_compiled_frame(), "unknown compiled frame size"); 717 return fp(); 718 } 719 720 #ifndef PRODUCT 721 // This is a generic constructor which is only used by pns() in debug.cpp. 722 frame::frame(Thread* thread, void* sp, void* fp, void* pc) { 723 init(thread, (intptr_t*)sp, (intptr_t*)fp, (address)pc); 724 } 725 #endif |