1 /* 2 * Copyright (c) 1997, 2024, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "compiler/oopMap.hpp" 27 #include "interpreter/interpreter.hpp" 28 #include "memory/resourceArea.hpp" 29 #include "memory/universe.hpp" 30 #include "oops/markWord.hpp" 31 #include "oops/method.hpp" 32 #include "oops/oop.inline.hpp" 33 #include "prims/methodHandles.hpp" 34 #include "runtime/continuation.hpp" 35 #include "runtime/frame.inline.hpp" 36 #include "runtime/handles.inline.hpp" 37 #include "runtime/javaCalls.hpp" 38 #include "runtime/monitorChunk.hpp" 39 #include "runtime/signature.hpp" 40 #include "runtime/stackWatermarkSet.hpp" 41 #include "runtime/stubCodeGenerator.hpp" 42 #include "runtime/stubRoutines.hpp" 43 #include "vmreg_x86.inline.hpp" 44 #include "utilities/formatBuffer.hpp" 45 #ifdef COMPILER1 46 #include "c1/c1_Runtime1.hpp" 47 #include "runtime/vframeArray.hpp" 48 #endif 49 50 #ifdef ASSERT 51 void RegisterMap::check_location_valid() { 52 } 53 #endif 54 55 // Profiling/safepoint support 56 57 bool frame::safe_for_sender(JavaThread *thread) { 58 if (is_heap_frame()) { 59 return true; 60 } 61 address sp = (address)_sp; 62 address fp = (address)_fp; 63 address unextended_sp = (address)_unextended_sp; 64 65 // consider stack guards when trying to determine "safe" stack pointers 66 // sp must be within the usable part of the stack (not in guards) 67 if (!thread->is_in_usable_stack(sp)) { 68 return false; 69 } 70 71 // unextended sp must be within the stack 72 // Note: sp can be greater than unextended_sp in the case of 73 // interpreted -> interpreted calls that go through a method handle linker, 74 // since those pop the last argument (the appendix) from the stack. 75 if (!thread->is_in_stack_range_incl(unextended_sp, sp - Interpreter::stackElementSize)) { 76 return false; 77 } 78 79 // an fp must be within the stack and above (but not equal) sp 80 // second evaluation on fp+ is added to handle situation where fp is -1 81 bool fp_safe = thread->is_in_stack_range_excl(fp, sp) && 82 thread->is_in_full_stack_checked(fp + (return_addr_offset * sizeof(void*))); 83 84 // We know sp/unextended_sp are safe only fp is questionable here 85 86 // If the current frame is known to the code cache then we can attempt to 87 // construct the sender and do some validation of it. This goes a long way 88 // toward eliminating issues when we get in frame construction code 89 90 if (_cb != nullptr ) { 91 92 // First check if frame is complete and tester is reliable 93 // Unfortunately we can only check frame complete for runtime stubs and nmethod 94 // other generic buffer blobs are more problematic so we just assume they are 95 // ok. adapter blobs never have a frame complete and are never ok. 96 97 if (!_cb->is_frame_complete_at(_pc)) { 98 if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) { 99 return false; 100 } 101 } 102 103 // Could just be some random pointer within the codeBlob 104 if (!_cb->code_contains(_pc)) { 105 return false; 106 } 107 108 // Entry frame checks 109 if (is_entry_frame()) { 110 // an entry frame must have a valid fp. 111 return fp_safe && is_entry_frame_valid(thread); 112 } else if (is_upcall_stub_frame()) { 113 return fp_safe; 114 } 115 116 intptr_t* sender_sp = nullptr; 117 intptr_t* sender_unextended_sp = nullptr; 118 address sender_pc = nullptr; 119 intptr_t* saved_fp = nullptr; 120 121 if (is_interpreted_frame()) { 122 // fp must be safe 123 if (!fp_safe) { 124 return false; 125 } 126 127 sender_pc = (address) this->fp()[return_addr_offset]; 128 // for interpreted frames, the value below is the sender "raw" sp, 129 // which can be different from the sender unextended sp (the sp seen 130 // by the sender) because of current frame local variables 131 sender_sp = (intptr_t*) addr_at(sender_sp_offset); 132 sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset]; 133 saved_fp = (intptr_t*) this->fp()[link_offset]; 134 135 } else { 136 // must be some sort of compiled/runtime frame 137 // fp does not have to be safe (although it could be check for c1?) 138 139 // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc 140 if (_cb->frame_size() <= 0) { 141 return false; 142 } 143 144 sender_sp = _unextended_sp + _cb->frame_size(); 145 // Is sender_sp safe? 146 if (!thread->is_in_full_stack_checked((address)sender_sp)) { 147 return false; 148 } 149 sender_unextended_sp = sender_sp; 150 // On Intel the return_address is always the word on the stack 151 sender_pc = (address) *(sender_sp-1); 152 // Note: frame::sender_sp_offset is only valid for compiled frame 153 saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset); 154 } 155 156 if (Continuation::is_return_barrier_entry(sender_pc)) { 157 // If our sender_pc is the return barrier, then our "real" sender is the continuation entry 158 frame s = Continuation::continuation_bottom_sender(thread, *this, sender_sp); 159 sender_sp = s.sp(); 160 sender_pc = s.pc(); 161 } 162 163 // If the potential sender is the interpreter then we can do some more checking 164 if (Interpreter::contains(sender_pc)) { 165 166 // ebp is always saved in a recognizable place in any code we generate. However 167 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp 168 // is really a frame pointer. 169 170 if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) { 171 return false; 172 } 173 174 // construct the potential sender 175 176 frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc); 177 178 return sender.is_interpreted_frame_valid(thread); 179 180 } 181 182 // We must always be able to find a recognizable pc 183 CodeBlob* sender_blob = CodeCache::find_blob(sender_pc); 184 if (sender_pc == nullptr || sender_blob == nullptr) { 185 return false; 186 } 187 188 // Could just be some random pointer within the codeBlob 189 if (!sender_blob->code_contains(sender_pc)) { 190 return false; 191 } 192 193 // We should never be able to see an adapter if the current frame is something from code cache 194 if (sender_blob->is_adapter_blob()) { 195 return false; 196 } 197 198 // Could be the call_stub 199 if (StubRoutines::returns_to_call_stub(sender_pc)) { 200 if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) { 201 return false; 202 } 203 204 // construct the potential sender 205 206 frame sender(sender_sp, sender_unextended_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 return thread->is_in_stack_range_excl(jcw, (address)sender.fp()); 212 } else if (sender_blob->is_upcall_stub()) { 213 return false; 214 } 215 216 nmethod* nm = sender_blob->as_nmethod_or_null(); 217 if (nm != nullptr) { 218 if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) || 219 nm->method()->is_method_handle_intrinsic()) { 220 return false; 221 } 222 } 223 224 // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size 225 // because the return address counts against the callee's frame. 226 227 if (sender_blob->frame_size() <= 0) { 228 assert(!sender_blob->is_nmethod(), "should count return address at least"); 229 return false; 230 } 231 232 // We should never be able to see anything here except an nmethod. If something in the 233 // code cache (current frame) is called by an entity within the code cache that entity 234 // should not be anything but the call stub (already covered), the interpreter (already covered) 235 // or an nmethod. 236 237 if (!sender_blob->is_nmethod()) { 238 return false; 239 } 240 241 // Could put some more validation for the potential non-interpreted sender 242 // frame we'd create by calling sender if I could think of any. Wait for next crash in forte... 243 244 // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb 245 246 // We've validated the potential sender that would be created 247 return true; 248 } 249 250 // Must be native-compiled frame. Since sender will try and use fp to find 251 // linkages it must be safe 252 253 if (!fp_safe) { 254 return false; 255 } 256 257 // Will the pc we fetch be non-zero (which we'll find at the oldest frame) 258 259 if ( (address) this->fp()[return_addr_offset] == nullptr) return false; 260 261 262 // could try and do some more potential verification of native frame if we could think of some... 263 264 return true; 265 266 } 267 268 269 void frame::patch_pc(Thread* thread, address pc) { 270 assert(_cb == CodeCache::find_blob(pc), "unexpected pc"); 271 address* pc_addr = &(((address*) sp())[-1]); 272 273 if (TracePcPatching) { 274 tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]", 275 p2i(pc_addr), p2i(*pc_addr), p2i(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 280 assert(!Continuation::is_return_barrier_entry(*pc_addr), "return barrier"); 281 282 assert(_pc == *pc_addr || pc == *pc_addr || *pc_addr == nullptr, ""); 283 DEBUG_ONLY(address old_pc = _pc;) 284 *pc_addr = pc; 285 _pc = pc; // must be set before call to get_deopt_original_pc 286 address original_pc = get_deopt_original_pc(); 287 if (original_pc != nullptr) { 288 assert(original_pc == old_pc, "expected original PC to be stored before patching"); 289 _deopt_state = is_deoptimized; 290 _pc = original_pc; 291 } else { 292 _deopt_state = not_deoptimized; 293 } 294 assert(!is_compiled_frame() || !_cb->as_nmethod()->is_deopt_entry(_pc), "must be"); 295 296 #ifdef ASSERT 297 { 298 frame f(this->sp(), this->unextended_sp(), this->fp(), pc); 299 assert(f.is_deoptimized_frame() == this->is_deoptimized_frame() && f.pc() == this->pc() && f.raw_pc() == this->raw_pc(), 300 "must be (f.is_deoptimized_frame(): %d this->is_deoptimized_frame(): %d " 301 "f.pc(): " INTPTR_FORMAT " this->pc(): " INTPTR_FORMAT " f.raw_pc(): " INTPTR_FORMAT " this->raw_pc(): " INTPTR_FORMAT ")", 302 f.is_deoptimized_frame(), this->is_deoptimized_frame(), p2i(f.pc()), p2i(this->pc()), p2i(f.raw_pc()), p2i(this->raw_pc())); 303 } 304 #endif 305 } 306 307 intptr_t* frame::entry_frame_argument_at(int offset) const { 308 // convert offset to index to deal with tsi 309 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); 310 // Entry frame's arguments are always in relation to unextended_sp() 311 return &unextended_sp()[index]; 312 } 313 314 // locals 315 316 void frame::interpreter_frame_set_locals(intptr_t* locs) { 317 assert(is_interpreted_frame(), "interpreted frame expected"); 318 // set relativized locals 319 ptr_at_put(interpreter_frame_locals_offset, (intptr_t) (locs - fp())); 320 } 321 322 // sender_sp 323 324 intptr_t* frame::interpreter_frame_sender_sp() const { 325 assert(is_interpreted_frame(), "interpreted frame expected"); 326 return (intptr_t*) at(interpreter_frame_sender_sp_offset); 327 } 328 329 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) { 330 assert(is_interpreted_frame(), "interpreted frame expected"); 331 ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp); 332 } 333 334 335 // monitor elements 336 337 BasicObjectLock* frame::interpreter_frame_monitor_begin() const { 338 return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset); 339 } 340 341 BasicObjectLock* frame::interpreter_frame_monitor_end() const { 342 BasicObjectLock* result = (BasicObjectLock*) at_relative(interpreter_frame_monitor_block_top_offset); 343 // make sure the pointer points inside the frame 344 assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer"); 345 assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer: result: " INTPTR_FORMAT " fp: " INTPTR_FORMAT, p2i(result), p2i(fp())); 346 return result; 347 } 348 349 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { 350 assert(is_interpreted_frame(), "interpreted frame expected"); 351 // set relativized monitor_block_top 352 ptr_at_put(interpreter_frame_monitor_block_top_offset, (intptr_t*)value - fp()); 353 assert(at_absolute(interpreter_frame_monitor_block_top_offset) <= interpreter_frame_monitor_block_top_offset, ""); 354 } 355 356 // Used by template based interpreter deoptimization 357 void frame::interpreter_frame_set_last_sp(intptr_t* sp) { 358 assert(is_interpreted_frame(), "interpreted frame expected"); 359 // set relativized last_sp 360 ptr_at_put(interpreter_frame_last_sp_offset, sp != nullptr ? (sp - fp()) : 0); 361 } 362 363 frame frame::sender_for_entry_frame(RegisterMap* map) const { 364 assert(map != nullptr, "map must be set"); 365 // Java frame called from C; skip all C frames and return top C 366 // frame of that chunk as the sender 367 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 368 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 369 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); 370 // Since we are walking the stack now this nested anchor is obviously walkable 371 // even if it wasn't when it was stacked. 372 jfa->make_walkable(); 373 map->clear(); 374 assert(map->include_argument_oops(), "should be set by clear"); 375 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); 376 377 return fr; 378 } 379 380 UpcallStub::FrameData* UpcallStub::frame_data_for_frame(const frame& frame) const { 381 assert(frame.is_upcall_stub_frame(), "wrong frame"); 382 // need unextended_sp here, since normal sp is wrong for interpreter callees 383 return reinterpret_cast<UpcallStub::FrameData*>( 384 reinterpret_cast<address>(frame.unextended_sp()) + in_bytes(_frame_data_offset)); 385 } 386 387 bool frame::upcall_stub_frame_is_first() const { 388 assert(is_upcall_stub_frame(), "must be optimzed entry frame"); 389 UpcallStub* blob = _cb->as_upcall_stub(); 390 JavaFrameAnchor* jfa = blob->jfa_for_frame(*this); 391 return jfa->last_Java_sp() == nullptr; 392 } 393 394 frame frame::sender_for_upcall_stub_frame(RegisterMap* map) const { 395 assert(map != nullptr, "map must be set"); 396 UpcallStub* blob = _cb->as_upcall_stub(); 397 // Java frame called from C; skip all C frames and return top C 398 // frame of that chunk as the sender 399 JavaFrameAnchor* jfa = blob->jfa_for_frame(*this); 400 assert(!upcall_stub_frame_is_first(), "must have a frame anchor to go back to"); 401 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); 402 // Since we are walking the stack now this nested anchor is obviously walkable 403 // even if it wasn't when it was stacked. 404 jfa->make_walkable(); 405 map->clear(); 406 assert(map->include_argument_oops(), "should be set by clear"); 407 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); 408 409 return fr; 410 } 411 412 //------------------------------------------------------------------------------ 413 // frame::verify_deopt_original_pc 414 // 415 // Verifies the calculated original PC of a deoptimization PC for the 416 // given unextended SP. 417 #ifdef ASSERT 418 void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp) { 419 frame fr; 420 421 // This is ugly but it's better than to change {get,set}_original_pc 422 // to take an SP value as argument. And it's only a debugging 423 // method anyway. 424 fr._unextended_sp = unextended_sp; 425 426 address original_pc = nm->get_original_pc(&fr); 427 assert(nm->insts_contains_inclusive(original_pc), 428 "original PC must be in the main code section of the compiled method (or must be immediately following it) original_pc: " INTPTR_FORMAT " unextended_sp: " INTPTR_FORMAT " name: %s", p2i(original_pc), p2i(unextended_sp), nm->name()); 429 } 430 #endif 431 432 //------------------------------------------------------------------------------ 433 // frame::adjust_unextended_sp 434 #ifdef ASSERT 435 void frame::adjust_unextended_sp() { 436 // On x86, sites calling method handle intrinsics and lambda forms are treated 437 // as any other call site. Therefore, no special action is needed when we are 438 // returning to any of these call sites. 439 440 if (_cb != nullptr) { 441 nmethod* sender_nm = _cb->as_nmethod_or_null(); 442 if (sender_nm != nullptr) { 443 // If the sender PC is a deoptimization point, get the original PC. 444 if (sender_nm->is_deopt_entry(_pc) || 445 sender_nm->is_deopt_mh_entry(_pc)) { 446 verify_deopt_original_pc(sender_nm, _unextended_sp); 447 } 448 } 449 } 450 } 451 #endif 452 453 //------------------------------------------------------------------------------ 454 // frame::sender_for_interpreter_frame 455 frame frame::sender_for_interpreter_frame(RegisterMap* map) const { 456 // SP is the raw SP from the sender after adapter or interpreter 457 // extension. 458 intptr_t* sender_sp = this->sender_sp(); 459 460 // This is the sp before any possible extension (adapter/locals). 461 intptr_t* unextended_sp = interpreter_frame_sender_sp(); 462 intptr_t* sender_fp = link(); 463 464 #if COMPILER2_OR_JVMCI 465 if (map->update_map()) { 466 update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset)); 467 } 468 #endif // COMPILER2_OR_JVMCI 469 470 address sender_pc = this->sender_pc(); 471 472 if (Continuation::is_return_barrier_entry(sender_pc)) { 473 if (map->walk_cont()) { // about to walk into an h-stack 474 return Continuation::top_frame(*this, map); 475 } else { 476 return Continuation::continuation_bottom_sender(map->thread(), *this, sender_sp); 477 } 478 } 479 480 return frame(sender_sp, unextended_sp, sender_fp, sender_pc); 481 } 482 483 bool frame::is_interpreted_frame_valid(JavaThread* thread) const { 484 assert(is_interpreted_frame(), "Not an interpreted frame"); 485 // These are reasonable sanity checks 486 if (fp() == nullptr || (intptr_t(fp()) & (wordSize-1)) != 0) { 487 return false; 488 } 489 if (sp() == nullptr || (intptr_t(sp()) & (wordSize-1)) != 0) { 490 return false; 491 } 492 if (fp() + interpreter_frame_initial_sp_offset < sp()) { 493 return false; 494 } 495 // These are hacks to keep us out of trouble. 496 // The problem with these is that they mask other problems 497 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above 498 return false; 499 } 500 501 // do some validation of frame elements 502 // first the method 503 504 Method* m = safe_interpreter_frame_method(); 505 506 // validate the method we'd find in this potential sender 507 if (!Method::is_valid_method(m)) return false; 508 509 // stack frames shouldn't be much larger than max_stack elements 510 // this test requires the use the unextended_sp which is the sp as seen by 511 // the current frame, and not sp which is the "raw" pc which could point 512 // further because of local variables of the callee method inserted after 513 // method arguments 514 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { 515 return false; 516 } 517 518 // validate bci/bcp 519 520 address bcp = interpreter_frame_bcp(); 521 if (m->validate_bci_from_bcp(bcp) < 0) { 522 return false; 523 } 524 525 // validate ConstantPoolCache* 526 ConstantPoolCache* cp = *interpreter_frame_cache_addr(); 527 if (MetaspaceObj::is_valid(cp) == false) return false; 528 529 // validate locals 530 531 address locals = (address)interpreter_frame_locals(); 532 return thread->is_in_stack_range_incl(locals, (address)fp()); 533 } 534 535 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) { 536 assert(is_interpreted_frame(), "interpreted frame expected"); 537 Method* method = interpreter_frame_method(); 538 BasicType type = method->result_type(); 539 540 intptr_t* tos_addr; 541 if (method->is_native()) { 542 // Prior to calling into the runtime to report the method_exit the possible 543 // return value is pushed to the native stack. If the result is a jfloat/jdouble 544 // then ST0 is saved before EAX/EDX. See the note in generate_native_result 545 tos_addr = (intptr_t*)sp(); 546 if (type == T_FLOAT || type == T_DOUBLE) { 547 // QQQ seems like this code is equivalent on the two platforms 548 #ifdef AMD64 549 // This is times two because we do a push(ltos) after pushing XMM0 550 // and that takes two interpreter stack slots. 551 tos_addr += 2 * Interpreter::stackElementWords; 552 #else 553 tos_addr += 2; 554 #endif // AMD64 555 } 556 } else { 557 tos_addr = (intptr_t*)interpreter_frame_tos_address(); 558 } 559 560 switch (type) { 561 case T_OBJECT : 562 case T_ARRAY : { 563 oop obj; 564 if (method->is_native()) { 565 obj = cast_to_oop(at(interpreter_frame_oop_temp_offset)); 566 } else { 567 oop* obj_p = (oop*)tos_addr; 568 obj = (obj_p == nullptr) ? (oop)nullptr : *obj_p; 569 } 570 assert(Universe::is_in_heap_or_null(obj), "sanity check"); 571 *oop_result = obj; 572 break; 573 } 574 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break; 575 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break; 576 case T_CHAR : value_result->c = *(jchar*)tos_addr; break; 577 case T_SHORT : value_result->s = *(jshort*)tos_addr; break; 578 case T_INT : value_result->i = *(jint*)tos_addr; break; 579 case T_LONG : value_result->j = *(jlong*)tos_addr; break; 580 case T_FLOAT : { 581 #ifdef AMD64 582 value_result->f = *(jfloat*)tos_addr; 583 #else 584 if (method->is_native()) { 585 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat 586 value_result->f = (jfloat)d; 587 } else { 588 value_result->f = *(jfloat*)tos_addr; 589 } 590 #endif // AMD64 591 break; 592 } 593 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break; 594 case T_VOID : /* Nothing to do */ break; 595 default : ShouldNotReachHere(); 596 } 597 598 return type; 599 } 600 601 intptr_t* frame::interpreter_frame_tos_at(jint offset) const { 602 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); 603 return &interpreter_frame_tos_address()[index]; 604 } 605 606 #ifndef PRODUCT 607 608 #define DESCRIBE_FP_OFFSET(name) \ 609 values.describe(frame_no, fp() + frame::name##_offset, #name, 1) 610 611 void frame::describe_pd(FrameValues& values, int frame_no) { 612 if (is_interpreted_frame()) { 613 DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp); 614 DESCRIBE_FP_OFFSET(interpreter_frame_last_sp); 615 DESCRIBE_FP_OFFSET(interpreter_frame_method); 616 DESCRIBE_FP_OFFSET(interpreter_frame_mirror); 617 DESCRIBE_FP_OFFSET(interpreter_frame_mdp); 618 DESCRIBE_FP_OFFSET(interpreter_frame_cache); 619 DESCRIBE_FP_OFFSET(interpreter_frame_locals); 620 DESCRIBE_FP_OFFSET(interpreter_frame_bcp); 621 DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp); 622 #ifdef AMD64 623 } else if (is_entry_frame()) { 624 // This could be more descriptive if we use the enum in 625 // stubGenerator to map to real names but it's most important to 626 // claim these frame slots so the error checking works. 627 for (int i = 0; i < entry_frame_after_call_words; i++) { 628 values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i)); 629 } 630 #endif // AMD64 631 } 632 633 if (is_java_frame() || Continuation::is_continuation_enterSpecial(*this)) { 634 intptr_t* ret_pc_loc; 635 intptr_t* fp_loc; 636 if (is_interpreted_frame()) { 637 ret_pc_loc = fp() + return_addr_offset; 638 fp_loc = fp(); 639 } else { 640 ret_pc_loc = real_fp() - return_addr_offset; 641 fp_loc = real_fp() - sender_sp_offset; 642 } 643 address ret_pc = *(address*)ret_pc_loc; 644 values.describe(frame_no, ret_pc_loc, 645 Continuation::is_return_barrier_entry(ret_pc) ? "return address (return barrier)" : "return address"); 646 values.describe(-1, fp_loc, "saved fp", 0); // "unowned" as value belongs to sender 647 } 648 } 649 650 #endif // !PRODUCT 651 652 intptr_t *frame::initial_deoptimization_info() { 653 // used to reset the saved FP 654 return fp(); 655 } 656 657 #ifndef PRODUCT 658 // This is a generic constructor which is only used by pns() in debug.cpp. 659 frame::frame(void* sp, void* fp, void* pc) { 660 init((intptr_t*)sp, (intptr_t*)fp, (address)pc); 661 } 662 663 #endif 664 665 void JavaFrameAnchor::make_walkable() { 666 // last frame set? 667 if (last_Java_sp() == nullptr) return; 668 // already walkable? 669 if (walkable()) return; 670 vmassert(last_Java_pc() == nullptr, "already walkable"); 671 _last_Java_pc = (address)_last_Java_sp[-1]; 672 vmassert(walkable(), "something went wrong"); 673 }