1 /*
   2  * Copyright (c) 1997, 2022, 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 "classfile/moduleEntry.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/scopeDesc.hpp"
  29 #include "code/vmreg.inline.hpp"
  30 #include "compiler/abstractCompiler.hpp"
  31 #include "compiler/disassembler.hpp"
  32 #include "compiler/oopMap.hpp"
  33 #include "gc/shared/collectedHeap.inline.hpp"
  34 #include "interpreter/interpreter.hpp"
  35 #include "interpreter/oopMapCache.hpp"
  36 #include "logging/log.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "memory/universe.hpp"
  39 #include "oops/instanceStackChunkKlass.inline.hpp"
  40 #include "oops/markWord.hpp"
  41 #include "oops/method.hpp"
  42 #include "oops/methodData.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "oops/verifyOopClosure.hpp"
  45 #include "prims/methodHandles.hpp"
  46 #include "runtime/continuation.hpp"
  47 #include "runtime/frame.inline.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/javaCalls.hpp"
  50 #include "runtime/monitorChunk.hpp"
  51 #include "runtime/os.hpp"
  52 #include "runtime/sharedRuntime.hpp"
  53 #include "runtime/signature.hpp"
  54 #include "runtime/stackValue.hpp"
  55 #include "runtime/stubCodeGenerator.hpp"
  56 #include "runtime/stubRoutines.hpp"
  57 #include "runtime/thread.inline.hpp"
  58 #include "utilities/debug.hpp"
  59 #include "utilities/decoder.hpp"
  60 #include "utilities/formatBuffer.hpp"
  61 
  62 RegisterMap::RegisterMap(JavaThread *thread, bool update_map, bool process_frames, bool walk_cont) {
  63   _thread         = thread;
  64   _update_map     = update_map;
  65   _walk_cont      = walk_cont;
  66   DEBUG_ONLY(_skip_missing = false;)
  67   _process_frames = process_frames;
  68   clear();
  69   debug_only(_update_for_id = NULL;)
  70 
  71   if (walk_cont && thread != NULL && thread->last_continuation() != NULL) {
  72     _chunk = stackChunkHandle(Thread::current(), NULL, true);
  73   }
  74 
  75 #ifndef PRODUCT
  76   for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL;
  77 #endif /* PRODUCT */
  78 }
  79 
  80 RegisterMap::RegisterMap(oop continuation, bool update_map) {
  81   _thread         = NULL;
  82   _update_map     = update_map;
  83   _walk_cont      = true;
  84   DEBUG_ONLY(_skip_missing = false;)
  85   _process_frames = false;
  86   clear();
  87   debug_only(_update_for_id = NULL;)
  88 
  89   _chunk = stackChunkHandle(Thread::current(), NULL, true);
  90 
  91 #ifndef PRODUCT
  92   for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL;
  93 #endif /* PRODUCT */
  94 }
  95 
  96 RegisterMap::RegisterMap(const RegisterMap* map) {
  97   assert(map != this, "bad initialization parameter");
  98   assert(map != NULL, "RegisterMap must be present");
  99   _thread                = map->thread();
 100   _update_map            = map->update_map();
 101   _process_frames        = map->process_frames();
 102   _include_argument_oops = map->include_argument_oops();
 103   debug_only(_update_for_id = map->_update_for_id;)
 104   _walk_cont     = map->_walk_cont;
 105   DEBUG_ONLY(_skip_missing = map->_skip_missing;)
 106 
 107   // only the original RegisterMap's handle lives long enough for StackWalker; this is bound to cause trouble with nested continuations.
 108   _chunk = map->_chunk; // stackChunkHandle(Thread::current(), map->_chunk(), map->_chunk.not_null()); //
 109 
 110   pd_initialize_from(map);
 111   if (update_map()) {
 112     for(int i = 0; i < location_valid_size; i++) {
 113       LocationValidType bits = map->_location_valid[i];
 114       _location_valid[i] = bits;
 115       // for whichever bits are set, pull in the corresponding map->_location
 116       int j = i*location_valid_type_size;
 117       while (bits != 0) {
 118         if ((bits & 1) != 0) {
 119           assert(0 <= j && j < reg_count, "range check");
 120           _location[j] = map->_location[j];
 121         }
 122         bits >>= 1;
 123         j += 1;
 124       }
 125     }
 126   }
 127 }
 128 
 129 oop RegisterMap::cont() const {
 130   return _chunk() != NULL ? _chunk()->cont() : (oop)NULL;
 131 }
 132 
 133 void RegisterMap::set_stack_chunk(stackChunkOop chunk) {
 134   assert (chunk == NULL || _walk_cont, "");
 135   assert (chunk == NULL || chunk->is_stackChunk(), "");
 136   assert (chunk == NULL || _chunk.not_null(), "");
 137   if (_chunk.is_null()) return;
 138   log_trace(jvmcont)("set_stack_chunk: " INTPTR_FORMAT " this: " INTPTR_FORMAT, p2i((oopDesc*)chunk), p2i(this));
 139   *(_chunk.raw_value()) = chunk; // reuse handle. see comment above in the constructor
 140 }
 141 
 142 void RegisterMap::clear() {
 143   set_include_argument_oops(true);
 144   if (update_map()) {
 145     for(int i = 0; i < location_valid_size; i++) {
 146       _location_valid[i] = 0;
 147     }
 148     pd_clear();
 149   } else {
 150     pd_initialize();
 151   }
 152 }
 153 
 154 #ifndef PRODUCT
 155 
 156 VMReg RegisterMap::find_register_spilled_here(void* p, intptr_t* sp) {
 157   for(int i = 0; i < RegisterMap::reg_count; i++) {
 158     VMReg r = VMRegImpl::as_VMReg(i);
 159     if (p == location(r, sp)) return r;
 160   }
 161   return NULL;
 162 }
 163 
 164 void RegisterMap::print_on(outputStream* st) const {
 165   st->print_cr("Register map");
 166   for(int i = 0; i < reg_count; i++) {
 167 
 168     VMReg r = VMRegImpl::as_VMReg(i);
 169     intptr_t* src = (intptr_t*) location(r, (intptr_t*)NULL);
 170     if (src != NULL) {
 171 
 172       r->print_on(st);
 173       st->print(" [" INTPTR_FORMAT "] = ", p2i(src));
 174       if (((uintptr_t)src & (sizeof(*src)-1)) != 0) {
 175         st->print_cr("<misaligned>");
 176       } else {
 177         st->print_cr(INTPTR_FORMAT, *src);
 178       }
 179     }
 180   }
 181 }
 182 
 183 void RegisterMap::print() const {
 184   print_on(tty);
 185 }
 186 
 187 #endif
 188 // This returns the pc that if you were in the debugger you'd see. Not
 189 // the idealized value in the frame object. This undoes the magic conversion
 190 // that happens for deoptimized frames. In addition it makes the value the
 191 // hardware would want to see in the native frame. The only user (at this point)
 192 // is deoptimization. It likely no one else should ever use it.
 193 
 194 address frame::raw_pc() const {
 195   if (is_deoptimized_frame()) {
 196     CompiledMethod* cm = cb()->as_compiled_method_or_null();
 197     if (cm->is_method_handle_return(pc()))
 198       return cm->deopt_mh_handler_begin() - pc_return_offset;
 199     else
 200       return cm->deopt_handler_begin() - pc_return_offset;
 201   } else {
 202     return (pc() - pc_return_offset);
 203   }
 204 }
 205 
 206 // Change the pc in a frame object. This does not change the actual pc in
 207 // actual frame. To do that use patch_pc.
 208 //
 209 void frame::set_pc(address   newpc ) {
 210 #ifdef ASSERT
 211   if (_cb != NULL && _cb->is_nmethod()) {
 212     assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");
 213   }
 214 #endif // ASSERT
 215 
 216   // Unsafe to use the is_deoptimized tester after changing pc
 217   _deopt_state = unknown;
 218   _pc = newpc;
 219   _cb = CodeCache::find_blob_unsafe(_pc);
 220 
 221 }
 222 
 223 void frame::set_pc_preserve_deopt(address newpc) {
 224   set_pc_preserve_deopt(newpc, CodeCache::find_blob_unsafe(newpc));
 225 }
 226 
 227 void frame::set_pc_preserve_deopt(address newpc, CodeBlob* cb) {
 228 #ifdef ASSERT
 229   if (_cb != NULL && _cb->is_nmethod()) {
 230     assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");
 231   }
 232 #endif // ASSERT
 233 
 234   _pc = newpc;
 235   _cb = cb;
 236 }
 237 
 238 // type testers
 239 bool frame::is_ignored_frame() const {
 240   return false;  // FIXME: some LambdaForm frames should be ignored
 241 }
 242 
 243 bool frame::is_native_frame() const {
 244   return (_cb != NULL &&
 245           _cb->is_nmethod() &&
 246           ((nmethod*)_cb)->is_native_method());
 247 }
 248 
 249 bool frame::is_java_frame() const {
 250   if (is_interpreted_frame()) return true;
 251   if (is_compiled_frame())    return true;
 252   return false;
 253 }
 254 
 255 bool frame::is_runtime_frame() const {
 256   return (_cb != NULL && _cb->is_runtime_stub());
 257 }
 258 
 259 bool frame::is_safepoint_blob_frame() const {
 260   return (_cb != NULL && _cb->is_safepoint_stub());
 261 }
 262 
 263 // testers
 264 
 265 bool frame::is_first_java_frame() const {
 266   RegisterMap map(JavaThread::current(), false); // No update
 267   frame s;
 268   for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map));
 269   return s.is_first_frame();
 270 }
 271 
 272 
 273 bool frame::entry_frame_is_first() const {
 274   return entry_frame_call_wrapper()->is_first_frame();
 275 }
 276 
 277 JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const {
 278   JavaCallWrapper** jcw = entry_frame_call_wrapper_addr();
 279   address addr = (address) jcw;
 280 
 281   // addr must be within the usable part of the stack
 282   if (thread->is_in_usable_stack(addr)) {
 283     return *jcw;
 284   }
 285 
 286   return NULL;
 287 }
 288 
 289 bool frame::is_entry_frame_valid(JavaThread* thread) const {
 290   // Validate the JavaCallWrapper an entry frame must have
 291   address jcw = (address)entry_frame_call_wrapper();
 292   if (!thread->is_in_stack_range_excl(jcw, (address)fp())) {
 293     return false;
 294   }
 295 
 296   // Validate sp saved in the java frame anchor
 297   JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
 298   return (jfa->last_Java_sp() > sp());
 299 }
 300 
 301 bool frame::should_be_deoptimized() const {
 302   if (_deopt_state == is_deoptimized ||
 303       !is_compiled_frame() ) return false;
 304   assert(_cb != NULL && _cb->is_compiled(), "must be an nmethod");
 305   CompiledMethod* nm = (CompiledMethod *)_cb;
 306   if (TraceDependencies) {
 307     tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
 308     nm->print_value_on(tty);
 309     tty->cr();
 310   }
 311 
 312   if( !nm->is_marked_for_deoptimization() )
 313     return false;
 314 
 315   // If at the return point, then the frame has already been popped, and
 316   // only the return needs to be executed. Don't deoptimize here.
 317   return !nm->is_at_poll_return(pc());
 318 }
 319 
 320 bool frame::can_be_deoptimized() const {
 321   if (!is_compiled_frame()) return false;
 322   CompiledMethod* nm = (CompiledMethod*)_cb;
 323 
 324   if(!nm->can_be_deoptimized())
 325     return false;
 326 
 327   return !nm->is_at_poll_return(pc());
 328 }
 329 
 330 void frame::deoptimize(JavaThread* thread) {
 331   // tty->print_cr(">>> frame::deoptimize");
 332   // print_on(tty);
 333   assert(thread == NULL
 334          || (thread->frame_anchor()->has_last_Java_frame() &&
 335              thread->frame_anchor()->walkable()), "must be");
 336   // Schedule deoptimization of an nmethod activation with this frame.
 337   assert(_cb != NULL && _cb->is_compiled(), "must be");
 338 
 339   // log_develop_trace(jvmcont)(">>>> frame::deoptimize %ld", os::current_thread_id());
 340   // tty->print_cr(">>>> frame::deoptimize: %ld", os::current_thread_id()); print_on(tty);
 341 
 342   // If the call site is a MethodHandle call site use the MH deopt
 343   // handler.
 344   CompiledMethod* cm = (CompiledMethod*) _cb;
 345   address deopt = cm->is_method_handle_return(pc()) ?
 346                         cm->deopt_mh_handler_begin() :
 347                         cm->deopt_handler_begin();
 348 
 349   NativePostCallNop* inst = nativePostCallNop_at(pc());
 350 
 351   // Save the original pc before we patch in the new one
 352   cm->set_original_pc(this, pc());
 353   patch_pc(thread, deopt);
 354   assert(is_deoptimized_frame(), "must be");
 355 
 356 #ifdef ASSERT
 357   if (thread != NULL) {
 358     frame check = thread->last_frame();
 359     if (is_older(check.id())) {
 360       RegisterMap map(thread, false);
 361       while (id() != check.id()) {
 362         check = check.sender(&map);
 363       }
 364       assert(check.is_deoptimized_frame(), "missed deopt");
 365     }
 366   }
 367 #endif // ASSERT
 368 }
 369 
 370 frame frame::java_sender() const {
 371   RegisterMap map(JavaThread::current(), false);
 372   frame s;
 373   for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ;
 374   guarantee(s.is_java_frame(), "tried to get caller of first java frame");
 375   return s;
 376 }
 377 
 378 frame frame::real_sender(RegisterMap* map) const {
 379   frame result = sender(map);
 380   while (result.is_runtime_frame() ||
 381          result.is_ignored_frame()) {
 382     result = result.sender(map);
 383   }
 384   return result;
 385 }
 386 
 387 // Interpreter frames
 388 
 389 
 390 void frame::interpreter_frame_set_locals(intptr_t* locs)  {
 391   assert(is_interpreted_frame(), "Not an interpreted frame");
 392   *interpreter_frame_locals_addr() = locs;
 393 }
 394 
 395 Method* frame::interpreter_frame_method() const {
 396   assert(is_interpreted_frame(), "interpreted frame expected");
 397   Method* m = *interpreter_frame_method_addr();
 398   assert(m->is_method(), "not a Method*");
 399   return m;
 400 }
 401 
 402 void frame::interpreter_frame_set_method(Method* method) {
 403   assert(is_interpreted_frame(), "interpreted frame expected");
 404   *interpreter_frame_method_addr() = method;
 405 }
 406 
 407 void frame::interpreter_frame_set_mirror(oop mirror) {
 408   assert(is_interpreted_frame(), "interpreted frame expected");
 409   *interpreter_frame_mirror_addr() = mirror;
 410 }
 411 
 412 jint frame::interpreter_frame_bci() const {
 413   assert(is_interpreted_frame(), "interpreted frame expected");
 414   address bcp = interpreter_frame_bcp();
 415   return interpreter_frame_method()->bci_from(bcp);
 416 }
 417 
 418 address frame::interpreter_frame_bcp() const {
 419   assert(is_interpreted_frame(), "interpreted frame expected");
 420   address bcp = (address)*interpreter_frame_bcp_addr();
 421   return interpreter_frame_method()->bcp_from(bcp);
 422 }
 423 
 424 void frame::interpreter_frame_set_bcp(address bcp) {
 425   assert(is_interpreted_frame(), "interpreted frame expected");
 426   *interpreter_frame_bcp_addr() = (intptr_t)bcp;
 427 }
 428 
 429 address frame::interpreter_frame_mdp() const {
 430   assert(ProfileInterpreter, "must be profiling interpreter");
 431   assert(is_interpreted_frame(), "interpreted frame expected");
 432   return (address)*interpreter_frame_mdp_addr();
 433 }
 434 
 435 void frame::interpreter_frame_set_mdp(address mdp) {
 436   assert(is_interpreted_frame(), "interpreted frame expected");
 437   assert(ProfileInterpreter, "must be profiling interpreter");
 438   *interpreter_frame_mdp_addr() = (intptr_t)mdp;
 439 }
 440 
 441 template BasicObjectLock* frame::next_monitor_in_interpreter_frame<true>(BasicObjectLock* current) const;
 442 template BasicObjectLock* frame::next_monitor_in_interpreter_frame<false>(BasicObjectLock* current) const;
 443 
 444 template <bool relative>
 445 BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const {
 446   assert(is_interpreted_frame(), "Not an interpreted frame");
 447 #ifdef ASSERT
 448   interpreter_frame_verify_monitor<relative>(current);
 449 #endif
 450   BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size());
 451   return next;
 452 }
 453 
 454 BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const {
 455   assert(is_interpreted_frame(), "Not an interpreted frame");
 456 #ifdef ASSERT
 457 //   // This verification needs to be checked before being enabled
 458 //   interpreter_frame_verify_monitor(current);
 459 #endif
 460   BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size());
 461   return previous;
 462 }
 463 
 464 // Interpreter locals and expression stack locations.
 465 
 466 template intptr_t* frame::interpreter_frame_local_at<true>(int index) const;
 467 template intptr_t* frame::interpreter_frame_local_at<false>(int index) const;
 468 
 469 template <bool relative>
 470 intptr_t* frame::interpreter_frame_local_at(int index) const {
 471   const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
 472   intptr_t* first = relative ? fp() + (intptr_t)*interpreter_frame_locals_addr()
 473                              : *interpreter_frame_locals_addr();
 474   return &(first[n]);
 475 }
 476 
 477 template intptr_t* frame::interpreter_frame_expression_stack_at<true>(jint index) const;
 478 template intptr_t* frame::interpreter_frame_expression_stack_at<false>(jint index) const;
 479 
 480 template <bool relative>
 481 intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
 482   const int i = offset * interpreter_frame_expression_stack_direction();
 483   const int n = i * Interpreter::stackElementWords;
 484   return &(interpreter_frame_expression_stack<relative>()[n]);
 485 }
 486 
 487 template jint frame::interpreter_frame_expression_stack_size<true>() const;
 488 template jint frame::interpreter_frame_expression_stack_size<false>() const;
 489 
 490 template <bool relative>
 491 jint frame::interpreter_frame_expression_stack_size() const {
 492   // Number of elements on the interpreter expression stack
 493   // Callers should span by stackElementWords
 494   int element_size = Interpreter::stackElementWords;
 495   size_t stack_size = 0;
 496   if (frame::interpreter_frame_expression_stack_direction() < 0) {
 497     stack_size = (interpreter_frame_expression_stack<relative>() -
 498                   interpreter_frame_tos_address<relative>() + 1)/element_size;
 499   } else {
 500     stack_size = (interpreter_frame_tos_address<relative>() -
 501                   interpreter_frame_expression_stack<relative>() + 1)/element_size;
 502   }
 503   assert( stack_size <= (size_t)max_jint, "stack size too big");
 504   return ((jint)stack_size);
 505 }
 506 
 507 
 508 // (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp)
 509 
 510 const char* frame::print_name() const {
 511   if (is_native_frame())      return "Native";
 512   if (is_interpreted_frame()) return "Interpreted";
 513   if (is_compiled_frame()) {
 514     if (is_deoptimized_frame()) return "Deoptimized";
 515     return "Compiled";
 516   }
 517   if (sp() == NULL)            return "Empty";
 518   return "C";
 519 }
 520 
 521 void frame::print_value_on(outputStream* st, JavaThread *thread) const {
 522   NOT_PRODUCT(address begin = pc()-40;)
 523   NOT_PRODUCT(address end   = NULL;)
 524 
 525   st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), p2i(sp()), p2i(unextended_sp()));
 526   if (sp() != NULL)
 527     st->print(", fp=" INTPTR_FORMAT ", real_fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT,
 528               p2i(fp()), p2i(real_fp()), p2i(pc()));
 529   st->print_cr(")");
 530 
 531   if (StubRoutines::contains(pc())) {
 532     StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
 533     st->print("~Stub::%s", desc->name());
 534     NOT_PRODUCT(begin = desc->begin(); end = desc->end();)
 535   } else if (Interpreter::contains(pc())) {
 536     InterpreterCodelet* desc = Interpreter::codelet_containing(pc());
 537     if (desc != NULL) {
 538       st->print("~");
 539       desc->print_on(st);
 540       NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();)
 541     } else {
 542       st->print("~interpreter");
 543     }
 544   }
 545 
 546 #ifndef PRODUCT
 547   if (_cb != NULL) {
 548     st->print("     ");
 549     _cb->print_value_on(st);
 550     if (end == NULL) {
 551       begin = _cb->code_begin();
 552       end   = _cb->code_end();
 553     }
 554   }
 555   if (WizardMode && Verbose) Disassembler::decode(begin, end);
 556 #endif
 557 }
 558 
 559 
 560 template void frame::print_on<false>(outputStream* st) const;
 561 template void frame::print_on<true >(outputStream* st) const;
 562 
 563 template <bool relative>
 564 void frame::print_on(outputStream* st) const {
 565   print_value_on(st,NULL);
 566   if (is_interpreted_frame()) {
 567     interpreter_frame_print_on<relative>(st);
 568   }
 569 }
 570 
 571 template <bool relative>
 572 void frame::interpreter_frame_print_on(outputStream* st) const {
 573 #ifndef PRODUCT
 574   assert(is_interpreted_frame(), "Not an interpreted frame");
 575   jint i;
 576   for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
 577     intptr_t x = *interpreter_frame_local_at<relative>(i);
 578     st->print(" - local  [" INTPTR_FORMAT "]", x);
 579     st->fill_to(23);
 580     st->print_cr("; #%d", i);
 581   }
 582   for (i = interpreter_frame_expression_stack_size<relative>() - 1; i >= 0; --i ) {
 583     intptr_t x = *interpreter_frame_expression_stack_at<relative>(i);
 584     st->print(" - stack  [" INTPTR_FORMAT "]", x);
 585     st->fill_to(23);
 586     st->print_cr("; #%d", i);
 587   }
 588   // locks for synchronization
 589   for (BasicObjectLock* current = interpreter_frame_monitor_end<relative>();
 590        current < interpreter_frame_monitor_begin();
 591        current = next_monitor_in_interpreter_frame<relative>(current)) {
 592     st->print(" - obj    [");
 593     current->obj()->print_value_on(st);
 594     st->print_cr("]");
 595     st->print(" - lock   [");
 596     current->lock()->print_on(st, current->obj());
 597     st->print_cr("]");
 598   }
 599   // monitor
 600   st->print_cr(" - monitor[" INTPTR_FORMAT "]", p2i(interpreter_frame_monitor_begin()));
 601   // bcp
 602   st->print(" - bcp    [" INTPTR_FORMAT "]", p2i(interpreter_frame_bcp()));
 603   st->fill_to(23);
 604   st->print_cr("; @%d", interpreter_frame_bci());
 605   // locals
 606   st->print_cr(" - locals [" INTPTR_FORMAT "]", p2i(interpreter_frame_local_at<relative>(0)));
 607   // method
 608   st->print(" - method [" INTPTR_FORMAT "]", p2i(interpreter_frame_method()));
 609   st->fill_to(23);
 610   st->print("; ");
 611   interpreter_frame_method()->print_name(st);
 612   st->cr();
 613 #endif
 614 }
 615 
 616 // Print whether the frame is in the VM or OS indicating a HotSpot problem.
 617 // Otherwise, it's likely a bug in the native library that the Java code calls,
 618 // hopefully indicating where to submit bugs.
 619 void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) {
 620   // C/C++ frame
 621   bool in_vm = os::address_is_in_vm(pc);
 622   st->print(in_vm ? "V" : "C");
 623 
 624   int offset;
 625   bool found;
 626 
 627   if (buf == NULL || buflen < 1) return;
 628   // libname
 629   buf[0] = '\0';
 630   found = os::dll_address_to_library_name(pc, buf, buflen, &offset);
 631   if (found && buf[0] != '\0') {
 632     // skip directory names
 633     const char *p1, *p2;
 634     p1 = buf;
 635     int len = (int)strlen(os::file_separator());
 636     while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
 637     st->print("  [%s+0x%x]", p1, offset);
 638   } else {
 639     st->print("  " PTR_FORMAT, p2i(pc));
 640   }
 641 
 642   found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
 643   if (found) {
 644     st->print("  %s+0x%x", buf, offset);
 645   }
 646 }
 647 
 648 // frame::print_on_error() is called by fatal error handler. Notice that we may
 649 // crash inside this function if stack frame is corrupted. The fatal error
 650 // handler can catch and handle the crash. Here we assume the frame is valid.
 651 //
 652 // First letter indicates type of the frame:
 653 //    J: Java frame (compiled)
 654 //    j: Java frame (interpreted)
 655 //    V: VM frame (C/C++)
 656 //    v: Other frames running VM generated code (e.g. stubs, adapters, etc.)
 657 //    C: C/C++ frame
 658 //
 659 // We don't need detailed frame type as that in frame::print_name(). "C"
 660 // suggests the problem is in user lib; everything else is likely a VM bug.
 661 
 662 void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const {
 663   if (_cb != NULL) {
 664     if (Interpreter::contains(pc())) {
 665       Method* m = this->interpreter_frame_method();
 666       if (m != NULL) {
 667         m->name_and_sig_as_C_string(buf, buflen);
 668         st->print("j  %s", buf);
 669         st->print("+%d", this->interpreter_frame_bci());
 670         ModuleEntry* module = m->method_holder()->module();
 671         if (module->is_named()) {
 672           module->name()->as_C_string(buf, buflen);
 673           st->print(" %s", buf);
 674           if (module->version() != NULL) {
 675             module->version()->as_C_string(buf, buflen);
 676             st->print("@%s", buf);
 677           }
 678         }
 679       } else {
 680         st->print("j  " PTR_FORMAT, p2i(pc()));
 681       }
 682     } else if (StubRoutines::contains(pc())) {
 683       StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
 684       if (desc != NULL) {
 685         st->print("v  ~StubRoutines::%s " PTR_FORMAT, desc->name(), p2i(pc()));
 686       } else {
 687         st->print("v  ~StubRoutines::" PTR_FORMAT, p2i(pc()));
 688       }
 689     } else if (_cb->is_buffer_blob()) {
 690       st->print("v  ~BufferBlob::%s " PTR_FORMAT, ((BufferBlob *)_cb)->name(), p2i(pc()));
 691     } else if (_cb->is_compiled()) {
 692       CompiledMethod* cm = (CompiledMethod*)_cb;
 693       Method* m = cm->method();
 694       if (m != NULL) {
 695         if (cm->is_nmethod()) {
 696           nmethod* nm = cm->as_nmethod();
 697           st->print("J %d%s", nm->compile_id(), (nm->is_osr_method() ? "%" : ""));
 698           st->print(" %s", nm->compiler_name());
 699         }
 700         m->name_and_sig_as_C_string(buf, buflen);
 701         st->print(" %s", buf);
 702         ModuleEntry* module = m->method_holder()->module();
 703         if (module->is_named()) {
 704           module->name()->as_C_string(buf, buflen);
 705           st->print(" %s", buf);
 706           if (module->version() != NULL) {
 707             module->version()->as_C_string(buf, buflen);
 708             st->print("@%s", buf);
 709           }
 710         }
 711         st->print(" (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+" INTPTR_FORMAT "]",
 712                   m->code_size(), p2i(_pc), p2i(_cb->code_begin()), _pc - _cb->code_begin());
 713 #if INCLUDE_JVMCI
 714         if (cm->is_nmethod()) {
 715           nmethod* nm = cm->as_nmethod();
 716           const char* jvmciName = nm->jvmci_name();
 717           if (jvmciName != NULL) {
 718             st->print(" (%s)", jvmciName);
 719           }
 720         }
 721 #endif
 722       } else {
 723         st->print("J  " PTR_FORMAT, p2i(pc()));
 724       }
 725     } else if (_cb->is_runtime_stub()) {
 726       st->print("v  ~RuntimeStub::%s " PTR_FORMAT, ((RuntimeStub *)_cb)->name(), p2i(pc()));
 727     } else if (_cb->is_deoptimization_stub()) {
 728       st->print("v  ~DeoptimizationBlob " PTR_FORMAT, p2i(pc()));
 729     } else if (_cb->is_exception_stub()) {
 730       st->print("v  ~ExceptionBlob " PTR_FORMAT, p2i(pc()));
 731     } else if (_cb->is_safepoint_stub()) {
 732       st->print("v  ~SafepointBlob " PTR_FORMAT, p2i(pc()));
 733     } else if (_cb->is_adapter_blob()) {
 734       st->print("v  ~AdapterBlob " PTR_FORMAT, p2i(pc()));
 735     } else if (_cb->is_vtable_blob()) {
 736       st->print("v  ~VtableBlob " PTR_FORMAT, p2i(pc()));
 737     } else if (_cb->is_method_handles_adapter_blob()) {
 738       st->print("v  ~MethodHandlesAdapterBlob " PTR_FORMAT, p2i(pc()));
 739     } else if (_cb->is_uncommon_trap_stub()) {
 740       st->print("v  ~UncommonTrapBlob " PTR_FORMAT, p2i(pc()));
 741     } else {
 742       st->print("v  blob " PTR_FORMAT, p2i(pc()));
 743     }
 744   } else {
 745     print_C_frame(st, buf, buflen, pc());
 746   }
 747 }
 748 
 749 
 750 /*
 751   The interpreter_frame_expression_stack_at method in the case of SPARC needs the
 752   max_stack value of the method in order to compute the expression stack address.
 753   It uses the Method* in order to get the max_stack value but during GC this
 754   Method* value saved on the frame is changed by reverse_and_push and hence cannot
 755   be used. So we save the max_stack value in the FrameClosure object and pass it
 756   down to the interpreter_frame_expression_stack_at method
 757 */
 758 template <bool relative>
 759 class InterpreterFrameClosure : public OffsetClosure {
 760  private:
 761   const frame* _fr;
 762   OopClosure*  _f;
 763   int          _max_locals;
 764   int          _max_stack;
 765 
 766  public:
 767   InterpreterFrameClosure(const frame* fr, int max_locals, int max_stack,
 768                           OopClosure* f) {
 769     _fr         = fr;
 770     _max_locals = max_locals;
 771     _max_stack  = max_stack;
 772     _f          = f;
 773   }
 774 
 775   void offset_do(int offset) {
 776     oop* addr;
 777     if (offset < _max_locals) {
 778       addr = (oop*) _fr->interpreter_frame_local_at<relative>(offset);
 779       assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
 780       DEBUG_ONLY(if (log_develop_is_enabled(Trace, jvmcont) && relative) log_develop_trace(jvmcont)("InterpreterFrameClosure::offset_do local p: " INTPTR_FORMAT, p2i(addr));)
 781       _f->do_oop(addr);
 782     } else {
 783       addr = (oop*) _fr->interpreter_frame_expression_stack_at<relative>((offset - _max_locals));
 784       // In case of exceptions, the expression stack is invalid and the esp will be reset to express
 785       // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
 786       bool in_stack;
 787       if (frame::interpreter_frame_expression_stack_direction() > 0) {
 788         in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address<relative>();
 789       } else {
 790         in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address<relative>();
 791       }
 792       if (in_stack) {
 793         DEBUG_ONLY(if (log_develop_is_enabled(Trace, jvmcont) && relative) log_develop_trace(jvmcont)("InterpreterFrameClosure::offset_do stack p: " INTPTR_FORMAT, p2i(addr));)
 794         _f->do_oop(addr);
 795       }
 796     }
 797   }
 798 
 799   int max_locals()  { return _max_locals; }
 800 };
 801 
 802 
 803 class InterpretedArgumentOopFinder: public SignatureIterator {
 804  private:
 805   OopClosure*  _f;             // Closure to invoke
 806   int          _offset;        // TOS-relative offset, decremented with each argument
 807   bool         _has_receiver;  // true if the callee has a receiver
 808   const frame* _fr;
 809 
 810   friend class SignatureIterator;  // so do_parameters_on can call do_type
 811   void do_type(BasicType type) {
 812     _offset -= parameter_type_word_count(type);
 813     if (is_reference_type(type)) oop_offset_do();
 814    }
 815 
 816   void oop_offset_do() {
 817     oop* addr;
 818     addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
 819     _f->do_oop(addr);
 820   }
 821 
 822  public:
 823   InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, const frame* fr, OopClosure* f) : SignatureIterator(signature), _has_receiver(has_receiver) {
 824     // compute size of arguments
 825     int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
 826     assert(!fr->is_interpreted_frame() ||
 827            args_size <= fr->interpreter_frame_expression_stack_size(),
 828             "args cannot be on stack anymore");
 829     // initialize InterpretedArgumentOopFinder
 830     _f         = f;
 831     _fr        = fr;
 832     _offset    = args_size;
 833   }
 834 
 835   void oops_do() {
 836     if (_has_receiver) {
 837       --_offset;
 838       oop_offset_do();
 839     }
 840     do_parameters_on(this);
 841   }
 842 };
 843 
 844 
 845 // Entry frame has following form (n arguments)
 846 //         +-----------+
 847 //   sp -> |  last arg |
 848 //         +-----------+
 849 //         :    :::    :
 850 //         +-----------+
 851 // (sp+n)->|  first arg|
 852 //         +-----------+
 853 
 854 
 855 
 856 // visits and GC's all the arguments in entry frame
 857 class EntryFrameOopFinder: public SignatureIterator {
 858  private:
 859   bool         _is_static;
 860   int          _offset;
 861   const frame* _fr;
 862   OopClosure*  _f;
 863 
 864   friend class SignatureIterator;  // so do_parameters_on can call do_type
 865   void do_type(BasicType type) {
 866     // decrement offset before processing the type
 867     _offset -= parameter_type_word_count(type);
 868     assert (_offset >= 0, "illegal offset");
 869     if (is_reference_type(type))  oop_at_offset_do(_offset);
 870  }
 871 
 872   void oop_at_offset_do(int offset) {
 873     assert (offset >= 0, "illegal offset");
 874     oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
 875     _f->do_oop(addr);
 876   }
 877 
 878  public:
 879   EntryFrameOopFinder(const frame* frame, Symbol* signature, bool is_static) : SignatureIterator(signature) {
 880     _f = NULL; // will be set later
 881     _fr = frame;
 882     _is_static = is_static;
 883     _offset = ArgumentSizeComputer(signature).size();  // pre-decremented down to zero
 884   }
 885 
 886   void arguments_do(OopClosure* f) {
 887     _f = f;
 888     if (!_is_static)  oop_at_offset_do(_offset); // do the receiver
 889     do_parameters_on(this);
 890   }
 891 
 892 };
 893 
 894 oop* frame::interpreter_callee_receiver_addr(Symbol* signature) {
 895   ArgumentSizeComputer asc(signature);
 896   int size = asc.size();
 897   return (oop *)interpreter_frame_tos_at(size);
 898 }
 899 
 900 oop frame::interpreter_callee_receiver(Symbol* signature) {
 901   // TODO: Erik: remove after integration with concurrent stack scanning
 902   oop r = *interpreter_callee_receiver_addr(signature);
 903   r = NativeAccess<>::oop_load(&r);
 904   return r;
 905 }
 906 
 907 template <bool relative>
 908 void frame::oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) const {
 909   Thread* current = Thread::current();
 910   methodHandle m(current, interpreter_frame_method());
 911   jint bci = interpreter_frame_bci();
 912 
 913   ResourceMark rm;
 914   InterpreterOopMap mask;
 915   if (query_oop_map_cache) {
 916     m->mask_for(bci, &mask);
 917   } else {
 918     OopMapCache::compute_one_oop_map(m, bci, &mask);
 919   }
 920 
 921   oops_interpreted_do0<relative>(f, map, m, bci, mask);
 922 }
 923 
 924 // Initialize explicitly so that these can be used only with definitions.
 925 // TODO: Rectify as Loom stabilizes...
 926 template void frame::oops_interpreted_do<true> (OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) const;
 927 template void frame::oops_interpreted_do<false>(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) const;
 928 
 929 template <bool relative>
 930 void frame::oops_interpreted_do0(OopClosure* f, const RegisterMap* map, methodHandle m, jint bci, const InterpreterOopMap& mask) const {
 931   assert(is_interpreted_frame(), "Not an interpreted frame");
 932   assert(!Universe::heap()->is_in(m()),
 933           "must be valid oop");
 934   assert(m->is_method(), "checking frame value");
 935   assert((m->is_native() && bci == 0)  ||
 936          (!m->is_native() && bci >= 0 && bci < m->code_size()),
 937          "invalid bci value");
 938 
 939   // Handle the monitor elements in the activation
 940   for (
 941     BasicObjectLock* current = interpreter_frame_monitor_end<relative>();
 942     current < interpreter_frame_monitor_begin();
 943     current = next_monitor_in_interpreter_frame<relative>(current)
 944   ) {
 945 #ifdef ASSERT
 946     interpreter_frame_verify_monitor<relative>(current);
 947 #endif
 948     current->oops_do(f);
 949   }
 950 
 951   if (m->is_native()) {
 952     f->do_oop(interpreter_frame_temp_oop_addr());
 953   }
 954 
 955   // The method pointer in the frame might be the only path to the method's
 956   // klass, and the klass needs to be kept alive while executing. The GCs
 957   // don't trace through method pointers, so the mirror of the method's klass
 958   // is installed as a GC root.
 959   f->do_oop(interpreter_frame_mirror_addr());
 960 
 961   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
 962 
 963   Symbol* signature = NULL;
 964   bool has_receiver = false;
 965 
 966   // Process a callee's arguments if we are at a call site
 967   // (i.e., if we are at an invoke bytecode)
 968   // This is used sometimes for calling into the VM, not for another
 969   // interpreted or compiled frame.
 970   if (!m->is_native()) {
 971     Bytecode_invoke call = Bytecode_invoke_check(m, bci);
 972     if (call.is_valid()) {
 973       signature = call.signature();
 974       has_receiver = call.has_receiver();
 975       if (map != NULL && map->include_argument_oops() &&
 976           interpreter_frame_expression_stack_size<relative>() > 0) {
 977         // ResourceMark rm(thread);  // is this right ???
 978         // we are at a call site & the expression stack is not empty
 979         // => process callee's arguments
 980         //
 981         // Note: The expression stack can be empty if an exception
 982         //       occurred during method resolution/execution. In all
 983         //       cases we empty the expression stack completely be-
 984         //       fore handling the exception (the exception handling
 985         //       code in the interpreter calls a blocking runtime
 986         //       routine which can cause this code to be executed).
 987         //       (was bug gri 7/27/98)
 988         oops_interpreted_arguments_do(signature, has_receiver, f);
 989       }
 990     }
 991   }
 992 
 993   InterpreterFrameClosure<relative> blk(this, max_locals, m->max_stack(), f);
 994 
 995   // process locals & expression stack
 996   // mask.print();
 997   mask.iterate_oop(&blk);
 998 }
 999 
1000 
1001 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) const {
1002   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
1003   finder.oops_do();
1004 }
1005 
1006 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, DerivedOopClosure* df, DerivedPointerIterationMode derived_mode, const RegisterMap* reg_map) const {
1007   assert(_cb != NULL, "sanity check");
1008   assert((oop_map() == NULL) == (_cb->oop_maps() == NULL), "frame and _cb must agree that oopmap is set or not");
1009   if (oop_map() != NULL) {
1010     if (df != NULL) {
1011       _oop_map->oops_do(this, reg_map, f, df);
1012     } else {
1013       _oop_map->oops_do(this, reg_map, f, derived_mode);
1014     }
1015 
1016     // Preserve potential arguments for a callee. We handle this by dispatching
1017     // on the codeblob. For c2i, we do
1018     if (reg_map->include_argument_oops()) {
1019       _cb->preserve_callee_argument_oops(*this, reg_map, f);
1020     }
1021   }
1022   // In cases where perm gen is collected, GC will want to mark
1023   // oops referenced from nmethods active on thread stacks so as to
1024   // prevent them from being collected. However, this visit should be
1025   // restricted to certain phases of the collection only. The
1026   // closure decides how it wants nmethods to be traced.
1027   if (cf != NULL)
1028     cf->do_code_blob(_cb);
1029 }
1030 
1031 class CompiledArgumentOopFinder: public SignatureIterator {
1032  protected:
1033   OopClosure*     _f;
1034   int             _offset;        // the current offset, incremented with each argument
1035   bool            _has_receiver;  // true if the callee has a receiver
1036   bool            _has_appendix;  // true if the call has an appendix
1037   frame           _fr;
1038   RegisterMap*    _reg_map;
1039   int             _arg_size;
1040   VMRegPair*      _regs;        // VMReg list of arguments
1041 
1042   friend class SignatureIterator;  // so do_parameters_on can call do_type
1043   void do_type(BasicType type) {
1044     if (is_reference_type(type))  handle_oop_offset();
1045     _offset += parameter_type_word_count(type);
1046   }
1047 
1048   virtual void handle_oop_offset() {
1049     // Extract low order register number from register array.
1050     // In LP64-land, the high-order bits are valid but unhelpful.
1051     VMReg reg = _regs[_offset].first();
1052     oop *loc = _fr.oopmapreg_to_oop_location(reg, _reg_map);
1053   #ifdef ASSERT
1054     if (loc == NULL) {
1055       if (_reg_map->should_skip_missing())
1056         return;
1057       tty->print_cr("Error walking frame oops:");
1058       _fr.print_on(tty);
1059       assert(loc != NULL, "missing register map entry reg: " INTPTR_FORMAT " %s loc: " INTPTR_FORMAT, reg->value(), reg->name(), p2i(loc));
1060     }
1061   #endif
1062     _f->do_oop(loc);
1063   }
1064 
1065  public:
1066   CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map)
1067     : SignatureIterator(signature) {
1068 
1069     // initialize CompiledArgumentOopFinder
1070     _f         = f;
1071     _offset    = 0;
1072     _has_receiver = has_receiver;
1073     _has_appendix = has_appendix;
1074     _fr        = fr;
1075     _reg_map   = (RegisterMap*)reg_map;
1076     _arg_size  = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0);
1077 
1078     int arg_size;
1079     _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size);
1080     assert(arg_size == _arg_size, "wrong arg size");
1081   }
1082 
1083   void oops_do() {
1084     if (_has_receiver) {
1085       handle_oop_offset();
1086       _offset++;
1087     }
1088     do_parameters_on(this);
1089     if (_has_appendix) {
1090       handle_oop_offset();
1091       _offset++;
1092     }
1093   }
1094 };
1095 
1096 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix,
1097                                        const RegisterMap* reg_map, OopClosure* f) const {
1098   // ResourceMark rm;
1099   CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
1100   finder.oops_do();
1101 }
1102 
1103 // Get receiver out of callers frame, i.e. find parameter 0 in callers
1104 // frame.  Consult ADLC for where parameter 0 is to be found.  Then
1105 // check local reg_map for it being a callee-save register or argument
1106 // register, both of which are saved in the local frame.  If not found
1107 // there, it must be an in-stack argument of the caller.
1108 // Note: caller.sp() points to callee-arguments
1109 oop frame::retrieve_receiver(RegisterMap* reg_map) {
1110   frame caller = *this;
1111 
1112   // First consult the ADLC on where it puts parameter 0 for this signature.
1113   VMReg reg = SharedRuntime::name_for_receiver();
1114   oop* oop_adr = caller.oopmapreg_to_oop_location(reg, reg_map);
1115   if (oop_adr == NULL) {
1116     guarantee(oop_adr != NULL, "bad register save location");
1117     return NULL;
1118   }
1119   oop r = *oop_adr;
1120   // TODO: Erik: remove after integration with concurrent stack scanning
1121   r = NativeAccess<>::oop_load(&r);
1122   assert(Universe::heap()->is_in_or_null(r), "bad receiver: " INTPTR_FORMAT " (" INTX_FORMAT ")", p2i(r), p2i(r));
1123   return r;
1124 }
1125 
1126 
1127 BasicLock* frame::get_native_monitor() {
1128   nmethod* nm = (nmethod*)_cb;
1129   assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
1130          "Should not call this unless it's a native nmethod");
1131   int byte_offset = in_bytes(nm->native_basic_lock_sp_offset());
1132   assert(byte_offset >= 0, "should not see invalid offset");
1133   return (BasicLock*) &sp()[byte_offset / wordSize];
1134 }
1135 
1136 oop frame::get_native_receiver() {
1137   nmethod* nm = (nmethod*)_cb;
1138   assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
1139          "Should not call this unless it's a native nmethod");
1140   int byte_offset = in_bytes(nm->native_receiver_sp_offset());
1141   assert(byte_offset >= 0, "should not see invalid offset");
1142   oop owner = ((oop*) sp())[byte_offset / wordSize];
1143   // TODO: Erik: remove after integration with concurrent stack scanning
1144   owner = NativeAccess<>::oop_load(&owner);
1145   assert( Universe::heap()->is_in(owner), "bad receiver" );
1146   return owner;
1147 }
1148 
1149 void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) const {
1150   assert(map != NULL, "map must be set");
1151   if (map->include_argument_oops()) {
1152     // must collect argument oops, as nobody else is doing it
1153     Thread *thread = Thread::current();
1154     methodHandle m (thread, entry_frame_call_wrapper()->callee_method());
1155     EntryFrameOopFinder finder(this, m->signature(), m->is_static());
1156     finder.arguments_do(f);
1157   }
1158   // Traverse the Handle Block saved in the entry frame
1159   entry_frame_call_wrapper()->oops_do(f);
1160 }
1161 
1162 bool frame::is_deoptimized_frame() const {
1163   assert(_deopt_state != unknown, "not answerable");
1164   if (_deopt_state == is_deoptimized) {
1165     return true;
1166   }
1167 
1168   /* This method only checks if the frame is deoptimized
1169    * as in return address being patched.
1170    * It doesn't care if the OP that we return to is a
1171    * deopt instruction */
1172   /*if (_cb != NULL && _cb->is_nmethod()) {
1173     return NativeDeoptInstruction::is_deopt_at(_pc);
1174   }*/
1175   return false;
1176 }
1177 
1178 void frame::oops_do_internal(OopClosure* f, CodeBlobClosure* cf, DerivedOopClosure* df, DerivedPointerIterationMode derived_mode, const RegisterMap* map, bool use_interpreter_oop_map_cache) const {
1179 #ifndef PRODUCT
1180   // simulate GC crash here to dump java thread in error report
1181   if (CrashGCForDumpingJavaThread) {
1182     char *t = NULL;
1183     *t = 'c';
1184   }
1185 #endif
1186   if (is_interpreted_frame()) {
1187     map->thread() != NULL ? oops_interpreted_do<false>(f, map, use_interpreter_oop_map_cache)
1188                           : oops_interpreted_do<true >(f, map, use_interpreter_oop_map_cache);
1189   } else if (is_entry_frame()) {
1190     oops_entry_do(f, map);
1191   } else if (is_optimized_entry_frame()) {
1192     _cb->as_optimized_entry_blob()->oops_do(f, *this);
1193   } else if (CodeCache::contains(pc())) {
1194     oops_code_blob_do(f, cf, df, derived_mode, map);
1195   } else {
1196     ShouldNotReachHere();
1197   }
1198 }
1199 
1200 void frame::nmethods_do(CodeBlobClosure* cf) const {
1201   if (_cb != NULL && _cb->is_nmethod()) {
1202     cf->do_code_blob(_cb);
1203   }
1204 }
1205 
1206 
1207 // Call f closure on the interpreted Method*s in the stack.
1208 void frame::metadata_do(MetadataClosure* f) const {
1209   ResourceMark rm;
1210   if (is_interpreted_frame()) {
1211     Method* m = this->interpreter_frame_method();
1212     assert(m != NULL, "expecting a method in this frame");
1213     f->do_metadata(m);
1214   }
1215 }
1216 
1217 void frame::verify(const RegisterMap* map) const {
1218 #ifndef PRODUCT
1219   if (TraceCodeBlobStacks) {
1220     tty->print_cr("*** verify");
1221     print_on(tty);
1222   }
1223 #endif
1224 
1225   // for now make sure receiver type is correct
1226   if (is_interpreted_frame()) {
1227     Method* method = interpreter_frame_method();
1228     guarantee(method->is_method(), "method is wrong in frame::verify");
1229     if (!method->is_static()) {
1230       // fetch the receiver
1231       oop* p = (oop*) interpreter_frame_local_at(0);
1232       // make sure we have the right receiver type
1233     }
1234   }
1235 #if COMPILER2_OR_JVMCI
1236   assert(DerivedPointerTable::is_empty(), "must be empty before verify");
1237 #endif
1238 
1239   if (map->update_map()) { // The map has to be up-to-date for the current frame
1240     oops_do_internal(&VerifyOopClosure::verify_oop, NULL, NULL, DerivedPointerIterationMode::_ignore, map, false);
1241   }
1242 }
1243 
1244 
1245 #ifdef ASSERT
1246 bool frame::verify_return_pc(address x) {
1247   if (StubRoutines::returns_to_call_stub(x)) {
1248     return true;
1249   }
1250   if (CodeCache::contains(x)) {
1251     return true;
1252   }
1253   if (Interpreter::contains(x)) {
1254     return true;
1255   }
1256   return false;
1257 }
1258 #endif
1259 
1260 #ifdef ASSERT
1261 template <bool relative>
1262 void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const {
1263   assert(is_interpreted_frame(), "Not an interpreted frame");
1264   // verify that the value is in the right part of the frame
1265   address low_mark  = (address) interpreter_frame_monitor_end<relative>();
1266   address high_mark = (address) interpreter_frame_monitor_begin();
1267   address current   = (address) value;
1268 
1269   const int monitor_size = frame::interpreter_frame_monitor_size();
1270   guarantee((high_mark - current) % monitor_size  ==  0         , "Misaligned top of BasicObjectLock*");
1271   guarantee( high_mark > current                                , "Current BasicObjectLock* higher than high_mark");
1272 
1273   guarantee((current - low_mark) % monitor_size  ==  0         , "Misaligned bottom of BasicObjectLock*");
1274   guarantee( current >= low_mark                               , "Current BasicObjectLock* below than low_mark");
1275 }
1276 #endif
1277 
1278 #ifndef PRODUCT
1279 
1280 // Returns true iff the address p is readable and *(intptr_t*)p != errvalue
1281 extern "C" bool dbg_is_safe(const void* p, intptr_t errvalue);
1282 
1283 class FrameValuesOopClosure: public OopClosure, public DerivedOopClosure {
1284 private:
1285   GrowableArray<oop*>* _oops;
1286   GrowableArray<narrowOop*>* _narrow_oops;
1287   GrowableArray<oop*>* _base;
1288   GrowableArray<derived_pointer*>* _derived;
1289   NoSafepointVerifier nsv;
1290 public:
1291   FrameValuesOopClosure() {
1292     _oops = new (ResourceObj::C_HEAP, mtThread) GrowableArray<oop*>(100, mtThread);
1293     _narrow_oops = new (ResourceObj::C_HEAP, mtThread) GrowableArray<narrowOop*>(100, mtThread);
1294     _base = new (ResourceObj::C_HEAP, mtThread) GrowableArray<oop*>(100, mtThread);
1295     _derived = new (ResourceObj::C_HEAP, mtThread) GrowableArray<derived_pointer*>(100, mtThread);
1296   }
1297   ~FrameValuesOopClosure() {
1298     delete _oops;
1299     delete _narrow_oops;
1300     delete _base;
1301     delete _derived;
1302   }
1303   void describe(FrameValues& values, int frame_no) {
1304     for (int i = 0; i < _oops->length(); i++) {
1305       oop* p = _oops->at(i);
1306       bool good = *p == nullptr || (dbg_is_safe(*p, -1) && dbg_is_safe((*p)->klass(), -1) && oopDesc::is_oop_or_null(*p));
1307       values.describe(frame_no, (intptr_t*)p, err_msg("oop%s for #%d", good ? "" : " (BAD)", frame_no));
1308     }
1309     for (int i = 0; i < _narrow_oops->length(); i++) {
1310       narrowOop* p = _narrow_oops->at(i);
1311       values.describe(frame_no, (intptr_t*)p, err_msg("narrow oop for #%d", frame_no));
1312     }
1313     assert(_base->length() == _derived->length(), "should be the same");
1314     for (int i = 0; i < _base->length(); i++) {
1315       oop* base = _base->at(i);
1316       derived_pointer* derived = _derived->at(i);
1317       values.describe(frame_no, (intptr_t*)derived, err_msg("derived pointer (base: " INTPTR_FORMAT ") for #%d", p2i(base), frame_no));
1318     }
1319   }
1320   virtual void do_oop(oop* p)       { _oops->push(p); }
1321   virtual void do_oop(narrowOop* p) { _narrow_oops->push(p); }
1322   virtual void do_derived_oop(oop* base, derived_pointer* derived) {
1323     _base->push(base);
1324     _derived->push(derived);
1325   }
1326 };
1327 
1328 class FrameValuesOopMapClosure: public OopMapClosure {
1329 private:
1330   const frame* _fr;
1331   const RegisterMap* _reg_map;
1332   FrameValues& _values;
1333   int _frame_no;
1334 public:
1335   FrameValuesOopMapClosure(const frame* fr, const RegisterMap* reg_map, FrameValues& values, int frame_no)
1336    : _fr(fr), _reg_map(reg_map), _values(values), _frame_no(frame_no) {}
1337 
1338   virtual void do_value(VMReg reg, OopMapValue::oop_types type) {
1339     intptr_t* p = (intptr_t*)_fr->oopmapreg_to_location(reg, _reg_map);
1340     if (p != NULL && (((intptr_t)p & WordAlignmentMask) == 0)) {
1341       const char* type_name = NULL;
1342       switch(type) {
1343         case OopMapValue::oop_value:          type_name = "oop";          break;
1344         case OopMapValue::narrowoop_value:    type_name = "narrow oop";   break;
1345         case OopMapValue::callee_saved_value: type_name = "callee-saved"; break;
1346         case OopMapValue::derived_oop_value:  type_name = "derived";      break;
1347         // case OopMapValue::live_value:         type_name = "live";         break;
1348         default: break;
1349       }
1350       if (type_name != NULL)
1351         _values.describe(_frame_no, p, err_msg("%s for #%d", type_name, _frame_no));
1352     }
1353   }
1354 };
1355 
1356 template void frame::describe<false>(FrameValues& values, int frame_no, const RegisterMap* reg_map);
1357 template void frame::describe<true >(FrameValues& values, int frame_no, const RegisterMap* reg_map);
1358 
1359 // callers need a ResourceMark because of name_and_sig_as_C_string() usage,
1360 // RA allocated string is returned to the caller
1361 template <bool relative>
1362 void frame::describe(FrameValues& values, int frame_no, const RegisterMap* reg_map) {
1363   // boundaries: sp and the 'real' frame pointer
1364   values.describe(-1, sp(), err_msg("sp for #%d", frame_no), 0);
1365   intptr_t* frame_pointer = real_fp(); // Note: may differ from fp()
1366 
1367   // print frame info at the highest boundary
1368   intptr_t* info_address = MAX2(sp(), frame_pointer);
1369 
1370   if (info_address != frame_pointer) {
1371     // print frame_pointer explicitly if not marked by the frame info
1372     values.describe(-1, frame_pointer, err_msg("frame pointer for #%d", frame_no), 1);
1373   }
1374 
1375   if (is_entry_frame() || is_compiled_frame() || is_interpreted_frame() || is_native_frame()) {
1376     // Label values common to most frames
1377     values.describe(-1, unextended_sp(), err_msg("unextended_sp for #%d", frame_no), 0);
1378   }
1379 
1380   if (is_interpreted_frame()) {
1381     Method* m = interpreter_frame_method();
1382     int bci = interpreter_frame_bci();
1383     InterpreterCodelet* desc = Interpreter::codelet_containing(pc());
1384 
1385     // Label the method and current bci
1386     values.describe(-1, info_address,
1387                     FormatBuffer<1024>("#%d method %s @ %d", frame_no, m->name_and_sig_as_C_string(), bci), 3);
1388     if (desc != NULL) {
1389       values.describe(-1, info_address, err_msg("- %s codelet: %s",
1390         desc->bytecode()    >= 0    ? Bytecodes::name(desc->bytecode()) : "",
1391         desc->description() != NULL ? desc->description()               : "?"), 2);
1392     }
1393     values.describe(-1, info_address,
1394                     err_msg("- %d locals %d max stack", m->max_locals(), m->max_stack()), 2);
1395     values.describe(frame_no, (intptr_t*)sender_pc_addr(), Continuation::is_return_barrier_entry(*sender_pc_addr()) ? "return address (return barrier)" : "return address");
1396 
1397     if (m->max_locals() > 0) {
1398       intptr_t* l0 = interpreter_frame_local_at<relative>(0);
1399       intptr_t* ln = interpreter_frame_local_at<relative>(m->max_locals() - 1);
1400       values.describe(-1, MAX2(l0, ln), err_msg("locals for #%d", frame_no), 2);
1401       // Report each local and mark as owned by this frame
1402       for (int l = 0; l < m->max_locals(); l++) {
1403         intptr_t* l0 = interpreter_frame_local_at<relative>(l);
1404         values.describe(frame_no, l0, err_msg("local %d", l), 1);
1405       }
1406     }
1407 
1408     if (interpreter_frame_monitor_begin() != interpreter_frame_monitor_end<relative>()) {
1409       values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_begin(), "monitors begin");
1410       values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_end<relative>(), "monitors end");
1411     }
1412 
1413     // Compute the actual expression stack size
1414     InterpreterOopMap mask;
1415     OopMapCache::compute_one_oop_map(methodHandle(Thread::current(), m), bci, &mask);
1416     intptr_t* tos = NULL;
1417     // Report each stack element and mark as owned by this frame
1418     for (int e = 0; e < mask.expression_stack_size(); e++) {
1419       tos = MAX2(tos, interpreter_frame_expression_stack_at<relative>(e));
1420       values.describe(frame_no, interpreter_frame_expression_stack_at<relative>(e),
1421                       err_msg("stack %d", e), 1);
1422     }
1423     if (tos != NULL) {
1424       values.describe(-1, tos, err_msg("expression stack for #%d", frame_no), 2);
1425     }
1426 
1427     if (reg_map != NULL) {
1428       FrameValuesOopClosure oopsFn;
1429       oops_do(&oopsFn, NULL, &oopsFn, reg_map);
1430       oopsFn.describe(values, frame_no);
1431     }
1432   } else if (is_entry_frame()) {
1433     // For now just label the frame
1434     values.describe(-1, info_address, err_msg("#%d entry frame", frame_no), 2);
1435   } else if (cb()->is_compiled()) {
1436     // For now just label the frame
1437     CompiledMethod* cm = cb()->as_compiled_method();
1438     values.describe(-1, info_address,
1439                     FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for method J %s%s", frame_no,
1440                                        p2i(cm),
1441                                        cm->method()->name_and_sig_as_C_string(),
1442                                        (_deopt_state == is_deoptimized) ?
1443                                        " (deoptimized)" :
1444                                        ((_deopt_state == unknown) ? " (state unknown)" : "")),
1445                     3);
1446 
1447     { // mark arguments (see nmethod::print_nmethod_labels)
1448       Method* m = cm->method();
1449 
1450       int stack_slot_offset = cm->frame_size() * wordSize; // offset, in bytes, to caller sp
1451       int sizeargs = m->size_of_parameters();
1452 
1453       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
1454       VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
1455       {
1456         int sig_index = 0;
1457         if (!m->is_static()) sig_bt[sig_index++] = T_OBJECT; // 'this'
1458         for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
1459           BasicType t = ss.type();
1460           assert(type2size[t] == 1 || type2size[t] == 2, "size is 1 or 2");
1461           sig_bt[sig_index++] = t;
1462           if (type2size[t] == 2) sig_bt[sig_index++] = T_VOID;
1463         }
1464         assert(sig_index == sizeargs, "");
1465       }
1466       int out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
1467       assert (out_preserve ==  m->num_stack_arg_slots(), "");
1468       int sig_index = 0;
1469       int arg_index = (m->is_static() ? 0 : -1);
1470       for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) {
1471         bool at_this = (arg_index == -1);
1472         bool at_old_sp = false;
1473         BasicType t = (at_this ? T_OBJECT : ss.type());
1474         assert(t == sig_bt[sig_index], "sigs in sync");
1475         VMReg fst = regs[sig_index].first();
1476         if (fst->is_stack()) {
1477           assert (((int)fst->reg2stack()) >= 0, "reg2stack: " INTPTR_FORMAT, fst->reg2stack());
1478           int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
1479           intptr_t* stack_address = (intptr_t*)((address)unextended_sp() + offset);
1480           if (at_this)
1481             values.describe(frame_no, stack_address, err_msg("this for #%d", frame_no), 1);
1482           else
1483             values.describe(frame_no, stack_address, err_msg("param %d %s for #%d", arg_index, type2name(t), frame_no), 1);
1484         }
1485         sig_index += type2size[t];
1486         arg_index += 1;
1487         if (!at_this) ss.next();
1488       }
1489     }
1490 
1491     if (reg_map != NULL && is_java_frame()) {
1492       int scope_no = 0;
1493       for (ScopeDesc* scope = cm->scope_desc_at(pc()); scope != NULL; scope = scope->sender(), scope_no++) {
1494         Method* m = scope->method();
1495         int  bci = scope->bci();
1496         values.describe(-1, info_address, err_msg("- #%d scope %s @ %d", scope_no, m->name_and_sig_as_C_string(), bci), 2);
1497 
1498         { // mark locals
1499           GrowableArray<ScopeValue*>* scvs = scope->locals();
1500           int scvs_length = scvs != NULL ? scvs->length() : 0;
1501           for (int i = 0; i < scvs_length; i++) {
1502             intptr_t* stack_address = (intptr_t*)StackValue::stack_value_address(this, reg_map, scvs->at(i));
1503             if (stack_address != NULL)
1504               values.describe(frame_no, stack_address, err_msg("local %d for #%d (scope %d)", i, frame_no, scope_no), 1);
1505           }
1506         }
1507         { // mark expression stack
1508           GrowableArray<ScopeValue*>* scvs = scope->expressions();
1509           int scvs_length = scvs != NULL ? scvs->length() : 0;
1510           for (int i = 0; i < scvs_length; i++) {
1511             intptr_t* stack_address = (intptr_t*)StackValue::stack_value_address(this, reg_map, scvs->at(i));
1512             if (stack_address != NULL)
1513               values.describe(frame_no, stack_address, err_msg("stack %d for #%d (scope %d)", i, frame_no, scope_no), 1);
1514           }
1515         }
1516       }
1517 
1518       FrameValuesOopClosure oopsFn;
1519       oops_do(&oopsFn, NULL, &oopsFn, reg_map);
1520       oopsFn.describe(values, frame_no);
1521 
1522       if (oop_map() != NULL) {
1523         FrameValuesOopMapClosure valuesFn(this, reg_map, values, frame_no);
1524         // also OopMapValue::live_value ??
1525         oop_map()->all_type_do(this, OopMapValue::callee_saved_value, &valuesFn);
1526       }
1527     }
1528 
1529     if (cm->method()->is_continuation_enter_intrinsic()) {
1530       address usp = (address)unextended_sp();
1531       values.describe(frame_no, (intptr_t*)(usp + in_bytes(ContinuationEntry::parent_offset())), "parent");
1532       values.describe(frame_no, (intptr_t*)(usp + in_bytes(ContinuationEntry::cont_offset())),   "continuation");
1533       values.describe(frame_no, (intptr_t*)(usp + in_bytes(ContinuationEntry::chunk_offset())),   "chunk");
1534       values.describe(frame_no, (intptr_t*)(usp + in_bytes(ContinuationEntry::argsize_offset())), "argsize");
1535       // values.describe(frame_no, (intptr_t*)(usp + in_bytes(ContinuationEntry::parent_cont_fastpath_offset())),      "parent fastpath");
1536       // values.describe(frame_no, (intptr_t*)(usp + in_bytes(ContinuationEntry::parent_held_monitor_count_offset())), "parent held monitor count");
1537     }
1538   } else if (is_native_frame()) {
1539     // For now just label the frame
1540     nmethod* nm = cb()->as_nmethod_or_null();
1541     values.describe(-1, info_address,
1542                     FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for native method %s", frame_no,
1543                                        p2i(nm), nm->method()->name_and_sig_as_C_string()), 2);
1544   } else {
1545     // provide default info if not handled before
1546     char *info = (char *) "special frame";
1547     if ((_cb != NULL) &&
1548         (_cb->name() != NULL)) {
1549       info = (char *)_cb->name();
1550     }
1551     values.describe(-1, info_address, err_msg("#%d <%s>", frame_no, info), 2);
1552   }
1553 
1554   // platform dependent additional data
1555   describe_pd(values, frame_no);
1556 }
1557 
1558 void frame::describe_top(FrameValues& values) {
1559   describe_top_pd(values);
1560 }
1561 #endif
1562 
1563 #ifndef PRODUCT
1564 
1565 void FrameValues::describe(int owner, intptr_t* location, const char* description, int priority) {
1566   FrameValue fv;
1567   fv.location = location;
1568   fv.owner = owner;
1569   fv.priority = priority;
1570   fv.description = NEW_RESOURCE_ARRAY(char, strlen(description) + 1);
1571   strcpy(fv.description, description);
1572   _values.append(fv);
1573 }
1574 
1575 
1576 #ifdef ASSERT
1577 void FrameValues::validate() {
1578   _values.sort(compare);
1579   bool error = false;
1580   FrameValue prev;
1581   prev.owner = -1;
1582   for (int i = _values.length() - 1; i >= 0; i--) {
1583     FrameValue fv = _values.at(i);
1584     if (fv.owner == -1) continue;
1585     if (prev.owner == -1) {
1586       prev = fv;
1587       continue;
1588     }
1589     if (prev.location == fv.location) {
1590       if (fv.owner != prev.owner) {
1591         tty->print_cr("overlapping storage");
1592         tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", p2i(prev.location), *prev.location, prev.description);
1593         tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", p2i(fv.location), *fv.location, fv.description);
1594         error = true;
1595       }
1596     } else {
1597       prev = fv;
1598     }
1599   }
1600   // if (error) { tty->cr(); print_on((JavaThread*)nullptr, tty); }
1601   assert(!error, "invalid layout");
1602 }
1603 #endif // ASSERT
1604 
1605 void FrameValues::print_on(JavaThread* thread, outputStream* st) {
1606   _values.sort(compare);
1607 
1608   // Sometimes values like the fp can be invalid values if the
1609   // register map wasn't updated during the walk.  Trim out values
1610   // that aren't actually in the stack of the thread.
1611   int min_index = 0;
1612   int max_index = _values.length() - 1;
1613   intptr_t* v0 = _values.at(min_index).location;
1614   intptr_t* v1 = _values.at(max_index).location;
1615 
1616   if (thread != NULL) {
1617     if (thread == Thread::current()) {
1618       while (!thread->is_in_live_stack((address)v0)) v0 = _values.at(++min_index).location;
1619       while (!thread->is_in_live_stack((address)v1)) v1 = _values.at(--max_index).location;
1620     } else {
1621       while (!thread->is_in_full_stack((address)v0)) v0 = _values.at(++min_index).location;
1622       while (!thread->is_in_full_stack((address)v1)) v1 = _values.at(--max_index).location;
1623     }
1624   }
1625 
1626   print_on(st, min_index, max_index, v0, v1);
1627 }
1628 
1629 void FrameValues::print_on(stackChunkOop chunk, outputStream* st) {
1630   assert (chunk->is_stackChunk(), "");
1631 
1632   _values.sort(compare);
1633 
1634   intptr_t* start = chunk->start_address();
1635   intptr_t* end = chunk->end_address() + 1;
1636 
1637   int min_index = 0;
1638   int max_index = _values.length() - 1;
1639   intptr_t* v0 = _values.at(min_index).location;
1640   intptr_t* v1 = _values.at(max_index).location;
1641   while (!(start <= v0 && v0 <= end)) v0 = _values.at(++min_index).location;
1642   while (!(start <= v1 && v1 <= end)) v1 = _values.at(--max_index).location;
1643 
1644   print_on(st, min_index, max_index, v0, v1, true);
1645 }
1646 
1647 void FrameValues::print_on(outputStream* st, int min_index, int max_index, intptr_t* v0, intptr_t* v1, bool relative) {
1648   intptr_t* min = MIN2(v0, v1);
1649   intptr_t* max = MAX2(v0, v1);
1650   intptr_t* cur = max;
1651   intptr_t* last = NULL;
1652   for (int i = max_index; i >= min_index; i--) {
1653     FrameValue fv = _values.at(i);
1654     while (cur > fv.location) {
1655       st->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT, p2i(cur), *cur);
1656       cur--;
1657     }
1658     if (last == fv.location) {
1659       const char* spacer = "          " LP64_ONLY("        ");
1660       st->print_cr(" %s  %s %s", spacer, spacer, fv.description);
1661     } else {
1662       if (relative
1663           && *fv.location != 0 && *fv.location > -100 && *fv.location < 100
1664           && (strncmp(fv.description, "interpreter_frame_", 18) == 0 || strstr(fv.description, " method "))) {
1665         st->print_cr(" " INTPTR_FORMAT ": %18d %s", p2i(fv.location), (int)*fv.location, fv.description);
1666       } else {
1667         st->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", p2i(fv.location), *fv.location, fv.description);
1668       }
1669       last = fv.location;
1670       cur--;
1671     }
1672   }
1673 }
1674 
1675 #endif // ndef PRODUCT