< prev index next >

src/hotspot/cpu/x86/frame_x86.cpp

Print this page




   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 "interpreter/interpreter.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "memory/universe.hpp"
  29 #include "oops/markOop.hpp"
  30 #include "oops/method.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "prims/methodHandles.hpp"

  33 #include "runtime/frame.inline.hpp"
  34 #include "runtime/handles.inline.hpp"
  35 #include "runtime/javaCalls.hpp"
  36 #include "runtime/monitorChunk.hpp"
  37 #include "runtime/os.inline.hpp"
  38 #include "runtime/signature.hpp"
  39 #include "runtime/stubCodeGenerator.hpp"
  40 #include "runtime/stubRoutines.hpp"
  41 #include "vmreg_x86.inline.hpp"
  42 #ifdef COMPILER1
  43 #include "c1/c1_Runtime1.hpp"
  44 #include "runtime/vframeArray.hpp"
  45 #endif
  46 
  47 #ifdef ASSERT
  48 void RegisterMap::check_location_valid() {
  49 }
  50 #endif
  51 
  52 // Profiling/safepoint support


 135       // must be some sort of compiled/runtime frame
 136       // fp does not have to be safe (although it could be check for c1?)
 137 
 138       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
 139       if (_cb->frame_size() <= 0) {
 140         return false;
 141       }
 142 
 143       sender_sp = _unextended_sp + _cb->frame_size();
 144       // Is sender_sp safe?
 145       if ((address)sender_sp >= thread->stack_base()) {
 146         return false;
 147       }
 148       sender_unextended_sp = sender_sp;
 149       // On Intel the return_address is always the word on the stack
 150       sender_pc = (address) *(sender_sp-1);
 151       // Note: frame::sender_sp_offset is only valid for compiled frame
 152       saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
 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       bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
 164 
 165       if (!saved_fp_safe) {
 166         return false;
 167       }
 168 
 169       // construct the potential sender
 170 
 171       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
 172 
 173       return sender.is_interpreted_frame_valid(thread);
 174 


 253   // linkages it must be safe
 254 
 255   if (!fp_safe) {
 256     return false;
 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                   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   assert(_pc == *pc_addr || pc == *pc_addr, "must be");




 280   *pc_addr = pc;
 281   _cb = CodeCache::find_blob(pc);

 282   address original_pc = CompiledMethod::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 
 297 int frame::frame_size(RegisterMap* map) const {
 298   frame sender = this->sender(map);
 299   return sender.sp() - sp();
 300 }
 301 
 302 intptr_t* frame::entry_frame_argument_at(int offset) const {
 303   // convert offset to index to deal with tsi
 304   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
 305   // Entry frame's arguments are always in relation to unextended_sp()
 306   return &unextended_sp()[index];
 307 }
 308 
 309 // sender_sp
 310 
 311 intptr_t* frame::interpreter_frame_sender_sp() const {
 312   assert(is_interpreted_frame(), "interpreted frame expected");
 313   return (intptr_t*) at(interpreter_frame_sender_sp_offset);
 314 }
 315 
 316 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
 317   assert(is_interpreted_frame(), "interpreted frame expected");
 318   ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
 319 }
 320 
 321 
 322 // monitor elements
 323 
 324 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
 325   return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
 326 }
 327 
 328 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
 329   BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
 330   // make sure the pointer points inside the frame
 331   assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
 332   assert((intptr_t*) result < fp(),  "monitor end should be strictly below the frame pointer");
 333   return result;
 334 }
 335 
 336 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
 337   *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
 338 }
 339 
 340 // Used by template based interpreter deoptimization
 341 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
 342     *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
 343 }
 344 
 345 frame frame::sender_for_entry_frame(RegisterMap* map) const {
 346   assert(map != NULL, "map must be set");
 347   // Java frame called from C; skip all C frames and return top C
 348   // frame of that chunk as the sender
 349   JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
 350   assert(!entry_frame_is_first(), "next Java fp must be non zero");
 351   assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
 352   // Since we are walking the stack now this nested anchor is obviously walkable


 361   frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
 362   return fr;
 363 }
 364 
 365 //------------------------------------------------------------------------------
 366 // frame::verify_deopt_original_pc
 367 //
 368 // Verifies the calculated original PC of a deoptimization PC for the
 369 // given unextended SP.
 370 #ifdef ASSERT
 371 void frame::verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp) {
 372   frame fr;
 373 
 374   // This is ugly but it's better than to change {get,set}_original_pc
 375   // to take an SP value as argument.  And it's only a debugging
 376   // method anyway.
 377   fr._unextended_sp = unextended_sp;
 378 
 379   address original_pc = nm->get_original_pc(&fr);
 380   assert(nm->insts_contains_inclusive(original_pc),
 381          "original PC must be in the main code section of the the compiled method (or must be immediately following it)");
 382 }
 383 #endif
 384 
 385 //------------------------------------------------------------------------------
 386 // frame::adjust_unextended_sp
 387 #ifdef ASSERT
 388 void frame::adjust_unextended_sp() {
 389   // On x86, sites calling method handle intrinsics and lambda forms are treated
 390   // as any other call site. Therefore, no special action is needed when we are
 391   // returning to any of these call sites.
 392 
 393   if (_cb != NULL) {
 394     CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();
 395     if (sender_cm != NULL) {
 396       // If the sender PC is a deoptimization point, get the original PC.
 397       if (sender_cm->is_deopt_entry(_pc) ||
 398           sender_cm->is_deopt_mh_entry(_pc)) {
 399         verify_deopt_original_pc(sender_cm, _unextended_sp);
 400       }
 401     }
 402   }
 403 }
 404 #endif
 405 
 406 //------------------------------------------------------------------------------
 407 // frame::update_map_with_saved_link
 408 void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {
 409   // The interpreter and compiler(s) always save EBP/RBP in a known
 410   // location on entry. We must record where that location is
 411   // so this if EBP/RBP was live on callout from c2 we can find
 412   // the saved copy no matter what it called.
 413 
 414   // Since the interpreter always saves EBP/RBP if we record where it is then
 415   // we don't have to always save EBP/RBP on entry and exit to c2 compiled
 416   // code, on entry will be enough.
 417   map->set_location(rbp->as_VMReg(), (address) link_addr);
 418 #ifdef AMD64
 419   // this is weird "H" ought to be at a higher address however the
 420   // oopMaps seems to have the "H" regs at the same address and the
 421   // vanilla register.
 422   // XXXX make this go away
 423   if (true) {
 424     map->set_location(rbp->as_VMReg()->next(), (address) link_addr);
 425   }
 426 #endif // AMD64
 427 }
 428 
 429 
 430 //------------------------------------------------------------------------------
 431 // frame::sender_for_interpreter_frame
 432 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {




 433   // SP is the raw SP from the sender after adapter or interpreter
 434   // extension.
 435   intptr_t* sender_sp = this->sender_sp();
 436 
 437   // This is the sp before any possible extension (adapter/locals).
 438   intptr_t* unextended_sp = interpreter_frame_sender_sp();
 439 
 440 #if COMPILER2_OR_JVMCI
 441   if (map->update_map()) {
 442     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
 443   }
 444 #endif // COMPILER2_OR_JVMCI
 445 
 446   return frame(sender_sp, unextended_sp, link(), sender_pc());
 447 }
 448 
 449 
 450 //------------------------------------------------------------------------------
 451 // frame::sender_for_compiled_frame
 452 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
 453   assert(map != NULL, "map must be set");
 454 
 455   // frame owned by optimizing compiler
 456   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
 457   intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
 458   intptr_t* unextended_sp = sender_sp;
 459 
 460   // On Intel the return_address is always the word on the stack
 461   address sender_pc = (address) *(sender_sp-1);
 462 
 463   // This is the saved value of EBP which may or may not really be an FP.
 464   // It is only an FP if the sender is an interpreter frame (or C1?).
 465   intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
 466 
 467   if (map->update_map()) {
 468     // Tell GC to use argument oopmaps for some runtime stubs that need it.
 469     // For C1, the runtime stub might not have oop maps, so set this flag
 470     // outside of update_register_map.
 471     map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
 472     if (_cb->oop_maps() != NULL) {
 473       OopMapSet::update_register_map(this, map);
 474     }
 475 
 476     // Since the prolog does the save and restore of EBP there is no oopmap
 477     // for it so we must fill in its location as if there was an oopmap entry
 478     // since if our caller was compiled code there could be live jvm state in it.
 479     update_map_with_saved_link(map, saved_fp_addr);
 480   }
 481 
 482   assert(sender_sp != sp(), "must have changed");
 483   return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
 484 }
 485 
 486 
 487 //------------------------------------------------------------------------------
 488 // frame::sender
 489 frame frame::sender(RegisterMap* map) const {
 490   // Default is we done have to follow them. The sender_for_xxx will
 491   // update it accordingly
 492   map->set_include_argument_oops(false);
 493 
 494   if (is_entry_frame())       return sender_for_entry_frame(map);
 495   if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
 496   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
 497 
 498   if (_cb != NULL) {
 499     return sender_for_compiled_frame(map);
 500   }
 501   // Must be native-compiled frame, i.e. the marshaling code for native
 502   // methods that exists in the core system.
 503   return frame(sender_sp(), link(), sender_pc());
 504 }
 505 
 506 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
 507   assert(is_interpreted_frame(), "Not an interpreted frame");
 508   // These are reasonable sanity checks
 509   if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
 510     return false;
 511   }
 512   if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
 513     return false;
 514   }
 515   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
 516     return false;
 517   }
 518   // These are hacks to keep us out of trouble.
 519   // The problem with these is that they mask other problems
 520   if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
 521     return false;
 522   }
 523 


 617 #endif // AMD64
 618       break;
 619     }
 620     case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
 621     case T_VOID    : /* Nothing to do */ break;
 622     default        : ShouldNotReachHere();
 623   }
 624 
 625   return type;
 626 }
 627 
 628 
 629 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
 630   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
 631   return &interpreter_frame_tos_address()[index];
 632 }
 633 
 634 #ifndef PRODUCT
 635 
 636 #define DESCRIBE_FP_OFFSET(name) \
 637   values.describe(frame_no, fp() + frame::name##_offset, #name)
 638 
 639 void frame::describe_pd(FrameValues& values, int frame_no) {
 640   if (is_interpreted_frame()) {
 641     DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
 642     DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
 643     DESCRIBE_FP_OFFSET(interpreter_frame_method);
 644     DESCRIBE_FP_OFFSET(interpreter_frame_mirror);
 645     DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
 646     DESCRIBE_FP_OFFSET(interpreter_frame_cache);
 647     DESCRIBE_FP_OFFSET(interpreter_frame_locals);
 648     DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
 649     DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);



 650 #ifdef AMD64
 651   } else if (is_entry_frame()) {
 652     // This could be more descriptive if we use the enum in
 653     // stubGenerator to map to real names but it's most important to
 654     // claim these frame slots so the error checking works.
 655     for (int i = 0; i < entry_frame_after_call_words; i++) {
 656       values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i));
 657     }
 658 #endif // AMD64
 659   }
 660 }
 661 #endif // !PRODUCT
 662 
 663 intptr_t *frame::initial_deoptimization_info() {
 664   // used to reset the saved FP
 665   return fp();
 666 }
 667 
 668 intptr_t* frame::real_fp() const {
 669   if (_cb != NULL) {
 670     // use the frame size if valid
 671     int size = _cb->frame_size();
 672     if (size > 0) {
 673       return unextended_sp() + size;
 674     }
 675   }
 676   // else rely on fp()
 677   assert(! is_compiled_frame(), "unknown compiled frame size");
 678   return fp();
 679 }
 680 
 681 #ifndef PRODUCT
 682 // This is a generic constructor which is only used by pns() in debug.cpp.
 683 frame::frame(void* sp, void* fp, void* pc) {
 684   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
 685 }
 686 
 687 void frame::pd_ps() {}
 688 #endif
 689 
 690 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
 691   // last frame set?
 692   if (last_Java_sp() == NULL) return;
 693   // already walkable?
 694   if (walkable()) return;
 695   vmassert(Thread::current() == (Thread*)thread, "not current thread");
 696   vmassert(last_Java_sp() != NULL, "not called from Java code?");
 697   vmassert(last_Java_pc() == NULL, "already walkable");


   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.inline.hpp"
  27 #include "interpreter/interpreter.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "memory/universe.hpp"
  30 #include "oops/markOop.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/os.inline.hpp"
  40 #include "runtime/signature.hpp"
  41 #include "runtime/stubCodeGenerator.hpp"
  42 #include "runtime/stubRoutines.hpp"
  43 #include "vmreg_x86.inline.hpp"
  44 #ifdef COMPILER1
  45 #include "c1/c1_Runtime1.hpp"
  46 #include "runtime/vframeArray.hpp"
  47 #endif
  48 
  49 #ifdef ASSERT
  50 void RegisterMap::check_location_valid() {
  51 }
  52 #endif
  53 
  54 // Profiling/safepoint support


 137       // must be some sort of compiled/runtime frame
 138       // fp does not have to be safe (although it could be check for c1?)
 139 
 140       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
 141       if (_cb->frame_size() <= 0) {
 142         return false;
 143       }
 144 
 145       sender_sp = _unextended_sp + _cb->frame_size();
 146       // Is sender_sp safe?
 147       if ((address)sender_sp >= thread->stack_base()) {
 148         return false;
 149       }
 150       sender_unextended_sp = sender_sp;
 151       // On Intel the return_address is always the word on the stack
 152       sender_pc = (address) *(sender_sp-1);
 153       // Note: frame::sender_sp_offset is only valid for compiled frame
 154       saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
 155     }
 156 
 157     if (Continuation::is_return_barrier_entry(sender_pc)) {     
 158       Continuation::fix_continuation_bottom_sender(thread, *this, &sender_pc, &sender_sp);      
 159     }
 160 
 161     // If the potential sender is the interpreter then we can do some more checking
 162     if (Interpreter::contains(sender_pc)) {
 163 
 164       // ebp is always saved in a recognizable place in any code we generate. However
 165       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
 166       // is really a frame pointer.
 167 
 168       bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
 169 
 170       if (!saved_fp_safe) {
 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 


 258   // linkages it must be safe
 259 
 260   if (!fp_safe) {
 261     return false;
 262   }
 263 
 264   // Will the pc we fetch be non-zero (which we'll find at the oldest frame)
 265 
 266   if ( (address) this->fp()[return_addr_offset] == NULL) return false;
 267 
 268 
 269   // could try and do some more potential verification of native frame if we could think of some...
 270 
 271   return true;
 272 
 273 }
 274 
 275 
 276 void frame::patch_pc(Thread* thread, address pc) {
 277   address* pc_addr = &(((address*) sp())[-1]);
 278   pc_addr = Continuation::get_continuation_entry_pc_for_sender(thread, *this, pc_addr);
 279 
 280   if (TracePcPatching) {
 281     tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
 282                   p2i(pc_addr), p2i(*pc_addr), p2i(pc));
 283   }
 284   // Either the return address is the original one or we are going to
 285   // patch in the same address that's already there.
 286 
 287   assert(!Continuation::is_return_barrier_entry(*pc_addr), "return barrier");
 288 
 289   assert(_pc == *pc_addr || pc == *pc_addr || *pc_addr == 0, "must be (pc: " INTPTR_FORMAT " _pc: " INTPTR_FORMAT " pc_addr: " INTPTR_FORMAT " *pc_addr: " INTPTR_FORMAT ")", p2i(pc), p2i(_pc), p2i(pc_addr), p2i(*pc_addr));
 290   DEBUG_ONLY(address old_pc = _pc;)
 291   *pc_addr = pc;
 292   _cb = CodeCache::find_blob(pc);
 293   _pc = pc; // must be set before call to get_deopt_original_pc
 294   address original_pc = CompiledMethod::get_deopt_original_pc(this);
 295   if (original_pc != NULL) {
 296     assert(original_pc == old_pc, "expected original PC to be stored before patching");
 297     _deopt_state = is_deoptimized;
 298     _pc = original_pc;
 299   } else {
 300     _deopt_state = not_deoptimized;

 301   }
 302   assert (!is_compiled_frame() || !_cb->as_compiled_method()->is_deopt_entry(_pc), "must be");
 303 
 304 #ifdef ASSERT
 305   {
 306     frame f(this->sp(), this->unextended_sp(), this->fp(), pc);
 307     assert(f.is_deoptimized_frame() == this->is_deoptimized_frame() && f.pc() == this->pc() && f.raw_pc() == this->raw_pc(), 
 308       "must be (f.is_deoptimized_frame(): %d this->is_deoptimized_frame(): %d "
 309       "f.pc(): " INTPTR_FORMAT " this->pc(): " INTPTR_FORMAT " f.raw_pc(): " INTPTR_FORMAT " this->raw_pc(): " INTPTR_FORMAT ")", 
 310       f.is_deoptimized_frame(), this->is_deoptimized_frame(), p2i(f.pc()), p2i(this->pc()), p2i(f.raw_pc()), p2i(this->raw_pc()));
 311   }
 312 #endif
 313 }
 314 
 315 int frame::frame_size(RegisterMap* map) const {
 316   frame sender = this->sender(map);
 317   return sender.sp() - sp();
 318 }
 319 
 320 intptr_t* frame::entry_frame_argument_at(int offset) const {
 321   // convert offset to index to deal with tsi
 322   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
 323   // Entry frame's arguments are always in relation to unextended_sp()
 324   return &unextended_sp()[index];
 325 }
 326 
 327 // sender_sp
 328 
 329 intptr_t* frame::interpreter_frame_sender_sp() const {
 330   assert(is_interpreted_frame(), "interpreted frame expected");
 331   return (intptr_t*) at(interpreter_frame_sender_sp_offset);
 332 }
 333 
 334 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
 335   assert(is_interpreted_frame(), "interpreted frame expected");
 336   ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
 337 }
 338 
 339 
 340 // monitor elements
 341 
 342 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
 343   return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
 344 }
 345 
 346 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
 347   BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
 348   // make sure the pointer points inside the frame
 349   assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
 350   assert((intptr_t*) result < fp(),  "monitor end should be strictly below the frame pointer: result: " INTPTR_FORMAT " fp: " INTPTR_FORMAT, p2i(result), p2i(fp()));
 351   return result;
 352 }
 353 
 354 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
 355   *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
 356 }
 357 
 358 // Used by template based interpreter deoptimization
 359 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
 360     *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
 361 }
 362 
 363 frame frame::sender_for_entry_frame(RegisterMap* map) const {
 364   assert(map != NULL, "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


 379   frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
 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(CompiledMethod* 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_inclusive(original_pc),
 399          "original PC must be in the main code section of the 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());
 400 }
 401 #endif
 402 
 403 //------------------------------------------------------------------------------
 404 // frame::adjust_unextended_sp
 405 #ifdef ASSERT
 406 void frame::adjust_unextended_sp() {
 407   // On x86, sites calling method handle intrinsics and lambda forms are treated
 408   // as any other call site. Therefore, no special action is needed when we are
 409   // returning to any of these call sites.
 410 
 411   if (_cb != NULL) {
 412     CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();
 413     if (sender_cm != NULL) {
 414       // If the sender PC is a deoptimization point, get the original PC.
 415       if (sender_cm->is_deopt_entry(_pc) ||
 416           sender_cm->is_deopt_mh_entry(_pc)) {
 417         verify_deopt_original_pc(sender_cm, _unextended_sp);
 418       }
 419     }
 420   }
 421 }
 422 #endif
 423 
 424 //------------------------------------------------------------------------------
























 425 // frame::sender_for_interpreter_frame
 426 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
 427   if (map->in_cont()) { // already in an h-stack
 428     return Continuation::sender_for_interpreter_frame(*this, map);
 429   }
 430 
 431   // SP is the raw SP from the sender after adapter or interpreter
 432   // extension.
 433   intptr_t* sender_sp = this->sender_sp();
 434 
 435   // This is the sp before any possible extension (adapter/locals).
 436   intptr_t* unextended_sp = interpreter_frame_sender_sp();
 437 
 438 #if COMPILER2_OR_JVMCI
 439   if (map->update_map()) {
 440     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
 441   }
 442 #endif // COMPILER2_OR_JVMCI
 443 
 444   address sender_pc = this->sender_pc();

 445 
 446   if (Continuation::is_return_barrier_entry(sender_pc)) {       
 447     if (map->walk_cont()) { // about to walk into an h-stack 
 448       return Continuation::top_frame(*this, map);       
 449     } else {
 450       Continuation::fix_continuation_bottom_sender(map, *this, &sender_pc, NULL);
 451     }

























 452   }
 453   return frame(sender_sp, unextended_sp, link(), sender_pc); // Continuation::fix_continuation_bottom_sender(*this, map, frame(sender_sp, unextended_sp, link(), sender_pc));


 454 }
 455 
 456 
 457 //------------------------------------------------------------------------------
 458 // frame::sender
 459 frame frame::sender(RegisterMap* map) const {
 460   return frame_sender<CodeCache>(map);













 461 }
 462 
 463 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
 464   assert(is_interpreted_frame(), "Not an interpreted frame");
 465   // These are reasonable sanity checks
 466   if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
 467     return false;
 468   }
 469   if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
 470     return false;
 471   }
 472   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
 473     return false;
 474   }
 475   // These are hacks to keep us out of trouble.
 476   // The problem with these is that they mask other problems
 477   if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
 478     return false;
 479   }
 480 


 574 #endif // AMD64
 575       break;
 576     }
 577     case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
 578     case T_VOID    : /* Nothing to do */ break;
 579     default        : ShouldNotReachHere();
 580   }
 581 
 582   return type;
 583 }
 584 
 585 
 586 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
 587   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
 588   return &interpreter_frame_tos_address()[index];
 589 }
 590 
 591 #ifndef PRODUCT
 592 
 593 #define DESCRIBE_FP_OFFSET(name) \
 594   values.describe(frame_no, fp() + frame::name##_offset, #name, 1)
 595 
 596 void frame::describe_pd(FrameValues& values, int frame_no) {
 597   if (is_interpreted_frame()) {
 598     DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
 599     DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
 600     DESCRIBE_FP_OFFSET(interpreter_frame_method);
 601     DESCRIBE_FP_OFFSET(interpreter_frame_mirror);
 602     DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
 603     DESCRIBE_FP_OFFSET(interpreter_frame_cache);
 604     DESCRIBE_FP_OFFSET(interpreter_frame_locals);
 605     DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
 606     DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
 607   } else if (is_compiled_frame()) {
 608     values.describe(frame_no, real_fp() - return_addr_offset, "return address");
 609     values.describe(frame_no, real_fp() - sender_sp_offset,   "saved fp", 2);
 610 #ifdef AMD64
 611   } else if (is_entry_frame()) {
 612     // This could be more descriptive if we use the enum in
 613     // stubGenerator to map to real names but it's most important to
 614     // claim these frame slots so the error checking works.
 615     for (int i = 0; i < entry_frame_after_call_words; i++) {
 616       values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i));
 617     }
 618 #endif // AMD64
 619   }
 620 }
 621 #endif // !PRODUCT
 622 
 623 intptr_t *frame::initial_deoptimization_info() {
 624   // used to reset the saved FP













 625   return fp();
 626 }
 627 
 628 #ifndef PRODUCT
 629 // This is a generic constructor which is only used by pns() in debug.cpp.
 630 frame::frame(void* sp, void* fp, void* pc) {
 631   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
 632 }
 633 
 634 void frame::pd_ps() {}
 635 #endif
 636 
 637 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
 638   // last frame set?
 639   if (last_Java_sp() == NULL) return;
 640   // already walkable?
 641   if (walkable()) return;
 642   vmassert(Thread::current() == (Thread*)thread, "not current thread");
 643   vmassert(last_Java_sp() != NULL, "not called from Java code?");
 644   vmassert(last_Java_pc() == NULL, "already walkable");
< prev index next >