1 /*
   2  * Copyright (c) 1997, 2018, 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.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
  55 
  56 bool frame::safe_for_sender(JavaThread *thread) {
  57   address   sp = (address)_sp;
  58   address   fp = (address)_fp;
  59   address   unextended_sp = (address)_unextended_sp;
  60 
  61   // consider stack guards when trying to determine "safe" stack pointers
  62   static size_t stack_guard_size = os::uses_stack_guard_pages() ?
  63     JavaThread::stack_red_zone_size() + JavaThread::stack_yellow_zone_size() : 0;
  64   size_t usable_stack_size = thread->stack_size() - stack_guard_size;
  65 
  66   // sp must be within the usable part of the stack (not in guards)
  67   bool sp_safe = (sp < thread->stack_base()) &&
  68                  (sp >= thread->stack_base() - usable_stack_size);
  69 
  70 
  71   if (!sp_safe) {
  72     return false;
  73   }
  74 
  75   // unextended sp must be within the stack and above or equal sp
  76   bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&
  77                             (unextended_sp >= sp);
  78 
  79   if (!unextended_sp_safe) {
  80     return false;
  81   }
  82 
  83   // an fp must be within the stack and above (but not equal) sp
  84   // second evaluation on fp+ is added to handle situation where fp is -1
  85   bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
  86 
  87   // We know sp/unextended_sp are safe only fp is questionable here
  88 
  89   // If the current frame is known to the code cache then we can attempt to
  90   // to construct the sender and do some validation of it. This goes a long way
  91   // toward eliminating issues when we get in frame construction code
  92 
  93   if (_cb != NULL ) {
  94 
  95     // First check if frame is complete and tester is reliable
  96     // Unfortunately we can only check frame complete for runtime stubs and nmethod
  97     // other generic buffer blobs are more problematic so we just assume they are
  98     // ok. adapter blobs never have a frame complete and are never ok.
  99 
 100     if (!_cb->is_frame_complete_at(_pc)) {
 101       if (_cb->is_compiled() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
 102         return false;
 103       }
 104     }
 105 
 106     // Could just be some random pointer within the codeBlob
 107     if (!_cb->code_contains(_pc)) {
 108       return false;
 109     }
 110 
 111     // Entry frame checks
 112     if (is_entry_frame()) {
 113       // an entry frame must have a valid fp.
 114       return fp_safe && is_entry_frame_valid(thread);
 115     }
 116 
 117     intptr_t* sender_sp = NULL;
 118     intptr_t* sender_unextended_sp = NULL;
 119     address   sender_pc = NULL;
 120     intptr_t* saved_fp =  NULL;
 121 
 122     if (is_interpreted_frame()) {
 123       // fp must be safe
 124       if (!fp_safe) {
 125         return false;
 126       }
 127 
 128       sender_pc = (address) this->fp()[return_addr_offset];
 129       // for interpreted frames, the value below is the sender "raw" sp,
 130       // which can be different from the sender unextended sp (the sp seen
 131       // by the sender) because of current frame local variables
 132       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
 133       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
 134       saved_fp = (intptr_t*) this->fp()[link_offset];
 135 
 136     } else {
 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 
 180     }
 181 
 182     // We must always be able to find a recognizable pc
 183     CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
 184     if (sender_pc == NULL ||  sender_blob == NULL) {
 185       return false;
 186     }
 187 
 188     // Could be a zombie method
 189     if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
 190       return false;
 191     }
 192 
 193     // Could just be some random pointer within the codeBlob
 194     if (!sender_blob->code_contains(sender_pc)) {
 195       return false;
 196     }
 197 
 198     // We should never be able to see an adapter if the current frame is something from code cache
 199     if (sender_blob->is_adapter_blob()) {
 200       return false;
 201     }
 202 
 203     // Could be the call_stub
 204     if (StubRoutines::returns_to_call_stub(sender_pc)) {
 205       bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
 206 
 207       if (!saved_fp_safe) {
 208         return false;
 209       }
 210 
 211       // construct the potential sender
 212 
 213       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
 214 
 215       // Validate the JavaCallWrapper an entry frame must have
 216       address jcw = (address)sender.entry_frame_call_wrapper();
 217 
 218       bool jcw_safe = (jcw < thread->stack_base()) && (jcw > (address)sender.fp());
 219 
 220       return jcw_safe;
 221     }
 222 
 223     CompiledMethod* nm = sender_blob->as_compiled_method_or_null();
 224     if (nm != NULL) {
 225         if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) ||
 226             nm->method()->is_method_handle_intrinsic()) {
 227             return false;
 228         }
 229     }
 230 
 231     // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
 232     // because the return address counts against the callee's frame.
 233 
 234     if (sender_blob->frame_size() <= 0) {
 235       assert(!sender_blob->is_compiled(), "should count return address at least");
 236       return false;
 237     }
 238 
 239     // We should never be able to see anything here except an nmethod. If something in the
 240     // code cache (current frame) is called by an entity within the code cache that entity
 241     // should not be anything but the call stub (already covered), the interpreter (already covered)
 242     // or an nmethod.
 243 
 244     if (!sender_blob->is_compiled()) {
 245         return false;
 246     }
 247 
 248     // Could put some more validation for the potential non-interpreted sender
 249     // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
 250 
 251     // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
 252 
 253     // We've validated the potential sender that would be created
 254     return true;
 255   }
 256 
 257   // Must be native-compiled frame. Since sender will try and use fp to find
 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
 371   // even if it wasn't when it was stacked.
 372   if (!jfa->walkable()) {
 373     // Capture _last_Java_pc (if needed) and mark anchor walkable.
 374     jfa->capture_last_Java_pc();
 375   }
 376   map->clear();
 377   assert(map->include_argument_oops(), "should be set by clear");
 378   vmassert(jfa->last_Java_pc() != NULL, "not 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 
 481   // do some validation of frame elements
 482   // first the method
 483 
 484   Method* m = *interpreter_frame_method_addr();
 485 
 486   // validate the method we'd find in this potential sender
 487   if (!Method::is_valid_method(m)) return false;
 488 
 489   // stack frames shouldn't be much larger than max_stack elements
 490   // this test requires the use the unextended_sp which is the sp as seen by
 491   // the current frame, and not sp which is the "raw" pc which could point
 492   // further because of local variables of the callee method inserted after
 493   // method arguments
 494   if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
 495     return false;
 496   }
 497 
 498   // validate bci/bcp
 499 
 500   address bcp = interpreter_frame_bcp();
 501   if (m->validate_bci_from_bcp(bcp) < 0) {
 502     return false;
 503   }
 504 
 505   // validate ConstantPoolCache*
 506   ConstantPoolCache* cp = *interpreter_frame_cache_addr();
 507   if (MetaspaceObj::is_valid(cp) == false) return false;
 508 
 509   // validate locals
 510 
 511   address locals =  (address) *interpreter_frame_locals_addr();
 512 
 513   if (locals > thread->stack_base() || locals < (address) fp()) return false;
 514 
 515   // We'd have to be pretty unlucky to be mislead at this point
 516   return true;
 517 }
 518 
 519 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
 520   assert(is_interpreted_frame(), "interpreted frame expected");
 521   Method* method = interpreter_frame_method();
 522   BasicType type = method->result_type();
 523 
 524   intptr_t* tos_addr;
 525   if (method->is_native()) {
 526     // Prior to calling into the runtime to report the method_exit the possible
 527     // return value is pushed to the native stack. If the result is a jfloat/jdouble
 528     // then ST0 is saved before EAX/EDX. See the note in generate_native_result
 529     tos_addr = (intptr_t*)sp();
 530     if (type == T_FLOAT || type == T_DOUBLE) {
 531     // QQQ seems like this code is equivalent on the two platforms
 532 #ifdef AMD64
 533       // This is times two because we do a push(ltos) after pushing XMM0
 534       // and that takes two interpreter stack slots.
 535       tos_addr += 2 * Interpreter::stackElementWords;
 536 #else
 537       tos_addr += 2;
 538 #endif // AMD64
 539     }
 540   } else {
 541     tos_addr = (intptr_t*)interpreter_frame_tos_address();
 542   }
 543 
 544   switch (type) {
 545     case T_OBJECT  :
 546     case T_ARRAY   : {
 547       oop obj;
 548       if (method->is_native()) {
 549         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
 550       } else {
 551         oop* obj_p = (oop*)tos_addr;
 552         obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
 553       }
 554       assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
 555       *oop_result = obj;
 556       break;
 557     }
 558     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
 559     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
 560     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
 561     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
 562     case T_INT     : value_result->i = *(jint*)tos_addr; break;
 563     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
 564     case T_FLOAT   : {
 565 #ifdef AMD64
 566         value_result->f = *(jfloat*)tos_addr;
 567 #else
 568       if (method->is_native()) {
 569         jdouble d = *(jdouble*)tos_addr;  // Result was in ST0 so need to convert to jfloat
 570         value_result->f = (jfloat)d;
 571       } else {
 572         value_result->f = *(jfloat*)tos_addr;
 573       }
 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");
 645   capture_last_Java_pc();
 646   vmassert(walkable(), "something went wrong");
 647 }
 648 
 649 void JavaFrameAnchor::capture_last_Java_pc() {
 650   vmassert(_last_Java_sp != NULL, "no last frame set");
 651   vmassert(_last_Java_pc == NULL, "already walkable");
 652   _last_Java_pc = (address)_last_Java_sp[-1];
 653 }