src/share/vm/runtime/frame.cpp

Thu, 13 Jan 2011 22:15:41 -0800

author
never
date
Thu, 13 Jan 2011 22:15:41 -0800
changeset 2462
8012aa3ccede
parent 2365
54f5dd2aa1d9
child 2497
3582bf76420e
permissions
-rw-r--r--

4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "gc_interface/collectedHeap.inline.hpp"
    27 #include "interpreter/interpreter.hpp"
    28 #include "interpreter/oopMapCache.hpp"
    29 #include "memory/resourceArea.hpp"
    30 #include "memory/universe.inline.hpp"
    31 #include "oops/markOop.hpp"
    32 #include "oops/methodDataOop.hpp"
    33 #include "oops/methodOop.hpp"
    34 #include "oops/oop.inline.hpp"
    35 #include "oops/oop.inline2.hpp"
    36 #include "runtime/frame.inline.hpp"
    37 #include "runtime/handles.inline.hpp"
    38 #include "runtime/javaCalls.hpp"
    39 #include "runtime/monitorChunk.hpp"
    40 #include "runtime/sharedRuntime.hpp"
    41 #include "runtime/signature.hpp"
    42 #include "runtime/stubCodeGenerator.hpp"
    43 #include "runtime/stubRoutines.hpp"
    44 #include "utilities/decoder.hpp"
    46 #ifdef TARGET_ARCH_x86
    47 # include "nativeInst_x86.hpp"
    48 #endif
    49 #ifdef TARGET_ARCH_sparc
    50 # include "nativeInst_sparc.hpp"
    51 #endif
    52 #ifdef TARGET_ARCH_zero
    53 # include "nativeInst_zero.hpp"
    54 #endif
    56 RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {
    57   _thread         = thread;
    58   _update_map     = update_map;
    59   clear();
    60   debug_only(_update_for_id = NULL;)
    61 #ifndef PRODUCT
    62   for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL;
    63 #endif /* PRODUCT */
    64 }
    66 RegisterMap::RegisterMap(const RegisterMap* map) {
    67   assert(map != this, "bad initialization parameter");
    68   assert(map != NULL, "RegisterMap must be present");
    69   _thread                = map->thread();
    70   _update_map            = map->update_map();
    71   _include_argument_oops = map->include_argument_oops();
    72   debug_only(_update_for_id = map->_update_for_id;)
    73   pd_initialize_from(map);
    74   if (update_map()) {
    75     for(int i = 0; i < location_valid_size; i++) {
    76       LocationValidType bits = !update_map() ? 0 : map->_location_valid[i];
    77       _location_valid[i] = bits;
    78       // for whichever bits are set, pull in the corresponding map->_location
    79       int j = i*location_valid_type_size;
    80       while (bits != 0) {
    81         if ((bits & 1) != 0) {
    82           assert(0 <= j && j < reg_count, "range check");
    83           _location[j] = map->_location[j];
    84         }
    85         bits >>= 1;
    86         j += 1;
    87       }
    88     }
    89   }
    90 }
    92 void RegisterMap::clear() {
    93   set_include_argument_oops(true);
    94   if (_update_map) {
    95     for(int i = 0; i < location_valid_size; i++) {
    96       _location_valid[i] = 0;
    97     }
    98     pd_clear();
    99   } else {
   100     pd_initialize();
   101   }
   102 }
   104 #ifndef PRODUCT
   106 void RegisterMap::print_on(outputStream* st) const {
   107   st->print_cr("Register map");
   108   for(int i = 0; i < reg_count; i++) {
   110     VMReg r = VMRegImpl::as_VMReg(i);
   111     intptr_t* src = (intptr_t*) location(r);
   112     if (src != NULL) {
   114       r->print_on(st);
   115       st->print(" [" INTPTR_FORMAT "] = ", src);
   116       if (((uintptr_t)src & (sizeof(*src)-1)) != 0) {
   117         st->print_cr("<misaligned>");
   118       } else {
   119         st->print_cr(INTPTR_FORMAT, *src);
   120       }
   121     }
   122   }
   123 }
   125 void RegisterMap::print() const {
   126   print_on(tty);
   127 }
   129 #endif
   130 // This returns the pc that if you were in the debugger you'd see. Not
   131 // the idealized value in the frame object. This undoes the magic conversion
   132 // that happens for deoptimized frames. In addition it makes the value the
   133 // hardware would want to see in the native frame. The only user (at this point)
   134 // is deoptimization. It likely no one else should ever use it.
   136 address frame::raw_pc() const {
   137   if (is_deoptimized_frame()) {
   138     nmethod* nm = cb()->as_nmethod_or_null();
   139     if (nm->is_method_handle_return(pc()))
   140       return nm->deopt_mh_handler_begin() - pc_return_offset;
   141     else
   142       return nm->deopt_handler_begin() - pc_return_offset;
   143   } else {
   144     return (pc() - pc_return_offset);
   145   }
   146 }
   148 // Change the pc in a frame object. This does not change the actual pc in
   149 // actual frame. To do that use patch_pc.
   150 //
   151 void frame::set_pc(address   newpc ) {
   152 #ifdef ASSERT
   153   if (_cb != NULL && _cb->is_nmethod()) {
   154     assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");
   155   }
   156 #endif // ASSERT
   158   // Unsafe to use the is_deoptimzed tester after changing pc
   159   _deopt_state = unknown;
   160   _pc = newpc;
   161   _cb = CodeCache::find_blob_unsafe(_pc);
   163 }
   165 // type testers
   166 bool frame::is_deoptimized_frame() const {
   167   assert(_deopt_state != unknown, "not answerable");
   168   return _deopt_state == is_deoptimized;
   169 }
   171 bool frame::is_native_frame() const {
   172   return (_cb != NULL &&
   173           _cb->is_nmethod() &&
   174           ((nmethod*)_cb)->is_native_method());
   175 }
   177 bool frame::is_java_frame() const {
   178   if (is_interpreted_frame()) return true;
   179   if (is_compiled_frame())    return true;
   180   return false;
   181 }
   184 bool frame::is_compiled_frame() const {
   185   if (_cb != NULL &&
   186       _cb->is_nmethod() &&
   187       ((nmethod*)_cb)->is_java_method()) {
   188     return true;
   189   }
   190   return false;
   191 }
   194 bool frame::is_runtime_frame() const {
   195   return (_cb != NULL && _cb->is_runtime_stub());
   196 }
   198 bool frame::is_safepoint_blob_frame() const {
   199   return (_cb != NULL && _cb->is_safepoint_stub());
   200 }
   202 // testers
   204 bool frame::is_first_java_frame() const {
   205   RegisterMap map(JavaThread::current(), false); // No update
   206   frame s;
   207   for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map));
   208   return s.is_first_frame();
   209 }
   212 bool frame::entry_frame_is_first() const {
   213   return entry_frame_call_wrapper()->anchor()->last_Java_sp() == NULL;
   214 }
   217 bool frame::should_be_deoptimized() const {
   218   if (_deopt_state == is_deoptimized ||
   219       !is_compiled_frame() ) return false;
   220   assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod");
   221   nmethod* nm = (nmethod *)_cb;
   222   if (TraceDependencies) {
   223     tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
   224     nm->print_value_on(tty);
   225     tty->cr();
   226   }
   228   if( !nm->is_marked_for_deoptimization() )
   229     return false;
   231   // If at the return point, then the frame has already been popped, and
   232   // only the return needs to be executed. Don't deoptimize here.
   233   return !nm->is_at_poll_return(pc());
   234 }
   236 bool frame::can_be_deoptimized() const {
   237   if (!is_compiled_frame()) return false;
   238   nmethod* nm = (nmethod*)_cb;
   240   if( !nm->can_be_deoptimized() )
   241     return false;
   243   return !nm->is_at_poll_return(pc());
   244 }
   246 void frame::deoptimize(JavaThread* thread) {
   247   // Schedule deoptimization of an nmethod activation with this frame.
   248   assert(_cb != NULL && _cb->is_nmethod(), "must be");
   249   nmethod* nm = (nmethod*)_cb;
   251   // This is a fix for register window patching race
   252   if (NeedsDeoptSuspend && Thread::current() != thread) {
   253     assert(SafepointSynchronize::is_at_safepoint(),
   254            "patching other threads for deopt may only occur at a safepoint");
   256     // It is possible especially with DeoptimizeALot/DeoptimizeRandom that
   257     // we could see the frame again and ask for it to be deoptimized since
   258     // it might move for a long time. That is harmless and we just ignore it.
   259     if (id() == thread->must_deopt_id()) {
   260       assert(thread->is_deopt_suspend(), "lost suspension");
   261       return;
   262     }
   264     // We are at a safepoint so the target thread can only be
   265     // in 4 states:
   266     //     blocked - no problem
   267     //     blocked_trans - no problem (i.e. could have woken up from blocked
   268     //                                 during a safepoint).
   269     //     native - register window pc patching race
   270     //     native_trans - momentary state
   271     //
   272     // We could just wait out a thread in native_trans to block.
   273     // Then we'd have all the issues that the safepoint code has as to
   274     // whether to spin or block. It isn't worth it. Just treat it like
   275     // native and be done with it.
   276     //
   277     // Examine the state of the thread at the start of safepoint since
   278     // threads that were in native at the start of the safepoint could
   279     // come to a halt during the safepoint, changing the current value
   280     // of the safepoint_state.
   281     JavaThreadState state = thread->safepoint_state()->orig_thread_state();
   282     if (state == _thread_in_native || state == _thread_in_native_trans) {
   283       // Since we are at a safepoint the target thread will stop itself
   284       // before it can return to java as long as we remain at the safepoint.
   285       // Therefore we can put an additional request for the thread to stop
   286       // no matter what no (like a suspend). This will cause the thread
   287       // to notice it needs to do the deopt on its own once it leaves native.
   288       //
   289       // The only reason we must do this is because on machine with register
   290       // windows we have a race with patching the return address and the
   291       // window coming live as the thread returns to the Java code (but still
   292       // in native mode) and then blocks. It is only this top most frame
   293       // that is at risk. So in truth we could add an additional check to
   294       // see if this frame is one that is at risk.
   295       RegisterMap map(thread, false);
   296       frame at_risk =  thread->last_frame().sender(&map);
   297       if (id() == at_risk.id()) {
   298         thread->set_must_deopt_id(id());
   299         thread->set_deopt_suspend();
   300         return;
   301       }
   302     }
   303   } // NeedsDeoptSuspend
   306   // If the call site is a MethodHandle call site use the MH deopt
   307   // handler.
   308   address deopt = nm->is_method_handle_return(pc()) ?
   309     nm->deopt_mh_handler_begin() :
   310     nm->deopt_handler_begin();
   312   // Save the original pc before we patch in the new one
   313   nm->set_original_pc(this, pc());
   314   patch_pc(thread, deopt);
   316 #ifdef ASSERT
   317   {
   318     RegisterMap map(thread, false);
   319     frame check = thread->last_frame();
   320     while (id() != check.id()) {
   321       check = check.sender(&map);
   322     }
   323     assert(check.is_deoptimized_frame(), "missed deopt");
   324   }
   325 #endif // ASSERT
   326 }
   328 frame frame::java_sender() const {
   329   RegisterMap map(JavaThread::current(), false);
   330   frame s;
   331   for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ;
   332   guarantee(s.is_java_frame(), "tried to get caller of first java frame");
   333   return s;
   334 }
   336 frame frame::real_sender(RegisterMap* map) const {
   337   frame result = sender(map);
   338   while (result.is_runtime_frame()) {
   339     result = result.sender(map);
   340   }
   341   return result;
   342 }
   344 // Note: called by profiler - NOT for current thread
   345 frame frame::profile_find_Java_sender_frame(JavaThread *thread) {
   346 // If we don't recognize this frame, walk back up the stack until we do
   347   RegisterMap map(thread, false);
   348   frame first_java_frame = frame();
   350   // Find the first Java frame on the stack starting with input frame
   351   if (is_java_frame()) {
   352     // top frame is compiled frame or deoptimized frame
   353     first_java_frame = *this;
   354   } else if (safe_for_sender(thread)) {
   355     for (frame sender_frame = sender(&map);
   356       sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame();
   357       sender_frame = sender_frame.sender(&map)) {
   358       if (sender_frame.is_java_frame()) {
   359         first_java_frame = sender_frame;
   360         break;
   361       }
   362     }
   363   }
   364   return first_java_frame;
   365 }
   367 // Interpreter frames
   370 void frame::interpreter_frame_set_locals(intptr_t* locs)  {
   371   assert(is_interpreted_frame(), "Not an interpreted frame");
   372   *interpreter_frame_locals_addr() = locs;
   373 }
   375 methodOop frame::interpreter_frame_method() const {
   376   assert(is_interpreted_frame(), "interpreted frame expected");
   377   methodOop m = *interpreter_frame_method_addr();
   378   assert(m->is_perm(), "bad methodOop in interpreter frame");
   379   assert(m->is_method(), "not a methodOop");
   380   return m;
   381 }
   383 void frame::interpreter_frame_set_method(methodOop method) {
   384   assert(is_interpreted_frame(), "interpreted frame expected");
   385   *interpreter_frame_method_addr() = method;
   386 }
   388 void frame::interpreter_frame_set_bcx(intptr_t bcx) {
   389   assert(is_interpreted_frame(), "Not an interpreted frame");
   390   if (ProfileInterpreter) {
   391     bool formerly_bci = is_bci(interpreter_frame_bcx());
   392     bool is_now_bci = is_bci(bcx);
   393     *interpreter_frame_bcx_addr() = bcx;
   395     intptr_t mdx = interpreter_frame_mdx();
   397     if (mdx != 0) {
   398       if (formerly_bci) {
   399         if (!is_now_bci) {
   400           // The bcx was just converted from bci to bcp.
   401           // Convert the mdx in parallel.
   402           methodDataOop mdo = interpreter_frame_method()->method_data();
   403           assert(mdo != NULL, "");
   404           int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
   405           address mdp = mdo->di_to_dp(mdi);
   406           interpreter_frame_set_mdx((intptr_t)mdp);
   407         }
   408       } else {
   409         if (is_now_bci) {
   410           // The bcx was just converted from bcp to bci.
   411           // Convert the mdx in parallel.
   412           methodDataOop mdo = interpreter_frame_method()->method_data();
   413           assert(mdo != NULL, "");
   414           int mdi = mdo->dp_to_di((address)mdx);
   415           interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
   416         }
   417       }
   418     }
   419   } else {
   420     *interpreter_frame_bcx_addr() = bcx;
   421   }
   422 }
   424 jint frame::interpreter_frame_bci() const {
   425   assert(is_interpreted_frame(), "interpreted frame expected");
   426   intptr_t bcx = interpreter_frame_bcx();
   427   return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx);
   428 }
   430 void frame::interpreter_frame_set_bci(jint bci) {
   431   assert(is_interpreted_frame(), "interpreted frame expected");
   432   assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC");
   433   interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci));
   434 }
   436 address frame::interpreter_frame_bcp() const {
   437   assert(is_interpreted_frame(), "interpreted frame expected");
   438   intptr_t bcx = interpreter_frame_bcx();
   439   return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx;
   440 }
   442 void frame::interpreter_frame_set_bcp(address bcp) {
   443   assert(is_interpreted_frame(), "interpreted frame expected");
   444   assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC");
   445   interpreter_frame_set_bcx((intptr_t)bcp);
   446 }
   448 void frame::interpreter_frame_set_mdx(intptr_t mdx) {
   449   assert(is_interpreted_frame(), "Not an interpreted frame");
   450   assert(ProfileInterpreter, "must be profiling interpreter");
   451   *interpreter_frame_mdx_addr() = mdx;
   452 }
   454 address frame::interpreter_frame_mdp() const {
   455   assert(ProfileInterpreter, "must be profiling interpreter");
   456   assert(is_interpreted_frame(), "interpreted frame expected");
   457   intptr_t bcx = interpreter_frame_bcx();
   458   intptr_t mdx = interpreter_frame_mdx();
   460   assert(!is_bci(bcx), "should not access mdp during GC");
   461   return (address)mdx;
   462 }
   464 void frame::interpreter_frame_set_mdp(address mdp) {
   465   assert(is_interpreted_frame(), "interpreted frame expected");
   466   if (mdp == NULL) {
   467     // Always allow the mdp to be cleared.
   468     interpreter_frame_set_mdx((intptr_t)mdp);
   469   }
   470   intptr_t bcx = interpreter_frame_bcx();
   471   assert(!is_bci(bcx), "should not set mdp during GC");
   472   interpreter_frame_set_mdx((intptr_t)mdp);
   473 }
   475 BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const {
   476   assert(is_interpreted_frame(), "Not an interpreted frame");
   477 #ifdef ASSERT
   478   interpreter_frame_verify_monitor(current);
   479 #endif
   480   BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size());
   481   return next;
   482 }
   484 BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const {
   485   assert(is_interpreted_frame(), "Not an interpreted frame");
   486 #ifdef ASSERT
   487 //   // This verification needs to be checked before being enabled
   488 //   interpreter_frame_verify_monitor(current);
   489 #endif
   490   BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size());
   491   return previous;
   492 }
   494 // Interpreter locals and expression stack locations.
   496 intptr_t* frame::interpreter_frame_local_at(int index) const {
   497   const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
   498   return &((*interpreter_frame_locals_addr())[n]);
   499 }
   501 intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
   502   const int i = offset * interpreter_frame_expression_stack_direction();
   503   const int n = i * Interpreter::stackElementWords;
   504   return &(interpreter_frame_expression_stack()[n]);
   505 }
   507 jint frame::interpreter_frame_expression_stack_size() const {
   508   // Number of elements on the interpreter expression stack
   509   // Callers should span by stackElementWords
   510   int element_size = Interpreter::stackElementWords;
   511   if (frame::interpreter_frame_expression_stack_direction() < 0) {
   512     return (interpreter_frame_expression_stack() -
   513             interpreter_frame_tos_address() + 1)/element_size;
   514   } else {
   515     return (interpreter_frame_tos_address() -
   516             interpreter_frame_expression_stack() + 1)/element_size;
   517   }
   518 }
   521 // (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp)
   523 const char* frame::print_name() const {
   524   if (is_native_frame())      return "Native";
   525   if (is_interpreted_frame()) return "Interpreted";
   526   if (is_compiled_frame()) {
   527     if (is_deoptimized_frame()) return "Deoptimized";
   528     return "Compiled";
   529   }
   530   if (sp() == NULL)            return "Empty";
   531   return "C";
   532 }
   534 void frame::print_value_on(outputStream* st, JavaThread *thread) const {
   535   NOT_PRODUCT(address begin = pc()-40;)
   536   NOT_PRODUCT(address end   = NULL;)
   538   st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp());
   539   if (sp() != NULL)
   540     st->print(", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), pc());
   542   if (StubRoutines::contains(pc())) {
   543     st->print_cr(")");
   544     st->print("(");
   545     StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
   546     st->print("~Stub::%s", desc->name());
   547     NOT_PRODUCT(begin = desc->begin(); end = desc->end();)
   548   } else if (Interpreter::contains(pc())) {
   549     st->print_cr(")");
   550     st->print("(");
   551     InterpreterCodelet* desc = Interpreter::codelet_containing(pc());
   552     if (desc != NULL) {
   553       st->print("~");
   554       desc->print();
   555       NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();)
   556     } else {
   557       st->print("~interpreter");
   558     }
   559   }
   560   st->print_cr(")");
   562   if (_cb != NULL) {
   563     st->print("     ");
   564     _cb->print_value_on(st);
   565     st->cr();
   566 #ifndef PRODUCT
   567     if (end == NULL) {
   568       begin = _cb->code_begin();
   569       end   = _cb->code_end();
   570     }
   571 #endif
   572   }
   573   NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);)
   574 }
   577 void frame::print_on(outputStream* st) const {
   578   print_value_on(st,NULL);
   579   if (is_interpreted_frame()) {
   580     interpreter_frame_print_on(st);
   581   }
   582 }
   585 void frame::interpreter_frame_print_on(outputStream* st) const {
   586 #ifndef PRODUCT
   587   assert(is_interpreted_frame(), "Not an interpreted frame");
   588   jint i;
   589   for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
   590     intptr_t x = *interpreter_frame_local_at(i);
   591     st->print(" - local  [" INTPTR_FORMAT "]", x);
   592     st->fill_to(23);
   593     st->print_cr("; #%d", i);
   594   }
   595   for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {
   596     intptr_t x = *interpreter_frame_expression_stack_at(i);
   597     st->print(" - stack  [" INTPTR_FORMAT "]", x);
   598     st->fill_to(23);
   599     st->print_cr("; #%d", i);
   600   }
   601   // locks for synchronization
   602   for (BasicObjectLock* current = interpreter_frame_monitor_end();
   603        current < interpreter_frame_monitor_begin();
   604        current = next_monitor_in_interpreter_frame(current)) {
   605     st->print(" - obj    [");
   606     current->obj()->print_value_on(st);
   607     st->print_cr("]");
   608     st->print(" - lock   [");
   609     current->lock()->print_on(st);
   610     st->print_cr("]");
   611   }
   612   // monitor
   613   st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin());
   614   // bcp
   615   st->print(" - bcp    [" INTPTR_FORMAT "]", interpreter_frame_bcp());
   616   st->fill_to(23);
   617   st->print_cr("; @%d", interpreter_frame_bci());
   618   // locals
   619   st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0));
   620   // method
   621   st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method());
   622   st->fill_to(23);
   623   st->print("; ");
   624   interpreter_frame_method()->print_name(st);
   625   st->cr();
   626 #endif
   627 }
   629 // Return whether the frame is in the VM or os indicating a Hotspot problem.
   630 // Otherwise, it's likely a bug in the native library that the Java code calls,
   631 // hopefully indicating where to submit bugs.
   632 static void print_C_frame(outputStream* st, char* buf, int buflen, address pc) {
   633   // C/C++ frame
   634   bool in_vm = os::address_is_in_vm(pc);
   635   st->print(in_vm ? "V" : "C");
   637   int offset;
   638   bool found;
   640   // libname
   641   found = os::dll_address_to_library_name(pc, buf, buflen, &offset);
   642   if (found) {
   643     // skip directory names
   644     const char *p1, *p2;
   645     p1 = buf;
   646     int len = (int)strlen(os::file_separator());
   647     while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
   648     st->print("  [%s+0x%x]", p1, offset);
   649   } else {
   650     st->print("  " PTR_FORMAT, pc);
   651   }
   653   // function name - os::dll_address_to_function_name() may return confusing
   654   // names if pc is within jvm.dll or libjvm.so, because JVM only has
   655   // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this
   656   // only for native libraries.
   657   if (!in_vm || Decoder::can_decode_C_frame_in_vm()) {
   658     found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
   660     if (found) {
   661       st->print("  %s+0x%x", buf, offset);
   662     }
   663   }
   664 }
   666 // frame::print_on_error() is called by fatal error handler. Notice that we may
   667 // crash inside this function if stack frame is corrupted. The fatal error
   668 // handler can catch and handle the crash. Here we assume the frame is valid.
   669 //
   670 // First letter indicates type of the frame:
   671 //    J: Java frame (compiled)
   672 //    j: Java frame (interpreted)
   673 //    V: VM frame (C/C++)
   674 //    v: Other frames running VM generated code (e.g. stubs, adapters, etc.)
   675 //    C: C/C++ frame
   676 //
   677 // We don't need detailed frame type as that in frame::print_name(). "C"
   678 // suggests the problem is in user lib; everything else is likely a VM bug.
   680 void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const {
   681   if (_cb != NULL) {
   682     if (Interpreter::contains(pc())) {
   683       methodOop m = this->interpreter_frame_method();
   684       if (m != NULL) {
   685         m->name_and_sig_as_C_string(buf, buflen);
   686         st->print("j  %s", buf);
   687         st->print("+%d", this->interpreter_frame_bci());
   688       } else {
   689         st->print("j  " PTR_FORMAT, pc());
   690       }
   691     } else if (StubRoutines::contains(pc())) {
   692       StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
   693       if (desc != NULL) {
   694         st->print("v  ~StubRoutines::%s", desc->name());
   695       } else {
   696         st->print("v  ~StubRoutines::" PTR_FORMAT, pc());
   697       }
   698     } else if (_cb->is_buffer_blob()) {
   699       st->print("v  ~BufferBlob::%s", ((BufferBlob *)_cb)->name());
   700     } else if (_cb->is_nmethod()) {
   701       methodOop m = ((nmethod *)_cb)->method();
   702       if (m != NULL) {
   703         m->name_and_sig_as_C_string(buf, buflen);
   704         st->print("J  %s", buf);
   705       } else {
   706         st->print("J  " PTR_FORMAT, pc());
   707       }
   708     } else if (_cb->is_runtime_stub()) {
   709       st->print("v  ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name());
   710     } else if (_cb->is_deoptimization_stub()) {
   711       st->print("v  ~DeoptimizationBlob");
   712     } else if (_cb->is_exception_stub()) {
   713       st->print("v  ~ExceptionBlob");
   714     } else if (_cb->is_safepoint_stub()) {
   715       st->print("v  ~SafepointBlob");
   716     } else {
   717       st->print("v  blob " PTR_FORMAT, pc());
   718     }
   719   } else {
   720     print_C_frame(st, buf, buflen, pc());
   721   }
   722 }
   725 /*
   726   The interpreter_frame_expression_stack_at method in the case of SPARC needs the
   727   max_stack value of the method in order to compute the expression stack address.
   728   It uses the methodOop in order to get the max_stack value but during GC this
   729   methodOop value saved on the frame is changed by reverse_and_push and hence cannot
   730   be used. So we save the max_stack value in the FrameClosure object and pass it
   731   down to the interpreter_frame_expression_stack_at method
   732 */
   733 class InterpreterFrameClosure : public OffsetClosure {
   734  private:
   735   frame* _fr;
   736   OopClosure* _f;
   737   int    _max_locals;
   738   int    _max_stack;
   740  public:
   741   InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
   742                           OopClosure* f) {
   743     _fr         = fr;
   744     _max_locals = max_locals;
   745     _max_stack  = max_stack;
   746     _f          = f;
   747   }
   749   void offset_do(int offset) {
   750     oop* addr;
   751     if (offset < _max_locals) {
   752       addr = (oop*) _fr->interpreter_frame_local_at(offset);
   753       assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
   754       _f->do_oop(addr);
   755     } else {
   756       addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
   757       // In case of exceptions, the expression stack is invalid and the esp will be reset to express
   758       // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
   759       bool in_stack;
   760       if (frame::interpreter_frame_expression_stack_direction() > 0) {
   761         in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
   762       } else {
   763         in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
   764       }
   765       if (in_stack) {
   766         _f->do_oop(addr);
   767       }
   768     }
   769   }
   771   int max_locals()  { return _max_locals; }
   772   frame* fr()       { return _fr; }
   773 };
   776 class InterpretedArgumentOopFinder: public SignatureInfo {
   777  private:
   778   OopClosure* _f;        // Closure to invoke
   779   int    _offset;        // TOS-relative offset, decremented with each argument
   780   bool   _has_receiver;  // true if the callee has a receiver
   781   frame* _fr;
   783   void set(int size, BasicType type) {
   784     _offset -= size;
   785     if (type == T_OBJECT || type == T_ARRAY) oop_offset_do();
   786   }
   788   void oop_offset_do() {
   789     oop* addr;
   790     addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
   791     _f->do_oop(addr);
   792   }
   794  public:
   795   InterpretedArgumentOopFinder(symbolHandle signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
   796     // compute size of arguments
   797     int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
   798     assert(!fr->is_interpreted_frame() ||
   799            args_size <= fr->interpreter_frame_expression_stack_size(),
   800             "args cannot be on stack anymore");
   801     // initialize InterpretedArgumentOopFinder
   802     _f         = f;
   803     _fr        = fr;
   804     _offset    = args_size;
   805   }
   807   void oops_do() {
   808     if (_has_receiver) {
   809       --_offset;
   810       oop_offset_do();
   811     }
   812     iterate_parameters();
   813   }
   814 };
   817 // Entry frame has following form (n arguments)
   818 //         +-----------+
   819 //   sp -> |  last arg |
   820 //         +-----------+
   821 //         :    :::    :
   822 //         +-----------+
   823 // (sp+n)->|  first arg|
   824 //         +-----------+
   828 // visits and GC's all the arguments in entry frame
   829 class EntryFrameOopFinder: public SignatureInfo {
   830  private:
   831   bool   _is_static;
   832   int    _offset;
   833   frame* _fr;
   834   OopClosure* _f;
   836   void set(int size, BasicType type) {
   837     assert (_offset >= 0, "illegal offset");
   838     if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset);
   839     _offset -= size;
   840   }
   842   void oop_at_offset_do(int offset) {
   843     assert (offset >= 0, "illegal offset");
   844     oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
   845     _f->do_oop(addr);
   846   }
   848  public:
   849    EntryFrameOopFinder(frame* frame, symbolHandle signature, bool is_static) : SignatureInfo(signature) {
   850      _f = NULL; // will be set later
   851      _fr = frame;
   852      _is_static = is_static;
   853      _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
   854    }
   856   void arguments_do(OopClosure* f) {
   857     _f = f;
   858     if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver
   859     iterate_parameters();
   860   }
   862 };
   864 oop* frame::interpreter_callee_receiver_addr(symbolHandle signature) {
   865   ArgumentSizeComputer asc(signature);
   866   int size = asc.size();
   867   return (oop *)interpreter_frame_tos_at(size);
   868 }
   871 void frame::oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) {
   872   assert(is_interpreted_frame(), "Not an interpreted frame");
   873   assert(map != NULL, "map must be set");
   874   Thread *thread = Thread::current();
   875   methodHandle m (thread, interpreter_frame_method());
   876   jint      bci = interpreter_frame_bci();
   878   assert(Universe::heap()->is_in(m()), "must be valid oop");
   879   assert(m->is_method(), "checking frame value");
   880   assert((m->is_native() && bci == 0)  || (!m->is_native() && bci >= 0 && bci < m->code_size()), "invalid bci value");
   882   // Handle the monitor elements in the activation
   883   for (
   884     BasicObjectLock* current = interpreter_frame_monitor_end();
   885     current < interpreter_frame_monitor_begin();
   886     current = next_monitor_in_interpreter_frame(current)
   887   ) {
   888 #ifdef ASSERT
   889     interpreter_frame_verify_monitor(current);
   890 #endif
   891     current->oops_do(f);
   892   }
   894   // process fixed part
   895   f->do_oop((oop*)interpreter_frame_method_addr());
   896   f->do_oop((oop*)interpreter_frame_cache_addr());
   898   // Hmm what about the mdp?
   899 #ifdef CC_INTERP
   900   // Interpreter frame in the midst of a call have a methodOop within the
   901   // object.
   902   interpreterState istate = get_interpreterState();
   903   if (istate->msg() == BytecodeInterpreter::call_method) {
   904     f->do_oop((oop*)&istate->_result._to_call._callee);
   905   }
   907 #endif /* CC_INTERP */
   909 #if !defined(PPC) || defined(ZERO)
   910   if (m->is_native()) {
   911 #ifdef CC_INTERP
   912     f->do_oop((oop*)&istate->_oop_temp);
   913 #else
   914     f->do_oop((oop*)( fp() + interpreter_frame_oop_temp_offset ));
   915 #endif /* CC_INTERP */
   916   }
   917 #else // PPC
   918   if (m->is_native() && m->is_static()) {
   919     f->do_oop(interpreter_frame_mirror_addr());
   920   }
   921 #endif // PPC
   923   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
   925   symbolHandle signature;
   926   bool has_receiver = false;
   928   // Process a callee's arguments if we are at a call site
   929   // (i.e., if we are at an invoke bytecode)
   930   // This is used sometimes for calling into the VM, not for another
   931   // interpreted or compiled frame.
   932   if (!m->is_native()) {
   933     Bytecode_invoke call = Bytecode_invoke_check(m, bci);
   934     if (call.is_valid()) {
   935       signature = symbolHandle(thread, call.signature());
   936       has_receiver = call.has_receiver();
   937       if (map->include_argument_oops() &&
   938           interpreter_frame_expression_stack_size() > 0) {
   939         ResourceMark rm(thread);  // is this right ???
   940         // we are at a call site & the expression stack is not empty
   941         // => process callee's arguments
   942         //
   943         // Note: The expression stack can be empty if an exception
   944         //       occurred during method resolution/execution. In all
   945         //       cases we empty the expression stack completely be-
   946         //       fore handling the exception (the exception handling
   947         //       code in the interpreter calls a blocking runtime
   948         //       routine which can cause this code to be executed).
   949         //       (was bug gri 7/27/98)
   950         oops_interpreted_arguments_do(signature, has_receiver, f);
   951       }
   952     }
   953   }
   955   InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
   957   // process locals & expression stack
   958   InterpreterOopMap mask;
   959   if (query_oop_map_cache) {
   960     m->mask_for(bci, &mask);
   961   } else {
   962     OopMapCache::compute_one_oop_map(m, bci, &mask);
   963   }
   964   mask.iterate_oop(&blk);
   965 }
   968 void frame::oops_interpreted_arguments_do(symbolHandle signature, bool has_receiver, OopClosure* f) {
   969   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
   970   finder.oops_do();
   971 }
   973 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
   974   assert(_cb != NULL, "sanity check");
   975   if (_cb->oop_maps() != NULL) {
   976     OopMapSet::oops_do(this, reg_map, f);
   978     // Preserve potential arguments for a callee. We handle this by dispatching
   979     // on the codeblob. For c2i, we do
   980     if (reg_map->include_argument_oops()) {
   981       _cb->preserve_callee_argument_oops(*this, reg_map, f);
   982     }
   983   }
   984   // In cases where perm gen is collected, GC will want to mark
   985   // oops referenced from nmethods active on thread stacks so as to
   986   // prevent them from being collected. However, this visit should be
   987   // restricted to certain phases of the collection only. The
   988   // closure decides how it wants nmethods to be traced.
   989   if (cf != NULL)
   990     cf->do_code_blob(_cb);
   991 }
   993 class CompiledArgumentOopFinder: public SignatureInfo {
   994  protected:
   995   OopClosure*     _f;
   996   int             _offset;        // the current offset, incremented with each argument
   997   bool            _has_receiver;  // true if the callee has a receiver
   998   frame           _fr;
   999   RegisterMap*    _reg_map;
  1000   int             _arg_size;
  1001   VMRegPair*      _regs;        // VMReg list of arguments
  1003   void set(int size, BasicType type) {
  1004     if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset();
  1005     _offset += size;
  1008   virtual void handle_oop_offset() {
  1009     // Extract low order register number from register array.
  1010     // In LP64-land, the high-order bits are valid but unhelpful.
  1011     VMReg reg = _regs[_offset].first();
  1012     oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
  1013     _f->do_oop(loc);
  1016  public:
  1017   CompiledArgumentOopFinder(symbolHandle signature, bool has_receiver, OopClosure* f, frame fr,  const RegisterMap* reg_map)
  1018     : SignatureInfo(signature) {
  1020     // initialize CompiledArgumentOopFinder
  1021     _f         = f;
  1022     _offset    = 0;
  1023     _has_receiver = has_receiver;
  1024     _fr        = fr;
  1025     _reg_map   = (RegisterMap*)reg_map;
  1026     _arg_size  = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
  1028     int arg_size;
  1029     _regs = SharedRuntime::find_callee_arguments(signature(), has_receiver, &arg_size);
  1030     assert(arg_size == _arg_size, "wrong arg size");
  1033   void oops_do() {
  1034     if (_has_receiver) {
  1035       handle_oop_offset();
  1036       _offset++;
  1038     iterate_parameters();
  1040 };
  1042 void frame::oops_compiled_arguments_do(symbolHandle signature, bool has_receiver, const RegisterMap* reg_map, OopClosure* f) {
  1043   ResourceMark rm;
  1044   CompiledArgumentOopFinder finder(signature, has_receiver, f, *this, reg_map);
  1045   finder.oops_do();
  1049 // Get receiver out of callers frame, i.e. find parameter 0 in callers
  1050 // frame.  Consult ADLC for where parameter 0 is to be found.  Then
  1051 // check local reg_map for it being a callee-save register or argument
  1052 // register, both of which are saved in the local frame.  If not found
  1053 // there, it must be an in-stack argument of the caller.
  1054 // Note: caller.sp() points to callee-arguments
  1055 oop frame::retrieve_receiver(RegisterMap* reg_map) {
  1056   frame caller = *this;
  1058   // First consult the ADLC on where it puts parameter 0 for this signature.
  1059   VMReg reg = SharedRuntime::name_for_receiver();
  1060   oop r = *caller.oopmapreg_to_location(reg, reg_map);
  1061   assert( Universe::heap()->is_in_or_null(r), "bad receiver" );
  1062   return r;
  1066 oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const {
  1067   if(reg->is_reg()) {
  1068     // If it is passed in a register, it got spilled in the stub frame.
  1069     return (oop *)reg_map->location(reg);
  1070   } else {
  1071     int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size;
  1072     return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes);
  1076 BasicLock* frame::get_native_monitor() {
  1077   nmethod* nm = (nmethod*)_cb;
  1078   assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
  1079          "Should not call this unless it's a native nmethod");
  1080   int byte_offset = in_bytes(nm->native_basic_lock_sp_offset());
  1081   assert(byte_offset >= 0, "should not see invalid offset");
  1082   return (BasicLock*) &sp()[byte_offset / wordSize];
  1085 oop frame::get_native_receiver() {
  1086   nmethod* nm = (nmethod*)_cb;
  1087   assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
  1088          "Should not call this unless it's a native nmethod");
  1089   int byte_offset = in_bytes(nm->native_receiver_sp_offset());
  1090   assert(byte_offset >= 0, "should not see invalid offset");
  1091   oop owner = ((oop*) sp())[byte_offset / wordSize];
  1092   assert( Universe::heap()->is_in(owner), "bad receiver" );
  1093   return owner;
  1096 void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) {
  1097   assert(map != NULL, "map must be set");
  1098   if (map->include_argument_oops()) {
  1099     // must collect argument oops, as nobody else is doing it
  1100     Thread *thread = Thread::current();
  1101     methodHandle m (thread, entry_frame_call_wrapper()->callee_method());
  1102     symbolHandle signature (thread, m->signature());
  1103     EntryFrameOopFinder finder(this, signature, m->is_static());
  1104     finder.arguments_do(f);
  1106   // Traverse the Handle Block saved in the entry frame
  1107   entry_frame_call_wrapper()->oops_do(f);
  1111 void frame::oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) {
  1112 #ifndef PRODUCT
  1113   // simulate GC crash here to dump java thread in error report
  1114   if (CrashGCForDumpingJavaThread) {
  1115     char *t = NULL;
  1116     *t = 'c';
  1118 #endif
  1119   if (is_interpreted_frame()) {
  1120     oops_interpreted_do(f, map, use_interpreter_oop_map_cache);
  1121   } else if (is_entry_frame()) {
  1122     oops_entry_do(f, map);
  1123   } else if (CodeCache::contains(pc())) {
  1124     oops_code_blob_do(f, cf, map);
  1125 #ifdef SHARK
  1126   } else if (is_fake_stub_frame()) {
  1127     // nothing to do
  1128 #endif // SHARK
  1129   } else {
  1130     ShouldNotReachHere();
  1134 void frame::nmethods_do(CodeBlobClosure* cf) {
  1135   if (_cb != NULL && _cb->is_nmethod()) {
  1136     cf->do_code_blob(_cb);
  1141 void frame::gc_prologue() {
  1142   if (is_interpreted_frame()) {
  1143     // set bcx to bci to become methodOop position independent during GC
  1144     interpreter_frame_set_bcx(interpreter_frame_bci());
  1149 void frame::gc_epilogue() {
  1150   if (is_interpreted_frame()) {
  1151     // set bcx back to bcp for interpreter
  1152     interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp());
  1154   // call processor specific epilog function
  1155   pd_gc_epilog();
  1159 # ifdef ENABLE_ZAP_DEAD_LOCALS
  1161 void frame::CheckValueClosure::do_oop(oop* p) {
  1162   if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) {
  1163     warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());
  1166 frame::CheckValueClosure frame::_check_value;
  1169 void frame::CheckOopClosure::do_oop(oop* p) {
  1170   if (*p != NULL && !(*p)->is_oop()) {
  1171     warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());
  1174 frame::CheckOopClosure frame::_check_oop;
  1176 void frame::check_derived_oop(oop* base, oop* derived) {
  1177   _check_oop.do_oop(base);
  1181 void frame::ZapDeadClosure::do_oop(oop* p) {
  1182   if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p);
  1183   // Need cast because on _LP64 the conversion to oop is ambiguous.  Constant
  1184   // can be either long or int.
  1185   *p = (oop)(int)0xbabebabe;
  1187 frame::ZapDeadClosure frame::_zap_dead;
  1189 void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) {
  1190   assert(thread == Thread::current(), "need to synchronize to do this to another thread");
  1191   // Tracing - part 1
  1192   if (TraceZapDeadLocals) {
  1193     ResourceMark rm(thread);
  1194     tty->print_cr("--------------------------------------------------------------------------------");
  1195     tty->print("Zapping dead locals in ");
  1196     print_on(tty);
  1197     tty->cr();
  1199   // Zapping
  1200        if (is_entry_frame      ()) zap_dead_entry_locals      (thread, map);
  1201   else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map);
  1202   else if (is_compiled_frame()) zap_dead_compiled_locals   (thread, map);
  1204   else
  1205     // could be is_runtime_frame
  1206     // so remove error: ShouldNotReachHere();
  1208   // Tracing - part 2
  1209   if (TraceZapDeadLocals) {
  1210     tty->cr();
  1215 void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) {
  1216   // get current interpreter 'pc'
  1217   assert(is_interpreted_frame(), "Not an interpreted frame");
  1218   methodOop m   = interpreter_frame_method();
  1219   int       bci = interpreter_frame_bci();
  1221   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
  1223   // process dynamic part
  1224   InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(),
  1225                                     &_check_value);
  1226   InterpreterFrameClosure   oop_blk(this, max_locals, m->max_stack(),
  1227                                     &_check_oop  );
  1228   InterpreterFrameClosure  dead_blk(this, max_locals, m->max_stack(),
  1229                                     &_zap_dead   );
  1231   // get frame map
  1232   InterpreterOopMap mask;
  1233   m->mask_for(bci, &mask);
  1234   mask.iterate_all( &oop_blk, &value_blk, &dead_blk);
  1238 void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) {
  1240   ResourceMark rm(thread);
  1241   assert(_cb != NULL, "sanity check");
  1242   if (_cb->oop_maps() != NULL) {
  1243     OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value);
  1248 void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) {
  1249   if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented");
  1253 void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) {
  1254   if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented");
  1257 # endif // ENABLE_ZAP_DEAD_LOCALS
  1259 void frame::verify(const RegisterMap* map) {
  1260   // for now make sure receiver type is correct
  1261   if (is_interpreted_frame()) {
  1262     methodOop method = interpreter_frame_method();
  1263     guarantee(method->is_method(), "method is wrong in frame::verify");
  1264     if (!method->is_static()) {
  1265       // fetch the receiver
  1266       oop* p = (oop*) interpreter_frame_local_at(0);
  1267       // make sure we have the right receiver type
  1270   COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");)
  1271   oops_do_internal(&VerifyOopClosure::verify_oop, NULL, (RegisterMap*)map, false);
  1275 #ifdef ASSERT
  1276 bool frame::verify_return_pc(address x) {
  1277   if (StubRoutines::returns_to_call_stub(x)) {
  1278     return true;
  1280   if (CodeCache::contains(x)) {
  1281     return true;
  1283   if (Interpreter::contains(x)) {
  1284     return true;
  1286   return false;
  1288 #endif
  1291 #ifdef ASSERT
  1292 void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const {
  1293   assert(is_interpreted_frame(), "Not an interpreted frame");
  1294   // verify that the value is in the right part of the frame
  1295   address low_mark  = (address) interpreter_frame_monitor_end();
  1296   address high_mark = (address) interpreter_frame_monitor_begin();
  1297   address current   = (address) value;
  1299   const int monitor_size = frame::interpreter_frame_monitor_size();
  1300   guarantee((high_mark - current) % monitor_size  ==  0         , "Misaligned top of BasicObjectLock*");
  1301   guarantee( high_mark > current                                , "Current BasicObjectLock* higher than high_mark");
  1303   guarantee((current - low_mark) % monitor_size  ==  0         , "Misaligned bottom of BasicObjectLock*");
  1304   guarantee( current >= low_mark                               , "Current BasicObjectLock* below than low_mark");
  1306 #endif
  1309 //-----------------------------------------------------------------------------------
  1310 // StackFrameStream implementation
  1312 StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) {
  1313   assert(thread->has_last_Java_frame(), "sanity check");
  1314   _fr = thread->last_frame();
  1315   _is_done = false;

mercurial