< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

 485     // verify nmethod
 486     debug_only(nm->verify();) // might block
 487 
 488     nm->log_new_nmethod();
 489   }
 490   return nm;
 491 }
 492 
 493 nmethod* nmethod::new_nmethod(const methodHandle& method,
 494   int compile_id,
 495   int entry_bci,
 496   CodeOffsets* offsets,
 497   int orig_pc_offset,
 498   DebugInformationRecorder* debug_info,
 499   Dependencies* dependencies,
 500   CodeBuffer* code_buffer, int frame_size,
 501   OopMapSet* oop_maps,
 502   ExceptionHandlerTable* handler_table,
 503   ImplicitExceptionTable* nul_chk_table,
 504   AbstractCompiler* compiler,
 505   int comp_level,
 506   const GrowableArrayView<RuntimeStub*>& native_invokers
 507 #if INCLUDE_JVMCI
 508   , char* speculations,
 509   int speculations_len,
 510   int nmethod_mirror_index,
 511   const char* nmethod_mirror_name,
 512   FailedSpeculation** failed_speculations
 513 #endif
 514 )
 515 {
 516   assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
 517   code_buffer->finalize_oop_references(method);
 518   // create nmethod
 519   nmethod* nm = NULL;
 520   { MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 521 #if INCLUDE_JVMCI
 522     int jvmci_data_size = !compiler->is_jvmci() ? 0 : JVMCINMethodData::compute_size(nmethod_mirror_name);
 523 #endif
 524     int nmethod_size =
 525       CodeBlob::allocation_size(code_buffer, sizeof(nmethod))
 526       + adjust_pcs_size(debug_info->pcs_size())
 527       + align_up((int)dependencies->size_in_bytes(), oopSize)
 528       + align_up(checked_cast<int>(native_invokers.data_size_in_bytes()), oopSize)
 529       + align_up(handler_table->size_in_bytes()    , oopSize)
 530       + align_up(nul_chk_table->size_in_bytes()    , oopSize)
 531 #if INCLUDE_JVMCI
 532       + align_up(speculations_len                  , oopSize)
 533       + align_up(jvmci_data_size                   , oopSize)
 534 #endif
 535       + align_up(debug_info->data_size()           , oopSize);
 536 
 537     nm = new (nmethod_size, comp_level)
 538     nmethod(method(), compiler->type(), nmethod_size, compile_id, entry_bci, offsets,
 539             orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
 540             oop_maps,
 541             handler_table,
 542             nul_chk_table,
 543             compiler,
 544             comp_level,
 545             native_invokers
 546 #if INCLUDE_JVMCI
 547             , speculations,
 548             speculations_len,
 549             jvmci_data_size
 550 #endif
 551             );
 552 
 553     if (nm != NULL) {
 554 #if INCLUDE_JVMCI
 555       if (compiler->is_jvmci()) {
 556         // Initialize the JVMCINMethodData object inlined into nm
 557         nm->jvmci_nmethod_data()->initialize(nmethod_mirror_index, nmethod_mirror_name, failed_speculations);
 558       }
 559 #endif
 560       // To make dependency checking during class loading fast, record
 561       // the nmethod dependencies in the classes it is dependent on.
 562       // This allows the dependency checking code to simply walk the
 563       // class hierarchy above the loaded class, checking only nmethods
 564       // which are dependent on those classes.  The slow way is to
 565       // check every nmethod for dependencies which makes it linear in

 613     int deoptimize_offset    = 0;
 614     int deoptimize_mh_offset = 0;
 615 
 616     debug_only(NoSafepointVerifier nsv;)
 617     assert_locked_or_safepoint(CodeCache_lock);
 618 
 619     init_defaults();
 620     _entry_bci               = InvocationEntryBci;
 621     // We have no exception handler or deopt handler make the
 622     // values something that will never match a pc like the nmethod vtable entry
 623     _exception_offset        = 0;
 624     _orig_pc_offset          = 0;
 625 
 626     _consts_offset           = data_offset();
 627     _stub_offset             = data_offset();
 628     _oops_offset             = data_offset();
 629     _metadata_offset         = _oops_offset         + align_up(code_buffer->total_oop_size(), oopSize);
 630     scopes_data_offset       = _metadata_offset     + align_up(code_buffer->total_metadata_size(), wordSize);
 631     _scopes_pcs_offset       = scopes_data_offset;
 632     _dependencies_offset     = _scopes_pcs_offset;
 633     _native_invokers_offset     = _dependencies_offset;
 634     _handler_table_offset    = _native_invokers_offset;
 635     _nul_chk_table_offset    = _handler_table_offset;
 636 #if INCLUDE_JVMCI
 637     _speculations_offset     = _nul_chk_table_offset;
 638     _jvmci_data_offset       = _speculations_offset;
 639     _nmethod_end_offset      = _jvmci_data_offset;
 640 #else
 641     _nmethod_end_offset      = _nul_chk_table_offset;
 642 #endif
 643     _compile_id              = compile_id;
 644     _comp_level              = CompLevel_none;
 645     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 646     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 647     _osr_entry_point         = NULL;
 648     _exception_cache         = NULL;
 649     _pc_desc_container.reset_to(NULL);
 650     _hotness_counter         = NMethodSweeper::hotness_counter_reset_val();
 651 
 652     _scopes_data_begin = (address) this + scopes_data_offset;
 653     _deopt_handler_begin = (address) this + deoptimize_offset;
 654     _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;

 710 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () {
 711   return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level));
 712 }
 713 
 714 nmethod::nmethod(
 715   Method* method,
 716   CompilerType type,
 717   int nmethod_size,
 718   int compile_id,
 719   int entry_bci,
 720   CodeOffsets* offsets,
 721   int orig_pc_offset,
 722   DebugInformationRecorder* debug_info,
 723   Dependencies* dependencies,
 724   CodeBuffer *code_buffer,
 725   int frame_size,
 726   OopMapSet* oop_maps,
 727   ExceptionHandlerTable* handler_table,
 728   ImplicitExceptionTable* nul_chk_table,
 729   AbstractCompiler* compiler,
 730   int comp_level,
 731   const GrowableArrayView<RuntimeStub*>& native_invokers
 732 #if INCLUDE_JVMCI
 733   , char* speculations,
 734   int speculations_len,
 735   int jvmci_data_size
 736 #endif
 737   )
 738   : CompiledMethod(method, "nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false),
 739   _is_unloading_state(0),
 740   _native_receiver_sp_offset(in_ByteSize(-1)),
 741   _native_basic_lock_sp_offset(in_ByteSize(-1))
 742 {
 743   assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
 744   {
 745     debug_only(NoSafepointVerifier nsv;)
 746     assert_locked_or_safepoint(CodeCache_lock);
 747 
 748     _deopt_handler_begin = (address) this;
 749     _deopt_mh_handler_begin = (address) this;
 750 
 751     init_defaults();

 788       _exception_offset       = _stub_offset          + offsets->value(CodeOffsets::Exceptions);
 789       _deopt_handler_begin    = (address) this + _stub_offset          + offsets->value(CodeOffsets::Deopt);
 790       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
 791         _deopt_mh_handler_begin  = (address) this + _stub_offset          + offsets->value(CodeOffsets::DeoptMH);
 792       } else {
 793         _deopt_mh_handler_begin  = NULL;
 794       }
 795     }
 796     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
 797       _unwind_handler_offset = code_offset()         + offsets->value(CodeOffsets::UnwindHandler);
 798     } else {
 799       _unwind_handler_offset = -1;
 800     }
 801 
 802     _oops_offset             = data_offset();
 803     _metadata_offset         = _oops_offset          + align_up(code_buffer->total_oop_size(), oopSize);
 804     int scopes_data_offset   = _metadata_offset      + align_up(code_buffer->total_metadata_size(), wordSize);
 805 
 806     _scopes_pcs_offset       = scopes_data_offset    + align_up(debug_info->data_size       (), oopSize);
 807     _dependencies_offset     = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
 808     _native_invokers_offset  = _dependencies_offset  + align_up((int)dependencies->size_in_bytes(), oopSize);
 809     _handler_table_offset    = _native_invokers_offset + align_up(checked_cast<int>(native_invokers.data_size_in_bytes()), oopSize);
 810     _nul_chk_table_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
 811 #if INCLUDE_JVMCI
 812     _speculations_offset     = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
 813     _jvmci_data_offset       = _speculations_offset  + align_up(speculations_len, oopSize);
 814     _nmethod_end_offset      = _jvmci_data_offset    + align_up(jvmci_data_size, oopSize);
 815 #else
 816     _nmethod_end_offset      = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
 817 #endif
 818     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 819     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 820     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 821     _exception_cache         = NULL;
 822     _scopes_data_begin       = (address) this + scopes_data_offset;
 823 
 824     _pc_desc_container.reset_to(scopes_pcs_begin());
 825 
 826     code_buffer->copy_code_and_locs_to(this);
 827     // Copy contents of ScopeDescRecorder to nmethod
 828     code_buffer->copy_values_to(this);
 829     debug_info->copy_to(this);
 830     dependencies->copy_to(this);
 831     if (native_invokers.is_nonempty()) { // can not get address of zero-length array
 832       // Copy native stubs
 833       memcpy(native_invokers_begin(), native_invokers.adr_at(0), native_invokers.data_size_in_bytes());
 834     }
 835     clear_unloading_state();
 836 
 837     Universe::heap()->register_nmethod(this);
 838     debug_only(Universe::heap()->verify_nmethod(this));
 839 
 840     CodeCache::commit(this);
 841 
 842     // Copy contents of ExceptionHandlerTable to nmethod
 843     handler_table->copy_to(this);
 844     nul_chk_table->copy_to(this);
 845 
 846 #if INCLUDE_JVMCI
 847     // Copy speculations to nmethod
 848     if (speculations_size() != 0) {
 849       memcpy(speculations_begin(), speculations, speculations_len);
 850     }
 851 #endif
 852 
 853     // we use the information of entry points to find out if a method is
 854     // static or non static

 979 #endif
 980   } else {
 981     print(); // print the header part only.
 982   }
 983 
 984 #if defined(SUPPORT_DATA_STRUCTS)
 985   if (AbstractDisassembler::show_structs()) {
 986     methodHandle mh(Thread::current(), _method);
 987     if (printmethod || PrintDebugInfo || CompilerOracle::has_option(mh, CompileCommand::PrintDebugInfo)) {
 988       print_scopes();
 989       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 990     }
 991     if (printmethod || PrintRelocations || CompilerOracle::has_option(mh, CompileCommand::PrintRelocations)) {
 992       print_relocations();
 993       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 994     }
 995     if (printmethod || PrintDependencies || CompilerOracle::has_option(mh, CompileCommand::PrintDependencies)) {
 996       print_dependencies();
 997       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 998     }
 999     if (printmethod && native_invokers_begin() < native_invokers_end()) {
1000       print_native_invokers();
1001       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
1002     }
1003     if (printmethod || PrintExceptionHandlers) {
1004       print_handler_table();
1005       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
1006       print_nul_chk_table();
1007       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
1008     }
1009 
1010     if (printmethod) {
1011       print_recorded_oops();
1012       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
1013       print_recorded_metadata();
1014       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
1015     }
1016   }
1017 #endif
1018 
1019   if (xtty != NULL) {
1020     xtty->tail("print_nmethod");
1021   }
1022 }

1043     initialize_immediate_oop(&dest[index], array->at(index));
1044   }
1045 
1046   // Now we can fix up all the oops in the code.  We need to do this
1047   // in the code because the assembler uses jobjects as placeholders.
1048   // The code and relocations have already been initialized by the
1049   // CodeBlob constructor, so it is valid even at this early point to
1050   // iterate over relocations and patch the code.
1051   fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true);
1052 }
1053 
1054 void nmethod::copy_values(GrowableArray<Metadata*>* array) {
1055   int length = array->length();
1056   assert((address)(metadata_begin() + length) <= (address)metadata_end(), "big enough");
1057   Metadata** dest = metadata_begin();
1058   for (int index = 0 ; index < length; index++) {
1059     dest[index] = array->at(index);
1060   }
1061 }
1062 
1063 void nmethod::free_native_invokers() {
1064   for (RuntimeStub** it = native_invokers_begin(); it < native_invokers_end(); it++) {
1065     CodeCache::free(*it);
1066   }
1067 }
1068 
1069 void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) {
1070   // re-patch all oop-bearing instructions, just in case some oops moved
1071   RelocIterator iter(this, begin, end);
1072   while (iter.next()) {
1073     if (iter.type() == relocInfo::oop_type) {
1074       oop_Relocation* reloc = iter.oop_reloc();
1075       if (initialize_immediates && reloc->oop_is_immediate()) {
1076         oop* dest = reloc->oop_addr();
1077         initialize_immediate_oop(dest, cast_from_oop<jobject>(*dest));
1078       }
1079       // Refresh the oop-related bits of this instruction.
1080       reloc->fix_oop_relocation();
1081     } else if (iter.type() == relocInfo::metadata_type) {
1082       metadata_Relocation* reloc = iter.metadata_reloc();
1083       reloc->fix_metadata_relocation();
1084     }
1085   }
1086 }
1087 
1088 

2698   ResourceMark m;       // in case methods get printed via the debugger
2699   tty->print_cr("relocations:");
2700   RelocIterator iter(this);
2701   iter.print();
2702 }
2703 #endif
2704 
2705 void nmethod::print_pcs_on(outputStream* st) {
2706   ResourceMark m;       // in case methods get printed via debugger
2707   st->print("pc-bytecode offsets:");
2708   if (scopes_pcs_begin() < scopes_pcs_end()) {
2709     st->cr();
2710     for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2711       p->print_on(st, this);  // print output ends with a newline
2712     }
2713   } else {
2714     st->print_cr(" <list empty>");
2715   }
2716 }
2717 
2718 void nmethod::print_native_invokers() {
2719   ResourceMark m;       // in case methods get printed via debugger
2720   tty->print_cr("Native invokers:");
2721   for (RuntimeStub** itt = native_invokers_begin(); itt < native_invokers_end(); itt++) {
2722     (*itt)->print_on(tty);
2723   }
2724 }
2725 
2726 void nmethod::print_handler_table() {
2727   ExceptionHandlerTable(this).print(code_begin());
2728 }
2729 
2730 void nmethod::print_nul_chk_table() {
2731   ImplicitExceptionTable(this).print(code_begin());
2732 }
2733 
2734 void nmethod::print_recorded_oop(int log_n, int i) {
2735   void* value;
2736 
2737   if (i == 0) {
2738     value = NULL;
2739   } else {
2740     // Be careful around non-oop words. Don't create an oop
2741     // with that value, or it will assert in verification code.
2742     if (Universe::contains_non_oop_word(oop_addr_at(i))) {
2743       value = Universe::non_oop_word();
2744     } else {
2745       value = oop_at(i);

 485     // verify nmethod
 486     debug_only(nm->verify();) // might block
 487 
 488     nm->log_new_nmethod();
 489   }
 490   return nm;
 491 }
 492 
 493 nmethod* nmethod::new_nmethod(const methodHandle& method,
 494   int compile_id,
 495   int entry_bci,
 496   CodeOffsets* offsets,
 497   int orig_pc_offset,
 498   DebugInformationRecorder* debug_info,
 499   Dependencies* dependencies,
 500   CodeBuffer* code_buffer, int frame_size,
 501   OopMapSet* oop_maps,
 502   ExceptionHandlerTable* handler_table,
 503   ImplicitExceptionTable* nul_chk_table,
 504   AbstractCompiler* compiler,
 505   int comp_level

 506 #if INCLUDE_JVMCI
 507   , char* speculations,
 508   int speculations_len,
 509   int nmethod_mirror_index,
 510   const char* nmethod_mirror_name,
 511   FailedSpeculation** failed_speculations
 512 #endif
 513 )
 514 {
 515   assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
 516   code_buffer->finalize_oop_references(method);
 517   // create nmethod
 518   nmethod* nm = NULL;
 519   { MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 520 #if INCLUDE_JVMCI
 521     int jvmci_data_size = !compiler->is_jvmci() ? 0 : JVMCINMethodData::compute_size(nmethod_mirror_name);
 522 #endif
 523     int nmethod_size =
 524       CodeBlob::allocation_size(code_buffer, sizeof(nmethod))
 525       + adjust_pcs_size(debug_info->pcs_size())
 526       + align_up((int)dependencies->size_in_bytes(), oopSize)

 527       + align_up(handler_table->size_in_bytes()    , oopSize)
 528       + align_up(nul_chk_table->size_in_bytes()    , oopSize)
 529 #if INCLUDE_JVMCI
 530       + align_up(speculations_len                  , oopSize)
 531       + align_up(jvmci_data_size                   , oopSize)
 532 #endif
 533       + align_up(debug_info->data_size()           , oopSize);
 534 
 535     nm = new (nmethod_size, comp_level)
 536     nmethod(method(), compiler->type(), nmethod_size, compile_id, entry_bci, offsets,
 537             orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
 538             oop_maps,
 539             handler_table,
 540             nul_chk_table,
 541             compiler,
 542             comp_level

 543 #if INCLUDE_JVMCI
 544             , speculations,
 545             speculations_len,
 546             jvmci_data_size
 547 #endif
 548             );
 549 
 550     if (nm != NULL) {
 551 #if INCLUDE_JVMCI
 552       if (compiler->is_jvmci()) {
 553         // Initialize the JVMCINMethodData object inlined into nm
 554         nm->jvmci_nmethod_data()->initialize(nmethod_mirror_index, nmethod_mirror_name, failed_speculations);
 555       }
 556 #endif
 557       // To make dependency checking during class loading fast, record
 558       // the nmethod dependencies in the classes it is dependent on.
 559       // This allows the dependency checking code to simply walk the
 560       // class hierarchy above the loaded class, checking only nmethods
 561       // which are dependent on those classes.  The slow way is to
 562       // check every nmethod for dependencies which makes it linear in

 610     int deoptimize_offset    = 0;
 611     int deoptimize_mh_offset = 0;
 612 
 613     debug_only(NoSafepointVerifier nsv;)
 614     assert_locked_or_safepoint(CodeCache_lock);
 615 
 616     init_defaults();
 617     _entry_bci               = InvocationEntryBci;
 618     // We have no exception handler or deopt handler make the
 619     // values something that will never match a pc like the nmethod vtable entry
 620     _exception_offset        = 0;
 621     _orig_pc_offset          = 0;
 622 
 623     _consts_offset           = data_offset();
 624     _stub_offset             = data_offset();
 625     _oops_offset             = data_offset();
 626     _metadata_offset         = _oops_offset         + align_up(code_buffer->total_oop_size(), oopSize);
 627     scopes_data_offset       = _metadata_offset     + align_up(code_buffer->total_metadata_size(), wordSize);
 628     _scopes_pcs_offset       = scopes_data_offset;
 629     _dependencies_offset     = _scopes_pcs_offset;
 630     _handler_table_offset    = _dependencies_offset;

 631     _nul_chk_table_offset    = _handler_table_offset;
 632 #if INCLUDE_JVMCI
 633     _speculations_offset     = _nul_chk_table_offset;
 634     _jvmci_data_offset       = _speculations_offset;
 635     _nmethod_end_offset      = _jvmci_data_offset;
 636 #else
 637     _nmethod_end_offset      = _nul_chk_table_offset;
 638 #endif
 639     _compile_id              = compile_id;
 640     _comp_level              = CompLevel_none;
 641     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 642     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 643     _osr_entry_point         = NULL;
 644     _exception_cache         = NULL;
 645     _pc_desc_container.reset_to(NULL);
 646     _hotness_counter         = NMethodSweeper::hotness_counter_reset_val();
 647 
 648     _scopes_data_begin = (address) this + scopes_data_offset;
 649     _deopt_handler_begin = (address) this + deoptimize_offset;
 650     _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;

 706 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () {
 707   return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level));
 708 }
 709 
 710 nmethod::nmethod(
 711   Method* method,
 712   CompilerType type,
 713   int nmethod_size,
 714   int compile_id,
 715   int entry_bci,
 716   CodeOffsets* offsets,
 717   int orig_pc_offset,
 718   DebugInformationRecorder* debug_info,
 719   Dependencies* dependencies,
 720   CodeBuffer *code_buffer,
 721   int frame_size,
 722   OopMapSet* oop_maps,
 723   ExceptionHandlerTable* handler_table,
 724   ImplicitExceptionTable* nul_chk_table,
 725   AbstractCompiler* compiler,
 726   int comp_level

 727 #if INCLUDE_JVMCI
 728   , char* speculations,
 729   int speculations_len,
 730   int jvmci_data_size
 731 #endif
 732   )
 733   : CompiledMethod(method, "nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false),
 734   _is_unloading_state(0),
 735   _native_receiver_sp_offset(in_ByteSize(-1)),
 736   _native_basic_lock_sp_offset(in_ByteSize(-1))
 737 {
 738   assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
 739   {
 740     debug_only(NoSafepointVerifier nsv;)
 741     assert_locked_or_safepoint(CodeCache_lock);
 742 
 743     _deopt_handler_begin = (address) this;
 744     _deopt_mh_handler_begin = (address) this;
 745 
 746     init_defaults();

 783       _exception_offset       = _stub_offset          + offsets->value(CodeOffsets::Exceptions);
 784       _deopt_handler_begin    = (address) this + _stub_offset          + offsets->value(CodeOffsets::Deopt);
 785       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
 786         _deopt_mh_handler_begin  = (address) this + _stub_offset          + offsets->value(CodeOffsets::DeoptMH);
 787       } else {
 788         _deopt_mh_handler_begin  = NULL;
 789       }
 790     }
 791     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
 792       _unwind_handler_offset = code_offset()         + offsets->value(CodeOffsets::UnwindHandler);
 793     } else {
 794       _unwind_handler_offset = -1;
 795     }
 796 
 797     _oops_offset             = data_offset();
 798     _metadata_offset         = _oops_offset          + align_up(code_buffer->total_oop_size(), oopSize);
 799     int scopes_data_offset   = _metadata_offset      + align_up(code_buffer->total_metadata_size(), wordSize);
 800 
 801     _scopes_pcs_offset       = scopes_data_offset    + align_up(debug_info->data_size       (), oopSize);
 802     _dependencies_offset     = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
 803     _handler_table_offset    = _dependencies_offset  + align_up((int)dependencies->size_in_bytes(), oopSize);

 804     _nul_chk_table_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
 805 #if INCLUDE_JVMCI
 806     _speculations_offset     = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
 807     _jvmci_data_offset       = _speculations_offset  + align_up(speculations_len, oopSize);
 808     _nmethod_end_offset      = _jvmci_data_offset    + align_up(jvmci_data_size, oopSize);
 809 #else
 810     _nmethod_end_offset      = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
 811 #endif
 812     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 813     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 814     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 815     _exception_cache         = NULL;
 816     _scopes_data_begin       = (address) this + scopes_data_offset;
 817 
 818     _pc_desc_container.reset_to(scopes_pcs_begin());
 819 
 820     code_buffer->copy_code_and_locs_to(this);
 821     // Copy contents of ScopeDescRecorder to nmethod
 822     code_buffer->copy_values_to(this);
 823     debug_info->copy_to(this);
 824     dependencies->copy_to(this);




 825     clear_unloading_state();
 826 
 827     Universe::heap()->register_nmethod(this);
 828     debug_only(Universe::heap()->verify_nmethod(this));
 829 
 830     CodeCache::commit(this);
 831 
 832     // Copy contents of ExceptionHandlerTable to nmethod
 833     handler_table->copy_to(this);
 834     nul_chk_table->copy_to(this);
 835 
 836 #if INCLUDE_JVMCI
 837     // Copy speculations to nmethod
 838     if (speculations_size() != 0) {
 839       memcpy(speculations_begin(), speculations, speculations_len);
 840     }
 841 #endif
 842 
 843     // we use the information of entry points to find out if a method is
 844     // static or non static

 969 #endif
 970   } else {
 971     print(); // print the header part only.
 972   }
 973 
 974 #if defined(SUPPORT_DATA_STRUCTS)
 975   if (AbstractDisassembler::show_structs()) {
 976     methodHandle mh(Thread::current(), _method);
 977     if (printmethod || PrintDebugInfo || CompilerOracle::has_option(mh, CompileCommand::PrintDebugInfo)) {
 978       print_scopes();
 979       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 980     }
 981     if (printmethod || PrintRelocations || CompilerOracle::has_option(mh, CompileCommand::PrintRelocations)) {
 982       print_relocations();
 983       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 984     }
 985     if (printmethod || PrintDependencies || CompilerOracle::has_option(mh, CompileCommand::PrintDependencies)) {
 986       print_dependencies();
 987       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 988     }




 989     if (printmethod || PrintExceptionHandlers) {
 990       print_handler_table();
 991       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 992       print_nul_chk_table();
 993       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 994     }
 995 
 996     if (printmethod) {
 997       print_recorded_oops();
 998       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
 999       print_recorded_metadata();
1000       tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
1001     }
1002   }
1003 #endif
1004 
1005   if (xtty != NULL) {
1006     xtty->tail("print_nmethod");
1007   }
1008 }

1029     initialize_immediate_oop(&dest[index], array->at(index));
1030   }
1031 
1032   // Now we can fix up all the oops in the code.  We need to do this
1033   // in the code because the assembler uses jobjects as placeholders.
1034   // The code and relocations have already been initialized by the
1035   // CodeBlob constructor, so it is valid even at this early point to
1036   // iterate over relocations and patch the code.
1037   fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true);
1038 }
1039 
1040 void nmethod::copy_values(GrowableArray<Metadata*>* array) {
1041   int length = array->length();
1042   assert((address)(metadata_begin() + length) <= (address)metadata_end(), "big enough");
1043   Metadata** dest = metadata_begin();
1044   for (int index = 0 ; index < length; index++) {
1045     dest[index] = array->at(index);
1046   }
1047 }
1048 






1049 void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) {
1050   // re-patch all oop-bearing instructions, just in case some oops moved
1051   RelocIterator iter(this, begin, end);
1052   while (iter.next()) {
1053     if (iter.type() == relocInfo::oop_type) {
1054       oop_Relocation* reloc = iter.oop_reloc();
1055       if (initialize_immediates && reloc->oop_is_immediate()) {
1056         oop* dest = reloc->oop_addr();
1057         initialize_immediate_oop(dest, cast_from_oop<jobject>(*dest));
1058       }
1059       // Refresh the oop-related bits of this instruction.
1060       reloc->fix_oop_relocation();
1061     } else if (iter.type() == relocInfo::metadata_type) {
1062       metadata_Relocation* reloc = iter.metadata_reloc();
1063       reloc->fix_metadata_relocation();
1064     }
1065   }
1066 }
1067 
1068 

2678   ResourceMark m;       // in case methods get printed via the debugger
2679   tty->print_cr("relocations:");
2680   RelocIterator iter(this);
2681   iter.print();
2682 }
2683 #endif
2684 
2685 void nmethod::print_pcs_on(outputStream* st) {
2686   ResourceMark m;       // in case methods get printed via debugger
2687   st->print("pc-bytecode offsets:");
2688   if (scopes_pcs_begin() < scopes_pcs_end()) {
2689     st->cr();
2690     for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2691       p->print_on(st, this);  // print output ends with a newline
2692     }
2693   } else {
2694     st->print_cr(" <list empty>");
2695   }
2696 }
2697 








2698 void nmethod::print_handler_table() {
2699   ExceptionHandlerTable(this).print(code_begin());
2700 }
2701 
2702 void nmethod::print_nul_chk_table() {
2703   ImplicitExceptionTable(this).print(code_begin());
2704 }
2705 
2706 void nmethod::print_recorded_oop(int log_n, int i) {
2707   void* value;
2708 
2709   if (i == 0) {
2710     value = NULL;
2711   } else {
2712     // Be careful around non-oop words. Don't create an oop
2713     // with that value, or it will assert in verification code.
2714     if (Universe::contains_non_oop_word(oop_addr_at(i))) {
2715       value = Universe::non_oop_word();
2716     } else {
2717       value = oop_at(i);
< prev index next >