annotate src/cpu/x86/vm/frame_x86.cpp @ 1135:e66fd840cb6b

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