src/share/vm/code/nmethod.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/code

src/share/vm/code/nmethod.cpp

Print this page
rev 8995 : 8046155: JEP165: Compiler Control
Summary:
Reviewed-by:


  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 "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/dependencies.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/scopeDesc.hpp"
  31 #include "compiler/abstractCompiler.hpp"
  32 #include "compiler/compileBroker.hpp"
  33 #include "compiler/compileLog.hpp"
  34 #include "compiler/compilerOracle.hpp"
  35 #include "compiler/disassembler.hpp"
  36 #include "interpreter/bytecode.hpp"
  37 #include "oops/methodData.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "prims/jvmtiRedefineClassesTrace.hpp"
  40 #include "prims/jvmtiImpl.hpp"
  41 #include "runtime/atomic.inline.hpp"
  42 #include "runtime/orderAccess.inline.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/sweeper.hpp"
  45 #include "utilities/resourceHash.hpp"
  46 #include "utilities/dtrace.hpp"
  47 #include "utilities/events.hpp"
  48 #include "utilities/xmlstream.hpp"
  49 #ifdef SHARK
  50 #include "shark/sharkCompiler.hpp"
  51 #endif
  52 
  53 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  54 


 487   int frame_complete,
 488   int frame_size,
 489   ByteSize basic_lock_owner_sp_offset,
 490   ByteSize basic_lock_sp_offset,
 491   OopMapSet* oop_maps) {
 492   code_buffer->finalize_oop_references(method);
 493   // create nmethod
 494   nmethod* nm = NULL;
 495   {
 496     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 497     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
 498     CodeOffsets offsets;
 499     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 500     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 501     nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), native_nmethod_size,
 502                                             compile_id, &offsets,
 503                                             code_buffer, frame_size,
 504                                             basic_lock_owner_sp_offset,
 505                                             basic_lock_sp_offset, oop_maps);
 506     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_native_nmethod(nm));
 507     if ((PrintAssembly || CompilerOracle::should_print(method)) && nm != NULL) {


 508       Disassembler::decode(nm);
 509     }
 510   }

 511   // verify nmethod
 512   debug_only(if (nm) nm->verify();) // might block
 513 
 514   if (nm != NULL) {
 515     nm->log_new_nmethod();
 516   }
 517 
 518   return nm;
 519 }
 520 
 521 nmethod* nmethod::new_nmethod(methodHandle method,
 522   int compile_id,
 523   int entry_bci,
 524   CodeOffsets* offsets,
 525   int orig_pc_offset,
 526   DebugInformationRecorder* debug_info,
 527   Dependencies* dependencies,
 528   CodeBuffer* code_buffer, int frame_size,
 529   OopMapSet* oop_maps,
 530   ExceptionHandlerTable* handler_table,


 562       // class hierarchy above the loaded class, checking only nmethods
 563       // which are dependent on those classes.  The slow way is to
 564       // check every nmethod for dependencies which makes it linear in
 565       // the number of methods compiled.  For applications with a lot
 566       // classes the slow way is too slow.
 567       for (Dependencies::DepStream deps(nm); deps.next(); ) {
 568         if (deps.type() == Dependencies::call_site_target_value) {
 569           // CallSite dependencies are managed on per-CallSite instance basis.
 570           oop call_site = deps.argument_oop(0);
 571           MethodHandles::add_dependent_nmethod(call_site, nm);
 572         } else {
 573           Klass* klass = deps.context_type();
 574           if (klass == NULL) {
 575             continue;  // ignore things like evol_method
 576           }
 577           // record this nmethod as dependent on this klass
 578           InstanceKlass::cast(klass)->add_dependent_nmethod(nm);
 579         }
 580       }
 581       NOT_PRODUCT(nmethod_stats.note_nmethod(nm));
 582       if (PrintAssembly || CompilerOracle::has_option_string(method, "PrintAssembly")) {
 583         Disassembler::decode(nm);
 584       }
 585     }
 586   }
 587   // Do verification and logging outside CodeCache_lock.
 588   if (nm != NULL) {
 589     // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
 590     DEBUG_ONLY(nm->verify();)
 591     nm->log_new_nmethod();
 592   }
 593   return nm;
 594 }
 595 
 596 
 597 // For native wrappers
 598 nmethod::nmethod(
 599   Method* method,
 600   int nmethod_size,
 601   int compile_id,
 602   CodeOffsets* offsets,
 603   CodeBuffer* code_buffer,
 604   int frame_size,


 766     if (ScavengeRootsInCode) {
 767       if (detect_scavenge_root_oops()) {
 768         CodeCache::add_scavenge_root_nmethod(this);
 769       }
 770       Universe::heap()->register_nmethod(this);
 771     }
 772     debug_only(verify_scavenge_root_oops());
 773 
 774     CodeCache::commit(this);
 775 
 776     // Copy contents of ExceptionHandlerTable to nmethod
 777     handler_table->copy_to(this);
 778     nul_chk_table->copy_to(this);
 779 
 780     // we use the information of entry points to find out if a method is
 781     // static or non static
 782     assert(compiler->is_c2() ||
 783            _method->is_static() == (entry_point() == _verified_entry_point),
 784            " entry points must be same for static methods and vice versa");
 785   }
 786 
 787   bool printnmethods = PrintNMethods
 788     || CompilerOracle::should_print(_method)
 789     || CompilerOracle::has_option_string(_method, "PrintNMethods");
 790   if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
 791     print_nmethod(printnmethods);
 792   }
 793 }
 794 
 795 
 796 // Print a short set of xml attributes to identify this nmethod.  The
 797 // output should be embedded in some other element.
 798 void nmethod::log_identity(xmlStream* log) const {
 799   log->print(" compile_id='%d'", compile_id());
 800   const char* nm_kind = compile_kind();
 801   if (nm_kind != NULL)  log->print(" compile_kind='%s'", nm_kind);
 802   if (compiler() != NULL) {
 803     log->print(" compiler='%s'", compiler()->name());
 804   }
 805   if (TieredCompilation) {
 806     log->print(" level='%d'", comp_level());
 807   }
 808 }
 809 
 810 
 811 #define LOG_OFFSET(log, name)                    \
 812   if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \
 813     log->print(" " XSTR(name) "_offset='%d'"    , \
 814                (intptr_t)name##_begin() - (intptr_t)this)




  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 "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/dependencies.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/scopeDesc.hpp"
  31 #include "compiler/abstractCompiler.hpp"
  32 #include "compiler/compileBroker.hpp"
  33 #include "compiler/compileLog.hpp"
  34 #include "compiler/compilerDirectives.hpp"
  35 #include "compiler/disassembler.hpp"
  36 #include "interpreter/bytecode.hpp"
  37 #include "oops/methodData.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "prims/jvmtiRedefineClassesTrace.hpp"
  40 #include "prims/jvmtiImpl.hpp"
  41 #include "runtime/atomic.inline.hpp"
  42 #include "runtime/orderAccess.inline.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/sweeper.hpp"
  45 #include "utilities/resourceHash.hpp"
  46 #include "utilities/dtrace.hpp"
  47 #include "utilities/events.hpp"
  48 #include "utilities/xmlstream.hpp"
  49 #ifdef SHARK
  50 #include "shark/sharkCompiler.hpp"
  51 #endif
  52 
  53 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  54 


 487   int frame_complete,
 488   int frame_size,
 489   ByteSize basic_lock_owner_sp_offset,
 490   ByteSize basic_lock_sp_offset,
 491   OopMapSet* oop_maps) {
 492   code_buffer->finalize_oop_references(method);
 493   // create nmethod
 494   nmethod* nm = NULL;
 495   {
 496     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 497     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
 498     CodeOffsets offsets;
 499     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 500     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 501     nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), native_nmethod_size,
 502                                             compile_id, &offsets,
 503                                             code_buffer, frame_size,
 504                                             basic_lock_owner_sp_offset,
 505                                             basic_lock_sp_offset, oop_maps);
 506     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_native_nmethod(nm));
 507 
 508     if (Thread::current()->is_Compiler_thread()) {
 509       if (CURRENT_ENV->dirset()->PrintAssemblyOption && nm != NULL) {
 510         Disassembler::decode(nm);
 511       }
 512     }
 513   }
 514   // verify nmethod
 515   debug_only(if (nm) nm->verify();) // might block
 516 
 517   if (nm != NULL) {
 518     nm->log_new_nmethod();
 519   }
 520 
 521   return nm;
 522 }
 523 
 524 nmethod* nmethod::new_nmethod(methodHandle method,
 525   int compile_id,
 526   int entry_bci,
 527   CodeOffsets* offsets,
 528   int orig_pc_offset,
 529   DebugInformationRecorder* debug_info,
 530   Dependencies* dependencies,
 531   CodeBuffer* code_buffer, int frame_size,
 532   OopMapSet* oop_maps,
 533   ExceptionHandlerTable* handler_table,


 565       // class hierarchy above the loaded class, checking only nmethods
 566       // which are dependent on those classes.  The slow way is to
 567       // check every nmethod for dependencies which makes it linear in
 568       // the number of methods compiled.  For applications with a lot
 569       // classes the slow way is too slow.
 570       for (Dependencies::DepStream deps(nm); deps.next(); ) {
 571         if (deps.type() == Dependencies::call_site_target_value) {
 572           // CallSite dependencies are managed on per-CallSite instance basis.
 573           oop call_site = deps.argument_oop(0);
 574           MethodHandles::add_dependent_nmethod(call_site, nm);
 575         } else {
 576           Klass* klass = deps.context_type();
 577           if (klass == NULL) {
 578             continue;  // ignore things like evol_method
 579           }
 580           // record this nmethod as dependent on this klass
 581           InstanceKlass::cast(klass)->add_dependent_nmethod(nm);
 582         }
 583       }
 584       NOT_PRODUCT(nmethod_stats.note_nmethod(nm));



 585     }
 586   }
 587   // Do verification and logging outside CodeCache_lock.
 588   if (nm != NULL) {
 589     // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
 590     DEBUG_ONLY(nm->verify();)
 591     nm->log_new_nmethod();
 592   }
 593   return nm;
 594 }
 595 
 596 
 597 // For native wrappers
 598 nmethod::nmethod(
 599   Method* method,
 600   int nmethod_size,
 601   int compile_id,
 602   CodeOffsets* offsets,
 603   CodeBuffer* code_buffer,
 604   int frame_size,


 766     if (ScavengeRootsInCode) {
 767       if (detect_scavenge_root_oops()) {
 768         CodeCache::add_scavenge_root_nmethod(this);
 769       }
 770       Universe::heap()->register_nmethod(this);
 771     }
 772     debug_only(verify_scavenge_root_oops());
 773 
 774     CodeCache::commit(this);
 775 
 776     // Copy contents of ExceptionHandlerTable to nmethod
 777     handler_table->copy_to(this);
 778     nul_chk_table->copy_to(this);
 779 
 780     // we use the information of entry points to find out if a method is
 781     // static or non static
 782     assert(compiler->is_c2() ||
 783            _method->is_static() == (entry_point() == _verified_entry_point),
 784            " entry points must be same for static methods and vice versa");
 785   }







 786 }

 787 
 788 // Print a short set of xml attributes to identify this nmethod.  The
 789 // output should be embedded in some other element.
 790 void nmethod::log_identity(xmlStream* log) const {
 791   log->print(" compile_id='%d'", compile_id());
 792   const char* nm_kind = compile_kind();
 793   if (nm_kind != NULL)  log->print(" compile_kind='%s'", nm_kind);
 794   if (compiler() != NULL) {
 795     log->print(" compiler='%s'", compiler()->name());
 796   }
 797   if (TieredCompilation) {
 798     log->print(" level='%d'", comp_level());
 799   }
 800 }
 801 
 802 
 803 #define LOG_OFFSET(log, name)                    \
 804   if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \
 805     log->print(" " XSTR(name) "_offset='%d'"    , \
 806                (intptr_t)name##_begin() - (intptr_t)this)


src/share/vm/code/nmethod.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File