hotspot/src/share/vm/code/nmethod.cpp
changeset 363 99d43e8a76ad
parent 347 df859fcca515
child 670 ddf3e9583f2f
equal deleted inserted replaced
362:00cf4bffd828 363:99d43e8a76ad
    25 # include "incls/_precompiled.incl"
    25 # include "incls/_precompiled.incl"
    26 # include "incls/_nmethod.cpp.incl"
    26 # include "incls/_nmethod.cpp.incl"
    27 
    27 
    28 #ifdef DTRACE_ENABLED
    28 #ifdef DTRACE_ENABLED
    29 
    29 
    30 
       
    31 // Only bother with this argument setup if dtrace is available
    30 // Only bother with this argument setup if dtrace is available
    32 
    31 
    33 HS_DTRACE_PROBE_DECL8(hotspot, compiled__method__load,
    32 HS_DTRACE_PROBE_DECL8(hotspot, compiled__method__load,
    34   const char*, int, const char*, int, const char*, int, void*, size_t);
    33   const char*, int, const char*, int, const char*, int, void*, size_t);
    35 
    34 
   436   // create nmethod
   435   // create nmethod
   437   nmethod* nm = NULL;
   436   nmethod* nm = NULL;
   438   {
   437   {
   439     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   438     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   440     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
   439     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
   441     const int dummy = -1;               // Flag to force proper "operator new"
       
   442     CodeOffsets offsets;
   440     CodeOffsets offsets;
   443     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
   441     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
   444     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
   442     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
   445     nm = new (native_nmethod_size)
   443     nm = new (native_nmethod_size)
   446       nmethod(method(), native_nmethod_size, &offsets,
   444       nmethod(method(), native_nmethod_size, &offsets,
   458     nm->log_new_nmethod();
   456     nm->log_new_nmethod();
   459   }
   457   }
   460 
   458 
   461   return nm;
   459   return nm;
   462 }
   460 }
       
   461 
       
   462 #ifdef HAVE_DTRACE_H
       
   463 nmethod* nmethod::new_dtrace_nmethod(methodHandle method,
       
   464                                      CodeBuffer *code_buffer,
       
   465                                      int vep_offset,
       
   466                                      int trap_offset,
       
   467                                      int frame_complete,
       
   468                                      int frame_size) {
       
   469   // create nmethod
       
   470   nmethod* nm = NULL;
       
   471   {
       
   472     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
       
   473     int nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
       
   474     CodeOffsets offsets;
       
   475     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
       
   476     offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset);
       
   477     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
       
   478 
       
   479     nm = new (nmethod_size) nmethod(method(), nmethod_size, &offsets, code_buffer, frame_size);
       
   480 
       
   481     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_nmethod(nm));
       
   482     if (PrintAssembly && nm != NULL)
       
   483       Disassembler::decode(nm);
       
   484   }
       
   485   // verify nmethod
       
   486   debug_only(if (nm) nm->verify();) // might block
       
   487 
       
   488   if (nm != NULL) {
       
   489     nm->log_new_nmethod();
       
   490   }
       
   491 
       
   492   return nm;
       
   493 }
       
   494 
       
   495 #endif // def HAVE_DTRACE_H
   463 
   496 
   464 nmethod* nmethod::new_nmethod(methodHandle method,
   497 nmethod* nmethod::new_nmethod(methodHandle method,
   465   int compile_id,
   498   int compile_id,
   466   int entry_bci,
   499   int entry_bci,
   467   CodeOffsets* offsets,
   500   CodeOffsets* offsets,
   556     // We have no exception handler or deopt handler make the
   589     // We have no exception handler or deopt handler make the
   557     // values something that will never match a pc like the nmethod vtable entry
   590     // values something that will never match a pc like the nmethod vtable entry
   558     _exception_offset        = 0;
   591     _exception_offset        = 0;
   559     _deoptimize_offset       = 0;
   592     _deoptimize_offset       = 0;
   560     _orig_pc_offset          = 0;
   593     _orig_pc_offset          = 0;
       
   594 #ifdef HAVE_DTRACE_H
       
   595     _trap_offset             = 0;
       
   596 #endif // def HAVE_DTRACE_H
   561     _stub_offset             = data_offset();
   597     _stub_offset             = data_offset();
   562     _consts_offset           = data_offset();
   598     _consts_offset           = data_offset();
   563     _scopes_data_offset      = data_offset();
   599     _scopes_data_offset      = data_offset();
   564     _scopes_pcs_offset       = _scopes_data_offset;
   600     _scopes_pcs_offset       = _scopes_data_offset;
   565     _dependencies_offset     = _scopes_pcs_offset;
   601     _dependencies_offset     = _scopes_pcs_offset;
   613     }
   649     }
   614   }
   650   }
   615   Events::log("Create nmethod " INTPTR_FORMAT, this);
   651   Events::log("Create nmethod " INTPTR_FORMAT, this);
   616 }
   652 }
   617 
   653 
       
   654 // For dtrace wrappers
       
   655 #ifdef HAVE_DTRACE_H
       
   656 nmethod::nmethod(
       
   657   methodOop method,
       
   658   int nmethod_size,
       
   659   CodeOffsets* offsets,
       
   660   CodeBuffer* code_buffer,
       
   661   int frame_size)
       
   662   : CodeBlob("dtrace nmethod", code_buffer, sizeof(nmethod),
       
   663              nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, NULL),
       
   664   _compiled_synchronized_native_basic_lock_owner_sp_offset(in_ByteSize(-1)),
       
   665   _compiled_synchronized_native_basic_lock_sp_offset(in_ByteSize(-1))
       
   666 {
       
   667   {
       
   668     debug_only(No_Safepoint_Verifier nsv;)
       
   669     assert_locked_or_safepoint(CodeCache_lock);
       
   670 
       
   671     NOT_PRODUCT(_has_debug_info = false; )
       
   672     _method                  = method;
       
   673     _entry_bci               = InvocationEntryBci;
       
   674     _link                    = NULL;
       
   675     _compiler                = NULL;
       
   676     // We have no exception handler or deopt handler make the
       
   677     // values something that will never match a pc like the nmethod vtable entry
       
   678     _exception_offset        = 0;
       
   679     _deoptimize_offset       = 0;
       
   680     _trap_offset             = offsets->value(CodeOffsets::Dtrace_trap);
       
   681     _orig_pc_offset          = 0;
       
   682     _stub_offset             = data_offset();
       
   683     _consts_offset           = data_offset();
       
   684     _scopes_data_offset      = data_offset();
       
   685     _scopes_pcs_offset       = _scopes_data_offset;
       
   686     _dependencies_offset     = _scopes_pcs_offset;
       
   687     _handler_table_offset    = _dependencies_offset;
       
   688     _nul_chk_table_offset    = _handler_table_offset;
       
   689     _nmethod_end_offset      = _nul_chk_table_offset;
       
   690     _compile_id              = 0;  // default
       
   691     _comp_level              = CompLevel_none;
       
   692     _entry_point             = instructions_begin();
       
   693     _verified_entry_point    = instructions_begin() + offsets->value(CodeOffsets::Verified_Entry);
       
   694     _osr_entry_point         = NULL;
       
   695     _exception_cache         = NULL;
       
   696     _pc_desc_cache.reset_to(NULL);
       
   697 
       
   698     flags.clear();
       
   699     flags.state              = alive;
       
   700     _markedForDeoptimization = 0;
       
   701 
       
   702     _lock_count = 0;
       
   703     _stack_traversal_mark    = 0;
       
   704 
       
   705     code_buffer->copy_oops_to(this);
       
   706     debug_only(check_store();)
       
   707     CodeCache::commit(this);
       
   708     VTune::create_nmethod(this);
       
   709   }
       
   710 
       
   711   if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
       
   712     ttyLocker ttyl;  // keep the following output all in one block
       
   713     // This output goes directly to the tty, not the compiler log.
       
   714     // To enable tools to match it up with the compilation activity,
       
   715     // be sure to tag this tty output with the compile ID.
       
   716     if (xtty != NULL) {
       
   717       xtty->begin_head("print_dtrace_nmethod");
       
   718       xtty->method(_method);
       
   719       xtty->stamp();
       
   720       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
       
   721     }
       
   722     // print the header part first
       
   723     print();
       
   724     // then print the requested information
       
   725     if (PrintNMethods) {
       
   726       print_code();
       
   727     }
       
   728     if (PrintRelocations) {
       
   729       print_relocations();
       
   730     }
       
   731     if (xtty != NULL) {
       
   732       xtty->tail("print_dtrace_nmethod");
       
   733     }
       
   734   }
       
   735   Events::log("Create nmethod " INTPTR_FORMAT, this);
       
   736 }
       
   737 #endif // def HAVE_DTRACE_H
   618 
   738 
   619 void* nmethod::operator new(size_t size, int nmethod_size) {
   739 void* nmethod::operator new(size_t size, int nmethod_size) {
   620   // Always leave some room in the CodeCache for I2C/C2I adapters
   740   // Always leave some room in the CodeCache for I2C/C2I adapters
   621   if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) return NULL;
   741   if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) return NULL;
   622   return CodeCache::allocate(nmethod_size);
   742   return CodeCache::allocate(nmethod_size);
   656     _comp_level              = comp_level;
   776     _comp_level              = comp_level;
   657     _entry_bci               = entry_bci;
   777     _entry_bci               = entry_bci;
   658     _link                    = NULL;
   778     _link                    = NULL;
   659     _compiler                = compiler;
   779     _compiler                = compiler;
   660     _orig_pc_offset          = orig_pc_offset;
   780     _orig_pc_offset          = orig_pc_offset;
       
   781 #ifdef HAVE_DTRACE_H
       
   782     _trap_offset             = 0;
       
   783 #endif // def HAVE_DTRACE_H
   661     _stub_offset             = instructions_offset() + code_buffer->total_offset_of(code_buffer->stubs()->start());
   784     _stub_offset             = instructions_offset() + code_buffer->total_offset_of(code_buffer->stubs()->start());
   662 
   785 
   663     // Exception handler and deopt handler are in the stub section
   786     // Exception handler and deopt handler are in the stub section
   664     _exception_offset        = _stub_offset + offsets->value(CodeOffsets::Exceptions);
   787     _exception_offset        = _stub_offset + offsets->value(CodeOffsets::Exceptions);
   665     _deoptimize_offset       = _stub_offset + offsets->value(CodeOffsets::Deopt);
   788     _deoptimize_offset       = _stub_offset + offsets->value(CodeOffsets::Deopt);
  1883   if (is_compiled_by_c1()) {
  2006   if (is_compiled_by_c1()) {
  1884     tty->print("(c1) ");
  2007     tty->print("(c1) ");
  1885   } else if (is_compiled_by_c2()) {
  2008   } else if (is_compiled_by_c2()) {
  1886     tty->print("(c2) ");
  2009     tty->print("(c2) ");
  1887   } else {
  2010   } else {
  1888     assert(is_native_method(), "Who else?");
       
  1889     tty->print("(nm) ");
  2011     tty->print("(nm) ");
  1890   }
  2012   }
  1891 
  2013 
  1892   print_on(tty, "nmethod");
  2014   print_on(tty, "nmethod");
  1893   tty->cr();
  2015   tty->cr();