src/cpu/x86/vm/frame_x86.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/x86/vm/frame_x86.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,719 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "interpreter/interpreter.hpp"
    1.30 +#include "memory/resourceArea.hpp"
    1.31 +#include "oops/markOop.hpp"
    1.32 +#include "oops/method.hpp"
    1.33 +#include "oops/oop.inline.hpp"
    1.34 +#include "prims/methodHandles.hpp"
    1.35 +#include "runtime/frame.inline.hpp"
    1.36 +#include "runtime/handles.inline.hpp"
    1.37 +#include "runtime/javaCalls.hpp"
    1.38 +#include "runtime/monitorChunk.hpp"
    1.39 +#include "runtime/os.hpp"
    1.40 +#include "runtime/signature.hpp"
    1.41 +#include "runtime/stubCodeGenerator.hpp"
    1.42 +#include "runtime/stubRoutines.hpp"
    1.43 +#include "vmreg_x86.inline.hpp"
    1.44 +#ifdef COMPILER1
    1.45 +#include "c1/c1_Runtime1.hpp"
    1.46 +#include "runtime/vframeArray.hpp"
    1.47 +#endif
    1.48 +
    1.49 +#ifdef ASSERT
    1.50 +void RegisterMap::check_location_valid() {
    1.51 +}
    1.52 +#endif
    1.53 +
    1.54 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    1.55 +
    1.56 +// Profiling/safepoint support
    1.57 +
    1.58 +bool frame::safe_for_sender(JavaThread *thread) {
    1.59 +  address   sp = (address)_sp;
    1.60 +  address   fp = (address)_fp;
    1.61 +  address   unextended_sp = (address)_unextended_sp;
    1.62 +
    1.63 +  // consider stack guards when trying to determine "safe" stack pointers
    1.64 +  static size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0;
    1.65 +  size_t usable_stack_size = thread->stack_size() - stack_guard_size;
    1.66 +
    1.67 +  // sp must be within the usable part of the stack (not in guards)
    1.68 +  bool sp_safe = (sp < thread->stack_base()) &&
    1.69 +                 (sp >= thread->stack_base() - usable_stack_size);
    1.70 +
    1.71 +
    1.72 +  if (!sp_safe) {
    1.73 +    return false;
    1.74 +  }
    1.75 +
    1.76 +  // unextended sp must be within the stack and above or equal sp
    1.77 +  bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&
    1.78 +                            (unextended_sp >= sp);
    1.79 +
    1.80 +  if (!unextended_sp_safe) {
    1.81 +    return false;
    1.82 +  }
    1.83 +
    1.84 +  // an fp must be within the stack and above (but not equal) sp
    1.85 +  // second evaluation on fp+ is added to handle situation where fp is -1
    1.86 +  bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
    1.87 +
    1.88 +  // We know sp/unextended_sp are safe only fp is questionable here
    1.89 +
    1.90 +  // If the current frame is known to the code cache then we can attempt to
    1.91 +  // to construct the sender and do some validation of it. This goes a long way
    1.92 +  // toward eliminating issues when we get in frame construction code
    1.93 +
    1.94 +  if (_cb != NULL ) {
    1.95 +
    1.96 +    // First check if frame is complete and tester is reliable
    1.97 +    // Unfortunately we can only check frame complete for runtime stubs and nmethod
    1.98 +    // other generic buffer blobs are more problematic so we just assume they are
    1.99 +    // ok. adapter blobs never have a frame complete and are never ok.
   1.100 +
   1.101 +    if (!_cb->is_frame_complete_at(_pc)) {
   1.102 +      if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
   1.103 +        return false;
   1.104 +      }
   1.105 +    }
   1.106 +
   1.107 +    // Could just be some random pointer within the codeBlob
   1.108 +    if (!_cb->code_contains(_pc)) {
   1.109 +      return false;
   1.110 +    }
   1.111 +
   1.112 +    // Entry frame checks
   1.113 +    if (is_entry_frame()) {
   1.114 +      // an entry frame must have a valid fp.
   1.115 +
   1.116 +      if (!fp_safe) return false;
   1.117 +
   1.118 +      // Validate the JavaCallWrapper an entry frame must have
   1.119 +
   1.120 +      address jcw = (address)entry_frame_call_wrapper();
   1.121 +
   1.122 +      bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > fp);
   1.123 +
   1.124 +      return jcw_safe;
   1.125 +
   1.126 +    }
   1.127 +
   1.128 +    intptr_t* sender_sp = NULL;
   1.129 +    address   sender_pc = NULL;
   1.130 +
   1.131 +    if (is_interpreted_frame()) {
   1.132 +      // fp must be safe
   1.133 +      if (!fp_safe) {
   1.134 +        return false;
   1.135 +      }
   1.136 +
   1.137 +      sender_pc = (address) this->fp()[return_addr_offset];
   1.138 +      sender_sp = (intptr_t*) addr_at(sender_sp_offset);
   1.139 +
   1.140 +    } else {
   1.141 +      // must be some sort of compiled/runtime frame
   1.142 +      // fp does not have to be safe (although it could be check for c1?)
   1.143 +
   1.144 +      // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
   1.145 +      if (_cb->frame_size() <= 0) {
   1.146 +        return false;
   1.147 +      }
   1.148 +
   1.149 +      sender_sp = _unextended_sp + _cb->frame_size();
   1.150 +      // On Intel the return_address is always the word on the stack
   1.151 +      sender_pc = (address) *(sender_sp-1);
   1.152 +    }
   1.153 +
   1.154 +
   1.155 +    // If the potential sender is the interpreter then we can do some more checking
   1.156 +    if (Interpreter::contains(sender_pc)) {
   1.157 +
   1.158 +      // ebp is always saved in a recognizable place in any code we generate. However
   1.159 +      // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
   1.160 +      // is really a frame pointer.
   1.161 +
   1.162 +      intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
   1.163 +      bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
   1.164 +
   1.165 +      if (!saved_fp_safe) {
   1.166 +        return false;
   1.167 +      }
   1.168 +
   1.169 +      // construct the potential sender
   1.170 +
   1.171 +      frame sender(sender_sp, saved_fp, sender_pc);
   1.172 +
   1.173 +      return sender.is_interpreted_frame_valid(thread);
   1.174 +
   1.175 +    }
   1.176 +
   1.177 +    // We must always be able to find a recognizable pc
   1.178 +    CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
   1.179 +    if (sender_pc == NULL ||  sender_blob == NULL) {
   1.180 +      return false;
   1.181 +    }
   1.182 +
   1.183 +    // Could be a zombie method
   1.184 +    if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
   1.185 +      return false;
   1.186 +    }
   1.187 +
   1.188 +    // Could just be some random pointer within the codeBlob
   1.189 +    if (!sender_blob->code_contains(sender_pc)) {
   1.190 +      return false;
   1.191 +    }
   1.192 +
   1.193 +    // We should never be able to see an adapter if the current frame is something from code cache
   1.194 +    if (sender_blob->is_adapter_blob()) {
   1.195 +      return false;
   1.196 +    }
   1.197 +
   1.198 +    // Could be the call_stub
   1.199 +    if (StubRoutines::returns_to_call_stub(sender_pc)) {
   1.200 +      intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
   1.201 +      bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
   1.202 +
   1.203 +      if (!saved_fp_safe) {
   1.204 +        return false;
   1.205 +      }
   1.206 +
   1.207 +      // construct the potential sender
   1.208 +
   1.209 +      frame sender(sender_sp, saved_fp, sender_pc);
   1.210 +
   1.211 +      // Validate the JavaCallWrapper an entry frame must have
   1.212 +      address jcw = (address)sender.entry_frame_call_wrapper();
   1.213 +
   1.214 +      bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp());
   1.215 +
   1.216 +      return jcw_safe;
   1.217 +    }
   1.218 +
   1.219 +    if (sender_blob->is_nmethod()) {
   1.220 +        nmethod* nm = sender_blob->as_nmethod_or_null();
   1.221 +        if (nm != NULL) {
   1.222 +            if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc)) {
   1.223 +                return false;
   1.224 +            }
   1.225 +        }
   1.226 +    }
   1.227 +
   1.228 +    // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
   1.229 +    // because the return address counts against the callee's frame.
   1.230 +
   1.231 +    if (sender_blob->frame_size() <= 0) {
   1.232 +      assert(!sender_blob->is_nmethod(), "should count return address at least");
   1.233 +      return false;
   1.234 +    }
   1.235 +
   1.236 +    // We should never be able to see anything here except an nmethod. If something in the
   1.237 +    // code cache (current frame) is called by an entity within the code cache that entity
   1.238 +    // should not be anything but the call stub (already covered), the interpreter (already covered)
   1.239 +    // or an nmethod.
   1.240 +
   1.241 +    if (!sender_blob->is_nmethod()) {
   1.242 +        return false;
   1.243 +    }
   1.244 +
   1.245 +    // Could put some more validation for the potential non-interpreted sender
   1.246 +    // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
   1.247 +
   1.248 +    // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
   1.249 +
   1.250 +    // We've validated the potential sender that would be created
   1.251 +    return true;
   1.252 +  }
   1.253 +
   1.254 +  // Must be native-compiled frame. Since sender will try and use fp to find
   1.255 +  // linkages it must be safe
   1.256 +
   1.257 +  if (!fp_safe) {
   1.258 +    return false;
   1.259 +  }
   1.260 +
   1.261 +  // Will the pc we fetch be non-zero (which we'll find at the oldest frame)
   1.262 +
   1.263 +  if ( (address) this->fp()[return_addr_offset] == NULL) return false;
   1.264 +
   1.265 +
   1.266 +  // could try and do some more potential verification of native frame if we could think of some...
   1.267 +
   1.268 +  return true;
   1.269 +
   1.270 +}
   1.271 +
   1.272 +
   1.273 +void frame::patch_pc(Thread* thread, address pc) {
   1.274 +  address* pc_addr = &(((address*) sp())[-1]);
   1.275 +  if (TracePcPatching) {
   1.276 +    tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
   1.277 +                  pc_addr, *pc_addr, pc);
   1.278 +  }
   1.279 +  // Either the return address is the original one or we are going to
   1.280 +  // patch in the same address that's already there.
   1.281 +  assert(_pc == *pc_addr || pc == *pc_addr, "must be");
   1.282 +  *pc_addr = pc;
   1.283 +  _cb = CodeCache::find_blob(pc);
   1.284 +  address original_pc = nmethod::get_deopt_original_pc(this);
   1.285 +  if (original_pc != NULL) {
   1.286 +    assert(original_pc == _pc, "expected original PC to be stored before patching");
   1.287 +    _deopt_state = is_deoptimized;
   1.288 +    // leave _pc as is
   1.289 +  } else {
   1.290 +    _deopt_state = not_deoptimized;
   1.291 +    _pc = pc;
   1.292 +  }
   1.293 +}
   1.294 +
   1.295 +bool frame::is_interpreted_frame() const  {
   1.296 +  return Interpreter::contains(pc());
   1.297 +}
   1.298 +
   1.299 +int frame::frame_size(RegisterMap* map) const {
   1.300 +  frame sender = this->sender(map);
   1.301 +  return sender.sp() - sp();
   1.302 +}
   1.303 +
   1.304 +intptr_t* frame::entry_frame_argument_at(int offset) const {
   1.305 +  // convert offset to index to deal with tsi
   1.306 +  int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
   1.307 +  // Entry frame's arguments are always in relation to unextended_sp()
   1.308 +  return &unextended_sp()[index];
   1.309 +}
   1.310 +
   1.311 +// sender_sp
   1.312 +#ifdef CC_INTERP
   1.313 +intptr_t* frame::interpreter_frame_sender_sp() const {
   1.314 +  assert(is_interpreted_frame(), "interpreted frame expected");
   1.315 +  // QQQ why does this specialize method exist if frame::sender_sp() does same thing?
   1.316 +  // seems odd and if we always know interpreted vs. non then sender_sp() is really
   1.317 +  // doing too much work.
   1.318 +  return get_interpreterState()->sender_sp();
   1.319 +}
   1.320 +
   1.321 +// monitor elements
   1.322 +
   1.323 +BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
   1.324 +  return get_interpreterState()->monitor_base();
   1.325 +}
   1.326 +
   1.327 +BasicObjectLock* frame::interpreter_frame_monitor_end() const {
   1.328 +  return (BasicObjectLock*) get_interpreterState()->stack_base();
   1.329 +}
   1.330 +
   1.331 +#else // CC_INTERP
   1.332 +
   1.333 +intptr_t* frame::interpreter_frame_sender_sp() const {
   1.334 +  assert(is_interpreted_frame(), "interpreted frame expected");
   1.335 +  return (intptr_t*) at(interpreter_frame_sender_sp_offset);
   1.336 +}
   1.337 +
   1.338 +void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
   1.339 +  assert(is_interpreted_frame(), "interpreted frame expected");
   1.340 +  ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
   1.341 +}
   1.342 +
   1.343 +
   1.344 +// monitor elements
   1.345 +
   1.346 +BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
   1.347 +  return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
   1.348 +}
   1.349 +
   1.350 +BasicObjectLock* frame::interpreter_frame_monitor_end() const {
   1.351 +  BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
   1.352 +  // make sure the pointer points inside the frame
   1.353 +  assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
   1.354 +  assert((intptr_t*) result < fp(),  "monitor end should be strictly below the frame pointer");
   1.355 +  return result;
   1.356 +}
   1.357 +
   1.358 +void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
   1.359 +  *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
   1.360 +}
   1.361 +
   1.362 +// Used by template based interpreter deoptimization
   1.363 +void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
   1.364 +    *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
   1.365 +}
   1.366 +#endif // CC_INTERP
   1.367 +
   1.368 +frame frame::sender_for_entry_frame(RegisterMap* map) const {
   1.369 +  assert(map != NULL, "map must be set");
   1.370 +  // Java frame called from C; skip all C frames and return top C
   1.371 +  // frame of that chunk as the sender
   1.372 +  JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
   1.373 +  assert(!entry_frame_is_first(), "next Java fp must be non zero");
   1.374 +  assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
   1.375 +  map->clear();
   1.376 +  assert(map->include_argument_oops(), "should be set by clear");
   1.377 +  if (jfa->last_Java_pc() != NULL ) {
   1.378 +    frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
   1.379 +    return fr;
   1.380 +  }
   1.381 +  frame fr(jfa->last_Java_sp(), jfa->last_Java_fp());
   1.382 +  return fr;
   1.383 +}
   1.384 +
   1.385 +//------------------------------------------------------------------------------
   1.386 +// frame::verify_deopt_original_pc
   1.387 +//
   1.388 +// Verifies the calculated original PC of a deoptimization PC for the
   1.389 +// given unextended SP.  The unextended SP might also be the saved SP
   1.390 +// for MethodHandle call sites.
   1.391 +#ifdef ASSERT
   1.392 +void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return) {
   1.393 +  frame fr;
   1.394 +
   1.395 +  // This is ugly but it's better than to change {get,set}_original_pc
   1.396 +  // to take an SP value as argument.  And it's only a debugging
   1.397 +  // method anyway.
   1.398 +  fr._unextended_sp = unextended_sp;
   1.399 +
   1.400 +  address original_pc = nm->get_original_pc(&fr);
   1.401 +  assert(nm->insts_contains(original_pc), "original PC must be in nmethod");
   1.402 +  assert(nm->is_method_handle_return(original_pc) == is_method_handle_return, "must be");
   1.403 +}
   1.404 +#endif
   1.405 +
   1.406 +//------------------------------------------------------------------------------
   1.407 +// frame::adjust_unextended_sp
   1.408 +void frame::adjust_unextended_sp() {
   1.409 +  // If we are returning to a compiled MethodHandle call site, the
   1.410 +  // saved_fp will in fact be a saved value of the unextended SP.  The
   1.411 +  // simplest way to tell whether we are returning to such a call site
   1.412 +  // is as follows:
   1.413 +
   1.414 +  nmethod* sender_nm = (_cb == NULL) ? NULL : _cb->as_nmethod_or_null();
   1.415 +  if (sender_nm != NULL) {
   1.416 +    // If the sender PC is a deoptimization point, get the original
   1.417 +    // PC.  For MethodHandle call site the unextended_sp is stored in
   1.418 +    // saved_fp.
   1.419 +    if (sender_nm->is_deopt_mh_entry(_pc)) {
   1.420 +      DEBUG_ONLY(verify_deopt_mh_original_pc(sender_nm, _fp));
   1.421 +      _unextended_sp = _fp;
   1.422 +    }
   1.423 +    else if (sender_nm->is_deopt_entry(_pc)) {
   1.424 +      DEBUG_ONLY(verify_deopt_original_pc(sender_nm, _unextended_sp));
   1.425 +    }
   1.426 +    else if (sender_nm->is_method_handle_return(_pc)) {
   1.427 +      _unextended_sp = _fp;
   1.428 +    }
   1.429 +  }
   1.430 +}
   1.431 +
   1.432 +//------------------------------------------------------------------------------
   1.433 +// frame::update_map_with_saved_link
   1.434 +void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {
   1.435 +  // The interpreter and compiler(s) always save EBP/RBP in a known
   1.436 +  // location on entry. We must record where that location is
   1.437 +  // so this if EBP/RBP was live on callout from c2 we can find
   1.438 +  // the saved copy no matter what it called.
   1.439 +
   1.440 +  // Since the interpreter always saves EBP/RBP if we record where it is then
   1.441 +  // we don't have to always save EBP/RBP on entry and exit to c2 compiled
   1.442 +  // code, on entry will be enough.
   1.443 +  map->set_location(rbp->as_VMReg(), (address) link_addr);
   1.444 +#ifdef AMD64
   1.445 +  // this is weird "H" ought to be at a higher address however the
   1.446 +  // oopMaps seems to have the "H" regs at the same address and the
   1.447 +  // vanilla register.
   1.448 +  // XXXX make this go away
   1.449 +  if (true) {
   1.450 +    map->set_location(rbp->as_VMReg()->next(), (address) link_addr);
   1.451 +  }
   1.452 +#endif // AMD64
   1.453 +}
   1.454 +
   1.455 +
   1.456 +//------------------------------------------------------------------------------
   1.457 +// frame::sender_for_interpreter_frame
   1.458 +frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
   1.459 +  // SP is the raw SP from the sender after adapter or interpreter
   1.460 +  // extension.
   1.461 +  intptr_t* sender_sp = this->sender_sp();
   1.462 +
   1.463 +  // This is the sp before any possible extension (adapter/locals).
   1.464 +  intptr_t* unextended_sp = interpreter_frame_sender_sp();
   1.465 +
   1.466 +#ifdef COMPILER2
   1.467 +  if (map->update_map()) {
   1.468 +    update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
   1.469 +  }
   1.470 +#endif // COMPILER2
   1.471 +
   1.472 +  return frame(sender_sp, unextended_sp, link(), sender_pc());
   1.473 +}
   1.474 +
   1.475 +
   1.476 +//------------------------------------------------------------------------------
   1.477 +// frame::sender_for_compiled_frame
   1.478 +frame frame::sender_for_compiled_frame(RegisterMap* map) const {
   1.479 +  assert(map != NULL, "map must be set");
   1.480 +
   1.481 +  // frame owned by optimizing compiler
   1.482 +  assert(_cb->frame_size() >= 0, "must have non-zero frame size");
   1.483 +  intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
   1.484 +  intptr_t* unextended_sp = sender_sp;
   1.485 +
   1.486 +  // On Intel the return_address is always the word on the stack
   1.487 +  address sender_pc = (address) *(sender_sp-1);
   1.488 +
   1.489 +  // This is the saved value of EBP which may or may not really be an FP.
   1.490 +  // It is only an FP if the sender is an interpreter frame (or C1?).
   1.491 +  intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
   1.492 +
   1.493 +  if (map->update_map()) {
   1.494 +    // Tell GC to use argument oopmaps for some runtime stubs that need it.
   1.495 +    // For C1, the runtime stub might not have oop maps, so set this flag
   1.496 +    // outside of update_register_map.
   1.497 +    map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
   1.498 +    if (_cb->oop_maps() != NULL) {
   1.499 +      OopMapSet::update_register_map(this, map);
   1.500 +    }
   1.501 +
   1.502 +    // Since the prolog does the save and restore of EBP there is no oopmap
   1.503 +    // for it so we must fill in its location as if there was an oopmap entry
   1.504 +    // since if our caller was compiled code there could be live jvm state in it.
   1.505 +    update_map_with_saved_link(map, saved_fp_addr);
   1.506 +  }
   1.507 +
   1.508 +  assert(sender_sp != sp(), "must have changed");
   1.509 +  return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
   1.510 +}
   1.511 +
   1.512 +
   1.513 +//------------------------------------------------------------------------------
   1.514 +// frame::sender
   1.515 +frame frame::sender(RegisterMap* map) const {
   1.516 +  // Default is we done have to follow them. The sender_for_xxx will
   1.517 +  // update it accordingly
   1.518 +  map->set_include_argument_oops(false);
   1.519 +
   1.520 +  if (is_entry_frame())       return sender_for_entry_frame(map);
   1.521 +  if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
   1.522 +  assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
   1.523 +
   1.524 +  if (_cb != NULL) {
   1.525 +    return sender_for_compiled_frame(map);
   1.526 +  }
   1.527 +  // Must be native-compiled frame, i.e. the marshaling code for native
   1.528 +  // methods that exists in the core system.
   1.529 +  return frame(sender_sp(), link(), sender_pc());
   1.530 +}
   1.531 +
   1.532 +
   1.533 +bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
   1.534 +  assert(is_interpreted_frame(), "must be interpreter frame");
   1.535 +  Method* method = interpreter_frame_method();
   1.536 +  // When unpacking an optimized frame the frame pointer is
   1.537 +  // adjusted with:
   1.538 +  int diff = (method->max_locals() - method->size_of_parameters()) *
   1.539 +             Interpreter::stackElementWords;
   1.540 +  return _fp == (fp - diff);
   1.541 +}
   1.542 +
   1.543 +void frame::pd_gc_epilog() {
   1.544 +  // nothing done here now
   1.545 +}
   1.546 +
   1.547 +bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
   1.548 +// QQQ
   1.549 +#ifdef CC_INTERP
   1.550 +#else
   1.551 +  assert(is_interpreted_frame(), "Not an interpreted frame");
   1.552 +  // These are reasonable sanity checks
   1.553 +  if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
   1.554 +    return false;
   1.555 +  }
   1.556 +  if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
   1.557 +    return false;
   1.558 +  }
   1.559 +  if (fp() + interpreter_frame_initial_sp_offset < sp()) {
   1.560 +    return false;
   1.561 +  }
   1.562 +  // These are hacks to keep us out of trouble.
   1.563 +  // The problem with these is that they mask other problems
   1.564 +  if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
   1.565 +    return false;
   1.566 +  }
   1.567 +
   1.568 +  // do some validation of frame elements
   1.569 +
   1.570 +  // first the method
   1.571 +
   1.572 +  Method* m = *interpreter_frame_method_addr();
   1.573 +
   1.574 +  // validate the method we'd find in this potential sender
   1.575 +  if (!m->is_valid_method()) return false;
   1.576 +
   1.577 +  // stack frames shouldn't be much larger than max_stack elements
   1.578 +
   1.579 +  if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
   1.580 +    return false;
   1.581 +  }
   1.582 +
   1.583 +  // validate bci/bcx
   1.584 +
   1.585 +  intptr_t  bcx    = interpreter_frame_bcx();
   1.586 +  if (m->validate_bci_from_bcx(bcx) < 0) {
   1.587 +    return false;
   1.588 +  }
   1.589 +
   1.590 +  // validate ConstantPoolCache*
   1.591 +  ConstantPoolCache* cp = *interpreter_frame_cache_addr();
   1.592 +  if (cp == NULL || !cp->is_metaspace_object()) return false;
   1.593 +
   1.594 +  // validate locals
   1.595 +
   1.596 +  address locals =  (address) *interpreter_frame_locals_addr();
   1.597 +
   1.598 +  if (locals > thread->stack_base() || locals < (address) fp()) return false;
   1.599 +
   1.600 +  // We'd have to be pretty unlucky to be mislead at this point
   1.601 +
   1.602 +#endif // CC_INTERP
   1.603 +  return true;
   1.604 +}
   1.605 +
   1.606 +BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
   1.607 +#ifdef CC_INTERP
   1.608 +  // Needed for JVMTI. The result should always be in the
   1.609 +  // interpreterState object
   1.610 +  interpreterState istate = get_interpreterState();
   1.611 +#endif // CC_INTERP
   1.612 +  assert(is_interpreted_frame(), "interpreted frame expected");
   1.613 +  Method* method = interpreter_frame_method();
   1.614 +  BasicType type = method->result_type();
   1.615 +
   1.616 +  intptr_t* tos_addr;
   1.617 +  if (method->is_native()) {
   1.618 +    // Prior to calling into the runtime to report the method_exit the possible
   1.619 +    // return value is pushed to the native stack. If the result is a jfloat/jdouble
   1.620 +    // then ST0 is saved before EAX/EDX. See the note in generate_native_result
   1.621 +    tos_addr = (intptr_t*)sp();
   1.622 +    if (type == T_FLOAT || type == T_DOUBLE) {
   1.623 +    // QQQ seems like this code is equivalent on the two platforms
   1.624 +#ifdef AMD64
   1.625 +      // This is times two because we do a push(ltos) after pushing XMM0
   1.626 +      // and that takes two interpreter stack slots.
   1.627 +      tos_addr += 2 * Interpreter::stackElementWords;
   1.628 +#else
   1.629 +      tos_addr += 2;
   1.630 +#endif // AMD64
   1.631 +    }
   1.632 +  } else {
   1.633 +    tos_addr = (intptr_t*)interpreter_frame_tos_address();
   1.634 +  }
   1.635 +
   1.636 +  switch (type) {
   1.637 +    case T_OBJECT  :
   1.638 +    case T_ARRAY   : {
   1.639 +      oop obj;
   1.640 +      if (method->is_native()) {
   1.641 +#ifdef CC_INTERP
   1.642 +        obj = istate->_oop_temp;
   1.643 +#else
   1.644 +        obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
   1.645 +#endif // CC_INTERP
   1.646 +      } else {
   1.647 +        oop* obj_p = (oop*)tos_addr;
   1.648 +        obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
   1.649 +      }
   1.650 +      assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
   1.651 +      *oop_result = obj;
   1.652 +      break;
   1.653 +    }
   1.654 +    case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
   1.655 +    case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
   1.656 +    case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
   1.657 +    case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
   1.658 +    case T_INT     : value_result->i = *(jint*)tos_addr; break;
   1.659 +    case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
   1.660 +    case T_FLOAT   : {
   1.661 +#ifdef AMD64
   1.662 +        value_result->f = *(jfloat*)tos_addr;
   1.663 +#else
   1.664 +      if (method->is_native()) {
   1.665 +        jdouble d = *(jdouble*)tos_addr;  // Result was in ST0 so need to convert to jfloat
   1.666 +        value_result->f = (jfloat)d;
   1.667 +      } else {
   1.668 +        value_result->f = *(jfloat*)tos_addr;
   1.669 +      }
   1.670 +#endif // AMD64
   1.671 +      break;
   1.672 +    }
   1.673 +    case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
   1.674 +    case T_VOID    : /* Nothing to do */ break;
   1.675 +    default        : ShouldNotReachHere();
   1.676 +  }
   1.677 +
   1.678 +  return type;
   1.679 +}
   1.680 +
   1.681 +
   1.682 +intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
   1.683 +  int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
   1.684 +  return &interpreter_frame_tos_address()[index];
   1.685 +}
   1.686 +
   1.687 +#ifndef PRODUCT
   1.688 +
   1.689 +#define DESCRIBE_FP_OFFSET(name) \
   1.690 +  values.describe(frame_no, fp() + frame::name##_offset, #name)
   1.691 +
   1.692 +void frame::describe_pd(FrameValues& values, int frame_no) {
   1.693 +  if (is_interpreted_frame()) {
   1.694 +    DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
   1.695 +    DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
   1.696 +    DESCRIBE_FP_OFFSET(interpreter_frame_method);
   1.697 +    DESCRIBE_FP_OFFSET(interpreter_frame_mdx);
   1.698 +    DESCRIBE_FP_OFFSET(interpreter_frame_cache);
   1.699 +    DESCRIBE_FP_OFFSET(interpreter_frame_locals);
   1.700 +    DESCRIBE_FP_OFFSET(interpreter_frame_bcx);
   1.701 +    DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
   1.702 +  }
   1.703 +}
   1.704 +#endif
   1.705 +
   1.706 +intptr_t *frame::initial_deoptimization_info() {
   1.707 +  // used to reset the saved FP
   1.708 +  return fp();
   1.709 +}
   1.710 +
   1.711 +intptr_t* frame::real_fp() const {
   1.712 +  if (_cb != NULL) {
   1.713 +    // use the frame size if valid
   1.714 +    int size = _cb->frame_size();
   1.715 +    if (size > 0) {
   1.716 +      return unextended_sp() + size;
   1.717 +    }
   1.718 +  }
   1.719 +  // else rely on fp()
   1.720 +  assert(! is_compiled_frame(), "unknown compiled frame size");
   1.721 +  return fp();
   1.722 +}

mercurial