src/cpu/x86/vm/frame_x86.cpp

Wed, 25 Aug 2010 05:27:54 -0700

author
twisti
date
Wed, 25 Aug 2010 05:27:54 -0700
changeset 2103
3e8fbc61cee8
parent 2036
126ea7725993
child 2314
f95d63e2154a
permissions
-rw-r--r--

6978355: renaming for 6961697
Summary: This is the renaming part of 6961697 to keep the actual changes small for review.
Reviewed-by: kvn, never

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

mercurial