< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page
rev 54542 : 8213084: Rework and enhance Print[Opto]Assembly output
Reviewed-by:


   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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"

  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/compiledMethod.inline.hpp"
  30 #include "code/dependencies.hpp"
  31 #include "code/nativeInst.hpp"
  32 #include "code/nmethod.hpp"
  33 #include "code/scopeDesc.hpp"
  34 #include "compiler/abstractCompiler.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "compiler/compileLog.hpp"
  37 #include "compiler/compilerDirectives.hpp"
  38 #include "compiler/directivesParser.hpp"
  39 #include "compiler/disassembler.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "logging/log.hpp"
  42 #include "logging/logStream.hpp"
  43 #include "memory/allocation.inline.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/access.inline.hpp"
  46 #include "oops/method.inline.hpp"


 431   _speculation_log        = NULL;
 432   _jvmci_installed_code_triggers_invalidation = false;
 433 #endif
 434 }
 435 
 436 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
 437   int compile_id,
 438   CodeBuffer *code_buffer,
 439   int vep_offset,
 440   int frame_complete,
 441   int frame_size,
 442   ByteSize basic_lock_owner_sp_offset,
 443   ByteSize basic_lock_sp_offset,
 444   OopMapSet* oop_maps) {
 445   code_buffer->finalize_oop_references(method);
 446   // create nmethod
 447   nmethod* nm = NULL;
 448   {
 449     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 450     int native_nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod));

 451     CodeOffsets offsets;
 452     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 453     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 454     nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), compiler_none, native_nmethod_size,

 455                                             compile_id, &offsets,
 456                                             code_buffer, frame_size,
 457                                             basic_lock_owner_sp_offset,
 458                                             basic_lock_sp_offset, oop_maps);

 459     NOT_PRODUCT(if (nm != NULL)  native_nmethod_stats.note_native_nmethod(nm));
 460   }
 461 
 462   if (nm != NULL) {
 463     // verify nmethod
 464     debug_only(nm->verify();) // might block
 465 
 466     nm->log_new_nmethod();
 467     nm->make_in_use();
 468   }
 469   return nm;
 470 }
 471 
 472 nmethod* nmethod::new_nmethod(const methodHandle& method,
 473   int compile_id,
 474   int entry_bci,
 475   CodeOffsets* offsets,
 476   int orig_pc_offset,
 477   DebugInformationRecorder* debug_info,
 478   Dependencies* dependencies,


 610 
 611     clear_unloading_state();
 612 
 613     Universe::heap()->register_nmethod(this);
 614     debug_only(Universe::heap()->verify_nmethod(this));
 615 
 616     CodeCache::commit(this);
 617   }
 618 
 619   if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 620     ttyLocker ttyl;  // keep the following output all in one block
 621     // This output goes directly to the tty, not the compiler log.
 622     // To enable tools to match it up with the compilation activity,
 623     // be sure to tag this tty output with the compile ID.
 624     if (xtty != NULL) {
 625       xtty->begin_head("print_native_nmethod");
 626       xtty->method(_method);
 627       xtty->stamp();
 628       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 629     }
 630     // print the header part first
 631     print();
 632     // then print the requested information
 633     if (PrintNativeNMethods) {

 634       print_code();



 635       if (oop_maps != NULL) {
 636         oop_maps->print();



 637       }



 638     }


 639     if (PrintRelocations) {
 640       print_relocations();

 641     }


 642     if (xtty != NULL) {
 643       xtty->tail("print_native_nmethod");
 644     }
 645   }
 646 }
 647 
 648 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () {
 649   return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level));
 650 }
 651 
 652 nmethod::nmethod(
 653   Method* method,
 654   CompilerType type,
 655   int nmethod_size,
 656   int compile_id,
 657   int entry_bci,
 658   CodeOffsets* offsets,
 659   int orig_pc_offset,
 660   DebugInformationRecorder* debug_info,
 661   Dependencies* dependencies,


 706       _jvmci_installed_code_triggers_invalidation = true;
 707     }
 708 
 709     if (compiler->is_jvmci()) {
 710       // JVMCI might not produce any stub sections
 711       if (offsets->value(CodeOffsets::Exceptions) != -1) {
 712         _exception_offset        = code_offset()          + offsets->value(CodeOffsets::Exceptions);
 713       } else {
 714         _exception_offset = -1;
 715       }
 716       if (offsets->value(CodeOffsets::Deopt) != -1) {
 717         _deopt_handler_begin       = (address) this + code_offset()          + offsets->value(CodeOffsets::Deopt);
 718       } else {
 719         _deopt_handler_begin = NULL;
 720       }
 721       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
 722         _deopt_mh_handler_begin  = (address) this + code_offset()          + offsets->value(CodeOffsets::DeoptMH);
 723       } else {
 724         _deopt_mh_handler_begin = NULL;
 725       }
 726     } else {
 727 #endif

 728     // Exception handler and deopt handler are in the stub section
 729     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set");
 730     assert(offsets->value(CodeOffsets::Deopt     ) != -1, "must be set");
 731 
 732     _exception_offset       = _stub_offset          + offsets->value(CodeOffsets::Exceptions);
 733     _deopt_handler_begin    = (address) this + _stub_offset          + offsets->value(CodeOffsets::Deopt);
 734     if (offsets->value(CodeOffsets::DeoptMH) != -1) {
 735       _deopt_mh_handler_begin  = (address) this + _stub_offset          + offsets->value(CodeOffsets::DeoptMH);
 736     } else {
 737       _deopt_mh_handler_begin  = NULL;
 738 #if INCLUDE_JVMCI
 739     }
 740 #endif
 741     }
 742     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
 743       _unwind_handler_offset = code_offset()         + offsets->value(CodeOffsets::UnwindHandler);
 744     } else {
 745       _unwind_handler_offset = -1;
 746     }
 747 
 748     _oops_offset             = data_offset();
 749     _metadata_offset         = _oops_offset          + align_up(code_buffer->total_oop_size(), oopSize);
 750     int scopes_data_offset   = _metadata_offset      + align_up(code_buffer->total_metadata_size(), wordSize);
 751 
 752     _scopes_pcs_offset       = scopes_data_offset    + align_up(debug_info->data_size       (), oopSize);
 753     _dependencies_offset     = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
 754     _handler_table_offset    = _dependencies_offset  + align_up((int)dependencies->size_in_bytes (), oopSize);
 755     _nul_chk_table_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
 756     _nmethod_end_offset      = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
 757     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 758     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 759     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 760     _exception_cache         = NULL;
 761 
 762     _scopes_data_begin = (address) this + scopes_data_offset;
 763 
 764     _pc_desc_container.reset_to(scopes_pcs_begin());
 765 
 766     code_buffer->copy_code_and_locs_to(this);
 767     // Copy contents of ScopeDescRecorder to nmethod
 768     code_buffer->copy_values_to(this);
 769     debug_info->copy_to(this);
 770     dependencies->copy_to(this);
 771     clear_unloading_state();
 772 
 773     Universe::heap()->register_nmethod(this);
 774     debug_only(Universe::heap()->verify_nmethod(this));
 775 
 776     CodeCache::commit(this);
 777 
 778     // Copy contents of ExceptionHandlerTable to nmethod
 779     handler_table->copy_to(this);
 780     nul_chk_table->copy_to(this);
 781 


 855     } else {
 856       CompileTask::print(st, this, msg, /*short_form:*/ false);
 857     }
 858   }
 859 }
 860 
 861 void nmethod::maybe_print_nmethod(DirectiveSet* directive) {
 862   bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
 863   if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
 864     print_nmethod(printnmethods);
 865   }
 866 }
 867 
 868 void nmethod::print_nmethod(bool printmethod) {
 869   ttyLocker ttyl;  // keep the following output all in one block
 870   if (xtty != NULL) {
 871     xtty->begin_head("print_nmethod");
 872     xtty->stamp();
 873     xtty->end_head();
 874   }
 875   // print the header part first
 876   print();
 877   // then print the requested information
 878   if (printmethod) {
 879     print_code();



















 880     print_pcs();
 881     if (oop_maps()) {
 882       oop_maps()->print();




 883     }



 884   }



 885   if (printmethod || PrintDebugInfo || CompilerOracle::has_option_string(_method, "PrintDebugInfo")) {
 886     print_scopes();

 887   }
 888   if (printmethod || PrintRelocations || CompilerOracle::has_option_string(_method, "PrintRelocations")) {
 889     print_relocations();

 890   }
 891   if (printmethod || PrintDependencies || CompilerOracle::has_option_string(_method, "PrintDependencies")) {
 892     print_dependencies();

 893   }
 894   if (printmethod || PrintExceptionHandlers) {
 895     print_handler_table();

 896     print_nul_chk_table();

 897   }

 898   if (printmethod) {
 899     print_recorded_oops();

 900     print_recorded_metadata();


 901   }


 902   if (xtty != NULL) {
 903     xtty->tail("print_nmethod");
 904   }
 905 }
 906 
 907 
 908 // Promote one word from an assembly-time handle to a live embedded oop.
 909 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) {
 910   if (handle == NULL ||
 911       // As a special case, IC oops are initialized to 1 or -1.
 912       handle == (jobject) Universe::non_oop_word()) {
 913     (*dest) = (oop) handle;
 914   } else {
 915     (*dest) = JNIHandles::resolve_non_null(handle);
 916   }
 917 }
 918 
 919 
 920 // Have to have the same name because it's called by a template
 921 void nmethod::copy_values(GrowableArray<jobject>* array) {


2010   }
2011   return true;
2012 }
2013 
2014 
2015 address nmethod::continuation_for_implicit_exception(address pc) {
2016   // Exception happened outside inline-cache check code => we are inside
2017   // an active nmethod => use cpc to determine a return address
2018   int exception_offset = pc - code_begin();
2019   int cont_offset = ImplicitExceptionTable(this).at( exception_offset );
2020 #ifdef ASSERT
2021   if (cont_offset == 0) {
2022     Thread* thread = Thread::current();
2023     ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
2024     HandleMark hm(thread);
2025     ResourceMark rm(thread);
2026     CodeBlob* cb = CodeCache::find_blob(pc);
2027     assert(cb != NULL && cb == this, "");
2028     ttyLocker ttyl;
2029     tty->print_cr("implicit exception happened at " INTPTR_FORMAT, p2i(pc));
2030     print();

2031     method()->print_codes();
2032     print_code();
2033     print_pcs();
2034   }
2035 #endif
2036   if (cont_offset == 0) {
2037     // Let the normal error handling report the exception
2038     return NULL;
2039   }
2040   return code_begin() + cont_offset;
2041 }
2042 
2043 
2044 
2045 void nmethod_init() {
2046   // make sure you didn't forget to adjust the filler fields
2047   assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
2048 }
2049 
2050 
2051 //-------------------------------------------------------------------------------------------
2052 
2053 
2054 // QQQ might we make this work from a frame??
2055 nmethodLocker::nmethodLocker(address pc) {
2056   CodeBlob* cb = CodeCache::find_blob(pc);
2057   guarantee(cb != NULL && cb->is_compiled(), "bad pc for a nmethod found");
2058   _nm = cb->as_compiled_method();
2059   lock_nmethod(_nm);
2060 }
2061 
2062 // Only JvmtiDeferredEvent::compiled_method_unload_event()
2063 // should pass zombie_ok == true.
2064 void nmethodLocker::lock_nmethod(CompiledMethod* cm, bool zombie_ok) {


2072 void nmethodLocker::unlock_nmethod(CompiledMethod* cm) {
2073   if (cm == NULL)  return;
2074   if (cm->is_aot()) return;  // FIXME: Revisit once _lock_count is added to aot_method
2075   nmethod* nm = cm->as_nmethod();
2076   Atomic::dec(&nm->_lock_count);
2077   assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
2078 }
2079 
2080 
2081 // -----------------------------------------------------------------------------
2082 // Verification
2083 
2084 class VerifyOopsClosure: public OopClosure {
2085   nmethod* _nm;
2086   bool     _ok;
2087 public:
2088   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2089   bool ok() { return _ok; }
2090   virtual void do_oop(oop* p) {
2091     if (oopDesc::is_oop_or_null(*p)) return;




2092     if (_ok) {
2093       _nm->print_nmethod(true);
2094       _ok = false;
2095     }
2096     tty->print_cr("*** non-oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2097                   p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2098   }
2099   virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2100 };
2101 
2102 void nmethod::verify() {
2103 
2104   // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant
2105   // seems odd.
2106 
2107   if (is_zombie() || is_not_entrant() || is_unloaded())
2108     return;
2109 
2110   // Make sure all the entry points are correctly aligned for patching.
2111   NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point());
2112 
2113   // assert(oopDesc::is_oop(method()), "must be valid");
2114 
2115   ResourceMark rm;
2116 
2117   if (!CodeCache::contains(this)) {


2186       case relocInfo::runtime_call_type:
2187       case relocInfo::runtime_call_w_cp_type: {
2188         address destination = iter.reloc()->value();
2189         // Right now there is no way to find out which entries support
2190         // an interrupt point.  It would be nice if we had this
2191         // information in a table.
2192         break;
2193       }
2194       default:
2195         break;
2196     }
2197     assert(stub == NULL || stub_contains(stub), "static call stub outside stub section");
2198   }
2199 }
2200 
2201 
2202 // -----------------------------------------------------------------------------
2203 // Printing operations
2204 
2205 void nmethod::print() const {
2206   ResourceMark rm;
2207   ttyLocker ttyl;   // keep the following output all in one block





2208 
2209   tty->print("Compiled method ");
2210 


2211   if (is_compiled_by_c1()) {
2212     tty->print("(c1) ");
2213   } else if (is_compiled_by_c2()) {
2214     tty->print("(c2) ");

2215   } else if (is_compiled_by_jvmci()) {
2216     tty->print("(JVMCI) ");

2217   } else {
2218     tty->print("(nm) ");
2219   }
2220 
2221   print_on(tty, NULL);










2222 
2223   if (WizardMode) {
2224     tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this));
2225     tty->print(" for method " INTPTR_FORMAT , p2i(method()));
2226     tty->print(" { ");
2227     tty->print_cr("%s ", state());
2228     tty->print_cr("}:");
2229   }
2230   if (size              () > 0) tty->print_cr(" total in heap  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2231                                               p2i(this),
2232                                               p2i(this) + size(),
2233                                               size());
2234   if (relocation_size   () > 0) tty->print_cr(" relocation     [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2235                                               p2i(relocation_begin()),
2236                                               p2i(relocation_end()),
2237                                               relocation_size());
2238   if (consts_size       () > 0) tty->print_cr(" constants      [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2239                                               p2i(consts_begin()),
2240                                               p2i(consts_end()),
2241                                               consts_size());
2242   if (insts_size        () > 0) tty->print_cr(" main code      [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2243                                               p2i(insts_begin()),
2244                                               p2i(insts_end()),
2245                                               insts_size());
2246   if (stub_size         () > 0) tty->print_cr(" stub code      [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2247                                               p2i(stub_begin()),
2248                                               p2i(stub_end()),
2249                                               stub_size());
2250   if (oops_size         () > 0) tty->print_cr(" oops           [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2251                                               p2i(oops_begin()),
2252                                               p2i(oops_end()),
2253                                               oops_size());
2254   if (metadata_size      () > 0) tty->print_cr(" metadata       [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2255                                               p2i(metadata_begin()),
2256                                               p2i(metadata_end()),
2257                                               metadata_size());
2258   if (scopes_data_size  () > 0) tty->print_cr(" scopes data    [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2259                                               p2i(scopes_data_begin()),
2260                                               p2i(scopes_data_end()),
2261                                               scopes_data_size());
2262   if (scopes_pcs_size   () > 0) tty->print_cr(" scopes pcs     [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2263                                               p2i(scopes_pcs_begin()),
2264                                               p2i(scopes_pcs_end()),
2265                                               scopes_pcs_size());
2266   if (dependencies_size () > 0) tty->print_cr(" dependencies   [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2267                                               p2i(dependencies_begin()),
2268                                               p2i(dependencies_end()),
2269                                               dependencies_size());
2270   if (handler_table_size() > 0) tty->print_cr(" handler table  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2271                                               p2i(handler_table_begin()),
2272                                               p2i(handler_table_end()),
2273                                               handler_table_size());
2274   if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2275                                               p2i(nul_chk_table_begin()),
2276                                               p2i(nul_chk_table_end()),
2277                                               nul_chk_table_size());
2278 }
2279 
2280 #ifndef PRODUCT
2281 
2282 void nmethod::print_scopes() {
2283   // Find the first pc desc for all scopes in the code and print it.
2284   ResourceMark rm;
2285   for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2286     if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null)
2287       continue;
2288 
2289     ScopeDesc* sd = scope_desc_at(p->real_pc(this));
2290     while (sd != NULL) {
2291       sd->print_on(tty, p);
2292       sd = sd->sender();
2293     }
2294   }
2295 }
2296 

2297 void nmethod::print_dependencies() {
2298   ResourceMark rm;
2299   ttyLocker ttyl;   // keep the following output all in one block
2300   tty->print_cr("Dependencies:");
2301   for (Dependencies::DepStream deps(this); deps.next(); ) {
2302     deps.print_dependency();
2303     Klass* ctxk = deps.context_type();
2304     if (ctxk != NULL) {
2305       if (ctxk->is_instance_klass() && InstanceKlass::cast(ctxk)->is_dependent_nmethod(this)) {
2306         tty->print_cr("   [nmethod<=klass]%s", ctxk->external_name());
2307       }
2308     }
2309     deps.log_dependency();  // put it into the xml log also
2310   }
2311 }




























































2312 











2313 

2314 void nmethod::print_relocations() {
2315   ResourceMark m;       // in case methods get printed via the debugger
2316   tty->print_cr("relocations:");
2317   RelocIterator iter(this);
2318   iter.print();
2319 }

2320 
2321 
2322 void nmethod::print_pcs() {
2323   ResourceMark m;       // in case methods get printed via debugger
2324   tty->print_cr("pc-bytecode offsets:");


2325   for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2326     p->print(this);



2327   }
2328 }
2329 








2330 void nmethod::print_recorded_oops() {
2331   tty->print_cr("Recorded oops:");
2332   for (int i = 0; i < oops_count(); i++) {




2333     oop o = oop_at(i);
2334     tty->print("#%3d: " INTPTR_FORMAT " ", i, p2i(o));
2335     if (o == Universe::non_oop_word()) {
2336       tty->print("non-oop word");


2337     } else {
2338       if (o != NULL) {
2339         o->print_value();
2340       } else {
2341         tty->print_cr("NULL");
2342       }
2343     }
2344     tty->cr();
2345   }



2346 }
2347 
2348 void nmethod::print_recorded_metadata() {
2349   tty->print_cr("Recorded metadata:");
2350   for (int i = 0; i < metadata_count(); i++) {




2351     Metadata* m = metadata_at(i);
2352     tty->print("#%3d: " INTPTR_FORMAT " ", i, p2i(m));
2353     if (m == (Metadata*)Universe::non_oop_word()) {
2354       tty->print("non-metadata word");


2355     } else {
2356       Metadata::print_value_on_maybe_null(tty, m);
2357     }
2358     tty->cr();
2359   }


































































































































































































































2360 }
2361 
2362 #endif // PRODUCT
2363 
2364 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) {
2365   RelocIterator iter(this, begin, end);
2366   bool have_one = false;
2367   while (iter.next()) {
2368     have_one = true;
2369     switch (iter.type()) {
2370         case relocInfo::none:                  return "no_reloc";
2371         case relocInfo::oop_type: {
2372           stringStream st;


2373           oop_Relocation* r = iter.oop_reloc();
2374           oop obj = r->oop_value();
2375           st.print("oop(");
2376           if (obj == NULL) st.print("NULL");
2377           else obj->print_value_on(&st);
2378           st.print(")");
2379           return st.as_string();
2380         }
2381         case relocInfo::metadata_type: {
2382           stringStream st;
2383           metadata_Relocation* r = iter.metadata_reloc();
2384           Metadata* obj = r->metadata_value();
2385           st.print("metadata(");
2386           if (obj == NULL) st.print("NULL");
2387           else obj->print_value_on(&st);
2388           st.print(")");
2389           return st.as_string();
2390         }
2391         case relocInfo::runtime_call_type:
2392         case relocInfo::runtime_call_w_cp_type: {


2454         case relocInfo::type_mask:             return "type_bit_mask";
2455 
2456         default:
2457           break;
2458     }
2459   }
2460   return have_one ? "other" : NULL;
2461 }
2462 
2463 // Return a the last scope in (begin..end]
2464 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
2465   PcDesc* p = pc_desc_near(begin+1);
2466   if (p != NULL && p->real_pc(this) <= end) {
2467     return new ScopeDesc(this, p->scope_decode_offset(),
2468                          p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(),
2469                          p->return_oop());
2470   }
2471   return NULL;
2472 }
2473 
2474 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const {
2475   if (block_begin == entry_point())             stream->print_cr("[Entry Point]");
2476   if (block_begin == verified_entry_point())    stream->print_cr("[Verified Entry Point]");
2477   if (JVMCI_ONLY(_exception_offset >= 0 &&) block_begin == exception_begin())         stream->print_cr("[Exception Handler]");
2478   if (block_begin == stub_begin())              stream->print_cr("[Stub Code]");
2479   if (JVMCI_ONLY(_deopt_handler_begin != NULL &&) block_begin == deopt_handler_begin())     stream->print_cr("[Deopt Handler Code]");
2480 
2481   if (has_method_handle_invokes())
2482     if (block_begin == deopt_mh_handler_begin())  stream->print_cr("[Deopt MH Handler Code]");
2483 
2484   if (block_begin == consts_begin())            stream->print_cr("[Constants]");











2485 
2486   if (block_begin == entry_point()) {
2487     methodHandle m = method();
2488     if (m.not_null()) {
2489       stream->print("  # ");
2490       m->print_value_on(stream);
2491       stream->cr();
2492     }
2493     if (m.not_null() && !is_osr_method()) {
2494       ResourceMark rm;
2495       int sizeargs = m->size_of_parameters();
2496       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
2497       VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
2498       {
2499         int sig_index = 0;
2500         if (!m->is_static())
2501           sig_bt[sig_index++] = T_OBJECT; // 'this'
2502         for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
2503           BasicType t = ss.type();
2504           sig_bt[sig_index++] = t;


2561         if (at_old_sp) {
2562           stream->print("  (%s of caller)", spname);
2563           did_old_sp = true;
2564         }
2565         stream->cr();
2566         sig_index += type2size[t];
2567         arg_index += 1;
2568         if (!at_this)  ss.next();
2569       }
2570       if (!did_old_sp) {
2571         stream->print("  # ");
2572         stream->move_to(tab1);
2573         stream->print("[%s+0x%x]", spname, stack_slot_offset);
2574         stream->print("  (%s of caller)", spname);
2575         stream->cr();
2576       }
2577     }
2578   }
2579 }
2580 
2581 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) {

















2582   // First, find an oopmap in (begin, end].
2583   // We use the odd half-closed interval so that oop maps and scope descs
2584   // which are tied to the byte after a call are printed with the call itself.
2585   address base = code_begin();
2586   ImmutableOopMapSet* oms = oop_maps();
2587   if (oms != NULL) {
2588     for (int i = 0, imax = oms->count(); i < imax; i++) {
2589       const ImmutableOopMapPair* pair = oms->pair_at(i);
2590       const ImmutableOopMap* om = pair->get_from(oms);
2591       address pc = base + pair->pc_offset();
2592       if (pc > begin) {
2593         if (pc <= end) {
2594           st->move_to(column);
2595           st->print("; ");
2596           om->print_on(st);
2597         }
2598         break;
2599       }
2600     }
2601   }
2602 
2603   // Print any debug info present at this pc.
2604   ScopeDesc* sd  = scope_desc_in(begin, end);
2605   if (sd != NULL) {
2606     st->move_to(column);
2607     if (sd->bci() == SynchronizationEntryBCI) {
2608       st->print(";*synchronization entry");
2609     } else if (sd->bci() == AfterBci) {
2610       st->print(";* method exit (unlocked if synchronized)");
2611     } else if (sd->bci() == UnwindBci) {
2612       st->print(";* unwind (locked if synchronized)");
2613     } else if (sd->bci() == AfterExceptionBci) {
2614       st->print(";* unwind (unlocked if synchronized)");
2615     } else if (sd->bci() == UnknownBci) {
2616       st->print(";* unknown");
2617     } else if (sd->bci() == InvalidFrameStateBci) {
2618       st->print(";* invalid frame state");
2619     } else {
2620       if (sd->method() == NULL) {
2621         st->print("method is NULL");
2622       } else if (sd->method()->is_native()) {
2623         st->print("method is native");
2624       } else {
2625         Bytecodes::Code bc = sd->method()->java_code_at(sd->bci());
2626         st->print(";*%s", Bytecodes::name(bc));


2642         case Bytecodes::_putfield:
2643         case Bytecodes::_getstatic:
2644         case Bytecodes::_putstatic:
2645           {
2646             Bytecode_field field(sd->method(), sd->bci());
2647             st->print(" ");
2648             if (field.name() != NULL)
2649               field.name()->print_symbol_on(st);
2650             else
2651               st->print("<UNKNOWN>");
2652           }
2653         default:
2654           break;
2655         }
2656       }
2657       st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
2658     }
2659 
2660     // Print all scopes
2661     for (;sd != NULL; sd = sd->sender()) {
2662       st->move_to(column);
2663       st->print("; -");



2664       if (sd->method() == NULL) {
2665         st->print("method is NULL");
2666       } else {
2667         sd->method()->print_short_name(st);
2668       }
2669       int lineno = sd->method()->line_number_from_bci(sd->bci());
2670       if (lineno != -1) {
2671         st->print("@%d (line %d)", sd->bci(), lineno);
2672       } else {
2673         st->print("@%d", sd->bci());
2674       }
2675       st->cr();
2676     }
2677   }
2678 
2679   // Print relocation information


2680   const char* str = reloc_string_for(begin, end);
2681   if (str != NULL) {
2682     if (sd != NULL) st->cr();
2683     st->move_to(column);
2684     st->print(";   {%s}", str);
2685   }
2686   int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin());
2687   if (cont_offset != 0) {
2688     st->move_to(column);
2689     st->print("; implicit exception: dispatches to " INTPTR_FORMAT, p2i(code_begin() + cont_offset));
2690   }
2691 
2692 }
2693 


2694 class DirectNativeCallWrapper: public NativeCallWrapper {
2695 private:
2696   NativeCall* _call;
2697 
2698 public:
2699   DirectNativeCallWrapper(NativeCall* call) : _call(call) {}
2700 
2701   virtual address destination() const { return _call->destination(); }
2702   virtual address instruction_address() const { return _call->instruction_address(); }
2703   virtual address next_instruction_address() const { return _call->next_instruction_address(); }
2704   virtual address return_address() const { return _call->return_address(); }
2705 
2706   virtual address get_resolve_call_stub(bool is_optimized) const {
2707     if (is_optimized) {
2708       return SharedRuntime::get_resolve_opt_virtual_call_stub();
2709     }
2710     return SharedRuntime::get_resolve_virtual_call_stub();
2711   }
2712 
2713   virtual void set_destination_mt_safe(address dest) {


2780 address nmethod::call_instruction_address(address pc) const {
2781   if (NativeCall::is_call_before(pc)) {
2782     NativeCall *ncall = nativeCall_before(pc);
2783     return ncall->instruction_address();
2784   }
2785   return NULL;
2786 }
2787 
2788 CompiledStaticCall* nmethod::compiledStaticCall_at(Relocation* call_site) const {
2789   return CompiledDirectStaticCall::at(call_site);
2790 }
2791 
2792 CompiledStaticCall* nmethod::compiledStaticCall_at(address call_site) const {
2793   return CompiledDirectStaticCall::at(call_site);
2794 }
2795 
2796 CompiledStaticCall* nmethod::compiledStaticCall_before(address return_addr) const {
2797   return CompiledDirectStaticCall::before(return_addr);
2798 }
2799 
2800 #ifndef PRODUCT
2801 
2802 void nmethod::print_value_on(outputStream* st) const {
2803   st->print("nmethod");
2804   print_on(st, NULL);
2805 }



2806 
2807 void nmethod::print_calls(outputStream* st) {
2808   RelocIterator iter(this);
2809   while (iter.next()) {
2810     switch (iter.type()) {
2811     case relocInfo::virtual_call_type:
2812     case relocInfo::opt_virtual_call_type: {
2813       CompiledICLocker ml_verify(this);
2814       CompiledIC_at(&iter)->print();
2815       break;
2816     }
2817     case relocInfo::static_call_type:
2818       st->print_cr("Static call at " INTPTR_FORMAT, p2i(iter.reloc()->addr()));
2819       CompiledDirectStaticCall::at(iter.reloc())->print();
2820       break;
2821     default:
2822       break;
2823     }
2824   }
2825 }
2826 
2827 void nmethod::print_handler_table() {
2828   ExceptionHandlerTable(this).print();
2829 }
2830 
2831 void nmethod::print_nul_chk_table() {
2832   ImplicitExceptionTable(this).print(code_begin());
2833 }
2834 
2835 void nmethod::print_statistics() {
2836   ttyLocker ttyl;
2837   if (xtty != NULL)  xtty->head("statistics type='nmethod'");
2838   native_nmethod_stats.print_native_nmethod_stats();
2839 #ifdef COMPILER1
2840   c1_java_nmethod_stats.print_nmethod_stats("C1");
2841 #endif
2842 #ifdef COMPILER2
2843   c2_java_nmethod_stats.print_nmethod_stats("C2");
2844 #endif
2845 #if INCLUDE_JVMCI
2846   jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
2847 #endif
2848   unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2849   DebugInformationRecorder::print_statistics();
2850 #ifndef PRODUCT
2851   pc_nmethod_stats.print_pc_stats();
2852 #endif




   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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "asm/assembler.inline.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "code/compiledIC.hpp"
  30 #include "code/compiledMethod.inline.hpp"
  31 #include "code/dependencies.hpp"
  32 #include "code/nativeInst.hpp"
  33 #include "code/nmethod.hpp"
  34 #include "code/scopeDesc.hpp"
  35 #include "compiler/abstractCompiler.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "compiler/compileLog.hpp"
  38 #include "compiler/compilerDirectives.hpp"
  39 #include "compiler/directivesParser.hpp"
  40 #include "compiler/disassembler.hpp"
  41 #include "interpreter/bytecode.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logStream.hpp"
  44 #include "memory/allocation.inline.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "oops/access.inline.hpp"
  47 #include "oops/method.inline.hpp"


 432   _speculation_log        = NULL;
 433   _jvmci_installed_code_triggers_invalidation = false;
 434 #endif
 435 }
 436 
 437 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
 438   int compile_id,
 439   CodeBuffer *code_buffer,
 440   int vep_offset,
 441   int frame_complete,
 442   int frame_size,
 443   ByteSize basic_lock_owner_sp_offset,
 444   ByteSize basic_lock_sp_offset,
 445   OopMapSet* oop_maps) {
 446   code_buffer->finalize_oop_references(method);
 447   // create nmethod
 448   nmethod* nm = NULL;
 449   {
 450     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 451     int native_nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod));
 452 
 453     CodeOffsets offsets;
 454     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 455     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 456     nm = new (native_nmethod_size, CompLevel_none)
 457     nmethod(method(), compiler_none, native_nmethod_size,
 458             compile_id, &offsets,
 459             code_buffer, frame_size,
 460             basic_lock_owner_sp_offset,
 461             basic_lock_sp_offset,
 462             oop_maps);
 463     NOT_PRODUCT(if (nm != NULL)  native_nmethod_stats.note_native_nmethod(nm));
 464   }
 465 
 466   if (nm != NULL) {
 467     // verify nmethod
 468     debug_only(nm->verify();) // might block
 469 
 470     nm->log_new_nmethod();
 471     nm->make_in_use();
 472   }
 473   return nm;
 474 }
 475 
 476 nmethod* nmethod::new_nmethod(const methodHandle& method,
 477   int compile_id,
 478   int entry_bci,
 479   CodeOffsets* offsets,
 480   int orig_pc_offset,
 481   DebugInformationRecorder* debug_info,
 482   Dependencies* dependencies,


 614 
 615     clear_unloading_state();
 616 
 617     Universe::heap()->register_nmethod(this);
 618     debug_only(Universe::heap()->verify_nmethod(this));
 619 
 620     CodeCache::commit(this);
 621   }
 622 
 623   if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 624     ttyLocker ttyl;  // keep the following output all in one block
 625     // This output goes directly to the tty, not the compiler log.
 626     // To enable tools to match it up with the compilation activity,
 627     // be sure to tag this tty output with the compile ID.
 628     if (xtty != NULL) {
 629       xtty->begin_head("print_native_nmethod");
 630       xtty->method(_method);
 631       xtty->stamp();
 632       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 633     }
 634     // Print the header part, then print the requested information.
 635     // This is both handled in decode2(), called via print_code() -> decode()

 636     if (PrintNativeNMethods) {
 637       tty->print_cr("-------------------------- Assembly (native nmethod) ---------------------------");
 638       print_code();
 639       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 640 #if defined(SUPPORT_DATA_STRUCTS)
 641       if (AbstractDisassembler::show_structs()) {
 642         if (oop_maps != NULL) {
 643           tty->print("oop maps:"); // oop_maps->print_on(tty) outputs a cr() at the beginning
 644           oop_maps->print_on(tty);
 645           tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 646         }
 647       }
 648 #endif
 649     } else {
 650       print(); // print the header part only.
 651     }
 652 #if defined(SUPPORT_DATA_STRUCTS)
 653     if (AbstractDisassembler::show_structs()) {
 654       if (PrintRelocations) {
 655         print_relocations();
 656         tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 657       }
 658     }
 659 #endif
 660     if (xtty != NULL) {
 661       xtty->tail("print_native_nmethod");
 662     }
 663   }
 664 }
 665 
 666 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () {
 667   return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level));
 668 }
 669 
 670 nmethod::nmethod(
 671   Method* method,
 672   CompilerType type,
 673   int nmethod_size,
 674   int compile_id,
 675   int entry_bci,
 676   CodeOffsets* offsets,
 677   int orig_pc_offset,
 678   DebugInformationRecorder* debug_info,
 679   Dependencies* dependencies,


 724       _jvmci_installed_code_triggers_invalidation = true;
 725     }
 726 
 727     if (compiler->is_jvmci()) {
 728       // JVMCI might not produce any stub sections
 729       if (offsets->value(CodeOffsets::Exceptions) != -1) {
 730         _exception_offset        = code_offset()          + offsets->value(CodeOffsets::Exceptions);
 731       } else {
 732         _exception_offset = -1;
 733       }
 734       if (offsets->value(CodeOffsets::Deopt) != -1) {
 735         _deopt_handler_begin       = (address) this + code_offset()          + offsets->value(CodeOffsets::Deopt);
 736       } else {
 737         _deopt_handler_begin = NULL;
 738       }
 739       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
 740         _deopt_mh_handler_begin  = (address) this + code_offset()          + offsets->value(CodeOffsets::DeoptMH);
 741       } else {
 742         _deopt_mh_handler_begin = NULL;
 743       }
 744     } else
 745 #endif
 746     {
 747       // Exception handler and deopt handler are in the stub section
 748       assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set");
 749       assert(offsets->value(CodeOffsets::Deopt     ) != -1, "must be set");
 750 
 751       _exception_offset       = _stub_offset          + offsets->value(CodeOffsets::Exceptions);
 752       _deopt_handler_begin    = (address) this + _stub_offset          + offsets->value(CodeOffsets::Deopt);
 753       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
 754         _deopt_mh_handler_begin  = (address) this + _stub_offset          + offsets->value(CodeOffsets::DeoptMH);
 755       } else {
 756         _deopt_mh_handler_begin  = NULL;

 757       }

 758     }
 759     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
 760       _unwind_handler_offset = code_offset()         + offsets->value(CodeOffsets::UnwindHandler);
 761     } else {
 762       _unwind_handler_offset = -1;
 763     }
 764 
 765     _oops_offset             = data_offset();
 766     _metadata_offset         = _oops_offset          + align_up(code_buffer->total_oop_size(), oopSize);
 767     int scopes_data_offset   = _metadata_offset      + align_up(code_buffer->total_metadata_size(), wordSize);
 768 
 769     _scopes_pcs_offset       = scopes_data_offset    + align_up(debug_info->data_size       (), oopSize);
 770     _dependencies_offset     = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
 771     _handler_table_offset    = _dependencies_offset  + align_up((int)dependencies->size_in_bytes (), oopSize);
 772     _nul_chk_table_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
 773     _nmethod_end_offset      = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
 774     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 775     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 776     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 777     _exception_cache         = NULL;

 778     _scopes_data_begin       = (address) this + scopes_data_offset;
 779 
 780     _pc_desc_container.reset_to(scopes_pcs_begin());
 781 
 782     code_buffer->copy_code_and_locs_to(this);
 783     // Copy contents of ScopeDescRecorder to nmethod
 784     code_buffer->copy_values_to(this);
 785     debug_info->copy_to(this);
 786     dependencies->copy_to(this);
 787     clear_unloading_state();
 788 
 789     Universe::heap()->register_nmethod(this);
 790     debug_only(Universe::heap()->verify_nmethod(this));
 791 
 792     CodeCache::commit(this);
 793 
 794     // Copy contents of ExceptionHandlerTable to nmethod
 795     handler_table->copy_to(this);
 796     nul_chk_table->copy_to(this);
 797 


 871     } else {
 872       CompileTask::print(st, this, msg, /*short_form:*/ false);
 873     }
 874   }
 875 }
 876 
 877 void nmethod::maybe_print_nmethod(DirectiveSet* directive) {
 878   bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
 879   if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
 880     print_nmethod(printnmethods);
 881   }
 882 }
 883 
 884 void nmethod::print_nmethod(bool printmethod) {
 885   ttyLocker ttyl;  // keep the following output all in one block
 886   if (xtty != NULL) {
 887     xtty->begin_head("print_nmethod");
 888     xtty->stamp();
 889     xtty->end_head();
 890   }
 891   // Print the header part, then print the requested information.
 892   // This is both handled in decode2().

 893   if (printmethod) {
 894     HandleMark hm;
 895     ResourceMark m;
 896     if (is_compiled_by_c1()) {
 897       tty->cr();
 898       tty->print_cr("============================= C1-compiled nmethod ==============================");
 899     }
 900     if (is_compiled_by_jvmci()) {
 901       tty->cr();
 902       tty->print_cr("=========================== JVMCI-compiled nmethod =============================");
 903     }
 904     tty->print_cr("----------------------------------- Assembly -----------------------------------");
 905     decode2(tty);
 906 #if defined(SUPPORT_DATA_STRUCTS)
 907     if (AbstractDisassembler::show_structs()) {
 908       // Print the oops from the underlying CodeBlob as well.
 909       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 910       print_oops(tty);
 911       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 912       print_metadata(tty);
 913       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 914       print_pcs();
 915       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 916       if (oop_maps() != NULL) {
 917         tty->print("oop maps:"); // oop_maps()->print_on(tty) outputs a cr() at the beginning
 918         oop_maps()->print_on(tty);
 919         tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 920       }
 921     }
 922 #endif
 923   } else {
 924     print(); // print the header part only.
 925   }
 926 
 927 #if defined(SUPPORT_DATA_STRUCTS)
 928   if (AbstractDisassembler::show_structs()) {
 929     if (printmethod || PrintDebugInfo || CompilerOracle::has_option_string(_method, "PrintDebugInfo")) {
 930       print_scopes();
 931       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 932     }
 933     if (printmethod || PrintRelocations || CompilerOracle::has_option_string(_method, "PrintRelocations")) {
 934       print_relocations();
 935       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 936     }
 937     if (printmethod || PrintDependencies || CompilerOracle::has_option_string(_method, "PrintDependencies")) {
 938       print_dependencies();
 939       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 940     }
 941     if (printmethod || PrintExceptionHandlers) {
 942       print_handler_table();
 943       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 944       print_nul_chk_table();
 945       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 946     }
 947 
 948     if (printmethod) {
 949       print_recorded_oops();
 950       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 951       print_recorded_metadata();
 952       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 953     }
 954   }
 955 #endif
 956 
 957   if (xtty != NULL) {
 958     xtty->tail("print_nmethod");
 959   }
 960 }
 961 
 962 
 963 // Promote one word from an assembly-time handle to a live embedded oop.
 964 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) {
 965   if (handle == NULL ||
 966       // As a special case, IC oops are initialized to 1 or -1.
 967       handle == (jobject) Universe::non_oop_word()) {
 968     (*dest) = (oop) handle;
 969   } else {
 970     (*dest) = JNIHandles::resolve_non_null(handle);
 971   }
 972 }
 973 
 974 
 975 // Have to have the same name because it's called by a template
 976 void nmethod::copy_values(GrowableArray<jobject>* array) {


2065   }
2066   return true;
2067 }
2068 
2069 
2070 address nmethod::continuation_for_implicit_exception(address pc) {
2071   // Exception happened outside inline-cache check code => we are inside
2072   // an active nmethod => use cpc to determine a return address
2073   int exception_offset = pc - code_begin();
2074   int cont_offset = ImplicitExceptionTable(this).at( exception_offset );
2075 #ifdef ASSERT
2076   if (cont_offset == 0) {
2077     Thread* thread = Thread::current();
2078     ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
2079     HandleMark hm(thread);
2080     ResourceMark rm(thread);
2081     CodeBlob* cb = CodeCache::find_blob(pc);
2082     assert(cb != NULL && cb == this, "");
2083     ttyLocker ttyl;
2084     tty->print_cr("implicit exception happened at " INTPTR_FORMAT, p2i(pc));
2085     // Print all available nmethod info.
2086     print_nmethod(true);
2087     method()->print_codes();


2088   }
2089 #endif
2090   if (cont_offset == 0) {
2091     // Let the normal error handling report the exception
2092     return NULL;
2093   }
2094   return code_begin() + cont_offset;
2095 }
2096 
2097 

2098 void nmethod_init() {
2099   // make sure you didn't forget to adjust the filler fields
2100   assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
2101 }
2102 
2103 
2104 //-------------------------------------------------------------------------------------------
2105 
2106 
2107 // QQQ might we make this work from a frame??
2108 nmethodLocker::nmethodLocker(address pc) {
2109   CodeBlob* cb = CodeCache::find_blob(pc);
2110   guarantee(cb != NULL && cb->is_compiled(), "bad pc for a nmethod found");
2111   _nm = cb->as_compiled_method();
2112   lock_nmethod(_nm);
2113 }
2114 
2115 // Only JvmtiDeferredEvent::compiled_method_unload_event()
2116 // should pass zombie_ok == true.
2117 void nmethodLocker::lock_nmethod(CompiledMethod* cm, bool zombie_ok) {


2125 void nmethodLocker::unlock_nmethod(CompiledMethod* cm) {
2126   if (cm == NULL)  return;
2127   if (cm->is_aot()) return;  // FIXME: Revisit once _lock_count is added to aot_method
2128   nmethod* nm = cm->as_nmethod();
2129   Atomic::dec(&nm->_lock_count);
2130   assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
2131 }
2132 
2133 
2134 // -----------------------------------------------------------------------------
2135 // Verification
2136 
2137 class VerifyOopsClosure: public OopClosure {
2138   nmethod* _nm;
2139   bool     _ok;
2140 public:
2141   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2142   bool ok() { return _ok; }
2143   virtual void do_oop(oop* p) {
2144     if (oopDesc::is_oop_or_null(*p)) return;
2145     // Print diagnostic information before calling print_nmethod().
2146     // Assertions therein might prevent call from returning.
2147     tty->print_cr("*** non-oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2148                   p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2149     if (_ok) {
2150       _nm->print_nmethod(true);
2151       _ok = false;
2152     }


2153   }
2154   virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2155 };
2156 
2157 void nmethod::verify() {
2158 
2159   // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant
2160   // seems odd.
2161 
2162   if (is_zombie() || is_not_entrant() || is_unloaded())
2163     return;
2164 
2165   // Make sure all the entry points are correctly aligned for patching.
2166   NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point());
2167 
2168   // assert(oopDesc::is_oop(method()), "must be valid");
2169 
2170   ResourceMark rm;
2171 
2172   if (!CodeCache::contains(this)) {


2241       case relocInfo::runtime_call_type:
2242       case relocInfo::runtime_call_w_cp_type: {
2243         address destination = iter.reloc()->value();
2244         // Right now there is no way to find out which entries support
2245         // an interrupt point.  It would be nice if we had this
2246         // information in a table.
2247         break;
2248       }
2249       default:
2250         break;
2251     }
2252     assert(stub == NULL || stub_contains(stub), "static call stub outside stub section");
2253   }
2254 }
2255 
2256 
2257 // -----------------------------------------------------------------------------
2258 // Printing operations
2259 
2260 void nmethod::print() const {

2261   ttyLocker ttyl;   // keep the following output all in one block
2262   print(tty);
2263 }
2264 
2265 void nmethod::print(outputStream* st) const {
2266   ResourceMark rm;
2267 
2268   st->print("Compiled method ");
2269 
2270   // Print compilation level in addition
2271   st->print("(t%c)", tier_digit(comp_level()));
2272   if (is_compiled_by_c1()) {
2273     st->print("(c1) ");
2274   } else if (is_compiled_by_c2()) {
2275     st->print("(c2) ");
2276 #if defined(INCLUDE_JVMCI)
2277   } else if (is_compiled_by_jvmci()) {
2278     st->print("(JVMCI) ");
2279 #endif
2280   } else {
2281     st->print("(nm) ");
2282   }
2283 
2284   print_on(st, NULL);
2285 
2286 #if INCLUDE_JVMCI
2287   {
2288     char buffer[O_BUFLEN];
2289     char* jvmciName = jvmci_installed_code_name(buffer, O_BUFLEN);
2290     if (jvmciName != NULL) {
2291       st->print(" (%s)", jvmciName);
2292     }
2293   }
2294 #endif
2295 
2296   if (WizardMode) {
2297     st->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this));
2298     st->print(" for method " INTPTR_FORMAT , p2i(method()));
2299     st->print(" { ");
2300     st->print_cr("%s ", state());
2301     st->print_cr("}:");
2302   }
2303   if (size              () > 0) st->print_cr(" total in heap  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2304                                              p2i(this),
2305                                              p2i(this) + size(),
2306                                              size());
2307   if (relocation_size   () > 0) st->print_cr(" relocation     [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2308                                              p2i(relocation_begin()),
2309                                              p2i(relocation_end()),
2310                                              relocation_size());
2311   if (consts_size       () > 0) st->print_cr(" constants      [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2312                                              p2i(consts_begin()),
2313                                              p2i(consts_end()),
2314                                              consts_size());
2315   if (insts_size        () > 0) st->print_cr(" main code      [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2316                                              p2i(insts_begin()),
2317                                              p2i(insts_end()),
2318                                              insts_size());
2319   if (stub_size         () > 0) st->print_cr(" stub code      [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2320                                              p2i(stub_begin()),
2321                                              p2i(stub_end()),
2322                                              stub_size());
2323   if (oops_size         () > 0) st->print_cr(" oops           [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2324                                              p2i(oops_begin()),
2325                                              p2i(oops_end()),
2326                                              oops_size());
2327   if (metadata_size     () > 0) st->print_cr(" metadata       [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2328                                              p2i(metadata_begin()),
2329                                              p2i(metadata_end()),
2330                                              metadata_size());
2331   if (scopes_data_size  () > 0) st->print_cr(" scopes data    [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2332                                              p2i(scopes_data_begin()),
2333                                              p2i(scopes_data_end()),
2334                                              scopes_data_size());
2335   if (scopes_pcs_size   () > 0) st->print_cr(" scopes pcs     [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2336                                              p2i(scopes_pcs_begin()),
2337                                              p2i(scopes_pcs_end()),
2338                                              scopes_pcs_size());
2339   if (dependencies_size () > 0) st->print_cr(" dependencies   [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2340                                              p2i(dependencies_begin()),
2341                                              p2i(dependencies_end()),
2342                                              dependencies_size());
2343   if (handler_table_size() > 0) st->print_cr(" handler table  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2344                                              p2i(handler_table_begin()),
2345                                              p2i(handler_table_end()),
2346                                              handler_table_size());
2347   if (nul_chk_table_size() > 0) st->print_cr(" nul chk table  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2348                                              p2i(nul_chk_table_begin()),
2349                                              p2i(nul_chk_table_end()),
2350                                              nul_chk_table_size());
2351 }
2352 
2353 void nmethod::print_code() {
2354   HandleMark hm;
2355   ResourceMark m;
2356   ttyLocker ttyl;
2357   // Call the specialized decode method of this class.
2358   decode(tty);









2359 }
2360 
2361 #ifndef PRODUCT  // called InstanceKlass methods are available only then. Declared as PRODUCT_RETURN
2362 void nmethod::print_dependencies() {
2363   ResourceMark rm;
2364   ttyLocker ttyl;   // keep the following output all in one block
2365   tty->print_cr("Dependencies:");
2366   for (Dependencies::DepStream deps(this); deps.next(); ) {
2367     deps.print_dependency();
2368     Klass* ctxk = deps.context_type();
2369     if (ctxk != NULL) {
2370       if (ctxk->is_instance_klass() && InstanceKlass::cast(ctxk)->is_dependent_nmethod(this)) {
2371         tty->print_cr("   [nmethod<=klass]%s", ctxk->external_name());
2372       }
2373     }
2374     deps.log_dependency();  // put it into the xml log also
2375   }
2376 }
2377 #endif
2378 
2379 #if defined(SUPPORT_DATA_STRUCTS)
2380 
2381 // Print the oops from the underlying CodeBlob.
2382 void nmethod::print_oops(outputStream* st) {
2383   HandleMark hm;
2384   ResourceMark m;
2385   st->print("Oops:");
2386   if (oops_begin() < oops_end()) {
2387     st->cr();
2388     for (oop* p = oops_begin(); p < oops_end(); p++) {
2389       Disassembler::print_location((unsigned char*)p, (unsigned char*)oops_begin(), (unsigned char*)oops_end(), st, true, false);
2390       st->print("0x%016lx ", *((unsigned long*)p));
2391       if (*p == Universe::non_oop_word()) {
2392         st->print_cr("NON_OOP");
2393         continue;  // skip non-oops
2394       }
2395       if (*p == NULL) {
2396         st->print_cr("LUCY: NULL-oop");
2397         continue;  // skip non-oops
2398       }
2399       (*p)->print_value_on(st);
2400       st->cr();
2401     }
2402   } else {
2403     st->print_cr(" <list empty>");
2404   }
2405 }
2406 
2407 // Print metadata pool.
2408 void nmethod::print_metadata(outputStream* st) {
2409   HandleMark hm;
2410   ResourceMark m;
2411   st->print("Metadata:");
2412   if (metadata_begin() < metadata_end()) {
2413     st->cr();
2414     for (Metadata** p = metadata_begin(); p < metadata_end(); p++) {
2415       Disassembler::print_location((unsigned char*)p, (unsigned char*)metadata_begin(), (unsigned char*)metadata_end(), st, true, false);
2416       st->print("0x%016lx ", *((unsigned long*)p));
2417       if (*p && *p != Universe::non_oop_word()) {
2418         (*p)->print_value_on(st);
2419       }
2420       st->cr();
2421     }
2422   } else {
2423     st->print_cr(" <list empty>");
2424   }
2425 }
2426 
2427 #ifndef PRODUCT  // ScopeDesc::print_on() is available only then. Declared as PRODUCT_RETURN
2428 void nmethod::print_scopes_on(outputStream* st) {
2429   // Find the first pc desc for all scopes in the code and print it.
2430   ResourceMark rm;
2431   st->print("scopes:");
2432   if (scopes_pcs_begin() < scopes_pcs_end()) {
2433     st->cr();
2434     for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2435       if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null)
2436         continue;
2437 
2438       ScopeDesc* sd = scope_desc_at(p->real_pc(this));
2439       while (sd != NULL) {
2440         sd->print_on(st, p);  // print output ends with a newline
2441         sd = sd->sender();
2442       }
2443     }
2444   } else {
2445     st->print_cr(" <list empty>");
2446   }
2447 }
2448 #endif
2449 
2450 #ifndef PRODUCT  // RelocIterator does support printing only then.
2451 void nmethod::print_relocations() {
2452   ResourceMark m;       // in case methods get printed via the debugger
2453   tty->print_cr("relocations:");
2454   RelocIterator iter(this);
2455   iter.print();
2456 }
2457 #endif
2458 
2459 void nmethod::print_pcs_on(outputStream* st) {

2460   ResourceMark m;       // in case methods get printed via debugger
2461   st->print("pc-bytecode offsets:");
2462   if (scopes_pcs_begin() < scopes_pcs_end()) {
2463     st->cr();
2464     for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2465       p->print_on(st, this);  // print output ends with a newline
2466     }
2467   } else {
2468     st->print_cr(" <list empty>");
2469   }
2470 }
2471 
2472 void nmethod::print_handler_table() {
2473   ExceptionHandlerTable(this).print();
2474 }
2475 
2476 void nmethod::print_nul_chk_table() {
2477   ImplicitExceptionTable(this).print(code_begin());
2478 }
2479 
2480 void nmethod::print_recorded_oops() {
2481   const int n = oops_count();
2482   const int log_n = (n<10) ? 1 : (n<100) ? 2 : (n<1000) ? 3 : (n<10000) ? 4 : 6;
2483   tty->print("Recorded oops:");
2484   if (n > 0) {
2485     tty->cr();
2486     for (int i = 0; i < n; i++) {
2487       oop o = oop_at(i);
2488       tty->print("#%*d: " INTPTR_FORMAT " ", log_n, i, p2i(o));
2489       if (o == (oop)Universe::non_oop_word()) {
2490         tty->print("non-oop word");
2491       } else if (o == NULL) {
2492         tty->print("LUCY NULL-oop");
2493       } else {
2494         o->print_value_on(tty);




2495       }
2496       tty->cr();
2497     }
2498   } else {
2499     tty->print_cr(" <list empty>");
2500   }
2501 }
2502 
2503 void nmethod::print_recorded_metadata() {
2504   const int n = metadata_count();
2505   const int log_n = (n<10) ? 1 : (n<100) ? 2 : (n<1000) ? 3 : (n<10000) ? 4 : 6;
2506   tty->print("Recorded metadata:");
2507   if (n > 0) {
2508     tty->cr();
2509     for (int i = 0; i < n; i++) {
2510       Metadata* m = metadata_at(i);
2511       tty->print("#%*d: " INTPTR_FORMAT " ", log_n, i, p2i(m));
2512       if (m == (Metadata*)Universe::non_oop_word()) {
2513         tty->print("non-metadata word");
2514       } else if (m == NULL) {
2515         tty->print("LUCY NULL-oop");
2516       } else {
2517         Metadata::print_value_on_maybe_null(tty, m);
2518       }
2519       tty->cr();
2520     }
2521   } else {
2522     tty->print_cr(" <list empty>");
2523   }
2524 }
2525 #endif
2526 
2527 #if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
2528 
2529 void nmethod::print_constant_pool(outputStream* st) {
2530   //-----------------------------------
2531   //---<  Print the constant pool  >---
2532   //-----------------------------------
2533   int consts_size = this->consts_size();
2534   if ( consts_size > 0 ) {
2535     unsigned char* cstart = this->consts_begin();
2536     unsigned char* cp     = cstart;
2537     unsigned char* cend   = cp + consts_size;
2538     unsigned int   bytes_per_line = 4;
2539     unsigned int   CP_alignment   = 8;
2540     unsigned int   n;
2541 
2542     st->cr();
2543 
2544     //---<  print CP header to make clear what's printed  >---
2545     if( ((uintptr_t)cp&(CP_alignment-1)) == 0 ) {
2546       n = bytes_per_line;
2547       st->print_cr("[Constant Pool]");
2548       Disassembler::print_location(cp, cstart, cend, st, true, true);
2549       Disassembler::print_hexdata(cp, n, st, true);
2550       st->cr();
2551     } else {
2552       n = (uintptr_t)cp&(bytes_per_line-1);
2553       st->print_cr("[Constant Pool (unaligned)]");
2554     }
2555 
2556     //---<  print CP contents, bytes_per_line at a time  >---
2557     while (cp < cend) {
2558       Disassembler::print_location(cp, cstart, cend, st, true, false);
2559       Disassembler::print_hexdata(cp, n, st, false);
2560       cp += n;
2561       n   = bytes_per_line;
2562       st->cr();
2563     }
2564 
2565     //---<  Show potential alignment gap between constant pool and code  >---
2566     cend = code_begin();
2567     if( cp < cend ) {
2568       n = 4;
2569       st->print_cr("[Code entry alignment]");
2570       while (cp < cend) {
2571         Disassembler::print_location(cp, cstart, cend, st, false, false);
2572         cp += n;
2573         st->cr();
2574       }
2575     }
2576   } else {
2577     st->print_cr("[Constant Pool (empty)]");
2578   }
2579   st->cr();
2580 }
2581 
2582 #endif
2583 
2584 // Disassemble this nmethod.
2585 // Print additional debug information, if requested. This could be code
2586 // comments, block comments, profiling counters, etc.
2587 // The undisassembled format is useful no disassembler library is available.
2588 // The resulting hex dump (with markers) can be disassembled later, or on
2589 // another system, when/where a disassembler library is available.
2590 void nmethod::decode2(outputStream* ost) const {
2591 
2592   // Called from frame::back_trace_with_decode without ResourceMark.
2593   ResourceMark rm;
2594 
2595   // Make sure we have a valid stream to print on.
2596   outputStream* st = ost ? ost : tty;
2597 
2598 #if defined(SUPPORT_ABSTRACT_ASSEMBLY) && ! defined(SUPPORT_ASSEMBLY)
2599   const bool use_compressed_format    = true;
2600   const bool compressed_with_comments = use_compressed_format && (AbstractDisassembler::show_comment() ||
2601                                                                   AbstractDisassembler::show_block_comment());
2602 #else
2603   const bool use_compressed_format    = Disassembler::is_abstract();
2604   const bool compressed_with_comments = use_compressed_format && (AbstractDisassembler::show_comment() ||
2605                                                                   AbstractDisassembler::show_block_comment());
2606 #endif
2607 
2608   st->cr();
2609   this->print(st);
2610   st->cr();
2611 
2612 #if defined(SUPPORT_ASSEMBLY)
2613   //----------------------------------
2614   //---<  Print real disassembly  >---
2615   //----------------------------------
2616   if (! use_compressed_format) {
2617     Disassembler::decode(const_cast<nmethod*>(this), st);
2618     return;
2619   }
2620 #endif
2621 
2622 #if defined(SUPPORT_ABSTRACT_ASSEMBLY)
2623 
2624   // Compressed undisassembled disassembly format.
2625   // The following stati are defined/supported:
2626   //   = 0 - currently at bol() position, nothing printed yet on current line.
2627   //   = 1 - currently at position after print_location().
2628   //   > 1 - in the midst of printing instruction stream bytes.
2629   int        compressed_format_idx    = 0;
2630   int        code_comment_column      = 0;
2631   const int  instr_maxlen             = Assembler::instr_maxlen();
2632   const uint tabspacing               = 8;
2633   unsigned char* start = this->code_begin();
2634   unsigned char* p     = this->code_begin();
2635   unsigned char* end   = this->code_end();
2636   unsigned char* pss   = p; // start of a code section (used for offsets)
2637 
2638   if ((start == NULL) || (end == NULL)) {
2639     st->print_cr("PrintAssembly not possible due to uninitialized section pointers");
2640     return;
2641   }
2642 #endif
2643 
2644 #if defined(SUPPORT_ABSTRACT_ASSEMBLY)
2645   //---<  plain abstract disassembly, no comments or anything, just section headers  >---
2646   if (use_compressed_format && ! compressed_with_comments) {
2647     const_cast<nmethod*>(this)->print_constant_pool(st);
2648 
2649     //---<  Open the output (Marker for post-mortem disassembler)  >---
2650     st->print_cr("[MachCode]");
2651     const char* header = NULL;
2652     address p0 = p;
2653     while (p < end) {
2654       address pp = p;
2655       while ((p < end) && (header == NULL)) {
2656         header = nmethod_section_label(p);
2657         pp  = p;
2658         p  += Assembler::instr_len(p);
2659       }
2660       if (pp > p0) {
2661         AbstractDisassembler::decode_range_abstract(p0, pp, start, end, st, Assembler::instr_maxlen());
2662         p0 = pp;
2663         p  = pp;
2664         header = NULL;
2665       } else if (header != NULL) {
2666         st->bol();
2667         st->print_cr("%s", header);
2668         header = NULL;
2669       }
2670     }
2671     //---<  Close the output (Marker for post-mortem disassembler)  >---
2672     st->bol();
2673     st->print_cr("[/MachCode]");
2674     return;
2675   }
2676 #endif
2677 
2678 #if defined(SUPPORT_ABSTRACT_ASSEMBLY)
2679   //---<  abstract disassembly with comments and section headers merged in  >---
2680   if (compressed_with_comments) {
2681     const_cast<nmethod*>(this)->print_constant_pool(st);
2682 
2683     //---<  Open the output (Marker for post-mortem disassembler)  >---
2684     st->print_cr("[MachCode]");
2685     while ((p < end) && (p != NULL)) {
2686       const int instruction_size_in_bytes = Assembler::instr_len(p);
2687 
2688       //---<  Block comments for nmethod. Interrupts instruction stream, if any.  >---
2689       // Outputs a bol() before and a cr() after, but only if a comment is printed.
2690       // Prints nmethod_section_label as well.
2691       if (AbstractDisassembler::show_block_comment()) {
2692         print_block_comment(st, p);
2693         if (st->position() == 0) {
2694           compressed_format_idx = 0;
2695         }
2696       }
2697 
2698       //---<  New location information after line break  >---
2699       if (compressed_format_idx == 0) {
2700         code_comment_column   = Disassembler::print_location(p, pss, end, st, false, false);
2701         compressed_format_idx = 1;
2702       }
2703 
2704       //---<  Code comment for current instruction. Address range [p..(p+len))  >---
2705       unsigned char* p_end = p + (ssize_t)instruction_size_in_bytes;
2706       S390_ONLY(if (p_end > end) p_end = end;) // avoid getting past the end
2707 
2708       if (AbstractDisassembler::show_comment() && const_cast<nmethod*>(this)->has_code_comment(p, p_end)) {
2709         //---<  interrupt instruction byte stream for code comment  >---
2710         if (compressed_format_idx > 1) {
2711           st->cr();  // interrupt byte stream
2712           st->cr();  // add an empty line
2713           code_comment_column = Disassembler::print_location(p, pss, end, st, false, false);
2714         }
2715         const_cast<nmethod*>(this)->print_code_comment_on(st, code_comment_column, p, p_end );
2716         st->bol();
2717         compressed_format_idx = 0;
2718       }
2719 
2720       //---<  New location information after line break  >---
2721       if (compressed_format_idx == 0) {
2722         code_comment_column   = Disassembler::print_location(p, pss, end, st, false, false);
2723         compressed_format_idx = 1;
2724       }
2725 
2726       //---<  Nicely align instructions for readability  >---
2727       if (compressed_format_idx > 1) {
2728         Disassembler::print_delimiter(st);
2729       }
2730 
2731       //---<  Now, finally, print the actual instruction bytes  >---
2732       unsigned char* p0 = p;
2733       p = Disassembler::decode_instruction_abstract(p, st, instruction_size_in_bytes, instr_maxlen);
2734       compressed_format_idx += p - p0;
2735 
2736       if (Disassembler::start_newline(compressed_format_idx-1)) {
2737         st->cr();
2738         compressed_format_idx = 0;
2739       }
2740     }
2741     //---<  Close the output (Marker for post-mortem disassembler)  >---
2742     st->bol();
2743     st->print_cr("[/MachCode]");
2744     return;
2745   }
2746 #endif
2747 }
2748 
2749 #if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
2750 
2751 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) {
2752   RelocIterator iter(this, begin, end);
2753   bool have_one = false;
2754   while (iter.next()) {
2755     have_one = true;
2756     switch (iter.type()) {
2757         case relocInfo::none:                  return "no_reloc";
2758         case relocInfo::oop_type: {
2759           // Get a non-resizable resource-allocated stringStream.
2760           // Our callees make use of (nested) ResourceMarks.
2761           stringStream st(NEW_RESOURCE_ARRAY(char, 1024), 1024);
2762           oop_Relocation* r = iter.oop_reloc();
2763           oop obj = r->oop_value();
2764           st.print("oop(");
2765           if (obj == NULL) st.print("NULL");
2766           else obj->print_value_on(&st);
2767           st.print(")");
2768           return st.as_string();
2769         }
2770         case relocInfo::metadata_type: {
2771           stringStream st;
2772           metadata_Relocation* r = iter.metadata_reloc();
2773           Metadata* obj = r->metadata_value();
2774           st.print("metadata(");
2775           if (obj == NULL) st.print("NULL");
2776           else obj->print_value_on(&st);
2777           st.print(")");
2778           return st.as_string();
2779         }
2780         case relocInfo::runtime_call_type:
2781         case relocInfo::runtime_call_w_cp_type: {


2843         case relocInfo::type_mask:             return "type_bit_mask";
2844 
2845         default:
2846           break;
2847     }
2848   }
2849   return have_one ? "other" : NULL;
2850 }
2851 
2852 // Return a the last scope in (begin..end]
2853 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
2854   PcDesc* p = pc_desc_near(begin+1);
2855   if (p != NULL && p->real_pc(this) <= end) {
2856     return new ScopeDesc(this, p->scope_decode_offset(),
2857                          p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(),
2858                          p->return_oop());
2859   }
2860   return NULL;
2861 }
2862 
2863 const char* nmethod::nmethod_section_label(address pos) const {
2864   const char* label = NULL;
2865   if (pos == code_begin())                                              label = "[Instructions begin]";
2866   if (pos == entry_point())                                             label = "[Entry Point]";
2867   if (pos == verified_entry_point())                                    label = "[Verified Entry Point]";
2868   if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
2869   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
2870   // Check stub_code before checking exception_handler or deopt_handler.
2871   if (pos == this->stub_begin())                                        label = "[Stub Code]";
2872   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())           label = "[Exception Handler]";
2873   if (JVMCI_ONLY(_deopt_handler_begin != NULL &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
2874   return label;
2875 }
2876 
2877 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
2878   if (print_section_labels) {
2879     const char* label = nmethod_section_label(block_begin);
2880     if (label != NULL) {
2881       stream->bol();
2882       stream->print_cr("%s", label);
2883     }
2884   }
2885 
2886   if (block_begin == entry_point()) {
2887     methodHandle m = method();
2888     if (m.not_null()) {
2889       stream->print("  # ");
2890       m->print_value_on(stream);
2891       stream->cr();
2892     }
2893     if (m.not_null() && !is_osr_method()) {
2894       ResourceMark rm;
2895       int sizeargs = m->size_of_parameters();
2896       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
2897       VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
2898       {
2899         int sig_index = 0;
2900         if (!m->is_static())
2901           sig_bt[sig_index++] = T_OBJECT; // 'this'
2902         for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
2903           BasicType t = ss.type();
2904           sig_bt[sig_index++] = t;


2961         if (at_old_sp) {
2962           stream->print("  (%s of caller)", spname);
2963           did_old_sp = true;
2964         }
2965         stream->cr();
2966         sig_index += type2size[t];
2967         arg_index += 1;
2968         if (!at_this)  ss.next();
2969       }
2970       if (!did_old_sp) {
2971         stream->print("  # ");
2972         stream->move_to(tab1);
2973         stream->print("[%s+0x%x]", spname, stack_slot_offset);
2974         stream->print("  (%s of caller)", spname);
2975         stream->cr();
2976       }
2977     }
2978   }
2979 }
2980 
2981 // Returns whether this nmethod has code comments.
2982 bool nmethod::has_code_comment(address begin, address end) {
2983   // scopes?
2984   ScopeDesc* sd  = scope_desc_in(begin, end);
2985   if (sd != NULL) return true;
2986 
2987   // relocations?
2988   const char* str = reloc_string_for(begin, end);
2989   if (str != NULL) return true;
2990 
2991   // implicit exceptions?
2992   int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin());
2993   if (cont_offset != 0) return true;
2994 
2995   return false;
2996 }
2997 
2998 void nmethod::print_code_comment_on(outputStream* st, int column, address begin, address end) {
2999   // First, find an oopmap in (begin, end].
3000   // We use the odd half-closed interval so that oop maps and scope descs
3001   // which are tied to the byte after a call are printed with the call itself.
3002   address base = code_begin();
3003   ImmutableOopMapSet* oms = oop_maps();
3004   if (oms != NULL) {
3005     for (int i = 0, imax = oms->count(); i < imax; i++) {
3006       const ImmutableOopMapPair* pair = oms->pair_at(i);
3007       const ImmutableOopMap* om = pair->get_from(oms);
3008       address pc = base + pair->pc_offset();
3009       if (pc > begin) {
3010         if (pc <= end) {
3011           st->move_to(column, 6, 0);
3012           st->print("; ");
3013           om->print_on(st);
3014         }
3015         break;
3016       }
3017     }
3018   }
3019 
3020   // Print any debug info present at this pc.
3021   ScopeDesc* sd  = scope_desc_in(begin, end);
3022   if (sd != NULL) {
3023     st->move_to(column, 6, 0);
3024     if (sd->bci() == SynchronizationEntryBCI) {
3025       st->print(";*synchronization entry");
3026     } else if (sd->bci() == AfterBci) {
3027       st->print(";* method exit (unlocked if synchronized)");
3028     } else if (sd->bci() == UnwindBci) {
3029       st->print(";* unwind (locked if synchronized)");
3030     } else if (sd->bci() == AfterExceptionBci) {
3031       st->print(";* unwind (unlocked if synchronized)");
3032     } else if (sd->bci() == UnknownBci) {
3033       st->print(";* unknown");
3034     } else if (sd->bci() == InvalidFrameStateBci) {
3035       st->print(";* invalid frame state");
3036     } else {
3037       if (sd->method() == NULL) {
3038         st->print("method is NULL");
3039       } else if (sd->method()->is_native()) {
3040         st->print("method is native");
3041       } else {
3042         Bytecodes::Code bc = sd->method()->java_code_at(sd->bci());
3043         st->print(";*%s", Bytecodes::name(bc));


3059         case Bytecodes::_putfield:
3060         case Bytecodes::_getstatic:
3061         case Bytecodes::_putstatic:
3062           {
3063             Bytecode_field field(sd->method(), sd->bci());
3064             st->print(" ");
3065             if (field.name() != NULL)
3066               field.name()->print_symbol_on(st);
3067             else
3068               st->print("<UNKNOWN>");
3069           }
3070         default:
3071           break;
3072         }
3073       }
3074       st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
3075     }
3076 
3077     // Print all scopes
3078     for (;sd != NULL; sd = sd->sender()) {
3079       st->move_to(column, 6, 0);
3080       st->print("; -");
3081       if (sd->should_reexecute()) {
3082         st->print(" (reexecute)");
3083       }
3084       if (sd->method() == NULL) {
3085         st->print("method is NULL");
3086       } else {
3087         sd->method()->print_short_name(st);
3088       }
3089       int lineno = sd->method()->line_number_from_bci(sd->bci());
3090       if (lineno != -1) {
3091         st->print("@%d (line %d)", sd->bci(), lineno);
3092       } else {
3093         st->print("@%d", sd->bci());
3094       }
3095       st->cr();
3096     }
3097   }
3098 
3099   // Print relocation information
3100   // Prevent memory leak: allocating without ResourceMark.
3101   ResourceMark rm;
3102   const char* str = reloc_string_for(begin, end);
3103   if (str != NULL) {
3104     if (sd != NULL) st->cr();
3105     st->move_to(column, 6, 0);
3106     st->print(";   {%s}", str);
3107   }
3108   int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin());
3109   if (cont_offset != 0) {
3110     st->move_to(column, 6, 0);
3111     st->print("; implicit exception: dispatches to " INTPTR_FORMAT, p2i(code_begin() + cont_offset));
3112   }
3113 
3114 }
3115 
3116 #endif
3117 
3118 class DirectNativeCallWrapper: public NativeCallWrapper {
3119 private:
3120   NativeCall* _call;
3121 
3122 public:
3123   DirectNativeCallWrapper(NativeCall* call) : _call(call) {}
3124 
3125   virtual address destination() const { return _call->destination(); }
3126   virtual address instruction_address() const { return _call->instruction_address(); }
3127   virtual address next_instruction_address() const { return _call->next_instruction_address(); }
3128   virtual address return_address() const { return _call->return_address(); }
3129 
3130   virtual address get_resolve_call_stub(bool is_optimized) const {
3131     if (is_optimized) {
3132       return SharedRuntime::get_resolve_opt_virtual_call_stub();
3133     }
3134     return SharedRuntime::get_resolve_virtual_call_stub();
3135   }
3136 
3137   virtual void set_destination_mt_safe(address dest) {


3204 address nmethod::call_instruction_address(address pc) const {
3205   if (NativeCall::is_call_before(pc)) {
3206     NativeCall *ncall = nativeCall_before(pc);
3207     return ncall->instruction_address();
3208   }
3209   return NULL;
3210 }
3211 
3212 CompiledStaticCall* nmethod::compiledStaticCall_at(Relocation* call_site) const {
3213   return CompiledDirectStaticCall::at(call_site);
3214 }
3215 
3216 CompiledStaticCall* nmethod::compiledStaticCall_at(address call_site) const {
3217   return CompiledDirectStaticCall::at(call_site);
3218 }
3219 
3220 CompiledStaticCall* nmethod::compiledStaticCall_before(address return_addr) const {
3221   return CompiledDirectStaticCall::before(return_addr);
3222 }
3223 
3224 #if defined(SUPPORT_DATA_STRUCTS)

3225 void nmethod::print_value_on(outputStream* st) const {
3226   st->print("nmethod");
3227   print_on(st, NULL);
3228 }
3229 #endif
3230 
3231 #ifndef PRODUCT
3232 
3233 void nmethod::print_calls(outputStream* st) {
3234   RelocIterator iter(this);
3235   while (iter.next()) {
3236     switch (iter.type()) {
3237     case relocInfo::virtual_call_type:
3238     case relocInfo::opt_virtual_call_type: {
3239       CompiledICLocker ml_verify(this);
3240       CompiledIC_at(&iter)->print();
3241       break;
3242     }
3243     case relocInfo::static_call_type:
3244       st->print_cr("Static call at " INTPTR_FORMAT, p2i(iter.reloc()->addr()));
3245       CompiledDirectStaticCall::at(iter.reloc())->print();
3246       break;
3247     default:
3248       break;
3249     }
3250   }








3251 }
3252 
3253 void nmethod::print_statistics() {
3254   ttyLocker ttyl;
3255   if (xtty != NULL)  xtty->head("statistics type='nmethod'");
3256   native_nmethod_stats.print_native_nmethod_stats();
3257 #ifdef COMPILER1
3258   c1_java_nmethod_stats.print_nmethod_stats("C1");
3259 #endif
3260 #ifdef COMPILER2
3261   c2_java_nmethod_stats.print_nmethod_stats("C2");
3262 #endif
3263 #if INCLUDE_JVMCI
3264   jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
3265 #endif
3266   unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
3267   DebugInformationRecorder::print_statistics();
3268 #ifndef PRODUCT
3269   pc_nmethod_stats.print_pc_stats();
3270 #endif


< prev index next >