1 /*
   2  * Copyright (c) 1997, 2019, 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 #ifndef SHARE_RUNTIME_FRAME_INLINE_HPP
  26 #define SHARE_RUNTIME_FRAME_INLINE_HPP
  27 
  28 #include "code/compiledMethod.inline.hpp"
  29 #include "interpreter/bytecodeInterpreter.hpp"
  30 #include "interpreter/bytecodeInterpreter.inline.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "oops/method.hpp"
  33 #include "runtime/continuation.hpp"
  34 #include "runtime/frame.hpp"
  35 #include "runtime/signature.hpp"
  36 #include "utilities/macros.hpp"
  37 #ifdef ZERO
  38 # include "entryFrame_zero.hpp"
  39 # include "fakeStubFrame_zero.hpp"
  40 # include "interpreterFrame_zero.hpp"
  41 #endif
  42 
  43 #include CPU_HEADER_INLINE(frame)
  44 
  45 inline bool frame::is_entry_frame() const {
  46   return StubRoutines::returns_to_call_stub(pc());
  47 }
  48 
  49 inline bool frame::is_deoptimized_frame() const {
  50   assert(_deopt_state != unknown, "not answerable");
  51   return _deopt_state == is_deoptimized;
  52 }
  53 
  54 inline bool frame::is_stub_frame() const {
  55   return StubRoutines::is_stub_code(pc()) || (_cb != NULL && _cb->is_adapter_blob());
  56 }
  57 
  58 inline bool frame::is_first_frame() const {
  59   return is_entry_frame() && entry_frame_is_first();
  60 }
  61 
  62 inline bool frame::is_compiled_frame() const {
  63   if (_cb != NULL &&
  64       _cb->is_compiled() &&
  65       ((CompiledMethod*)_cb)->is_java_method()) {
  66     return true;
  67   }
  68   return false;
  69 }
  70 
  71 template <typename RegisterMapT>
  72 inline oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMapT* reg_map) const {
  73   if (reg->is_reg()) {
  74     // If it is passed in a register, it got spilled in the stub frame.
  75     return (oop *)reg_map->location(reg);
  76   } else {
  77     int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size;
  78     if (reg_map->in_cont()) {
  79       return reinterpret_cast<oop*>((uintptr_t)Continuation::usp_offset_to_index(*this, reg_map->as_RegisterMap(), sp_offset_in_bytes));
  80     }
  81     address usp = (address)unextended_sp();
  82     assert(reg_map->thread()->is_in_usable_stack(usp), INTPTR_FORMAT, p2i(usp)); 
  83     return (oop*)(usp + sp_offset_in_bytes);
  84   }
  85 }
  86 
  87 inline CodeBlob* frame::get_cb() const {
  88   // if (_cb == NULL) _cb = CodeCache::find_blob(_pc);
  89   if (_cb == NULL) {
  90     int slot;
  91     _cb = CodeCache::find_blob_and_oopmap(_pc, slot);
  92     if (_oop_map == NULL && slot >= 0) {
  93       _oop_map = _cb->oop_map_for_slot(slot, _pc);
  94     }
  95   }
  96   return _cb;
  97 }
  98 
  99 // inline void frame::set_cb(CodeBlob* cb) {
 100 //   if (_cb == NULL) _cb = cb;
 101 //   assert (_cb == cb, "");
 102 //   assert (_cb->contains(_pc), "");
 103 // }
 104 
 105 inline bool StackFrameStream::is_done() {
 106   return (_is_done) ? true : (_is_done = _fr.is_first_frame(), false);
 107 }
 108 
 109 #endif // SHARE_RUNTIME_FRAME_INLINE_HPP