hotspot/src/cpu/sparc/vm/frame_sparc.cpp

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)frame_sparc.cpp      1.175 07/08/29 13:42:16 JVM"
   3 #endif
   4 /*
   5  * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


 143 
 144   lv &= ~R_LIO_mask;  // clear %l, %o, %i regs
 145 
 146   // if we cleared some non-%g locations, we may have to do some shifting
 147   if (lv != lv0) {
 148     // copy %i0-%i5 to %o0-%o5, if they have special locations
 149     // This can happen in within stubs which spill argument registers
 150     // around a dynamic link operation, such as resolve_opt_virtual_call.
 151     for (int i = 0; i < 8; i++) {
 152       if (lv0 & (1LL << R_I_nums[i])) {
 153         _location[R_O_nums[i]] = _location[R_I_nums[i]];
 154         lv |=  (1LL << R_O_nums[i]);
 155       }
 156     }
 157   }
 158 
 159   _location_valid[0] = lv;
 160   check_location_valid();
 161 }
 162 
 163 
 164 bool frame::safe_for_sender(JavaThread *thread) {
 165   address   sp = (address)_sp;
 166   if (sp != NULL && 
 167       (sp <= thread->stack_base() && sp >= thread->stack_base() - thread->stack_size())) {




























 168       // Unfortunately we can only check frame complete for runtime stubs and nmethod
 169       // other generic buffer blobs are more problematic so we just assume they are
 170       // ok. adapter blobs never have a frame complete and are never ok.
 171       if (_cb != NULL && !_cb->is_frame_complete_at(_pc)) {

 172         if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
 173           return false;
 174         }
 175       }
 176       return true;














































































 177   }









 178   return false;





















 179 }
 180 
 181 // constructors
 182 
 183 // Construct an unpatchable, deficient frame
 184 frame::frame(intptr_t* sp, unpatchable_t, address pc, CodeBlob* cb) {
 185 #ifdef _LP64
 186   assert( (((intptr_t)sp & (wordSize-1)) == 0), "frame constructor passed an invalid sp");   
 187 #endif
 188   _sp = sp;
 189   _younger_sp = NULL;
 190   _pc = pc;
 191   _cb = cb;
 192   _sp_adjustment_by_callee = 0;
 193   assert(pc == NULL && cb == NULL || pc != NULL, "can't have a cb and no pc!");
 194   if (_cb == NULL && _pc != NULL ) {
 195     _cb = CodeCache::find_blob(_pc);
 196   }
 197   _deopt_state = unknown;
 198 #ifdef ASSERT


 436   return next_younger_sp_or_null(valid_sp, sp) != NULL;
 437 }
 438 
 439 
 440 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
 441   assert(is_interpreted_frame(), "must be interpreter frame");
 442   return this->fp() == fp;
 443 }
 444 
 445 
 446 void frame::pd_gc_epilog() {
 447   if (is_interpreted_frame()) {
 448     // set constant pool cache entry for interpreter
 449     methodOop m = interpreter_frame_method();
 450 
 451     *interpreter_frame_cpoolcache_addr() = m->constants()->cache();
 452   }
 453 }
 454 
 455 
 456 bool frame::is_interpreted_frame_valid() const {
 457 #ifdef CC_INTERP
 458   // Is there anything to do?
 459 #else
 460   assert(is_interpreted_frame(), "Not an interpreted frame");
 461   // These are reasonable sanity checks
 462   if (fp() == 0 || (intptr_t(fp()) & (2*wordSize-1)) != 0) {
 463     return false;
 464   }
 465   if (sp() == 0 || (intptr_t(sp()) & (2*wordSize-1)) != 0) {
 466     return false;
 467   }

 468   const intptr_t interpreter_frame_initial_sp_offset = interpreter_frame_vm_local_words;
 469   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
 470     return false;
 471   }
 472   // These are hacks to keep us out of trouble.
 473   // The problem with these is that they mask other problems
 474   if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
 475     return false;
 476   }
 477   if (fp() - sp() > 4096) {  // stack frames shouldn't be large.


















 478     return false;
 479   }
















 480 #endif /* CC_INTERP */
 481   return true;
 482 }
 483 
 484 
 485 // Windows have been flushed on entry (but not marked). Capture the pc that
 486 // is the return address to the frame that contains "sp" as its stack pointer. 
 487 // This pc resides in the called of the frame corresponding to "sp". 
 488 // As a side effect we mark this JavaFrameAnchor as having flushed the windows.
 489 // This side effect lets us mark stacked JavaFrameAnchors (stacked in the 
 490 // call_helper) as flushed when we have flushed the windows for the most
 491 // recent (i.e. current) JavaFrameAnchor. This saves useless flushing calls
 492 // and lets us find the pc just once rather than multiple times as it did
 493 // in the bad old _post_Java_state days.
 494 //
 495 void JavaFrameAnchor::capture_last_Java_pc(intptr_t* sp) {
 496   if (last_Java_sp() != NULL && last_Java_pc() == NULL) {
 497     // try and find the sp just younger than _last_Java_sp
 498     intptr_t* _post_Java_sp = frame::next_younger_sp_or_null(last_Java_sp(), sp);
 499     // Really this should never fail otherwise VM call must have non-standard





   1 /*
   2  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *


 140 
 141   lv &= ~R_LIO_mask;  // clear %l, %o, %i regs
 142 
 143   // if we cleared some non-%g locations, we may have to do some shifting
 144   if (lv != lv0) {
 145     // copy %i0-%i5 to %o0-%o5, if they have special locations
 146     // This can happen in within stubs which spill argument registers
 147     // around a dynamic link operation, such as resolve_opt_virtual_call.
 148     for (int i = 0; i < 8; i++) {
 149       if (lv0 & (1LL << R_I_nums[i])) {
 150         _location[R_O_nums[i]] = _location[R_I_nums[i]];
 151         lv |=  (1LL << R_O_nums[i]);
 152       }
 153     }
 154   }
 155 
 156   _location_valid[0] = lv;
 157   check_location_valid();
 158 }
 159 

 160 bool frame::safe_for_sender(JavaThread *thread) {
 161 
 162   address _SP = (address) sp();
 163   address _FP = (address) fp();
 164   address _UNEXTENDED_SP = (address) unextended_sp();
 165   // sp must be within the stack
 166   bool sp_safe = (_SP <= thread->stack_base()) &&
 167                  (_SP >= thread->stack_base() - thread->stack_size());
 168 
 169   if (!sp_safe) {
 170     return false;
 171   }
 172 
 173   // unextended sp must be within the stack and above or equal sp
 174   bool unextended_sp_safe = (_UNEXTENDED_SP <= thread->stack_base()) &&
 175                             (_UNEXTENDED_SP >= _SP);
 176 
 177   if (!unextended_sp_safe) return false;
 178 
 179   // an fp must be within the stack and above (but not equal) sp
 180   bool fp_safe = (_FP <= thread->stack_base()) &&
 181                  (_FP > _SP);
 182 
 183   // We know sp/unextended_sp are safe only fp is questionable here
 184 
 185   // If the current frame is known to the code cache then we can attempt to
 186   // to construct the sender and do some validation of it. This goes a long way
 187   // toward eliminating issues when we get in frame construction code
 188 
 189   if (_cb != NULL ) {
 190 
 191     // First check if frame is complete and tester is reliable
 192     // Unfortunately we can only check frame complete for runtime stubs and nmethod
 193     // other generic buffer blobs are more problematic so we just assume they are
 194     // ok. adapter blobs never have a frame complete and are never ok.
 195 
 196     if (!_cb->is_frame_complete_at(_pc)) {
 197       if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
 198         return false;
 199       }
 200     }
 201 
 202     // Entry frame checks
 203     if (is_entry_frame()) {
 204       // an entry frame must have a valid fp.
 205 
 206       if (!fp_safe) {
 207         return false;
 208       }
 209 
 210       // Validate the JavaCallWrapper an entry frame must have
 211 
 212       address jcw = (address)entry_frame_call_wrapper();
 213 
 214       bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > _FP);
 215 
 216       return jcw_safe;
 217 
 218     }
 219 
 220     intptr_t* younger_sp = sp();
 221     intptr_t* _SENDER_SP = sender_sp(); // sender is actually just _FP
 222     bool adjusted_stack = is_interpreted_frame();
 223 
 224     address   sender_pc = (address)younger_sp[I7->sp_offset_in_saved_window()] + pc_return_offset;
 225 
 226 
 227     // We must always be able to find a recognizable pc
 228     CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
 229     if (sender_pc == NULL ||  sender_blob == NULL) {
 230       return false;
 231     }
 232 
 233     // It should be safe to construct the sender though it might not be valid
 234 
 235     frame sender(_SENDER_SP, younger_sp, adjusted_stack);
 236 
 237     // Do we have a valid fp?
 238     address sender_fp = (address) sender.fp();
 239 
 240     // an fp must be within the stack and above (but not equal) current frame's _FP
 241 
 242     bool sender_fp_safe = (sender_fp <= thread->stack_base()) &&
 243                    (sender_fp > _FP);
 244 
 245     if (!sender_fp_safe) {
 246       return false;
 247     }
 248 
 249 
 250     // If the potential sender is the interpreter then we can do some more checking
 251     if (Interpreter::contains(sender_pc)) {
 252       return sender.is_interpreted_frame_valid(thread);
 253     }
 254 
 255     // Could just be some random pointer within the codeBlob
 256     if (!sender.cb()->instructions_contains(sender_pc)) return false;
 257 
 258     // We should never be able to see an adapter if the current frame is something from code cache
 259 
 260     if ( sender_blob->is_adapter_blob()) {
 261       return false;
 262     }
 263 
 264     if( sender.is_entry_frame()) {
 265       // Validate the JavaCallWrapper an entry frame must have
 266 
 267       address jcw = (address)sender.entry_frame_call_wrapper();
 268 
 269       bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > sender_fp);
 270 
 271       return jcw_safe;
 272     }
 273 
 274     // If the frame size is 0 something is bad because every nmethod has a non-zero frame size
 275     // because you must allocate window space
 276 
 277     if (sender_blob->frame_size() == 0) {
 278       assert(!sender_blob->is_nmethod(), "should count return address at least");
 279       return false;
 280     }
 281 
 282     // The sender should positively be an nmethod or call_stub. On sparc we might in fact see something else.
 283     // The cause of this is because at a save instruction the O7 we get is a leftover from an earlier
 284     // window use. So if a runtime stub creates two frames (common in fastdebug/jvmg) then we see the
 285     // stale pc. So if the sender blob is not something we'd expect we have little choice but to declare
 286     // the stack unwalkable. pd_get_top_frame_for_signal_handler tries to recover from this by unwinding
 287     // that initial frame and retrying.
 288 
 289     if (!sender_blob->is_nmethod()) {
 290       return false;
 291     }
 292 
 293     // Could put some more validation for the potential non-interpreted sender
 294     // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
 295 
 296     // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
 297 
 298     // We've validated the potential sender that would be created
 299 
 300     return true;
 301 
 302   }
 303 
 304   // Must be native-compiled frame. Since sender will try and use fp to find
 305   // linkages it must be safe
 306 
 307   if (!fp_safe) return false;
 308 
 309   // could try and do some more potential verification of native frame if we could think of some...
 310 
 311   return true;
 312 }
 313 
 314 // constructors
 315 
 316 // Construct an unpatchable, deficient frame
 317 frame::frame(intptr_t* sp, unpatchable_t, address pc, CodeBlob* cb) {
 318 #ifdef _LP64
 319   assert( (((intptr_t)sp & (wordSize-1)) == 0), "frame constructor passed an invalid sp");
 320 #endif
 321   _sp = sp;
 322   _younger_sp = NULL;
 323   _pc = pc;
 324   _cb = cb;
 325   _sp_adjustment_by_callee = 0;
 326   assert(pc == NULL && cb == NULL || pc != NULL, "can't have a cb and no pc!");
 327   if (_cb == NULL && _pc != NULL ) {
 328     _cb = CodeCache::find_blob(_pc);
 329   }
 330   _deopt_state = unknown;
 331 #ifdef ASSERT


 569   return next_younger_sp_or_null(valid_sp, sp) != NULL;
 570 }
 571 
 572 
 573 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
 574   assert(is_interpreted_frame(), "must be interpreter frame");
 575   return this->fp() == fp;
 576 }
 577 
 578 
 579 void frame::pd_gc_epilog() {
 580   if (is_interpreted_frame()) {
 581     // set constant pool cache entry for interpreter
 582     methodOop m = interpreter_frame_method();
 583 
 584     *interpreter_frame_cpoolcache_addr() = m->constants()->cache();
 585   }
 586 }
 587 
 588 
 589 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
 590 #ifdef CC_INTERP
 591   // Is there anything to do?
 592 #else
 593   assert(is_interpreted_frame(), "Not an interpreted frame");
 594   // These are reasonable sanity checks
 595   if (fp() == 0 || (intptr_t(fp()) & (2*wordSize-1)) != 0) {
 596     return false;
 597   }
 598   if (sp() == 0 || (intptr_t(sp()) & (2*wordSize-1)) != 0) {
 599     return false;
 600   }
 601 
 602   const intptr_t interpreter_frame_initial_sp_offset = interpreter_frame_vm_local_words;
 603   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
 604     return false;
 605   }
 606   // These are hacks to keep us out of trouble.
 607   // The problem with these is that they mask other problems
 608   if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
 609     return false;
 610   }
 611   // do some validation of frame elements
 612 
 613   // first the method
 614 
 615   methodOop m = *interpreter_frame_method_addr();
 616 
 617   // validate the method we'd find in this potential sender
 618   if (!Universe::heap()->is_valid_method(m)) return false;
 619 
 620   // stack frames shouldn't be much larger than max_stack elements
 621 
 622   if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize()) {
 623     return false;
 624   }
 625 
 626   // validate bci/bcx
 627 
 628   intptr_t  bcx    = interpreter_frame_bcx();
 629   if (m->validate_bci_from_bcx(bcx) < 0) {
 630     return false;
 631   }
 632 
 633   // validate constantPoolCacheOop
 634 
 635   constantPoolCacheOop cp = *interpreter_frame_cache_addr();
 636 
 637   if (cp == NULL ||
 638       !Space::is_aligned(cp) ||
 639       !Universe::heap()->is_permanent((void*)cp)) return false;
 640 
 641   // validate locals
 642 
 643   address locals =  (address) *interpreter_frame_locals_addr();
 644 
 645   if (locals > thread->stack_base() || locals < (address) fp()) return false;
 646 
 647   // We'd have to be pretty unlucky to be mislead at this point
 648 #endif /* CC_INTERP */
 649   return true;
 650 }
 651 
 652 
 653 // Windows have been flushed on entry (but not marked). Capture the pc that
 654 // is the return address to the frame that contains "sp" as its stack pointer.
 655 // This pc resides in the called of the frame corresponding to "sp".
 656 // As a side effect we mark this JavaFrameAnchor as having flushed the windows.
 657 // This side effect lets us mark stacked JavaFrameAnchors (stacked in the
 658 // call_helper) as flushed when we have flushed the windows for the most
 659 // recent (i.e. current) JavaFrameAnchor. This saves useless flushing calls
 660 // and lets us find the pc just once rather than multiple times as it did
 661 // in the bad old _post_Java_state days.
 662 //
 663 void JavaFrameAnchor::capture_last_Java_pc(intptr_t* sp) {
 664   if (last_Java_sp() != NULL && last_Java_pc() == NULL) {
 665     // try and find the sp just younger than _last_Java_sp
 666     intptr_t* _post_Java_sp = frame::next_younger_sp_or_null(last_Java_sp(), sp);
 667     // Really this should never fail otherwise VM call must have non-standard