src/share/vm/runtime/frame.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 1
2d8a650513c2
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2014, 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 /*
    26  * This file has been modified by Loongson Technology in 2015. These
    27  * modifications are Copyright (c) 2015 Loongson Technology, and are made
    28  * available on the same license terms set forth above.
    29  */
    31 #include "precompiled.hpp"
    32 #include "compiler/abstractCompiler.hpp"
    33 #include "compiler/disassembler.hpp"
    34 #include "gc_interface/collectedHeap.inline.hpp"
    35 #include "interpreter/interpreter.hpp"
    36 #include "interpreter/oopMapCache.hpp"
    37 #include "memory/resourceArea.hpp"
    38 #include "memory/universe.inline.hpp"
    39 #include "oops/markOop.hpp"
    40 #include "oops/methodData.hpp"
    41 #include "oops/method.hpp"
    42 #include "oops/oop.inline.hpp"
    43 #include "oops/oop.inline2.hpp"
    44 #include "prims/methodHandles.hpp"
    45 #include "runtime/frame.inline.hpp"
    46 #include "runtime/handles.inline.hpp"
    47 #include "runtime/javaCalls.hpp"
    48 #include "runtime/monitorChunk.hpp"
    49 #include "runtime/sharedRuntime.hpp"
    50 #include "runtime/signature.hpp"
    51 #include "runtime/stubCodeGenerator.hpp"
    52 #include "runtime/stubRoutines.hpp"
    53 #include "utilities/decoder.hpp"
    55 #ifdef TARGET_ARCH_x86
    56 # include "nativeInst_x86.hpp"
    57 #endif
    58 #ifdef TARGET_ARCH_sparc
    59 # include "nativeInst_sparc.hpp"
    60 #endif
    61 #ifdef TARGET_ARCH_zero
    62 # include "nativeInst_zero.hpp"
    63 #endif
    64 #ifdef TARGET_ARCH_arm
    65 # include "nativeInst_arm.hpp"
    66 #endif
    67 #ifdef TARGET_ARCH_ppc
    68 # include "nativeInst_ppc.hpp"
    69 #endif
    70 #ifdef TARGET_ARCH_mips
    71 # include "nativeInst_mips.hpp"
    72 #endif
    75 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    77 RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {
    78   _thread         = thread;
    79   _update_map     = update_map;
    80   clear();
    81   debug_only(_update_for_id = NULL;)
    82 #ifndef PRODUCT
    83   for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL;
    84 #endif /* PRODUCT */
    85 }
    87 RegisterMap::RegisterMap(const RegisterMap* map) {
    88   assert(map != this, "bad initialization parameter");
    89   assert(map != NULL, "RegisterMap must be present");
    90   _thread                = map->thread();
    91   _update_map            = map->update_map();
    92   _include_argument_oops = map->include_argument_oops();
    93   debug_only(_update_for_id = map->_update_for_id;)
    94   pd_initialize_from(map);
    95   if (update_map()) {
    96     for(int i = 0; i < location_valid_size; i++) {
    97       LocationValidType bits = !update_map() ? 0 : map->_location_valid[i];
    98       _location_valid[i] = bits;
    99       // for whichever bits are set, pull in the corresponding map->_location
   100       int j = i*location_valid_type_size;
   101       while (bits != 0) {
   102         if ((bits & 1) != 0) {
   103           assert(0 <= j && j < reg_count, "range check");
   104           _location[j] = map->_location[j];
   105         }
   106         bits >>= 1;
   107         j += 1;
   108       }
   109     }
   110   }
   111 }
   113 void RegisterMap::clear() {
   114   set_include_argument_oops(true);
   115   if (_update_map) {
   116     for(int i = 0; i < location_valid_size; i++) {
   117       _location_valid[i] = 0;
   118     }
   119     pd_clear();
   120   } else {
   121     pd_initialize();
   122   }
   123 }
   125 #ifndef PRODUCT
   127 void RegisterMap::print_on(outputStream* st) const {
   128   st->print_cr("Register map");
   129   for(int i = 0; i < reg_count; i++) {
   131     VMReg r = VMRegImpl::as_VMReg(i);
   132     intptr_t* src = (intptr_t*) location(r);
   133     if (src != NULL) {
   135       r->print_on(st);
   136       st->print(" [" INTPTR_FORMAT "] = ", src);
   137       if (((uintptr_t)src & (sizeof(*src)-1)) != 0) {
   138         st->print_cr("<misaligned>");
   139       } else {
   140         st->print_cr(INTPTR_FORMAT, *src);
   141       }
   142     }
   143   }
   144 }
   146 void RegisterMap::print() const {
   147   print_on(tty);
   148 }
   150 #endif
   151 // This returns the pc that if you were in the debugger you'd see. Not
   152 // the idealized value in the frame object. This undoes the magic conversion
   153 // that happens for deoptimized frames. In addition it makes the value the
   154 // hardware would want to see in the native frame. The only user (at this point)
   155 // is deoptimization. It likely no one else should ever use it.
   157 address frame::raw_pc() const {
   158   if (is_deoptimized_frame()) {
   159     nmethod* nm = cb()->as_nmethod_or_null();
   160     if (nm->is_method_handle_return(pc()))
   161       return nm->deopt_mh_handler_begin() - pc_return_offset;
   162     else
   163       return nm->deopt_handler_begin() - pc_return_offset;
   164   } else {
   165     return (pc() - pc_return_offset);
   166   }
   167 }
   169 // Change the pc in a frame object. This does not change the actual pc in
   170 // actual frame. To do that use patch_pc.
   171 //
   172 void frame::set_pc(address   newpc ) {
   173 #ifdef ASSERT
   174   if (_cb != NULL && _cb->is_nmethod()) {
   175     assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");
   176   }
   177 #endif // ASSERT
   179   // Unsafe to use the is_deoptimzed tester after changing pc
   180   _deopt_state = unknown;
   181   _pc = newpc;
   182   _cb = CodeCache::find_blob_unsafe(_pc);
   184 }
   186 // type testers
   187 bool frame::is_ignored_frame() const {
   188   return false;  // FIXME: some LambdaForm frames should be ignored
   189 }
   190 bool frame::is_deoptimized_frame() const {
   191   assert(_deopt_state != unknown, "not answerable");
   192   return _deopt_state == is_deoptimized;
   193 }
   195 bool frame::is_native_frame() const {
   196   return (_cb != NULL &&
   197           _cb->is_nmethod() &&
   198           ((nmethod*)_cb)->is_native_method());
   199 }
   201 bool frame::is_java_frame() const {
   202   if (is_interpreted_frame()) return true;
   203   if (is_compiled_frame())    return true;
   204   return false;
   205 }
   208 bool frame::is_compiled_frame() const {
   209   if (_cb != NULL &&
   210       _cb->is_nmethod() &&
   211       ((nmethod*)_cb)->is_java_method()) {
   212     return true;
   213   }
   214   return false;
   215 }
   218 bool frame::is_runtime_frame() const {
   219   return (_cb != NULL && _cb->is_runtime_stub());
   220 }
   222 bool frame::is_safepoint_blob_frame() const {
   223   return (_cb != NULL && _cb->is_safepoint_stub());
   224 }
   226 // testers
   228 bool frame::is_first_java_frame() const {
   229   RegisterMap map(JavaThread::current(), false); // No update
   230   frame s;
   231   for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map));
   232   return s.is_first_frame();
   233 }
   236 bool frame::entry_frame_is_first() const {
   237   return entry_frame_call_wrapper()->is_first_frame();
   238 }
   240 JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const {
   241   JavaCallWrapper** jcw = entry_frame_call_wrapper_addr();
   242   address addr = (address) jcw;
   244   // addr must be within the usable part of the stack
   245   if (thread->is_in_usable_stack(addr)) {
   246     return *jcw;
   247   }
   249   return NULL;
   250 }
   252 bool frame::should_be_deoptimized() const {
   253   if (_deopt_state == is_deoptimized ||
   254       !is_compiled_frame() ) return false;
   255   assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod");
   256   nmethod* nm = (nmethod *)_cb;
   257   if (TraceDependencies) {
   258     tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
   259     nm->print_value_on(tty);
   260     tty->cr();
   261   }
   263   if( !nm->is_marked_for_deoptimization() )
   264     return false;
   266   // If at the return point, then the frame has already been popped, and
   267   // only the return needs to be executed. Don't deoptimize here.
   268   return !nm->is_at_poll_return(pc());
   269 }
   271 bool frame::can_be_deoptimized() const {
   272   if (!is_compiled_frame()) return false;
   273   nmethod* nm = (nmethod*)_cb;
   275   if( !nm->can_be_deoptimized() )
   276     return false;
   278   return !nm->is_at_poll_return(pc());
   279 }
   281 void frame::deoptimize(JavaThread* thread) {
   282   // Schedule deoptimization of an nmethod activation with this frame.
   283   assert(_cb != NULL && _cb->is_nmethod(), "must be");
   284   nmethod* nm = (nmethod*)_cb;
   286   // This is a fix for register window patching race
   287   if (NeedsDeoptSuspend && Thread::current() != thread) {
   288     assert(SafepointSynchronize::is_at_safepoint(),
   289            "patching other threads for deopt may only occur at a safepoint");
   291     // It is possible especially with DeoptimizeALot/DeoptimizeRandom that
   292     // we could see the frame again and ask for it to be deoptimized since
   293     // it might move for a long time. That is harmless and we just ignore it.
   294     if (id() == thread->must_deopt_id()) {
   295       assert(thread->is_deopt_suspend(), "lost suspension");
   296       return;
   297     }
   299     // We are at a safepoint so the target thread can only be
   300     // in 4 states:
   301     //     blocked - no problem
   302     //     blocked_trans - no problem (i.e. could have woken up from blocked
   303     //                                 during a safepoint).
   304     //     native - register window pc patching race
   305     //     native_trans - momentary state
   306     //
   307     // We could just wait out a thread in native_trans to block.
   308     // Then we'd have all the issues that the safepoint code has as to
   309     // whether to spin or block. It isn't worth it. Just treat it like
   310     // native and be done with it.
   311     //
   312     // Examine the state of the thread at the start of safepoint since
   313     // threads that were in native at the start of the safepoint could
   314     // come to a halt during the safepoint, changing the current value
   315     // of the safepoint_state.
   316     JavaThreadState state = thread->safepoint_state()->orig_thread_state();
   317     if (state == _thread_in_native || state == _thread_in_native_trans) {
   318       // Since we are at a safepoint the target thread will stop itself
   319       // before it can return to java as long as we remain at the safepoint.
   320       // Therefore we can put an additional request for the thread to stop
   321       // no matter what no (like a suspend). This will cause the thread
   322       // to notice it needs to do the deopt on its own once it leaves native.
   323       //
   324       // The only reason we must do this is because on machine with register
   325       // windows we have a race with patching the return address and the
   326       // window coming live as the thread returns to the Java code (but still
   327       // in native mode) and then blocks. It is only this top most frame
   328       // that is at risk. So in truth we could add an additional check to
   329       // see if this frame is one that is at risk.
   330       RegisterMap map(thread, false);
   331       frame at_risk =  thread->last_frame().sender(&map);
   332       if (id() == at_risk.id()) {
   333         thread->set_must_deopt_id(id());
   334         thread->set_deopt_suspend();
   335         return;
   336       }
   337     }
   338   } // NeedsDeoptSuspend
   341   // If the call site is a MethodHandle call site use the MH deopt
   342   // handler.
   343   address deopt = nm->is_method_handle_return(pc()) ?
   344     nm->deopt_mh_handler_begin() :
   345     nm->deopt_handler_begin();
   347   // Save the original pc before we patch in the new one
   348   nm->set_original_pc(this, pc());
   349   patch_pc(thread, deopt);
   351 #ifdef ASSERT
   352   {
   353     RegisterMap map(thread, false);
   354     frame check = thread->last_frame();
   355     while (id() != check.id()) {
   356       check = check.sender(&map);
   357     }
   358     assert(check.is_deoptimized_frame(), "missed deopt");
   359   }
   360 #endif // ASSERT
   361 }
   363 frame frame::java_sender() const {
   364   RegisterMap map(JavaThread::current(), false);
   365   frame s;
   366   for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ;
   367   guarantee(s.is_java_frame(), "tried to get caller of first java frame");
   368   return s;
   369 }
   371 frame frame::real_sender(RegisterMap* map) const {
   372   frame result = sender(map);
   373   while (result.is_runtime_frame() ||
   374          result.is_ignored_frame()) {
   375     result = result.sender(map);
   376   }
   377   return result;
   378 }
   380 // Note: called by profiler - NOT for current thread
   381 frame frame::profile_find_Java_sender_frame(JavaThread *thread) {
   382 // If we don't recognize this frame, walk back up the stack until we do
   383   RegisterMap map(thread, false);
   384   frame first_java_frame = frame();
   386   // Find the first Java frame on the stack starting with input frame
   387   if (is_java_frame()) {
   388     // top frame is compiled frame or deoptimized frame
   389     first_java_frame = *this;
   390   } else if (safe_for_sender(thread)) {
   391     for (frame sender_frame = sender(&map);
   392       sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame();
   393       sender_frame = sender_frame.sender(&map)) {
   394       if (sender_frame.is_java_frame()) {
   395         first_java_frame = sender_frame;
   396         break;
   397       }
   398     }
   399   }
   400   return first_java_frame;
   401 }
   403 // Interpreter frames
   406 void frame::interpreter_frame_set_locals(intptr_t* locs)  {
   407   assert(is_interpreted_frame(), "Not an interpreted frame");
   408   *interpreter_frame_locals_addr() = locs;
   409 }
   411 Method* frame::interpreter_frame_method() const {
   412   assert(is_interpreted_frame(), "interpreted frame expected");
   413   Method* m = *interpreter_frame_method_addr();
   414   assert(m->is_method(), "not a Method*");
   415   return m;
   416 }
   418 void frame::interpreter_frame_set_method(Method* method) {
   419   assert(is_interpreted_frame(), "interpreted frame expected");
   420   *interpreter_frame_method_addr() = method;
   421 }
   423 void frame::interpreter_frame_set_bcx(intptr_t bcx) {
   424   assert(is_interpreted_frame(), "Not an interpreted frame");
   425   if (ProfileInterpreter) {
   426     bool formerly_bci = is_bci(interpreter_frame_bcx());
   427     bool is_now_bci = is_bci(bcx);
   428     *interpreter_frame_bcx_addr() = bcx;
   430     intptr_t mdx = interpreter_frame_mdx();
   432     if (mdx != 0) {
   433       if (formerly_bci) {
   434         if (!is_now_bci) {
   435           // The bcx was just converted from bci to bcp.
   436           // Convert the mdx in parallel.
   437           MethodData* mdo = interpreter_frame_method()->method_data();
   438           assert(mdo != NULL, "");
   439           int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
   440           address mdp = mdo->di_to_dp(mdi);
   441           interpreter_frame_set_mdx((intptr_t)mdp);
   442         }
   443       } else {
   444         if (is_now_bci) {
   445           // The bcx was just converted from bcp to bci.
   446           // Convert the mdx in parallel.
   447           MethodData* mdo = interpreter_frame_method()->method_data();
   448           assert(mdo != NULL, "");
   449           int mdi = mdo->dp_to_di((address)mdx);
   450           interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
   451         }
   452       }
   453     }
   454   } else {
   455     *interpreter_frame_bcx_addr() = bcx;
   456   }
   457 }
   459 jint frame::interpreter_frame_bci() const {
   460   assert(is_interpreted_frame(), "interpreted frame expected");
   461   intptr_t bcx = interpreter_frame_bcx();
   462   return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx);
   463 }
   465 void frame::interpreter_frame_set_bci(jint bci) {
   466   assert(is_interpreted_frame(), "interpreted frame expected");
   467   assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC");
   468   interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci));
   469 }
   471 address frame::interpreter_frame_bcp() const {
   472   assert(is_interpreted_frame(), "interpreted frame expected");
   473   intptr_t bcx = interpreter_frame_bcx();
   474   return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx;
   475 }
   477 void frame::interpreter_frame_set_bcp(address bcp) {
   478   assert(is_interpreted_frame(), "interpreted frame expected");
   479   assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC");
   480   interpreter_frame_set_bcx((intptr_t)bcp);
   481 }
   483 void frame::interpreter_frame_set_mdx(intptr_t mdx) {
   484   assert(is_interpreted_frame(), "Not an interpreted frame");
   485   assert(ProfileInterpreter, "must be profiling interpreter");
   486   *interpreter_frame_mdx_addr() = mdx;
   487 }
   489 address frame::interpreter_frame_mdp() const {
   490   assert(ProfileInterpreter, "must be profiling interpreter");
   491   assert(is_interpreted_frame(), "interpreted frame expected");
   492   intptr_t bcx = interpreter_frame_bcx();
   493   intptr_t mdx = interpreter_frame_mdx();
   495   assert(!is_bci(bcx), "should not access mdp during GC");
   496   return (address)mdx;
   497 }
   499 void frame::interpreter_frame_set_mdp(address mdp) {
   500   assert(is_interpreted_frame(), "interpreted frame expected");
   501   if (mdp == NULL) {
   502     // Always allow the mdp to be cleared.
   503     interpreter_frame_set_mdx((intptr_t)mdp);
   504   }
   505   intptr_t bcx = interpreter_frame_bcx();
   506   assert(!is_bci(bcx), "should not set mdp during GC");
   507   interpreter_frame_set_mdx((intptr_t)mdp);
   508 }
   510 BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const {
   511   assert(is_interpreted_frame(), "Not an interpreted frame");
   512 #ifdef ASSERT
   513   interpreter_frame_verify_monitor(current);
   514 #endif
   515   BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size());
   516   return next;
   517 }
   519 BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const {
   520   assert(is_interpreted_frame(), "Not an interpreted frame");
   521 #ifdef ASSERT
   522 //   // This verification needs to be checked before being enabled
   523 //   interpreter_frame_verify_monitor(current);
   524 #endif
   525   BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size());
   526   return previous;
   527 }
   529 // Interpreter locals and expression stack locations.
   531 intptr_t* frame::interpreter_frame_local_at(int index) const {
   532   const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
   533   return &((*interpreter_frame_locals_addr())[n]);
   534 }
   536 intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
   537   const int i = offset * interpreter_frame_expression_stack_direction();
   538   const int n = i * Interpreter::stackElementWords;
   539   return &(interpreter_frame_expression_stack()[n]);
   540 }
   542 jint frame::interpreter_frame_expression_stack_size() const {
   543   // Number of elements on the interpreter expression stack
   544   // Callers should span by stackElementWords
   545   int element_size = Interpreter::stackElementWords;
   546   size_t stack_size = 0;
   547   if (frame::interpreter_frame_expression_stack_direction() < 0) {
   548     stack_size = (interpreter_frame_expression_stack() -
   549                   interpreter_frame_tos_address() + 1)/element_size;
   550   } else {
   551     stack_size = (interpreter_frame_tos_address() -
   552                   interpreter_frame_expression_stack() + 1)/element_size;
   553   }
   554   assert( stack_size <= (size_t)max_jint, "stack size too big");
   555   return ((jint)stack_size);
   556 }
   559 // (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp)
   561 const char* frame::print_name() const {
   562   if (is_native_frame())      return "Native";
   563   if (is_interpreted_frame()) return "Interpreted";
   564   if (is_compiled_frame()) {
   565     if (is_deoptimized_frame()) return "Deoptimized";
   566     return "Compiled";
   567   }
   568   if (sp() == NULL)            return "Empty";
   569   return "C";
   570 }
   572 void frame::print_value_on(outputStream* st, JavaThread *thread) const {
   573   NOT_PRODUCT(address begin = pc()-40;)
   574   NOT_PRODUCT(address end   = NULL;)
   576   st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp());
   577   if (sp() != NULL)
   578     st->print(", fp=" INTPTR_FORMAT ", real_fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), real_fp(), pc());
   580   if (StubRoutines::contains(pc())) {
   581     st->print_cr(")");
   582     st->print("(");
   583     StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
   584     st->print("~Stub::%s", desc->name());
   585     NOT_PRODUCT(begin = desc->begin(); end = desc->end();)
   586   } else if (Interpreter::contains(pc())) {
   587     st->print_cr(")");
   588     st->print("(");
   589     InterpreterCodelet* desc = Interpreter::codelet_containing(pc());
   590     if (desc != NULL) {
   591       st->print("~");
   592       desc->print_on(st);
   593       NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();)
   594     } else {
   595       st->print("~interpreter");
   596     }
   597   }
   598   st->print_cr(")");
   600   if (_cb != NULL) {
   601     st->print("     ");
   602     _cb->print_value_on(st);
   603     st->cr();
   604 #ifndef PRODUCT
   605     if (end == NULL) {
   606       begin = _cb->code_begin();
   607       end   = _cb->code_end();
   608     }
   609 #endif
   610   }
   611   NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);)
   612 }
   615 void frame::print_on(outputStream* st) const {
   616   print_value_on(st,NULL);
   617   if (is_interpreted_frame()) {
   618     interpreter_frame_print_on(st);
   619   }
   620 }
   623 void frame::interpreter_frame_print_on(outputStream* st) const {
   624 #ifndef PRODUCT
   625   assert(is_interpreted_frame(), "Not an interpreted frame");
   626   jint i;
   627   for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
   628     intptr_t x = *interpreter_frame_local_at(i);
   629     st->print(" - local  [" INTPTR_FORMAT "]", x);
   630     st->fill_to(23);
   631     st->print_cr("; #%d", i);
   632   }
   633   for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {
   634     intptr_t x = *interpreter_frame_expression_stack_at(i);
   635     st->print(" - stack  [" INTPTR_FORMAT "]", x);
   636     st->fill_to(23);
   637     st->print_cr("; #%d", i);
   638   }
   639   // locks for synchronization
   640   for (BasicObjectLock* current = interpreter_frame_monitor_end();
   641        current < interpreter_frame_monitor_begin();
   642        current = next_monitor_in_interpreter_frame(current)) {
   643     st->print(" - obj    [");
   644     current->obj()->print_value_on(st);
   645     st->print_cr("]");
   646     st->print(" - lock   [");
   647     current->lock()->print_on(st);
   648     st->print_cr("]");
   649   }
   650   // monitor
   651   st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin());
   652   // bcp
   653   st->print(" - bcp    [" INTPTR_FORMAT "]", interpreter_frame_bcp());
   654   st->fill_to(23);
   655   st->print_cr("; @%d", interpreter_frame_bci());
   656   // locals
   657   st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0));
   658   // method
   659   st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method());
   660   st->fill_to(23);
   661   st->print("; ");
   662   interpreter_frame_method()->print_name(st);
   663   st->cr();
   664 #endif
   665 }
   667 // Return whether the frame is in the VM or os indicating a Hotspot problem.
   668 // Otherwise, it's likely a bug in the native library that the Java code calls,
   669 // hopefully indicating where to submit bugs.
   670 void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) {
   671   // C/C++ frame
   672   bool in_vm = os::address_is_in_vm(pc);
   673   st->print(in_vm ? "V" : "C");
   675   int offset;
   676   bool found;
   678   // libname
   679   found = os::dll_address_to_library_name(pc, buf, buflen, &offset);
   680   if (found) {
   681     // skip directory names
   682     const char *p1, *p2;
   683     p1 = buf;
   684     int len = (int)strlen(os::file_separator());
   685     while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
   686     st->print("  [%s+0x%x]", p1, offset);
   687   } else {
   688     st->print("  " PTR_FORMAT, pc);
   689   }
   691   // function name - os::dll_address_to_function_name() may return confusing
   692   // names if pc is within jvm.dll or libjvm.so, because JVM only has
   693   // JVM_xxxx and a few other symbols in the dynamic symbol table. Do this
   694   // only for native libraries.
   695   if (!in_vm || Decoder::can_decode_C_frame_in_vm()) {
   696     found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
   698     if (found) {
   699       st->print("  %s+0x%x", buf, offset);
   700     }
   701   }
   702 }
   704 // frame::print_on_error() is called by fatal error handler. Notice that we may
   705 // crash inside this function if stack frame is corrupted. The fatal error
   706 // handler can catch and handle the crash. Here we assume the frame is valid.
   707 //
   708 // First letter indicates type of the frame:
   709 //    J: Java frame (compiled)
   710 //    j: Java frame (interpreted)
   711 //    V: VM frame (C/C++)
   712 //    v: Other frames running VM generated code (e.g. stubs, adapters, etc.)
   713 //    C: C/C++ frame
   714 //
   715 // We don't need detailed frame type as that in frame::print_name(). "C"
   716 // suggests the problem is in user lib; everything else is likely a VM bug.
   718 void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const {
   719   if (_cb != NULL) {
   720     if (Interpreter::contains(pc())) {
   721       Method* m = this->interpreter_frame_method();
   722       if (m != NULL) {
   723         m->name_and_sig_as_C_string(buf, buflen);
   724         st->print("j  %s", buf);
   725         st->print("+%d", this->interpreter_frame_bci());
   726       } else {
   727         st->print("j  " PTR_FORMAT, pc());
   728       }
   729     } else if (StubRoutines::contains(pc())) {
   730       StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
   731       if (desc != NULL) {
   732         st->print("v  ~StubRoutines::%s", desc->name());
   733       } else {
   734         st->print("v  ~StubRoutines::" PTR_FORMAT, pc());
   735       }
   736     } else if (_cb->is_buffer_blob()) {
   737       st->print("v  ~BufferBlob::%s", ((BufferBlob *)_cb)->name());
   738     } else if (_cb->is_nmethod()) {
   739       nmethod* nm = (nmethod*)_cb;
   740       Method* m = nm->method();
   741       if (m != NULL) {
   742         m->name_and_sig_as_C_string(buf, buflen);
   743         st->print("J %d%s %s %s (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",
   744                   nm->compile_id(), (nm->is_osr_method() ? "%" : ""),
   745                   ((nm->compiler() != NULL) ? nm->compiler()->name() : ""),
   746                   buf, m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());
   747       } else {
   748         st->print("J  " PTR_FORMAT, pc());
   749       }
   750     } else if (_cb->is_runtime_stub()) {
   751       st->print("v  ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name());
   752     } else if (_cb->is_deoptimization_stub()) {
   753       st->print("v  ~DeoptimizationBlob");
   754     } else if (_cb->is_exception_stub()) {
   755       st->print("v  ~ExceptionBlob");
   756     } else if (_cb->is_safepoint_stub()) {
   757       st->print("v  ~SafepointBlob");
   758     } else {
   759       st->print("v  blob " PTR_FORMAT, pc());
   760     }
   761   } else {
   762     print_C_frame(st, buf, buflen, pc());
   763   }
   764 }
   767 /*
   768   The interpreter_frame_expression_stack_at method in the case of SPARC needs the
   769   max_stack value of the method in order to compute the expression stack address.
   770   It uses the Method* in order to get the max_stack value but during GC this
   771   Method* value saved on the frame is changed by reverse_and_push and hence cannot
   772   be used. So we save the max_stack value in the FrameClosure object and pass it
   773   down to the interpreter_frame_expression_stack_at method
   774 */
   775 class InterpreterFrameClosure : public OffsetClosure {
   776  private:
   777   frame* _fr;
   778   OopClosure* _f;
   779   int    _max_locals;
   780   int    _max_stack;
   782  public:
   783   InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
   784                           OopClosure* f) {
   785     _fr         = fr;
   786     _max_locals = max_locals;
   787     _max_stack  = max_stack;
   788     _f          = f;
   789   }
   791   void offset_do(int offset) {
   792     oop* addr;
   793     if (offset < _max_locals) {
   794       addr = (oop*) _fr->interpreter_frame_local_at(offset);
   795       assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
   796       _f->do_oop(addr);
   797     } else {
   798       addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
   799       // In case of exceptions, the expression stack is invalid and the esp will be reset to express
   800       // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
   801       bool in_stack;
   802       if (frame::interpreter_frame_expression_stack_direction() > 0) {
   803         in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
   804       } else {
   805         in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
   806       }
   807       if (in_stack) {
   808         _f->do_oop(addr);
   809       }
   810     }
   811   }
   813   int max_locals()  { return _max_locals; }
   814   frame* fr()       { return _fr; }
   815 };
   818 class InterpretedArgumentOopFinder: public SignatureInfo {
   819  private:
   820   OopClosure* _f;        // Closure to invoke
   821   int    _offset;        // TOS-relative offset, decremented with each argument
   822   bool   _has_receiver;  // true if the callee has a receiver
   823   frame* _fr;
   825   void set(int size, BasicType type) {
   826     _offset -= size;
   827     if (type == T_OBJECT || type == T_ARRAY) oop_offset_do();
   828   }
   830   void oop_offset_do() {
   831     oop* addr;
   832     addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
   833     _f->do_oop(addr);
   834   }
   836  public:
   837   InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
   838     // compute size of arguments
   839     int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
   840     assert(!fr->is_interpreted_frame() ||
   841            args_size <= fr->interpreter_frame_expression_stack_size(),
   842             "args cannot be on stack anymore");
   843     // initialize InterpretedArgumentOopFinder
   844     _f         = f;
   845     _fr        = fr;
   846     _offset    = args_size;
   847   }
   849   void oops_do() {
   850     if (_has_receiver) {
   851       --_offset;
   852       oop_offset_do();
   853     }
   854     iterate_parameters();
   855   }
   856 };
   859 // Entry frame has following form (n arguments)
   860 //         +-----------+
   861 //   sp -> |  last arg |
   862 //         +-----------+
   863 //         :    :::    :
   864 //         +-----------+
   865 // (sp+n)->|  first arg|
   866 //         +-----------+
   870 // visits and GC's all the arguments in entry frame
   871 class EntryFrameOopFinder: public SignatureInfo {
   872  private:
   873   bool   _is_static;
   874   int    _offset;
   875   frame* _fr;
   876   OopClosure* _f;
   878   void set(int size, BasicType type) {
   879     assert (_offset >= 0, "illegal offset");
   880     if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset);
   881     _offset -= size;
   882   }
   884   void oop_at_offset_do(int offset) {
   885     assert (offset >= 0, "illegal offset");
   886     oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
   887     _f->do_oop(addr);
   888   }
   890  public:
   891    EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {
   892      _f = NULL; // will be set later
   893      _fr = frame;
   894      _is_static = is_static;
   895      _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
   896    }
   898   void arguments_do(OopClosure* f) {
   899     _f = f;
   900     if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver
   901     iterate_parameters();
   902   }
   904 };
   906 oop* frame::interpreter_callee_receiver_addr(Symbol* signature) {
   907   ArgumentSizeComputer asc(signature);
   908   int size = asc.size();
   909   return (oop *)interpreter_frame_tos_at(size);
   910 }
   913 void frame::oops_interpreted_do(OopClosure* f, CLDToOopClosure* cld_f,
   914     const RegisterMap* map, bool query_oop_map_cache) {
   915   assert(is_interpreted_frame(), "Not an interpreted frame");
   916   assert(map != NULL, "map must be set");
   917   Thread *thread = Thread::current();
   918   methodHandle m (thread, interpreter_frame_method());
   919   jint      bci = interpreter_frame_bci();
   921   assert(!Universe::heap()->is_in(m()),
   922           "must be valid oop");
   923   assert(m->is_method(), "checking frame value");
   924   assert((m->is_native() && bci == 0)  ||
   925          (!m->is_native() && bci >= 0 && bci < m->code_size()),
   926          "invalid bci value");
   928   // Handle the monitor elements in the activation
   929   for (
   930     BasicObjectLock* current = interpreter_frame_monitor_end();
   931     current < interpreter_frame_monitor_begin();
   932     current = next_monitor_in_interpreter_frame(current)
   933   ) {
   934 #ifdef ASSERT
   935     interpreter_frame_verify_monitor(current);
   936 #endif
   937     current->oops_do(f);
   938   }
   940   // process fixed part
   941   if (cld_f != NULL) {
   942     // The method pointer in the frame might be the only path to the method's
   943     // klass, and the klass needs to be kept alive while executing. The GCs
   944     // don't trace through method pointers, so typically in similar situations
   945     // the mirror or the class loader of the klass are installed as a GC root.
   946     // To minimze the overhead of doing that here, we ask the GC to pass down a
   947     // closure that knows how to keep klasses alive given a ClassLoaderData.
   948     cld_f->do_cld(m->method_holder()->class_loader_data());
   949   }
   951   if (m->is_native() PPC32_ONLY(&& m->is_static())) {
   952     f->do_oop(interpreter_frame_temp_oop_addr());
   953   }
   955   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
   957   Symbol* signature = NULL;
   958   bool has_receiver = false;
   960   // Process a callee's arguments if we are at a call site
   961   // (i.e., if we are at an invoke bytecode)
   962   // This is used sometimes for calling into the VM, not for another
   963   // interpreted or compiled frame.
   964   if (!m->is_native()) {
   965     Bytecode_invoke call = Bytecode_invoke_check(m, bci);
   966     if (call.is_valid()) {
   967       signature = call.signature();
   968       has_receiver = call.has_receiver();
   969       if (map->include_argument_oops() &&
   970           interpreter_frame_expression_stack_size() > 0) {
   971         ResourceMark rm(thread);  // is this right ???
   972         // we are at a call site & the expression stack is not empty
   973         // => process callee's arguments
   974         //
   975         // Note: The expression stack can be empty if an exception
   976         //       occurred during method resolution/execution. In all
   977         //       cases we empty the expression stack completely be-
   978         //       fore handling the exception (the exception handling
   979         //       code in the interpreter calls a blocking runtime
   980         //       routine which can cause this code to be executed).
   981         //       (was bug gri 7/27/98)
   982         oops_interpreted_arguments_do(signature, has_receiver, f);
   983       }
   984     }
   985   }
   987   InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
   989   // process locals & expression stack
   990   InterpreterOopMap mask;
   991   if (query_oop_map_cache) {
   992     m->mask_for(bci, &mask);
   993   } else {
   994     OopMapCache::compute_one_oop_map(m, bci, &mask);
   995   }
   996   mask.iterate_oop(&blk);
   997 }
  1000 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {
  1001   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
  1002   finder.oops_do();
  1005 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
  1006   assert(_cb != NULL, "sanity check");
  1007   if (_cb->oop_maps() != NULL) {
  1008     OopMapSet::oops_do(this, reg_map, f);
  1010     // Preserve potential arguments for a callee. We handle this by dispatching
  1011     // on the codeblob. For c2i, we do
  1012     if (reg_map->include_argument_oops()) {
  1013       _cb->preserve_callee_argument_oops(*this, reg_map, f);
  1016   // In cases where perm gen is collected, GC will want to mark
  1017   // oops referenced from nmethods active on thread stacks so as to
  1018   // prevent them from being collected. However, this visit should be
  1019   // restricted to certain phases of the collection only. The
  1020   // closure decides how it wants nmethods to be traced.
  1021   if (cf != NULL)
  1022     cf->do_code_blob(_cb);
  1025 class CompiledArgumentOopFinder: public SignatureInfo {
  1026  protected:
  1027   OopClosure*     _f;
  1028   int             _offset;        // the current offset, incremented with each argument
  1029   bool            _has_receiver;  // true if the callee has a receiver
  1030   bool            _has_appendix;  // true if the call has an appendix
  1031   frame           _fr;
  1032   RegisterMap*    _reg_map;
  1033   int             _arg_size;
  1034   VMRegPair*      _regs;        // VMReg list of arguments
  1036   void set(int size, BasicType type) {
  1037     if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset();
  1038     _offset += size;
  1041   virtual void handle_oop_offset() {
  1042     // Extract low order register number from register array.
  1043     // In LP64-land, the high-order bits are valid but unhelpful.
  1044     VMReg reg = _regs[_offset].first();
  1045     oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
  1046     _f->do_oop(loc);
  1049  public:
  1050   CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr,  const RegisterMap* reg_map)
  1051     : SignatureInfo(signature) {
  1053     // initialize CompiledArgumentOopFinder
  1054     _f         = f;
  1055     _offset    = 0;
  1056     _has_receiver = has_receiver;
  1057     _has_appendix = has_appendix;
  1058     _fr        = fr;
  1059     _reg_map   = (RegisterMap*)reg_map;
  1060     _arg_size  = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0);
  1062     int arg_size;
  1063     _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size);
  1064     assert(arg_size == _arg_size, "wrong arg size");
  1067   void oops_do() {
  1068     if (_has_receiver) {
  1069       handle_oop_offset();
  1070       _offset++;
  1072     iterate_parameters();
  1073     if (_has_appendix) {
  1074       handle_oop_offset();
  1075       _offset++;
  1078 };
  1080 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f) {
  1081   ResourceMark rm;
  1082   CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
  1083   finder.oops_do();
  1087 // Get receiver out of callers frame, i.e. find parameter 0 in callers
  1088 // frame.  Consult ADLC for where parameter 0 is to be found.  Then
  1089 // check local reg_map for it being a callee-save register or argument
  1090 // register, both of which are saved in the local frame.  If not found
  1091 // there, it must be an in-stack argument of the caller.
  1092 // Note: caller.sp() points to callee-arguments
  1093 oop frame::retrieve_receiver(RegisterMap* reg_map) {
  1094   frame caller = *this;
  1096   // First consult the ADLC on where it puts parameter 0 for this signature.
  1097   VMReg reg = SharedRuntime::name_for_receiver();
  1098   oop* oop_adr = caller.oopmapreg_to_location(reg, reg_map);
  1099   if (oop_adr == NULL) {
  1100     guarantee(oop_adr != NULL, "bad register save location");
  1101     return NULL;
  1103   oop r = *oop_adr;
  1104   assert(Universe::heap()->is_in_or_null(r), err_msg("bad receiver: " INTPTR_FORMAT " (" INTX_FORMAT ")", (void *) r, (void *) r));
  1105   return r;
  1109 oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const {
  1110   if(reg->is_reg()) {
  1111     // If it is passed in a register, it got spilled in the stub frame.
  1112     return (oop *)reg_map->location(reg);
  1113   } else {
  1114     int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size;
  1115     return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes);
  1119 BasicLock* frame::get_native_monitor() {
  1120   nmethod* nm = (nmethod*)_cb;
  1121   assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
  1122          "Should not call this unless it's a native nmethod");
  1123   int byte_offset = in_bytes(nm->native_basic_lock_sp_offset());
  1124   assert(byte_offset >= 0, "should not see invalid offset");
  1125   return (BasicLock*) &sp()[byte_offset / wordSize];
  1128 oop frame::get_native_receiver() {
  1129   nmethod* nm = (nmethod*)_cb;
  1130   assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),
  1131          "Should not call this unless it's a native nmethod");
  1132   int byte_offset = in_bytes(nm->native_receiver_sp_offset());
  1133   assert(byte_offset >= 0, "should not see invalid offset");
  1134   oop owner = ((oop*) sp())[byte_offset / wordSize];
  1135   assert( Universe::heap()->is_in(owner), "bad receiver" );
  1136   return owner;
  1139 void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) {
  1140   assert(map != NULL, "map must be set");
  1141   if (map->include_argument_oops()) {
  1142     // must collect argument oops, as nobody else is doing it
  1143     Thread *thread = Thread::current();
  1144     methodHandle m (thread, entry_frame_call_wrapper()->callee_method());
  1145     EntryFrameOopFinder finder(this, m->signature(), m->is_static());
  1146     finder.arguments_do(f);
  1148   // Traverse the Handle Block saved in the entry frame
  1149   entry_frame_call_wrapper()->oops_do(f);
  1153 void frame::oops_do_internal(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) {
  1154 #ifndef PRODUCT
  1155   // simulate GC crash here to dump java thread in error report
  1156   if (CrashGCForDumpingJavaThread) {
  1157     char *t = NULL;
  1158     *t = 'c';
  1160 #endif
  1161   if (is_interpreted_frame()) {
  1162     oops_interpreted_do(f, cld_f, map, use_interpreter_oop_map_cache);
  1163   } else if (is_entry_frame()) {
  1164     oops_entry_do(f, map);
  1165   } else if (CodeCache::contains(pc())) {
  1166     oops_code_blob_do(f, cf, map);
  1167 #ifdef SHARK
  1168   } else if (is_fake_stub_frame()) {
  1169     // nothing to do
  1170 #endif // SHARK
  1171   } else {
  1172     ShouldNotReachHere();
  1176 void frame::nmethods_do(CodeBlobClosure* cf) {
  1177   if (_cb != NULL && _cb->is_nmethod()) {
  1178     cf->do_code_blob(_cb);
  1183 // call f() on the interpreted Method*s in the stack.
  1184 // Have to walk the entire code cache for the compiled frames Yuck.
  1185 void frame::metadata_do(void f(Metadata*)) {
  1186   if (_cb != NULL && Interpreter::contains(pc())) {
  1187     Method* m = this->interpreter_frame_method();
  1188     assert(m != NULL, "huh?");
  1189     f(m);
  1193 void frame::gc_prologue() {
  1194   if (is_interpreted_frame()) {
  1195     // set bcx to bci to become Method* position independent during GC
  1196     interpreter_frame_set_bcx(interpreter_frame_bci());
  1201 void frame::gc_epilogue() {
  1202   if (is_interpreted_frame()) {
  1203     // set bcx back to bcp for interpreter
  1204     interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp());
  1206   // call processor specific epilog function
  1207   pd_gc_epilog();
  1211 # ifdef ENABLE_ZAP_DEAD_LOCALS
  1213 void frame::CheckValueClosure::do_oop(oop* p) {
  1214   if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) {
  1215     warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());
  1218 frame::CheckValueClosure frame::_check_value;
  1221 void frame::CheckOopClosure::do_oop(oop* p) {
  1222   if (*p != NULL && !(*p)->is_oop()) {
  1223     warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());
  1226 frame::CheckOopClosure frame::_check_oop;
  1228 void frame::check_derived_oop(oop* base, oop* derived) {
  1229   _check_oop.do_oop(base);
  1233 void frame::ZapDeadClosure::do_oop(oop* p) {
  1234   if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p);
  1235   *p = cast_to_oop<intptr_t>(0xbabebabe);
  1237 frame::ZapDeadClosure frame::_zap_dead;
  1239 void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) {
  1240   assert(thread == Thread::current(), "need to synchronize to do this to another thread");
  1241   // Tracing - part 1
  1242   if (TraceZapDeadLocals) {
  1243     ResourceMark rm(thread);
  1244     tty->print_cr("--------------------------------------------------------------------------------");
  1245     tty->print("Zapping dead locals in ");
  1246     print_on(tty);
  1247     tty->cr();
  1249   // Zapping
  1250        if (is_entry_frame      ()) zap_dead_entry_locals      (thread, map);
  1251   else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map);
  1252   else if (is_compiled_frame()) zap_dead_compiled_locals   (thread, map);
  1254   else
  1255     // could be is_runtime_frame
  1256     // so remove error: ShouldNotReachHere();
  1258   // Tracing - part 2
  1259   if (TraceZapDeadLocals) {
  1260     tty->cr();
  1265 void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) {
  1266   // get current interpreter 'pc'
  1267   assert(is_interpreted_frame(), "Not an interpreted frame");
  1268   Method* m   = interpreter_frame_method();
  1269   int       bci = interpreter_frame_bci();
  1271   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
  1273   // process dynamic part
  1274   InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(),
  1275                                     &_check_value);
  1276   InterpreterFrameClosure   oop_blk(this, max_locals, m->max_stack(),
  1277                                     &_check_oop  );
  1278   InterpreterFrameClosure  dead_blk(this, max_locals, m->max_stack(),
  1279                                     &_zap_dead   );
  1281   // get frame map
  1282   InterpreterOopMap mask;
  1283   m->mask_for(bci, &mask);
  1284   mask.iterate_all( &oop_blk, &value_blk, &dead_blk);
  1288 void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) {
  1290   ResourceMark rm(thread);
  1291   assert(_cb != NULL, "sanity check");
  1292   if (_cb->oop_maps() != NULL) {
  1293     OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value);
  1298 void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) {
  1299   if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented");
  1303 void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) {
  1304   if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented");
  1307 # endif // ENABLE_ZAP_DEAD_LOCALS
  1309 void frame::verify(const RegisterMap* map) {
  1310   // for now make sure receiver type is correct
  1311   if (is_interpreted_frame()) {
  1312     Method* method = interpreter_frame_method();
  1313     guarantee(method->is_method(), "method is wrong in frame::verify");
  1314     if (!method->is_static()) {
  1315       // fetch the receiver
  1316       oop* p = (oop*) interpreter_frame_local_at(0);
  1317       // make sure we have the right receiver type
  1320   COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");)
  1321   oops_do_internal(&VerifyOopClosure::verify_oop, NULL, NULL, (RegisterMap*)map, false);
  1325 #ifdef ASSERT
  1326 bool frame::verify_return_pc(address x) {
  1327   if (StubRoutines::returns_to_call_stub(x)) {
  1328     return true;
  1330   if (CodeCache::contains(x)) {
  1331     return true;
  1333   if (Interpreter::contains(x)) {
  1334     return true;
  1336   return false;
  1338 #endif
  1340 #ifdef ASSERT
  1341 void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const {
  1342   assert(is_interpreted_frame(), "Not an interpreted frame");
  1343   // verify that the value is in the right part of the frame
  1344   address low_mark  = (address) interpreter_frame_monitor_end();
  1345   address high_mark = (address) interpreter_frame_monitor_begin();
  1346   address current   = (address) value;
  1348   const int monitor_size = frame::interpreter_frame_monitor_size();
  1349   guarantee((high_mark - current) % monitor_size  ==  0         , "Misaligned top of BasicObjectLock*");
  1350   guarantee( high_mark > current                                , "Current BasicObjectLock* higher than high_mark");
  1352   guarantee((current - low_mark) % monitor_size  ==  0         , "Misaligned bottom of BasicObjectLock*");
  1353   guarantee( current >= low_mark                               , "Current BasicObjectLock* below than low_mark");
  1355 #endif
  1357 #ifndef PRODUCT
  1358 void frame::describe(FrameValues& values, int frame_no) {
  1359   // boundaries: sp and the 'real' frame pointer
  1360   values.describe(-1, sp(), err_msg("sp for #%d", frame_no), 1);
  1361   intptr_t* frame_pointer = real_fp(); // Note: may differ from fp()
  1363   // print frame info at the highest boundary
  1364   intptr_t* info_address = MAX2(sp(), frame_pointer);
  1366   if (info_address != frame_pointer) {
  1367     // print frame_pointer explicitly if not marked by the frame info
  1368     values.describe(-1, frame_pointer, err_msg("frame pointer for #%d", frame_no), 1);
  1371   if (is_entry_frame() || is_compiled_frame() || is_interpreted_frame() || is_native_frame()) {
  1372     // Label values common to most frames
  1373     values.describe(-1, unextended_sp(), err_msg("unextended_sp for #%d", frame_no));
  1376   if (is_interpreted_frame()) {
  1377     Method* m = interpreter_frame_method();
  1378     int bci = interpreter_frame_bci();
  1380     // Label the method and current bci
  1381     values.describe(-1, info_address,
  1382                     FormatBuffer<1024>("#%d method %s @ %d", frame_no, m->name_and_sig_as_C_string(), bci), 2);
  1383     values.describe(-1, info_address,
  1384                     err_msg("- %d locals %d max stack", m->max_locals(), m->max_stack()), 1);
  1385     if (m->max_locals() > 0) {
  1386       intptr_t* l0 = interpreter_frame_local_at(0);
  1387       intptr_t* ln = interpreter_frame_local_at(m->max_locals() - 1);
  1388       values.describe(-1, MAX2(l0, ln), err_msg("locals for #%d", frame_no), 1);
  1389       // Report each local and mark as owned by this frame
  1390       for (int l = 0; l < m->max_locals(); l++) {
  1391         intptr_t* l0 = interpreter_frame_local_at(l);
  1392         values.describe(frame_no, l0, err_msg("local %d", l));
  1396     // Compute the actual expression stack size
  1397     InterpreterOopMap mask;
  1398     OopMapCache::compute_one_oop_map(m, bci, &mask);
  1399     intptr_t* tos = NULL;
  1400     // Report each stack element and mark as owned by this frame
  1401     for (int e = 0; e < mask.expression_stack_size(); e++) {
  1402       tos = MAX2(tos, interpreter_frame_expression_stack_at(e));
  1403       values.describe(frame_no, interpreter_frame_expression_stack_at(e),
  1404                       err_msg("stack %d", e));
  1406     if (tos != NULL) {
  1407       values.describe(-1, tos, err_msg("expression stack for #%d", frame_no), 1);
  1409     if (interpreter_frame_monitor_begin() != interpreter_frame_monitor_end()) {
  1410       values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_begin(), "monitors begin");
  1411       values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_end(), "monitors end");
  1413   } else if (is_entry_frame()) {
  1414     // For now just label the frame
  1415     values.describe(-1, info_address, err_msg("#%d entry frame", frame_no), 2);
  1416   } else if (is_compiled_frame()) {
  1417     // For now just label the frame
  1418     nmethod* nm = cb()->as_nmethod_or_null();
  1419     values.describe(-1, info_address,
  1420                     FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for method %s%s", frame_no,
  1421                                        nm, nm->method()->name_and_sig_as_C_string(),
  1422                                        (_deopt_state == is_deoptimized) ?
  1423                                        " (deoptimized)" :
  1424                                        ((_deopt_state == unknown) ? " (state unknown)" : "")),
  1425                     2);
  1426   } else if (is_native_frame()) {
  1427     // For now just label the frame
  1428     nmethod* nm = cb()->as_nmethod_or_null();
  1429     values.describe(-1, info_address,
  1430                     FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for native method %s", frame_no,
  1431                                        nm, nm->method()->name_and_sig_as_C_string()), 2);
  1432   } else {
  1433     // provide default info if not handled before
  1434     char *info = (char *) "special frame";
  1435     if ((_cb != NULL) &&
  1436         (_cb->name() != NULL)) {
  1437       info = (char *)_cb->name();
  1439     values.describe(-1, info_address, err_msg("#%d <%s>", frame_no, info), 2);
  1442   // platform dependent additional data
  1443   describe_pd(values, frame_no);
  1446 #endif
  1449 //-----------------------------------------------------------------------------------
  1450 // StackFrameStream implementation
  1452 StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) {
  1453   assert(thread->has_last_Java_frame(), "sanity check");
  1454   _fr = thread->last_frame();
  1455   _is_done = false;
  1459 #ifndef PRODUCT
  1461 void FrameValues::describe(int owner, intptr_t* location, const char* description, int priority) {
  1462   FrameValue fv;
  1463   fv.location = location;
  1464   fv.owner = owner;
  1465   fv.priority = priority;
  1466   fv.description = NEW_RESOURCE_ARRAY(char, strlen(description) + 1);
  1467   strcpy(fv.description, description);
  1468   _values.append(fv);
  1472 #ifdef ASSERT
  1473 void FrameValues::validate() {
  1474   _values.sort(compare);
  1475   bool error = false;
  1476   FrameValue prev;
  1477   prev.owner = -1;
  1478   for (int i = _values.length() - 1; i >= 0; i--) {
  1479     FrameValue fv = _values.at(i);
  1480     if (fv.owner == -1) continue;
  1481     if (prev.owner == -1) {
  1482       prev = fv;
  1483       continue;
  1485     if (prev.location == fv.location) {
  1486       if (fv.owner != prev.owner) {
  1487         tty->print_cr("overlapping storage");
  1488         tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", prev.location, *prev.location, prev.description);
  1489         tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description);
  1490         error = true;
  1492     } else {
  1493       prev = fv;
  1496   assert(!error, "invalid layout");
  1498 #endif // ASSERT
  1500 void FrameValues::print(JavaThread* thread) {
  1501   _values.sort(compare);
  1503   // Sometimes values like the fp can be invalid values if the
  1504   // register map wasn't updated during the walk.  Trim out values
  1505   // that aren't actually in the stack of the thread.
  1506   int min_index = 0;
  1507   int max_index = _values.length() - 1;
  1508   intptr_t* v0 = _values.at(min_index).location;
  1509   intptr_t* v1 = _values.at(max_index).location;
  1511   if (thread == Thread::current()) {
  1512     while (!thread->is_in_stack((address)v0)) {
  1513       v0 = _values.at(++min_index).location;
  1515     while (!thread->is_in_stack((address)v1)) {
  1516       v1 = _values.at(--max_index).location;
  1518   } else {
  1519     while (!thread->on_local_stack((address)v0)) {
  1520       v0 = _values.at(++min_index).location;
  1522     while (!thread->on_local_stack((address)v1)) {
  1523       v1 = _values.at(--max_index).location;
  1526   intptr_t* min = MIN2(v0, v1);
  1527   intptr_t* max = MAX2(v0, v1);
  1528   intptr_t* cur = max;
  1529   intptr_t* last = NULL;
  1530   for (int i = max_index; i >= min_index; i--) {
  1531     FrameValue fv = _values.at(i);
  1532     while (cur > fv.location) {
  1533       tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT, cur, *cur);
  1534       cur--;
  1536     if (last == fv.location) {
  1537       const char* spacer = "          " LP64_ONLY("        ");
  1538       tty->print_cr(" %s  %s %s", spacer, spacer, fv.description);
  1539     } else {
  1540       tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description);
  1541       last = fv.location;
  1542       cur--;
  1547 #endif // ndef PRODUCT

mercurial