src/cpu/x86/vm/frame_x86.cpp

Tue, 08 Apr 2008 12:23:15 -0400

author
sgoldman
date
Tue, 08 Apr 2008 12:23:15 -0400
changeset 542
93b6525e3b82
parent 435
a61af66fc99e
child 631
d1605aabd0a1
permissions
-rw-r--r--

6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
Summary: Rewrite frame::safe_for_sender and friends to be safe for collector/analyzer
Reviewed-by: dcubed, kvn

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any 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
sgoldman@542 144
sgoldman@542 145 if (!sender_blob->instructions_contains(sender_pc)) return false;
sgoldman@542 146
sgoldman@542 147 // We should never be able to see an adapter if the current frame is something from code cache
sgoldman@542 148
sgoldman@542 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) {
duke@435 220 tty->print_cr("patch_pc at address 0x%x [0x%x -> 0x%x] ", &((address *)sp())[-1], ((address *)sp())[-1], pc);
duke@435 221 }
duke@435 222 ((address *)sp())[-1] = pc;
duke@435 223 _cb = CodeCache::find_blob(pc);
duke@435 224 if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {
duke@435 225 address orig = (((nmethod*)_cb)->get_original_pc(this));
duke@435 226 assert(orig == _pc, "expected original to be stored before patching");
duke@435 227 _deopt_state = is_deoptimized;
duke@435 228 // leave _pc as is
duke@435 229 } else {
duke@435 230 _deopt_state = not_deoptimized;
duke@435 231 _pc = pc;
duke@435 232 }
duke@435 233 }
duke@435 234
duke@435 235 bool frame::is_interpreted_frame() const {
duke@435 236 return Interpreter::contains(pc());
duke@435 237 }
duke@435 238
duke@435 239 int frame::frame_size() const {
duke@435 240 RegisterMap map(JavaThread::current(), false);
duke@435 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
duke@435 294 assert((intptr_t) fp() > (intptr_t) result, "result must < than frame pointer");
duke@435 295 assert((intptr_t) sp() <= (intptr_t) result, "result must >= than stack 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
duke@435 326 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
duke@435 327 // sp is the raw sp from the sender after adapter or interpreter extension
duke@435 328 intptr_t* sp = (intptr_t*) addr_at(sender_sp_offset);
duke@435 329
duke@435 330 // This is the sp before any possible extension (adapter/locals).
duke@435 331 intptr_t* unextended_sp = interpreter_frame_sender_sp();
duke@435 332
duke@435 333 // The interpreter and compiler(s) always save EBP/RBP in a known
duke@435 334 // location on entry. We must record where that location is
duke@435 335 // so this if EBP/RBP was live on callout from c2 we can find
duke@435 336 // the saved copy no matter what it called.
duke@435 337
duke@435 338 // Since the interpreter always saves EBP/RBP if we record where it is then
duke@435 339 // we don't have to always save EBP/RBP on entry and exit to c2 compiled
duke@435 340 // code, on entry will be enough.
duke@435 341 #ifdef COMPILER2
duke@435 342 if (map->update_map()) {
duke@435 343 map->set_location(rbp->as_VMReg(), (address) addr_at(link_offset));
duke@435 344 #ifdef AMD64
duke@435 345 // this is weird "H" ought to be at a higher address however the
duke@435 346 // oopMaps seems to have the "H" regs at the same address and the
duke@435 347 // vanilla register.
duke@435 348 // XXXX make this go away
duke@435 349 if (true) {
duke@435 350 map->set_location(rbp->as_VMReg()->next(), (address)addr_at(link_offset));
duke@435 351 }
duke@435 352 #endif // AMD64
duke@435 353 }
duke@435 354 #endif /* COMPILER2 */
duke@435 355 return frame(sp, unextended_sp, link(), sender_pc());
duke@435 356 }
duke@435 357
duke@435 358
duke@435 359 //------------------------------sender_for_compiled_frame-----------------------
duke@435 360 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
duke@435 361 assert(map != NULL, "map must be set");
duke@435 362 const bool c1_compiled = _cb->is_compiled_by_c1();
duke@435 363
duke@435 364 // frame owned by optimizing compiler
duke@435 365 intptr_t* sender_sp = NULL;
duke@435 366
duke@435 367 assert(_cb->frame_size() >= 0, "must have non-zero frame size");
duke@435 368 sender_sp = unextended_sp() + _cb->frame_size();
duke@435 369
duke@435 370 // On Intel the return_address is always the word on the stack
duke@435 371 address sender_pc = (address) *(sender_sp-1);
duke@435 372
duke@435 373 // This is the saved value of ebp which may or may not really be an fp.
duke@435 374 // it is only an fp if the sender is an interpreter frame (or c1?)
duke@435 375
duke@435 376 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
duke@435 377
duke@435 378 if (map->update_map()) {
duke@435 379 // Tell GC to use argument oopmaps for some runtime stubs that need it.
duke@435 380 // For C1, the runtime stub might not have oop maps, so set this flag
duke@435 381 // outside of update_register_map.
duke@435 382 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
duke@435 383 if (_cb->oop_maps() != NULL) {
duke@435 384 OopMapSet::update_register_map(this, map);
duke@435 385 }
duke@435 386 // Since the prolog does the save and restore of epb there is no oopmap
duke@435 387 // for it so we must fill in its location as if there was an oopmap entry
duke@435 388 // since if our caller was compiled code there could be live jvm state in it.
duke@435 389 map->set_location(rbp->as_VMReg(), (address) (sender_sp - frame::sender_sp_offset));
duke@435 390 #ifdef AMD64
duke@435 391 // this is weird "H" ought to be at a higher address however the
duke@435 392 // oopMaps seems to have the "H" regs at the same address and the
duke@435 393 // vanilla register.
duke@435 394 // XXXX make this go away
duke@435 395 if (true) {
duke@435 396 map->set_location(rbp->as_VMReg()->next(), (address) (sender_sp - frame::sender_sp_offset));
duke@435 397 }
duke@435 398 #endif // AMD64
duke@435 399 }
duke@435 400
duke@435 401 assert(sender_sp != sp(), "must have changed");
duke@435 402 return frame(sender_sp, saved_fp, sender_pc);
duke@435 403 }
duke@435 404
duke@435 405 frame frame::sender(RegisterMap* map) const {
duke@435 406 // Default is we done have to follow them. The sender_for_xxx will
duke@435 407 // update it accordingly
duke@435 408 map->set_include_argument_oops(false);
duke@435 409
duke@435 410 if (is_entry_frame()) return sender_for_entry_frame(map);
duke@435 411 if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
duke@435 412 assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
duke@435 413
duke@435 414 if (_cb != NULL) {
duke@435 415 return sender_for_compiled_frame(map);
duke@435 416 }
duke@435 417 // Must be native-compiled frame, i.e. the marshaling code for native
duke@435 418 // methods that exists in the core system.
duke@435 419 return frame(sender_sp(), link(), sender_pc());
duke@435 420 }
duke@435 421
duke@435 422
duke@435 423 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
duke@435 424 assert(is_interpreted_frame(), "must be interpreter frame");
duke@435 425 methodOop method = interpreter_frame_method();
duke@435 426 // When unpacking an optimized frame the frame pointer is
duke@435 427 // adjusted with:
duke@435 428 int diff = (method->max_locals() - method->size_of_parameters()) *
duke@435 429 Interpreter::stackElementWords();
duke@435 430 return _fp == (fp - diff);
duke@435 431 }
duke@435 432
duke@435 433 void frame::pd_gc_epilog() {
duke@435 434 // nothing done here now
duke@435 435 }
duke@435 436
sgoldman@542 437 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
duke@435 438 // QQQ
duke@435 439 #ifdef CC_INTERP
duke@435 440 #else
duke@435 441 assert(is_interpreted_frame(), "Not an interpreted frame");
duke@435 442 // These are reasonable sanity checks
duke@435 443 if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
duke@435 444 return false;
duke@435 445 }
duke@435 446 if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
duke@435 447 return false;
duke@435 448 }
duke@435 449 if (fp() + interpreter_frame_initial_sp_offset < sp()) {
duke@435 450 return false;
duke@435 451 }
duke@435 452 // These are hacks to keep us out of trouble.
duke@435 453 // The problem with these is that they mask other problems
duke@435 454 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
duke@435 455 return false;
duke@435 456 }
sgoldman@542 457
sgoldman@542 458 // do some validation of frame elements
sgoldman@542 459
sgoldman@542 460 // first the method
sgoldman@542 461
sgoldman@542 462 methodOop m = *interpreter_frame_method_addr();
sgoldman@542 463
sgoldman@542 464 // validate the method we'd find in this potential sender
sgoldman@542 465 if (!Universe::heap()->is_valid_method(m)) return false;
sgoldman@542 466
sgoldman@542 467 // stack frames shouldn't be much larger than max_stack elements
sgoldman@542 468
sgoldman@542 469 if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize()) {
duke@435 470 return false;
duke@435 471 }
sgoldman@542 472
sgoldman@542 473 // validate bci/bcx
sgoldman@542 474
sgoldman@542 475 intptr_t bcx = interpreter_frame_bcx();
sgoldman@542 476 if (m->validate_bci_from_bcx(bcx) < 0) {
sgoldman@542 477 return false;
sgoldman@542 478 }
sgoldman@542 479
sgoldman@542 480 // validate constantPoolCacheOop
sgoldman@542 481
sgoldman@542 482 constantPoolCacheOop cp = *interpreter_frame_cache_addr();
sgoldman@542 483
sgoldman@542 484 if (cp == NULL ||
sgoldman@542 485 !Space::is_aligned(cp) ||
sgoldman@542 486 !Universe::heap()->is_permanent((void*)cp)) return false;
sgoldman@542 487
sgoldman@542 488 // validate locals
sgoldman@542 489
sgoldman@542 490 address locals = (address) *interpreter_frame_locals_addr();
sgoldman@542 491
sgoldman@542 492 if (locals > thread->stack_base() || locals < (address) fp()) return false;
sgoldman@542 493
sgoldman@542 494 // We'd have to be pretty unlucky to be mislead at this point
sgoldman@542 495
duke@435 496 #endif // CC_INTERP
duke@435 497 return true;
duke@435 498 }
duke@435 499
duke@435 500 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
duke@435 501 #ifdef CC_INTERP
duke@435 502 // Needed for JVMTI. The result should always be in the interpreterState object
duke@435 503 assert(false, "NYI");
duke@435 504 interpreterState istate = get_interpreterState();
duke@435 505 #endif // CC_INTERP
duke@435 506 assert(is_interpreted_frame(), "interpreted frame expected");
duke@435 507 methodOop method = interpreter_frame_method();
duke@435 508 BasicType type = method->result_type();
duke@435 509
duke@435 510 intptr_t* tos_addr;
duke@435 511 if (method->is_native()) {
duke@435 512 // Prior to calling into the runtime to report the method_exit the possible
duke@435 513 // return value is pushed to the native stack. If the result is a jfloat/jdouble
duke@435 514 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
duke@435 515 tos_addr = (intptr_t*)sp();
duke@435 516 if (type == T_FLOAT || type == T_DOUBLE) {
duke@435 517 // QQQ seems like this code is equivalent on the two platforms
duke@435 518 #ifdef AMD64
duke@435 519 // This is times two because we do a push(ltos) after pushing XMM0
duke@435 520 // and that takes two interpreter stack slots.
duke@435 521 tos_addr += 2 * Interpreter::stackElementWords();
duke@435 522 #else
duke@435 523 tos_addr += 2;
duke@435 524 #endif // AMD64
duke@435 525 }
duke@435 526 } else {
duke@435 527 tos_addr = (intptr_t*)interpreter_frame_tos_address();
duke@435 528 }
duke@435 529
duke@435 530 switch (type) {
duke@435 531 case T_OBJECT :
duke@435 532 case T_ARRAY : {
duke@435 533 oop obj;
duke@435 534 if (method->is_native()) {
duke@435 535 #ifdef CC_INTERP
duke@435 536 obj = istate->_oop_temp;
duke@435 537 #else
duke@435 538 obj = (oop) at(interpreter_frame_oop_temp_offset);
duke@435 539 #endif // CC_INTERP
duke@435 540 } else {
duke@435 541 oop* obj_p = (oop*)tos_addr;
duke@435 542 obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
duke@435 543 }
duke@435 544 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
duke@435 545 *oop_result = obj;
duke@435 546 break;
duke@435 547 }
duke@435 548 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
duke@435 549 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
duke@435 550 case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
duke@435 551 case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
duke@435 552 case T_INT : value_result->i = *(jint*)tos_addr; break;
duke@435 553 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
duke@435 554 case T_FLOAT : {
duke@435 555 #ifdef AMD64
duke@435 556 value_result->f = *(jfloat*)tos_addr;
duke@435 557 #else
duke@435 558 if (method->is_native()) {
duke@435 559 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat
duke@435 560 value_result->f = (jfloat)d;
duke@435 561 } else {
duke@435 562 value_result->f = *(jfloat*)tos_addr;
duke@435 563 }
duke@435 564 #endif // AMD64
duke@435 565 break;
duke@435 566 }
duke@435 567 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
duke@435 568 case T_VOID : /* Nothing to do */ break;
duke@435 569 default : ShouldNotReachHere();
duke@435 570 }
duke@435 571
duke@435 572 return type;
duke@435 573 }
duke@435 574
duke@435 575
duke@435 576 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
duke@435 577 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
duke@435 578 return &interpreter_frame_tos_address()[index];
duke@435 579 }

mercurial