annotate src/cpu/x86/vm/frame_x86.cpp @ 5863:935cc67fbbf9

Added tag jdk7u241-ga for changeset c6a8482b1d38
author andrew
date Wed, 16 Oct 2019 13:45:47 +0100
parents bec5f1758368
children
rev   line source
duke@0 1 /*
bdelsart@3087 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "interpreter/interpreter.hpp"
stefank@1879 27 #include "memory/resourceArea.hpp"
stefank@1879 28 #include "oops/markOop.hpp"
stefank@1879 29 #include "oops/methodOop.hpp"
stefank@1879 30 #include "oops/oop.inline.hpp"
iveresov@3153 31 #include "prims/methodHandles.hpp"
stefank@1879 32 #include "runtime/frame.inline.hpp"
stefank@1879 33 #include "runtime/handles.inline.hpp"
stefank@1879 34 #include "runtime/javaCalls.hpp"
stefank@1879 35 #include "runtime/monitorChunk.hpp"
sla@4141 36 #include "runtime/os.hpp"
stefank@1879 37 #include "runtime/signature.hpp"
stefank@1879 38 #include "runtime/stubCodeGenerator.hpp"
stefank@1879 39 #include "runtime/stubRoutines.hpp"
stefank@1879 40 #include "vmreg_x86.inline.hpp"
stefank@1879 41 #ifdef COMPILER1
stefank@1879 42 #include "c1/c1_Runtime1.hpp"
stefank@1879 43 #include "runtime/vframeArray.hpp"
stefank@1879 44 #endif
duke@0 45
duke@0 46 #ifdef ASSERT
duke@0 47 void RegisterMap::check_location_valid() {
duke@0 48 }
duke@0 49 #endif
duke@0 50
duke@0 51
duke@0 52 // Profiling/safepoint support
duke@0 53
duke@0 54 bool frame::safe_for_sender(JavaThread *thread) {
duke@0 55 address sp = (address)_sp;
duke@0 56 address fp = (address)_fp;
duke@0 57 address unextended_sp = (address)_unextended_sp;
sla@4141 58
sla@4141 59 // consider stack guards when trying to determine "safe" stack pointers
sla@4141 60 static size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0;
sla@4141 61 size_t usable_stack_size = thread->stack_size() - stack_guard_size;
sla@4141 62
sla@4141 63 // sp must be within the usable part of the stack (not in guards)
sla@4141 64 bool sp_safe = (sp < thread->stack_base()) &&
sla@4141 65 (sp >= thread->stack_base() - usable_stack_size);
sla@4141 66
sgoldman@107 67
sgoldman@107 68 if (!sp_safe) {
sgoldman@107 69 return false;
sgoldman@107 70 }
sgoldman@107 71
sgoldman@107 72 // unextended sp must be within the stack and above or equal sp
sla@4141 73 bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&
sgoldman@107 74 (unextended_sp >= sp);
sgoldman@107 75
sgoldman@107 76 if (!unextended_sp_safe) {
sgoldman@107 77 return false;
sgoldman@107 78 }
sgoldman@107 79
sgoldman@107 80 // an fp must be within the stack and above (but not equal) sp
sla@4141 81 // second evaluation on fp+ is added to handle situation where fp is -1
sla@4141 82 bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
sgoldman@107 83
sgoldman@107 84 // We know sp/unextended_sp are safe only fp is questionable here
sgoldman@107 85
sgoldman@107 86 // If the current frame is known to the code cache then we can attempt to
sgoldman@107 87 // to construct the sender and do some validation of it. This goes a long way
sgoldman@107 88 // toward eliminating issues when we get in frame construction code
sgoldman@107 89
sgoldman@107 90 if (_cb != NULL ) {
sgoldman@107 91
sgoldman@107 92 // First check if frame is complete and tester is reliable
duke@0 93 // Unfortunately we can only check frame complete for runtime stubs and nmethod
duke@0 94 // other generic buffer blobs are more problematic so we just assume they are
duke@0 95 // ok. adapter blobs never have a frame complete and are never ok.
sgoldman@107 96
sgoldman@107 97 if (!_cb->is_frame_complete_at(_pc)) {
duke@0 98 if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
duke@0 99 return false;
duke@0 100 }
duke@0 101 }
rbackman@4248 102
rbackman@4248 103 // Could just be some random pointer within the codeBlob
rbackman@4248 104 if (!_cb->code_contains(_pc)) {
rbackman@4248 105 return false;
rbackman@4248 106 }
rbackman@4248 107
sgoldman@107 108 // Entry frame checks
sgoldman@107 109 if (is_entry_frame()) {
sgoldman@107 110 // an entry frame must have a valid fp.
sgoldman@107 111
sgoldman@107 112 if (!fp_safe) return false;
sgoldman@107 113 // Validate the JavaCallWrapper an entry frame must have
sgoldman@107 114
sgoldman@107 115 address jcw = (address)entry_frame_call_wrapper();
sla@4141 116 bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > fp);
sgoldman@107 117 return jcw_safe;
sgoldman@107 118 }
sgoldman@107 119
sgoldman@107 120 intptr_t* sender_sp = NULL;
sgoldman@107 121 address sender_pc = NULL;
sgoldman@107 122
sgoldman@107 123 if (is_interpreted_frame()) {
sgoldman@107 124 // fp must be safe
sgoldman@107 125 if (!fp_safe) {
sgoldman@107 126 return false;
sgoldman@107 127 }
sgoldman@107 128
sgoldman@107 129 sender_pc = (address) this->fp()[return_addr_offset];
sgoldman@107 130 sender_sp = (intptr_t*) addr_at(sender_sp_offset);
sgoldman@107 131
sgoldman@107 132 } else {
sgoldman@107 133 // must be some sort of compiled/runtime frame
sgoldman@107 134 // fp does not have to be safe (although it could be check for c1?)
sgoldman@107 135
mgronlun@4838 136 // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
mgronlun@4838 137 if (_cb->frame_size() <= 0) {
mgronlun@4838 138 return false;
mgronlun@4838 139 }
mgronlun@4838 140
sgoldman@107 141 sender_sp = _unextended_sp + _cb->frame_size();
sgoldman@107 142 // On Intel the return_address is always the word on the stack
sgoldman@107 143 sender_pc = (address) *(sender_sp-1);
sgoldman@107 144 }
sgoldman@107 145
sgoldman@107 146
sgoldman@107 147 // If the potential sender is the interpreter then we can do some more checking
sgoldman@107 148 if (Interpreter::contains(sender_pc)) {
sgoldman@107 149
sgoldman@107 150 // ebp is always saved in a recognizable place in any code we generate. However
sgoldman@107 151 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
sgoldman@107 152 // is really a frame pointer.
sgoldman@107 153
sgoldman@107 154 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
sla@4141 155 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
sgoldman@107 156
sgoldman@107 157 if (!saved_fp_safe) {
sgoldman@107 158 return false;
sgoldman@107 159 }
sgoldman@107 160
sgoldman@107 161 // construct the potential sender
sgoldman@107 162
sgoldman@107 163 frame sender(sender_sp, saved_fp, sender_pc);
sgoldman@107 164
sgoldman@107 165 return sender.is_interpreted_frame_valid(thread);
sgoldman@107 166
sgoldman@107 167 }
sgoldman@107 168
sla@4141 169 // We must always be able to find a recognizable pc
sla@4141 170 CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
sla@4141 171 if (sender_pc == NULL || sender_blob == NULL) {
sla@4141 172 return false;
sla@4141 173 }
sla@4141 174
sla@4141 175 // Could be a zombie method
sla@4141 176 if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
sla@4141 177 return false;
sla@4141 178 }
sla@4141 179
sgoldman@107 180 // Could just be some random pointer within the codeBlob
twisti@1668 181 if (!sender_blob->code_contains(sender_pc)) {
twisti@1668 182 return false;
twisti@1668 183 }
sgoldman@107 184
sgoldman@107 185 // We should never be able to see an adapter if the current frame is something from code cache
twisti@1668 186 if (sender_blob->is_adapter_blob()) {
sgoldman@107 187 return false;
sgoldman@107 188 }
sgoldman@107 189
sgoldman@107 190 // Could be the call_stub
sgoldman@107 191 if (StubRoutines::returns_to_call_stub(sender_pc)) {
sgoldman@107 192 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
sla@4141 193 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
sgoldman@107 194
sgoldman@107 195 if (!saved_fp_safe) {
sgoldman@107 196 return false;
sgoldman@107 197 }
sgoldman@107 198
sgoldman@107 199 // construct the potential sender
sgoldman@107 200
sgoldman@107 201 frame sender(sender_sp, saved_fp, sender_pc);
sgoldman@107 202
sgoldman@107 203 // Validate the JavaCallWrapper an entry frame must have
sgoldman@107 204 address jcw = (address)sender.entry_frame_call_wrapper();
sgoldman@107 205
sla@4141 206 bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp());
sgoldman@107 207
sgoldman@107 208 return jcw_safe;
sgoldman@107 209 }
sgoldman@107 210
sla@4141 211 if (sender_blob->is_nmethod()) {
sla@4141 212 nmethod* nm = sender_blob->as_nmethod_or_null();
sla@4141 213 if (nm != NULL) {
sla@4141 214 if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc)) {
sla@4141 215 return false;
sla@4141 216 }
sla@4141 217 }
sla@4141 218 }
sla@4141 219
rbackman@4310 220 // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
sgoldman@107 221 // because the return address counts against the callee's frame.
sgoldman@107 222
rbackman@4310 223 if (sender_blob->frame_size() <= 0) {
sgoldman@107 224 assert(!sender_blob->is_nmethod(), "should count return address at least");
sgoldman@107 225 return false;
sgoldman@107 226 }
sgoldman@107 227
sgoldman@107 228 // We should never be able to see anything here except an nmethod. If something in the
sgoldman@107 229 // code cache (current frame) is called by an entity within the code cache that entity
sgoldman@107 230 // should not be anything but the call stub (already covered), the interpreter (already covered)
sgoldman@107 231 // or an nmethod.
sgoldman@107 232
rbackman@4310 233 if (!sender_blob->is_nmethod()) {
rbackman@4310 234 return false;
rbackman@4310 235 }
sgoldman@107 236
sgoldman@107 237 // Could put some more validation for the potential non-interpreted sender
sgoldman@107 238 // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
sgoldman@107 239
sgoldman@107 240 // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
sgoldman@107 241
sgoldman@107 242 // We've validated the potential sender that would be created
duke@0 243 return true;
duke@0 244 }
sgoldman@107 245
sgoldman@107 246 // Must be native-compiled frame. Since sender will try and use fp to find
sgoldman@107 247 // linkages it must be safe
sgoldman@107 248
sgoldman@107 249 if (!fp_safe) {
sgoldman@107 250 return false;
duke@0 251 }
sgoldman@107 252
sgoldman@107 253 // Will the pc we fetch be non-zero (which we'll find at the oldest frame)
sgoldman@107 254
sgoldman@107 255 if ( (address) this->fp()[return_addr_offset] == NULL) return false;
sgoldman@107 256
sgoldman@107 257
sgoldman@107 258 // could try and do some more potential verification of native frame if we could think of some...
sgoldman@107 259
sgoldman@107 260 return true;
sgoldman@107 261
duke@0 262 }
duke@0 263
duke@0 264
duke@0 265 void frame::patch_pc(Thread* thread, address pc) {
twisti@2836 266 address* pc_addr = &(((address*) sp())[-1]);
duke@0 267 if (TracePcPatching) {
twisti@2894 268 tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
twisti@2836 269 pc_addr, *pc_addr, pc);
duke@0 270 }
twisti@2894 271 // Either the return address is the original one or we are going to
twisti@2894 272 // patch in the same address that's already there.
twisti@2894 273 assert(_pc == *pc_addr || pc == *pc_addr, "must be");
twisti@2836 274 *pc_addr = pc;
duke@0 275 _cb = CodeCache::find_blob(pc);
twisti@1204 276 address original_pc = nmethod::get_deopt_original_pc(this);
twisti@1204 277 if (original_pc != NULL) {
twisti@1204 278 assert(original_pc == _pc, "expected original PC to be stored before patching");
duke@0 279 _deopt_state = is_deoptimized;
duke@0 280 // leave _pc as is
duke@0 281 } else {
duke@0 282 _deopt_state = not_deoptimized;
duke@0 283 _pc = pc;
duke@0 284 }
duke@0 285 }
duke@0 286
duke@0 287 bool frame::is_interpreted_frame() const {
duke@0 288 return Interpreter::contains(pc());
duke@0 289 }
duke@0 290
cfang@793 291 int frame::frame_size(RegisterMap* map) const {
cfang@793 292 frame sender = this->sender(map);
duke@0 293 return sender.sp() - sp();
duke@0 294 }
duke@0 295
duke@0 296 intptr_t* frame::entry_frame_argument_at(int offset) const {
duke@0 297 // convert offset to index to deal with tsi
duke@0 298 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
duke@0 299 // Entry frame's arguments are always in relation to unextended_sp()
duke@0 300 return &unextended_sp()[index];
duke@0 301 }
duke@0 302
duke@0 303 // sender_sp
duke@0 304 #ifdef CC_INTERP
duke@0 305 intptr_t* frame::interpreter_frame_sender_sp() const {
duke@0 306 assert(is_interpreted_frame(), "interpreted frame expected");
duke@0 307 // QQQ why does this specialize method exist if frame::sender_sp() does same thing?
duke@0 308 // seems odd and if we always know interpreted vs. non then sender_sp() is really
duke@0 309 // doing too much work.
duke@0 310 return get_interpreterState()->sender_sp();
duke@0 311 }
duke@0 312
duke@0 313 // monitor elements
duke@0 314
duke@0 315 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
duke@0 316 return get_interpreterState()->monitor_base();
duke@0 317 }
duke@0 318
duke@0 319 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
duke@0 320 return (BasicObjectLock*) get_interpreterState()->stack_base();
duke@0 321 }
duke@0 322
duke@0 323 #else // CC_INTERP
duke@0 324
duke@0 325 intptr_t* frame::interpreter_frame_sender_sp() const {
duke@0 326 assert(is_interpreted_frame(), "interpreted frame expected");
duke@0 327 return (intptr_t*) at(interpreter_frame_sender_sp_offset);
duke@0 328 }
duke@0 329
duke@0 330 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
duke@0 331 assert(is_interpreted_frame(), "interpreted frame expected");
duke@0 332 ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
duke@0 333 }
duke@0 334
duke@0 335
duke@0 336 // monitor elements
duke@0 337
duke@0 338 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
duke@0 339 return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
duke@0 340 }
duke@0 341
duke@0 342 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
duke@0 343 BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
duke@0 344 // make sure the pointer points inside the frame
johnc@1408 345 assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
johnc@1408 346 assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer");
duke@0 347 return result;
duke@0 348 }
duke@0 349
duke@0 350 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
duke@0 351 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
duke@0 352 }
duke@0 353
duke@0 354 // Used by template based interpreter deoptimization
duke@0 355 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
duke@0 356 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
duke@0 357 }
duke@0 358 #endif // CC_INTERP
duke@0 359
duke@0 360 frame frame::sender_for_entry_frame(RegisterMap* map) const {
duke@0 361 assert(map != NULL, "map must be set");
duke@0 362 // Java frame called from C; skip all C frames and return top C
duke@0 363 // frame of that chunk as the sender
duke@0 364 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
duke@0 365 assert(!entry_frame_is_first(), "next Java fp must be non zero");
duke@0 366 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
duke@0 367 map->clear();
duke@0 368 assert(map->include_argument_oops(), "should be set by clear");
duke@0 369 if (jfa->last_Java_pc() != NULL ) {
duke@0 370 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
duke@0 371 return fr;
duke@0 372 }
duke@0 373 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp());
duke@0 374 return fr;
duke@0 375 }
duke@0 376
twisti@1204 377 //------------------------------------------------------------------------------
twisti@1204 378 // frame::verify_deopt_original_pc
twisti@1204 379 //
twisti@1204 380 // Verifies the calculated original PC of a deoptimization PC for the
twisti@1204 381 // given unextended SP. The unextended SP might also be the saved SP
twisti@1204 382 // for MethodHandle call sites.
twisti@1204 383 #if ASSERT
twisti@1204 384 void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return) {
twisti@1204 385 frame fr;
twisti@1204 386
twisti@1204 387 // This is ugly but it's better than to change {get,set}_original_pc
twisti@1204 388 // to take an SP value as argument. And it's only a debugging
twisti@1204 389 // method anyway.
twisti@1204 390 fr._unextended_sp = unextended_sp;
twisti@1204 391
twisti@1204 392 address original_pc = nm->get_original_pc(&fr);
twisti@1668 393 assert(nm->insts_contains(original_pc), "original PC must be in nmethod");
twisti@1204 394 assert(nm->is_method_handle_return(original_pc) == is_method_handle_return, "must be");
twisti@1204 395 }
twisti@1204 396 #endif
twisti@1204 397
never@2460 398 //------------------------------------------------------------------------------
never@2460 399 // frame::adjust_unextended_sp
never@2460 400 void frame::adjust_unextended_sp() {
never@2460 401 // If we are returning to a compiled MethodHandle call site, the
never@2460 402 // saved_fp will in fact be a saved value of the unextended SP. The
never@2460 403 // simplest way to tell whether we are returning to such a call site
never@2460 404 // is as follows:
never@2460 405
never@2460 406 nmethod* sender_nm = (_cb == NULL) ? NULL : _cb->as_nmethod_or_null();
never@2460 407 if (sender_nm != NULL) {
never@2460 408 // If the sender PC is a deoptimization point, get the original
never@2460 409 // PC. For MethodHandle call site the unextended_sp is stored in
never@2460 410 // saved_fp.
never@2460 411 if (sender_nm->is_deopt_mh_entry(_pc)) {
never@2460 412 DEBUG_ONLY(verify_deopt_mh_original_pc(sender_nm, _fp));
never@2460 413 _unextended_sp = _fp;
never@2460 414 }
never@2460 415 else if (sender_nm->is_deopt_entry(_pc)) {
never@2460 416 DEBUG_ONLY(verify_deopt_original_pc(sender_nm, _unextended_sp));
never@2460 417 }
never@2460 418 else if (sender_nm->is_method_handle_return(_pc)) {
never@2460 419 _unextended_sp = _fp;
never@2460 420 }
never@2460 421 }
never@2460 422 }
never@2460 423
never@2460 424 //------------------------------------------------------------------------------
never@2460 425 // frame::update_map_with_saved_link
never@2460 426 void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {
never@2460 427 // The interpreter and compiler(s) always save EBP/RBP in a known
never@2460 428 // location on entry. We must record where that location is
never@2460 429 // so this if EBP/RBP was live on callout from c2 we can find
never@2460 430 // the saved copy no matter what it called.
never@2460 431
never@2460 432 // Since the interpreter always saves EBP/RBP if we record where it is then
never@2460 433 // we don't have to always save EBP/RBP on entry and exit to c2 compiled
never@2460 434 // code, on entry will be enough.
never@2460 435 map->set_location(rbp->as_VMReg(), (address) link_addr);
never@2460 436 #ifdef AMD64
never@2460 437 // this is weird "H" ought to be at a higher address however the
never@2460 438 // oopMaps seems to have the "H" regs at the same address and the
never@2460 439 // vanilla register.
never@2460 440 // XXXX make this go away
never@2460 441 if (true) {
never@2460 442 map->set_location(rbp->as_VMReg()->next(), (address) link_addr);
never@2460 443 }
never@2460 444 #endif // AMD64
never@2460 445 }
never@2460 446
twisti@1204 447
twisti@1204 448 //------------------------------------------------------------------------------
twisti@1204 449 // frame::sender_for_interpreter_frame
duke@0 450 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
twisti@1204 451 // SP is the raw SP from the sender after adapter or interpreter
twisti@1204 452 // extension.
twisti@1204 453 intptr_t* sender_sp = this->sender_sp();
duke@0 454
duke@0 455 // This is the sp before any possible extension (adapter/locals).
duke@0 456 intptr_t* unextended_sp = interpreter_frame_sender_sp();
duke@0 457
duke@0 458 #ifdef COMPILER2
duke@0 459 if (map->update_map()) {
never@2460 460 update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
duke@0 461 }
twisti@1204 462 #endif // COMPILER2
twisti@1204 463
never@2460 464 return frame(sender_sp, unextended_sp, link(), sender_pc());
duke@0 465 }
duke@0 466
duke@0 467
twisti@1204 468 //------------------------------------------------------------------------------
twisti@1204 469 // frame::sender_for_compiled_frame
duke@0 470 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
duke@0 471 assert(map != NULL, "map must be set");
duke@0 472
duke@0 473 // frame owned by optimizing compiler
duke@0 474 assert(_cb->frame_size() >= 0, "must have non-zero frame size");
twisti@1204 475 intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
twisti@1204 476 intptr_t* unextended_sp = sender_sp;
duke@0 477
duke@0 478 // On Intel the return_address is always the word on the stack
duke@0 479 address sender_pc = (address) *(sender_sp-1);
duke@0 480
twisti@1204 481 // This is the saved value of EBP which may or may not really be an FP.
twisti@1204 482 // It is only an FP if the sender is an interpreter frame (or C1?).
never@2460 483 intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
twisti@1135 484
duke@0 485 if (map->update_map()) {
duke@0 486 // Tell GC to use argument oopmaps for some runtime stubs that need it.
duke@0 487 // For C1, the runtime stub might not have oop maps, so set this flag
duke@0 488 // outside of update_register_map.
duke@0 489 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
duke@0 490 if (_cb->oop_maps() != NULL) {
duke@0 491 OopMapSet::update_register_map(this, map);
duke@0 492 }
never@2460 493
twisti@1204 494 // Since the prolog does the save and restore of EBP there is no oopmap
duke@0 495 // for it so we must fill in its location as if there was an oopmap entry
duke@0 496 // since if our caller was compiled code there could be live jvm state in it.
never@2460 497 update_map_with_saved_link(map, saved_fp_addr);
duke@0 498 }
duke@0 499
duke@0 500 assert(sender_sp != sp(), "must have changed");
never@2460 501 return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
duke@0 502 }
duke@0 503
twisti@1204 504
twisti@1204 505 //------------------------------------------------------------------------------
twisti@1204 506 // frame::sender
duke@0 507 frame frame::sender(RegisterMap* map) const {
duke@0 508 // Default is we done have to follow them. The sender_for_xxx will
duke@0 509 // update it accordingly
duke@0 510 map->set_include_argument_oops(false);
duke@0 511
duke@0 512 if (is_entry_frame()) return sender_for_entry_frame(map);
duke@0 513 if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
duke@0 514 assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
duke@0 515
duke@0 516 if (_cb != NULL) {
duke@0 517 return sender_for_compiled_frame(map);
duke@0 518 }
duke@0 519 // Must be native-compiled frame, i.e. the marshaling code for native
duke@0 520 // methods that exists in the core system.
duke@0 521 return frame(sender_sp(), link(), sender_pc());
duke@0 522 }
duke@0 523
duke@0 524
duke@0 525 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
duke@0 526 assert(is_interpreted_frame(), "must be interpreter frame");
duke@0 527 methodOop method = interpreter_frame_method();
duke@0 528 // When unpacking an optimized frame the frame pointer is
duke@0 529 // adjusted with:
duke@0 530 int diff = (method->max_locals() - method->size_of_parameters()) *
twisti@1426 531 Interpreter::stackElementWords;
duke@0 532 return _fp == (fp - diff);
duke@0 533 }
duke@0 534
duke@0 535 void frame::pd_gc_epilog() {
duke@0 536 // nothing done here now
duke@0 537 }
duke@0 538
sgoldman@107 539 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
duke@0 540 // QQQ
duke@0 541 #ifdef CC_INTERP
duke@0 542 #else
duke@0 543 assert(is_interpreted_frame(), "Not an interpreted frame");
duke@0 544 // These are reasonable sanity checks
duke@0 545 if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
duke@0 546 return false;
duke@0 547 }
duke@0 548 if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
duke@0 549 return false;
duke@0 550 }
duke@0 551 if (fp() + interpreter_frame_initial_sp_offset < sp()) {
duke@0 552 return false;
duke@0 553 }
duke@0 554 // These are hacks to keep us out of trouble.
duke@0 555 // The problem with these is that they mask other problems
duke@0 556 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
duke@0 557 return false;
duke@0 558 }
sgoldman@107 559
sgoldman@107 560 // do some validation of frame elements
sgoldman@107 561
sgoldman@107 562 // first the method
sgoldman@107 563
sgoldman@107 564 methodOop m = *interpreter_frame_method_addr();
sgoldman@107 565
sgoldman@107 566 // validate the method we'd find in this potential sender
sgoldman@107 567 if (!Universe::heap()->is_valid_method(m)) return false;
sgoldman@107 568
sgoldman@107 569 // stack frames shouldn't be much larger than max_stack elements
sgoldman@107 570
twisti@1426 571 if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
duke@0 572 return false;
duke@0 573 }
sgoldman@107 574
sgoldman@107 575 // validate bci/bcx
sgoldman@107 576
sgoldman@107 577 intptr_t bcx = interpreter_frame_bcx();
sgoldman@107 578 if (m->validate_bci_from_bcx(bcx) < 0) {
sgoldman@107 579 return false;
sgoldman@107 580 }
sgoldman@107 581
sgoldman@107 582 // validate constantPoolCacheOop
sgoldman@107 583
sgoldman@107 584 constantPoolCacheOop cp = *interpreter_frame_cache_addr();
sgoldman@107 585
sgoldman@107 586 if (cp == NULL ||
sgoldman@107 587 !Space::is_aligned(cp) ||
sgoldman@107 588 !Universe::heap()->is_permanent((void*)cp)) return false;
sgoldman@107 589
sgoldman@107 590 // validate locals
sgoldman@107 591
sgoldman@107 592 address locals = (address) *interpreter_frame_locals_addr();
sgoldman@107 593
sgoldman@107 594 if (locals > thread->stack_base() || locals < (address) fp()) return false;
sgoldman@107 595
sgoldman@107 596 // We'd have to be pretty unlucky to be mislead at this point
sgoldman@107 597
duke@0 598 #endif // CC_INTERP
duke@0 599 return true;
duke@0 600 }
duke@0 601
duke@0 602 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
duke@0 603 #ifdef CC_INTERP
bobv@1601 604 // Needed for JVMTI. The result should always be in the
bobv@1601 605 // interpreterState object
duke@0 606 interpreterState istate = get_interpreterState();
duke@0 607 #endif // CC_INTERP
duke@0 608 assert(is_interpreted_frame(), "interpreted frame expected");
duke@0 609 methodOop method = interpreter_frame_method();
duke@0 610 BasicType type = method->result_type();
duke@0 611
duke@0 612 intptr_t* tos_addr;
duke@0 613 if (method->is_native()) {
duke@0 614 // Prior to calling into the runtime to report the method_exit the possible
duke@0 615 // return value is pushed to the native stack. If the result is a jfloat/jdouble
duke@0 616 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
duke@0 617 tos_addr = (intptr_t*)sp();
duke@0 618 if (type == T_FLOAT || type == T_DOUBLE) {
duke@0 619 // QQQ seems like this code is equivalent on the two platforms
duke@0 620 #ifdef AMD64
duke@0 621 // This is times two because we do a push(ltos) after pushing XMM0
duke@0 622 // and that takes two interpreter stack slots.
twisti@1426 623 tos_addr += 2 * Interpreter::stackElementWords;
duke@0 624 #else
duke@0 625 tos_addr += 2;
duke@0 626 #endif // AMD64
duke@0 627 }
duke@0 628 } else {
duke@0 629 tos_addr = (intptr_t*)interpreter_frame_tos_address();
duke@0 630 }
duke@0 631
duke@0 632 switch (type) {
duke@0 633 case T_OBJECT :
duke@0 634 case T_ARRAY : {
duke@0 635 oop obj;
duke@0 636 if (method->is_native()) {
duke@0 637 #ifdef CC_INTERP
duke@0 638 obj = istate->_oop_temp;
duke@0 639 #else
duke@0 640 obj = (oop) at(interpreter_frame_oop_temp_offset);
duke@0 641 #endif // CC_INTERP
duke@0 642 } else {
duke@0 643 oop* obj_p = (oop*)tos_addr;
duke@0 644 obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
duke@0 645 }
duke@0 646 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
duke@0 647 *oop_result = obj;
duke@0 648 break;
duke@0 649 }
duke@0 650 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
duke@0 651 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
duke@0 652 case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
duke@0 653 case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
duke@0 654 case T_INT : value_result->i = *(jint*)tos_addr; break;
duke@0 655 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
duke@0 656 case T_FLOAT : {
duke@0 657 #ifdef AMD64
duke@0 658 value_result->f = *(jfloat*)tos_addr;
duke@0 659 #else
duke@0 660 if (method->is_native()) {
duke@0 661 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat
duke@0 662 value_result->f = (jfloat)d;
duke@0 663 } else {
duke@0 664 value_result->f = *(jfloat*)tos_addr;
duke@0 665 }
duke@0 666 #endif // AMD64
duke@0 667 break;
duke@0 668 }
duke@0 669 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
duke@0 670 case T_VOID : /* Nothing to do */ break;
duke@0 671 default : ShouldNotReachHere();
duke@0 672 }
duke@0 673
duke@0 674 return type;
duke@0 675 }
duke@0 676
duke@0 677
duke@0 678 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
duke@0 679 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
duke@0 680 return &interpreter_frame_tos_address()[index];
duke@0 681 }
never@2433 682
bdelsart@3107 683 #ifndef PRODUCT
never@2433 684
never@2433 685 #define DESCRIBE_FP_OFFSET(name) \
never@2462 686 values.describe(frame_no, fp() + frame::name##_offset, #name)
never@2433 687
never@2433 688 void frame::describe_pd(FrameValues& values, int frame_no) {
twisti@3932 689 if (is_interpreted_frame()) {
never@2433 690 DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
never@2433 691 DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
never@2433 692 DESCRIBE_FP_OFFSET(interpreter_frame_method);
never@2433 693 DESCRIBE_FP_OFFSET(interpreter_frame_mdx);
never@2433 694 DESCRIBE_FP_OFFSET(interpreter_frame_cache);
never@2433 695 DESCRIBE_FP_OFFSET(interpreter_frame_locals);
never@2433 696 DESCRIBE_FP_OFFSET(interpreter_frame_bcx);
never@2433 697 DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
never@2433 698 }
never@2433 699 }
never@2433 700 #endif
bdelsart@2764 701
bdelsart@2764 702 intptr_t *frame::initial_deoptimization_info() {
bdelsart@2764 703 // used to reset the saved FP
bdelsart@2764 704 return fp();
bdelsart@2764 705 }
bdelsart@3087 706
bdelsart@3087 707 intptr_t* frame::real_fp() const {
bdelsart@3087 708 if (_cb != NULL) {
bdelsart@3087 709 // use the frame size if valid
bdelsart@3087 710 int size = _cb->frame_size();
twisti@3932 711 if (size > 0) {
bdelsart@3087 712 return unextended_sp() + size;
bdelsart@3087 713 }
bdelsart@3087 714 }
bdelsart@3087 715 // else rely on fp()
bdelsart@3087 716 assert(! is_compiled_frame(), "unknown compiled frame size");
bdelsart@3087 717 return fp();
bdelsart@3087 718 }