< prev index next >

src/share/vm/code/nmethod.cpp

Print this page
rev 12906 : [mq]: gc_interface


  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/dependencies.hpp"
  29 #include "code/nativeInst.hpp"
  30 #include "code/nmethod.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "compiler/abstractCompiler.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "compiler/compileLog.hpp"
  35 #include "compiler/compilerDirectives.hpp"
  36 #include "compiler/directivesParser.hpp"
  37 #include "compiler/disassembler.hpp"
  38 #include "interpreter/bytecode.hpp"
  39 #include "logging/log.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "oops/methodData.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "prims/jvmtiImpl.hpp"

  44 #include "runtime/atomic.hpp"
  45 #include "runtime/orderAccess.inline.hpp"
  46 #include "runtime/os.hpp"
  47 #include "runtime/sharedRuntime.hpp"
  48 #include "runtime/sweeper.hpp"
  49 #include "utilities/resourceHash.hpp"
  50 #include "utilities/dtrace.hpp"
  51 #include "utilities/events.hpp"
  52 #include "utilities/xmlstream.hpp"
  53 #include "logging/log.hpp"
  54 #ifdef SHARK
  55 #include "shark/sharkCompiler.hpp"
  56 #endif
  57 #if INCLUDE_JVMCI
  58 #include "jvmci/jvmciJavaClasses.hpp"
  59 #endif
  60 
  61 #ifdef DTRACE_ENABLED
  62 
  63 // Only bother with this argument setup if dtrace is available


 392   if (method() != NULL && is_native_method())  return "c2n";
 393   return NULL;
 394 }
 395 
 396 // Fill in default values for various flag fields
 397 void nmethod::init_defaults() {
 398   _state                      = in_use;
 399   _has_flushed_dependencies   = 0;
 400   _lock_count                 = 0;
 401   _stack_traversal_mark       = 0;
 402   _unload_reported            = false; // jvmti state
 403   _is_far_code                = false; // nmethods are located in CodeCache
 404 
 405 #ifdef ASSERT
 406   _oops_are_stale             = false;
 407 #endif
 408 
 409   _oops_do_mark_link       = NULL;
 410   _jmethod_id              = NULL;
 411   _osr_link                = NULL;
 412   if (UseG1GC) {
 413     _unloading_next        = NULL;
 414   } else {
 415     _scavenge_root_link    = NULL;
 416   }
 417   _scavenge_root_state     = 0;
 418 #if INCLUDE_RTM_OPT
 419   _rtm_state               = NoRTM;
 420 #endif
 421 #if INCLUDE_JVMCI
 422   _jvmci_installed_code   = NULL;
 423   _speculation_log        = NULL;
 424 #endif
 425 }
 426 
 427 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
 428   int compile_id,
 429   CodeBuffer *code_buffer,
 430   int vep_offset,
 431   int frame_complete,
 432   int frame_size,
 433   ByteSize basic_lock_owner_sp_offset,
 434   ByteSize basic_lock_sp_offset,
 435   OopMapSet* oop_maps) {
 436   code_buffer->finalize_oop_references(method);


 580     _dependencies_offset     = _scopes_pcs_offset;
 581     _handler_table_offset    = _dependencies_offset;
 582     _nul_chk_table_offset    = _handler_table_offset;
 583     _nmethod_end_offset      = _nul_chk_table_offset;
 584     _compile_id              = compile_id;
 585     _comp_level              = CompLevel_none;
 586     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 587     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 588     _osr_entry_point         = NULL;
 589     _exception_cache         = NULL;
 590     _pc_desc_container.reset_to(NULL);
 591     _hotness_counter         = NMethodSweeper::hotness_counter_reset_val();
 592 
 593     _scopes_data_begin = (address) this + scopes_data_offset;
 594     _deopt_handler_begin = (address) this + deoptimize_offset;
 595     _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;
 596 
 597     code_buffer->copy_code_and_locs_to(this);
 598     code_buffer->copy_values_to(this);
 599     if (ScavengeRootsInCode) {
 600       if (detect_scavenge_root_oops()) {
 601         CodeCache::add_scavenge_root_nmethod(this);
 602       }
 603       Universe::heap()->register_nmethod(this);
 604     }
 605     debug_only(verify_scavenge_root_oops());
 606     CodeCache::commit(this);
 607   }
 608 
 609   if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 610     ttyLocker ttyl;  // keep the following output all in one block
 611     // This output goes directly to the tty, not the compiler log.
 612     // To enable tools to match it up with the compilation activity,
 613     // be sure to tag this tty output with the compile ID.
 614     if (xtty != NULL) {
 615       xtty->begin_head("print_native_nmethod");
 616       xtty->method(_method);
 617       xtty->stamp();
 618       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 619     }
 620     // print the header part first
 621     print();
 622     // then print the requested information
 623     if (PrintNativeNMethods) {
 624       print_code();
 625       if (oop_maps != NULL) {


 735     _scopes_pcs_offset       = scopes_data_offset    + round_to(debug_info->data_size       (), oopSize);
 736     _dependencies_offset     = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
 737     _handler_table_offset    = _dependencies_offset  + round_to(dependencies->size_in_bytes (), oopSize);
 738     _nul_chk_table_offset    = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
 739     _nmethod_end_offset      = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
 740     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 741     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 742     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 743     _exception_cache         = NULL;
 744 
 745     _scopes_data_begin = (address) this + scopes_data_offset;
 746 
 747     _pc_desc_container.reset_to(scopes_pcs_begin());
 748 
 749     code_buffer->copy_code_and_locs_to(this);
 750     // Copy contents of ScopeDescRecorder to nmethod
 751     code_buffer->copy_values_to(this);
 752     debug_info->copy_to(this);
 753     dependencies->copy_to(this);
 754     if (ScavengeRootsInCode) {
 755       if (detect_scavenge_root_oops()) {
 756         CodeCache::add_scavenge_root_nmethod(this);
 757       }
 758       Universe::heap()->register_nmethod(this);
 759     }
 760     debug_only(verify_scavenge_root_oops());
 761 
 762     CodeCache::commit(this);
 763 
 764     // Copy contents of ExceptionHandlerTable to nmethod
 765     handler_table->copy_to(this);
 766     nul_chk_table->copy_to(this);
 767 
 768     // we use the information of entry points to find out if a method is
 769     // static or non static
 770     assert(compiler->is_c2() || compiler->is_jvmci() ||
 771            _method->is_static() == (entry_point() == _verified_entry_point),
 772            " entry points must be same for static methods and vice versa");
 773   }
 774 }
 775 
 776 // Print a short set of xml attributes to identify this nmethod.  The
 777 // output should be embedded in some other element.
 778 void nmethod::log_identity(xmlStream* log) const {
 779   log->print(" compile_id='%d'", compile_id());
 780   const char* nm_kind = compile_kind();


1510 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred) {
1511   // Compiled code
1512   {
1513   RelocIterator iter(this, low_boundary);
1514   while (iter.next()) {
1515     if (iter.type() == relocInfo::oop_type) {
1516       if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) {
1517         return true;
1518       }
1519     }
1520   }
1521   }
1522 
1523   return do_unloading_scopes(is_alive, unloading_occurred);
1524 }
1525 
1526 #if INCLUDE_JVMCI
1527 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) {
1528   bool is_unloaded = false;
1529   // Follow JVMCI method
1530   BarrierSet* bs = Universe::heap()->barrier_set();
1531   if (_jvmci_installed_code != NULL) {
1532     if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) {
1533       if (!is_alive->do_object_b(_jvmci_installed_code)) {
1534         clear_jvmci_installed_code();
1535       }
1536     } else {
1537       if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) {
1538         return true;
1539       }
1540     }
1541   }
1542 
1543   if (_speculation_log != NULL) {
1544     if (!is_alive->do_object_b(_speculation_log)) {
1545       bs->write_ref_nmethod_pre(&_speculation_log, this);
1546       _speculation_log = NULL;
1547       bs->write_ref_nmethod_post(&_speculation_log, this);
1548     }
1549   }
1550   return is_unloaded;
1551 }
1552 #endif
1553 
1554 // Iterate over metadata calling this function.   Used by RedefineClasses
1555 void nmethod::metadata_do(void f(Metadata*)) {
1556   address low_boundary = verified_entry_point();
1557   if (is_not_entrant()) {
1558     low_boundary += NativeJump::instruction_size;
1559     // %%% Note:  On SPARC we patch only a 4-byte trap, not a full NativeJump.
1560     // (See comment above.)
1561   }
1562   {
1563     // Visit all immediate references that are embedded in the instruction stream.
1564     RelocIterator iter(this, low_boundary);
1565     while (iter.next()) {
1566       if (iter.type() == relocInfo::metadata_type ) {
1567         metadata_Relocation* r = iter.metadata_reloc();


2121     fatal("nmethod at " INTPTR_FORMAT " not in zone", p2i(this));
2122   }
2123 
2124   if(is_native_method() )
2125     return;
2126 
2127   nmethod* nm = CodeCache::find_nmethod(verified_entry_point());
2128   if (nm != this) {
2129     fatal("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", p2i(this));
2130   }
2131 
2132   for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2133     if (! p->verify(this)) {
2134       tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", p2i(this));
2135     }
2136   }
2137 
2138   VerifyOopsClosure voc(this);
2139   oops_do(&voc);
2140   assert(voc.ok(), "embedded oops must be OK");
2141   verify_scavenge_root_oops();
2142 
2143   verify_scopes();
2144 }
2145 
2146 
2147 void nmethod::verify_interrupt_point(address call_site) {
2148   // Verify IC only when nmethod installation is finished.
2149   bool is_installed = (method()->code() == this) // nmethod is in state 'in_use' and installed
2150                       || !this->is_in_use();     // nmethod is installed, but not in 'in_use' state
2151   if (is_installed) {
2152     Thread *cur = Thread::current();
2153     if (CompiledIC_lock->owner() == cur ||
2154         ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) &&
2155          SafepointSynchronize::is_at_safepoint())) {
2156       CompiledIC_at(this, call_site);
2157       CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
2158     } else {
2159       MutexLocker ml_verify (CompiledIC_lock);
2160       CompiledIC_at(this, call_site);
2161     }


2211 class DebugScavengeRoot: public OopClosure {
2212   nmethod* _nm;
2213   bool     _ok;
2214 public:
2215   DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { }
2216   bool ok() { return _ok; }
2217   virtual void do_oop(oop* p) {
2218     if ((*p) == NULL || !(*p)->is_scavengable())  return;
2219     if (_ok) {
2220       _nm->print_nmethod(true);
2221       _ok = false;
2222     }
2223     tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2224                   p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2225     (*p)->print();
2226   }
2227   virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2228 };
2229 
2230 void nmethod::verify_scavenge_root_oops() {
2231   if (UseG1GC) {
2232     return;
2233   }
2234 
2235   if (!on_scavenge_root_list()) {
2236     // Actually look inside, to verify the claim that it's clean.
2237     DebugScavengeRoot debug_scavenge_root(this);
2238     oops_do(&debug_scavenge_root);
2239     if (!debug_scavenge_root.ok())
2240       fatal("found an unadvertised bad scavengable oop in the code cache");
2241   }
2242   assert(scavenge_root_not_marked(), "");
2243 }
2244 
2245 #endif // PRODUCT
2246 
2247 // Printing operations
2248 
2249 void nmethod::print() const {
2250   ResourceMark rm;
2251   ttyLocker ttyl;   // keep the following output all in one block
2252 
2253   tty->print("Compiled method ");
2254 


2897 #endif
2898   unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2899   DebugInformationRecorder::print_statistics();
2900 #ifndef PRODUCT
2901   pc_nmethod_stats.print_pc_stats();
2902 #endif
2903   Dependencies::print_statistics();
2904   if (xtty != NULL)  xtty->tail("statistics");
2905 }
2906 
2907 #endif // !PRODUCT
2908 
2909 #if INCLUDE_JVMCI
2910 void nmethod::clear_jvmci_installed_code() {
2911   // write_ref_method_pre/post can only be safely called at a
2912   // safepoint or while holding the CodeCache_lock
2913   assert(CodeCache_lock->is_locked() ||
2914          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2915   if (_jvmci_installed_code != NULL) {
2916     // This must be done carefully to maintain nmethod remembered sets properly
2917     BarrierSet* bs = Universe::heap()->barrier_set();
2918     bs->write_ref_nmethod_pre(&_jvmci_installed_code, this);
2919     _jvmci_installed_code = NULL;
2920     bs->write_ref_nmethod_post(&_jvmci_installed_code, this);
2921   }
2922 }
2923 
2924 void nmethod::maybe_invalidate_installed_code() {
2925   assert(Patching_lock->is_locked() ||
2926          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2927   oop installed_code = jvmci_installed_code();
2928   if (installed_code != NULL) {
2929     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
2930     if (nm == NULL || nm != this) {
2931       // The link has been broken or the InstalledCode instance is
2932       // associated with another nmethod so do nothing.
2933       return;
2934     }
2935     if (!is_alive()) {
2936       // Break the link between nmethod and InstalledCode such that the nmethod
2937       // can subsequently be flushed safely.  The link must be maintained while
2938       // the method could have live activations since invalidateInstalledCode
2939       // might want to invalidate all existing activations.
2940       InstalledCode::set_address(installed_code, 0);


2989   if (!this->is_compiled_by_jvmci()) {
2990     return NULL;
2991   }
2992   oop installedCode = this->jvmci_installed_code();
2993   if (installedCode != NULL) {
2994     oop installedCodeName = NULL;
2995     if (installedCode->is_a(InstalledCode::klass())) {
2996       installedCodeName = InstalledCode::name(installedCode);
2997     }
2998     if (installedCodeName != NULL) {
2999       return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen);
3000     } else {
3001       jio_snprintf(buf, buflen, "null");
3002       return buf;
3003     }
3004   }
3005   jio_snprintf(buf, buflen, "noInstalledCode");
3006   return buf;
3007 }
3008 #endif
3009 


  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/dependencies.hpp"
  29 #include "code/nativeInst.hpp"
  30 #include "code/nmethod.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #include "compiler/abstractCompiler.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "compiler/compileLog.hpp"
  35 #include "compiler/compilerDirectives.hpp"
  36 #include "compiler/directivesParser.hpp"
  37 #include "compiler/disassembler.hpp"
  38 #include "interpreter/bytecode.hpp"
  39 #include "logging/log.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "oops/methodData.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "prims/jvmtiImpl.hpp"
  44 #include "runtime/access.inline.hpp"
  45 #include "runtime/atomic.hpp"
  46 #include "runtime/orderAccess.inline.hpp"
  47 #include "runtime/os.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 #include "runtime/sweeper.hpp"
  50 #include "utilities/resourceHash.hpp"
  51 #include "utilities/dtrace.hpp"
  52 #include "utilities/events.hpp"
  53 #include "utilities/xmlstream.hpp"
  54 #include "logging/log.hpp"
  55 #ifdef SHARK
  56 #include "shark/sharkCompiler.hpp"
  57 #endif
  58 #if INCLUDE_JVMCI
  59 #include "jvmci/jvmciJavaClasses.hpp"
  60 #endif
  61 
  62 #ifdef DTRACE_ENABLED
  63 
  64 // Only bother with this argument setup if dtrace is available


 393   if (method() != NULL && is_native_method())  return "c2n";
 394   return NULL;
 395 }
 396 
 397 // Fill in default values for various flag fields
 398 void nmethod::init_defaults() {
 399   _state                      = in_use;
 400   _has_flushed_dependencies   = 0;
 401   _lock_count                 = 0;
 402   _stack_traversal_mark       = 0;
 403   _unload_reported            = false; // jvmti state
 404   _is_far_code                = false; // nmethods are located in CodeCache
 405 
 406 #ifdef ASSERT
 407   _oops_are_stale             = false;
 408 #endif
 409 
 410   _oops_do_mark_link       = NULL;
 411   _jmethod_id              = NULL;
 412   _osr_link                = NULL;

 413   _unloading_next          = NULL;

 414   _scavenge_root_link      = NULL;

 415   _scavenge_root_state     = 0;
 416 #if INCLUDE_RTM_OPT
 417   _rtm_state               = NoRTM;
 418 #endif
 419 #if INCLUDE_JVMCI
 420   _jvmci_installed_code   = NULL;
 421   _speculation_log        = NULL;
 422 #endif
 423 }
 424 
 425 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
 426   int compile_id,
 427   CodeBuffer *code_buffer,
 428   int vep_offset,
 429   int frame_complete,
 430   int frame_size,
 431   ByteSize basic_lock_owner_sp_offset,
 432   ByteSize basic_lock_sp_offset,
 433   OopMapSet* oop_maps) {
 434   code_buffer->finalize_oop_references(method);


 578     _dependencies_offset     = _scopes_pcs_offset;
 579     _handler_table_offset    = _dependencies_offset;
 580     _nul_chk_table_offset    = _handler_table_offset;
 581     _nmethod_end_offset      = _nul_chk_table_offset;
 582     _compile_id              = compile_id;
 583     _comp_level              = CompLevel_none;
 584     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 585     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 586     _osr_entry_point         = NULL;
 587     _exception_cache         = NULL;
 588     _pc_desc_container.reset_to(NULL);
 589     _hotness_counter         = NMethodSweeper::hotness_counter_reset_val();
 590 
 591     _scopes_data_begin = (address) this + scopes_data_offset;
 592     _deopt_handler_begin = (address) this + deoptimize_offset;
 593     _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;
 594 
 595     code_buffer->copy_code_and_locs_to(this);
 596     code_buffer->copy_values_to(this);
 597     if (ScavengeRootsInCode) {



 598       Universe::heap()->register_nmethod(this);
 599     }
 600     debug_only(Universe::heap()->verify_nmethod_roots(this));
 601     CodeCache::commit(this);
 602   }
 603 
 604   if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 605     ttyLocker ttyl;  // keep the following output all in one block
 606     // This output goes directly to the tty, not the compiler log.
 607     // To enable tools to match it up with the compilation activity,
 608     // be sure to tag this tty output with the compile ID.
 609     if (xtty != NULL) {
 610       xtty->begin_head("print_native_nmethod");
 611       xtty->method(_method);
 612       xtty->stamp();
 613       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 614     }
 615     // print the header part first
 616     print();
 617     // then print the requested information
 618     if (PrintNativeNMethods) {
 619       print_code();
 620       if (oop_maps != NULL) {


 730     _scopes_pcs_offset       = scopes_data_offset    + round_to(debug_info->data_size       (), oopSize);
 731     _dependencies_offset     = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
 732     _handler_table_offset    = _dependencies_offset  + round_to(dependencies->size_in_bytes (), oopSize);
 733     _nul_chk_table_offset    = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
 734     _nmethod_end_offset      = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
 735     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 736     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 737     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 738     _exception_cache         = NULL;
 739 
 740     _scopes_data_begin = (address) this + scopes_data_offset;
 741 
 742     _pc_desc_container.reset_to(scopes_pcs_begin());
 743 
 744     code_buffer->copy_code_and_locs_to(this);
 745     // Copy contents of ScopeDescRecorder to nmethod
 746     code_buffer->copy_values_to(this);
 747     debug_info->copy_to(this);
 748     dependencies->copy_to(this);
 749     if (ScavengeRootsInCode) {



 750       Universe::heap()->register_nmethod(this);
 751     }
 752     debug_only(Universe::heap()->verify_nmethod_roots(this));
 753 
 754     CodeCache::commit(this);
 755 
 756     // Copy contents of ExceptionHandlerTable to nmethod
 757     handler_table->copy_to(this);
 758     nul_chk_table->copy_to(this);
 759 
 760     // we use the information of entry points to find out if a method is
 761     // static or non static
 762     assert(compiler->is_c2() || compiler->is_jvmci() ||
 763            _method->is_static() == (entry_point() == _verified_entry_point),
 764            " entry points must be same for static methods and vice versa");
 765   }
 766 }
 767 
 768 // Print a short set of xml attributes to identify this nmethod.  The
 769 // output should be embedded in some other element.
 770 void nmethod::log_identity(xmlStream* log) const {
 771   log->print(" compile_id='%d'", compile_id());
 772   const char* nm_kind = compile_kind();


1502 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred) {
1503   // Compiled code
1504   {
1505   RelocIterator iter(this, low_boundary);
1506   while (iter.next()) {
1507     if (iter.type() == relocInfo::oop_type) {
1508       if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) {
1509         return true;
1510       }
1511     }
1512   }
1513   }
1514 
1515   return do_unloading_scopes(is_alive, unloading_occurred);
1516 }
1517 
1518 #if INCLUDE_JVMCI
1519 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) {
1520   bool is_unloaded = false;
1521   // Follow JVMCI method

1522   if (_jvmci_installed_code != NULL) {
1523     if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) {
1524       if (!is_alive->do_object_b(_jvmci_installed_code)) {
1525         clear_jvmci_installed_code();
1526       }
1527     } else {
1528       if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) {
1529         return true;
1530       }
1531     }
1532   }
1533 
1534   if (_speculation_log != NULL) {
1535     if (!is_alive->do_object_b(_speculation_log)) {
1536       NMethodAccess<>::oop_store_at(this, in_bytes(byte_offset_of(nmethod, _speculation_log)), NULL);


1537     }
1538   }
1539   return is_unloaded;
1540 }
1541 #endif
1542 
1543 // Iterate over metadata calling this function.   Used by RedefineClasses
1544 void nmethod::metadata_do(void f(Metadata*)) {
1545   address low_boundary = verified_entry_point();
1546   if (is_not_entrant()) {
1547     low_boundary += NativeJump::instruction_size;
1548     // %%% Note:  On SPARC we patch only a 4-byte trap, not a full NativeJump.
1549     // (See comment above.)
1550   }
1551   {
1552     // Visit all immediate references that are embedded in the instruction stream.
1553     RelocIterator iter(this, low_boundary);
1554     while (iter.next()) {
1555       if (iter.type() == relocInfo::metadata_type ) {
1556         metadata_Relocation* r = iter.metadata_reloc();


2110     fatal("nmethod at " INTPTR_FORMAT " not in zone", p2i(this));
2111   }
2112 
2113   if(is_native_method() )
2114     return;
2115 
2116   nmethod* nm = CodeCache::find_nmethod(verified_entry_point());
2117   if (nm != this) {
2118     fatal("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", p2i(this));
2119   }
2120 
2121   for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2122     if (! p->verify(this)) {
2123       tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", p2i(this));
2124     }
2125   }
2126 
2127   VerifyOopsClosure voc(this);
2128   oops_do(&voc);
2129   assert(voc.ok(), "embedded oops must be OK");
2130   Universe::heap()->verify_nmethod_roots(this);
2131 
2132   verify_scopes();
2133 }
2134 
2135 
2136 void nmethod::verify_interrupt_point(address call_site) {
2137   // Verify IC only when nmethod installation is finished.
2138   bool is_installed = (method()->code() == this) // nmethod is in state 'in_use' and installed
2139                       || !this->is_in_use();     // nmethod is installed, but not in 'in_use' state
2140   if (is_installed) {
2141     Thread *cur = Thread::current();
2142     if (CompiledIC_lock->owner() == cur ||
2143         ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) &&
2144          SafepointSynchronize::is_at_safepoint())) {
2145       CompiledIC_at(this, call_site);
2146       CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
2147     } else {
2148       MutexLocker ml_verify (CompiledIC_lock);
2149       CompiledIC_at(this, call_site);
2150     }


2200 class DebugScavengeRoot: public OopClosure {
2201   nmethod* _nm;
2202   bool     _ok;
2203 public:
2204   DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { }
2205   bool ok() { return _ok; }
2206   virtual void do_oop(oop* p) {
2207     if ((*p) == NULL || !(*p)->is_scavengable())  return;
2208     if (_ok) {
2209       _nm->print_nmethod(true);
2210       _ok = false;
2211     }
2212     tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2213                   p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2214     (*p)->print();
2215   }
2216   virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2217 };
2218 
2219 void nmethod::verify_scavenge_root_oops() {




2220   if (!on_scavenge_root_list()) {
2221     // Actually look inside, to verify the claim that it's clean.
2222     DebugScavengeRoot debug_scavenge_root(this);
2223     oops_do(&debug_scavenge_root);
2224     if (!debug_scavenge_root.ok())
2225       fatal("found an unadvertised bad scavengable oop in the code cache");
2226   }
2227   assert(scavenge_root_not_marked(), "");
2228 }
2229 
2230 #endif // PRODUCT
2231 
2232 // Printing operations
2233 
2234 void nmethod::print() const {
2235   ResourceMark rm;
2236   ttyLocker ttyl;   // keep the following output all in one block
2237 
2238   tty->print("Compiled method ");
2239 


2882 #endif
2883   unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2884   DebugInformationRecorder::print_statistics();
2885 #ifndef PRODUCT
2886   pc_nmethod_stats.print_pc_stats();
2887 #endif
2888   Dependencies::print_statistics();
2889   if (xtty != NULL)  xtty->tail("statistics");
2890 }
2891 
2892 #endif // !PRODUCT
2893 
2894 #if INCLUDE_JVMCI
2895 void nmethod::clear_jvmci_installed_code() {
2896   // write_ref_method_pre/post can only be safely called at a
2897   // safepoint or while holding the CodeCache_lock
2898   assert(CodeCache_lock->is_locked() ||
2899          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2900   if (_jvmci_installed_code != NULL) {
2901     // This must be done carefully to maintain nmethod remembered sets properly
2902     NMethodAccess<>::oop_store_at(this, in_bytes(byte_offset_of(nmethod, _jvmci_installed_code)), NULL);



2903   }
2904 }
2905 
2906 void nmethod::maybe_invalidate_installed_code() {
2907   assert(Patching_lock->is_locked() ||
2908          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2909   oop installed_code = jvmci_installed_code();
2910   if (installed_code != NULL) {
2911     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
2912     if (nm == NULL || nm != this) {
2913       // The link has been broken or the InstalledCode instance is
2914       // associated with another nmethod so do nothing.
2915       return;
2916     }
2917     if (!is_alive()) {
2918       // Break the link between nmethod and InstalledCode such that the nmethod
2919       // can subsequently be flushed safely.  The link must be maintained while
2920       // the method could have live activations since invalidateInstalledCode
2921       // might want to invalidate all existing activations.
2922       InstalledCode::set_address(installed_code, 0);


2971   if (!this->is_compiled_by_jvmci()) {
2972     return NULL;
2973   }
2974   oop installedCode = this->jvmci_installed_code();
2975   if (installedCode != NULL) {
2976     oop installedCodeName = NULL;
2977     if (installedCode->is_a(InstalledCode::klass())) {
2978       installedCodeName = InstalledCode::name(installedCode);
2979     }
2980     if (installedCodeName != NULL) {
2981       return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen);
2982     } else {
2983       jio_snprintf(buf, buflen, "null");
2984       return buf;
2985     }
2986   }
2987   jio_snprintf(buf, buflen, "noInstalledCode");
2988   return buf;
2989 }
2990 #endif

< prev index next >