< prev index next >

src/hotspot/share/code/relocInfo.cpp

Print this page

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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 "code/codeCache.hpp"
  26 #include "code/compiledIC.hpp"
  27 #include "code/nmethod.hpp"
  28 #include "code/relocInfo.hpp"

  29 #include "memory/resourceArea.hpp"
  30 #include "memory/universe.hpp"
  31 #include "oops/compressedOops.inline.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "runtime/flags/flagSetting.hpp"
  34 #include "runtime/stubCodeGenerator.hpp"
  35 #include "utilities/align.hpp"
  36 #include "utilities/checkedCast.hpp"
  37 #include "utilities/copy.hpp"
  38 
  39 #include <new>
  40 #include <type_traits>
  41 
  42 const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
  43 
  44 
  45 // Implementation of relocInfo
  46 
  47 #ifdef ASSERT
  48 relocInfo::relocType relocInfo::check_relocType(relocType type) {

 155   _addr    = cs->start();
 156   _code    = nullptr; // Not cb->blob();
 157 
 158   CodeBuffer* cb = cs->outer();
 159   assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
 160   for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
 161     CodeSection* cs = cb->code_section(n);
 162     _section_start[n] = cs->start();
 163     _section_end  [n] = cs->end();
 164   }
 165 
 166   assert(!has_current(), "just checking");
 167 
 168   assert(begin == nullptr || begin >= cs->start(), "in bounds");
 169   assert(limit == nullptr || limit <= cs->end(),   "in bounds");
 170   set_limits(begin, limit);
 171 }
 172 
 173 bool RelocIterator::addr_in_const() const {
 174   const int n = CodeBuffer::SECT_CONSTS;



 175   return section_start(n) <= addr() && addr() < section_end(n);
 176 }
 177 
 178 
 179 void RelocIterator::set_limits(address begin, address limit) {
 180   _limit = limit;
 181 
 182   // the limit affects this next stuff:
 183   if (begin != nullptr) {
 184     relocInfo* backup;
 185     address    backup_addr;
 186     while (true) {
 187       backup      = _current;
 188       backup_addr = _addr;
 189       if (!next() || addr() >= begin) break;
 190     }
 191     // At this point, either we are at the first matching record,
 192     // or else there is no such record, and !has_current().
 193     // In either case, revert to the immediately preceding state.
 194     _current = backup;

 445   jint offset = unpack_1_int();
 446   _static_call = address_from_scaled_offset(offset, base);
 447 }
 448 
 449 void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
 450   short* p = (short*) dest->locs_end();
 451   CodeSection* insts = dest->outer()->insts();
 452   normalize_address(_owner, insts);
 453   p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
 454   dest->set_locs_end((relocInfo*) p);
 455 }
 456 
 457 void trampoline_stub_Relocation::unpack_data() {
 458   address base = binding()->section_start(CodeBuffer::SECT_INSTS);
 459   _owner = address_from_scaled_offset(unpack_1_int(), base);
 460 }
 461 
 462 void external_word_Relocation::pack_data_to(CodeSection* dest) {
 463   short* p = (short*) dest->locs_end();
 464   int index = ExternalsRecorder::find_index(_target);
 465   p = pack_1_int_to(p, index);


 466   dest->set_locs_end((relocInfo*) p);
 467 }
 468 
 469 
 470 void external_word_Relocation::unpack_data() {
 471   int index = unpack_1_int();
 472   _target = ExternalsRecorder::at(index);
 473 }
 474 
 475 
 476 void internal_word_Relocation::pack_data_to(CodeSection* dest) {
 477   short* p = (short*) dest->locs_end();
 478   normalize_address(_target, dest, true);
 479 
 480   // Check whether my target address is valid within this section.
 481   // If not, strengthen the relocation type to point to another section.
 482   int sindex = _section;
 483   if (sindex == CodeBuffer::SECT_NONE && _target != nullptr
 484       && (!dest->allocates(_target) || _target == dest->locs_point())) {
 485     sindex = dest->outer()->section_index_of(_target);
 486     guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
 487     relocInfo* base = dest->locs_end() - 1;
 488     assert(base->type() == this->type(), "sanity");
 489     // Change the written type, to be section_word_type instead.

 718 
 719   return nullptr;
 720 }
 721 
 722 void static_stub_Relocation::clear_inline_cache() {
 723   // Call stub is only used when calling the interpreted code.
 724   // It does not really need to be cleared, except that we want to clean out the methodoop.
 725   CompiledDirectCall::set_stub_to_clean(this);
 726 }
 727 
 728 
 729 void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 730   if (_target != nullptr) {
 731     // Probably this reference is absolute,  not relative, so the following is
 732     // probably a no-op.
 733     set_value(_target);
 734   }
 735   // If target is nullptr, this is  an absolute embedded reference to an external
 736   // location, which means  there is nothing to fix here.  In either case, the
 737   // resulting target should be an "external" address.








 738   postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
 739   postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
 740 }
 741 
 742 
 743 address external_word_Relocation::target() {
 744   address target = _target;
 745   if (target == nullptr) {
 746     target = pd_get_address_from_code();
 747   }
 748   return target;
 749 }
 750 
 751 
 752 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 753   address target = _target;
 754   if (target == nullptr) {
 755     target = new_addr_for(this->target(), src, dest);
 756   }
 757   set_value(target);
 758 }
 759 
 760 
 761 address internal_word_Relocation::target() {
 762   address target = _target;
 763   if (target == nullptr) {
 764     if (addr_in_const()) {
 765       target = *(address*)addr();
 766     } else {
 767       target = pd_get_address_from_code();
 768     }
 769   }
 770   return target;
 771 }
 772 
 773 //---------------------------------------------------------------------------------
 774 // Non-product code
 775 
 776 #ifndef PRODUCT
 777 
 778 static const char* reloc_type_string(relocInfo::relocType t) {
 779   switch (t) {
 780   #define EACH_CASE(name) \
 781   case relocInfo::name##_type: \
 782     return #name;
 783 
 784   APPLY_TO_RELOCATIONS(EACH_CASE);
 785   #undef EACH_CASE
 786 
 787   case relocInfo::none:
 788     return "none";
 789   case relocInfo::data_prefix_tag:
 790     return "prefix";
 791   default:
 792     return "UNKNOWN RELOC TYPE";
 793   }
 794 }
 795 
 796 
 797 void RelocIterator::print_current() {
 798   if (!has_current()) {
 799     tty->print_cr("(no relocs)");
 800     return;
 801   }
 802   tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
 803              p2i(_current), type(), reloc_type_string((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset());
 804   if (current()->format() != 0)
 805     tty->print(" format=%d", current()->format());
 806   if (datalen() == 1) {
 807     tty->print(" data=%d", data()[0]);
 808   } else if (datalen() > 0) {
 809     tty->print(" data={");
 810     for (int i = 0; i < datalen(); i++) {
 811       tty->print("%04x", data()[i] & 0xFFFF);
 812     }
 813     tty->print("}");
 814   }
 815   tty->print("]");
 816   switch (type()) {
 817   case relocInfo::oop_type:
 818     {
 819       oop_Relocation* r = oop_reloc();
 820       oop* oop_addr  = nullptr;
 821       oop  raw_oop   = nullptr;
 822       oop  oop_value = nullptr;
 823       if (code() != nullptr || r->oop_is_immediate()) {
 824         oop_addr  = r->oop_addr();
 825         raw_oop   = *oop_addr;
 826         oop_value = r->oop_value();
 827       }
 828       tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
 829                  p2i(oop_addr), p2i(raw_oop));
 830       // Do not print the oop by default--we want this routine to
 831       // work even during GC or other inconvenient times.
 832       if (WizardMode && oop_value != nullptr) {
 833         tty->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
 834         if (oopDesc::is_oop(oop_value)) {
 835           oop_value->print_value_on(tty);
 836         }
 837       }
 838       break;
 839     }
 840   case relocInfo::metadata_type:
 841     {
 842       metadata_Relocation* r = metadata_reloc();
 843       Metadata** metadata_addr  = nullptr;
 844       Metadata*    raw_metadata   = nullptr;
 845       Metadata*    metadata_value = nullptr;
 846       if (code() != nullptr || r->metadata_is_immediate()) {
 847         metadata_addr  = r->metadata_addr();
 848         raw_metadata   = *metadata_addr;
 849         metadata_value = r->metadata_value();
 850       }
 851       tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
 852                  p2i(metadata_addr), p2i(raw_metadata));
 853       if (metadata_value != nullptr) {
 854         tty->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
 855         metadata_value->print_value_on(tty);
 856       }
 857       break;
 858     }
 859   case relocInfo::external_word_type:
 860   case relocInfo::internal_word_type:
 861   case relocInfo::section_word_type:
 862     {
 863       DataRelocation* r = (DataRelocation*) reloc();
 864       tty->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
 865       break;
 866     }
 867   case relocInfo::static_call_type:
 868     {
 869       static_call_Relocation* r = (static_call_Relocation*) reloc();
 870       tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 871                  p2i(r->destination()), p2i(r->method_value()));




 872       break;
 873     }
 874   case relocInfo::runtime_call_type:
 875   case relocInfo::runtime_call_w_cp_type:
 876     {
 877       CallRelocation* r = (CallRelocation*) reloc();
 878       tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));


























 879       break;
 880     }
 881   case relocInfo::virtual_call_type:
 882     {
 883       virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
 884       tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 885                  p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));




 886       break;
 887     }
 888   case relocInfo::static_stub_type:
 889     {
 890       static_stub_Relocation* r = (static_stub_Relocation*) reloc();
 891       tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
 892       break;
 893     }
 894   case relocInfo::trampoline_stub_type:
 895     {
 896       trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
 897       tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
 898       break;
 899     }
 900   case relocInfo::opt_virtual_call_type:
 901     {
 902       opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();
 903       tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 904                  p2i(r->destination()), p2i(r->method_value()));




 905       break;
 906     }
 907   default:
 908     break;
 909   }
 910   tty->cr();
 911 }
 912 
 913 
 914 void RelocIterator::print() {
 915   RelocIterator save_this = (*this);
 916   relocInfo* scan = _current;
 917   if (!has_current())  scan += 1;  // nothing to scan here!
 918 
 919   bool skip_next = has_current();
 920   bool got_next;
 921   while (true) {
 922     got_next = (skip_next || next());
 923     skip_next = false;
 924 
 925     tty->print("         @" INTPTR_FORMAT ": ", p2i(scan));
 926     relocInfo* newscan = _current+1;
 927     if (!has_current())  newscan -= 1;  // nothing to scan here!
 928     while (scan < newscan) {
 929       tty->print("%04x", *(short*)scan & 0xFFFF);
 930       scan++;
 931     }
 932     tty->cr();
 933 
 934     if (!got_next)  break;
 935     print_current();
 936   }
 937 
 938   (*this) = save_this;
 939 }
 940 





 941 // For the debugger:
 942 extern "C"
 943 void print_blob_locs(nmethod* nm) {
 944   nm->print();
 945   RelocIterator iter(nm);
 946   iter.print();
 947 }
 948 extern "C"
 949 void print_buf_locs(CodeBuffer* cb) {
 950   FlagSetting fs(PrintRelocations, true);
 951   cb->print();
 952 }
 953 #endif // !PRODUCT

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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 "ci/ciUtilities.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/nmethod.hpp"
  29 #include "code/relocInfo.hpp"
  30 #include "code/SCCache.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "memory/universe.hpp"
  33 #include "oops/compressedOops.inline.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "runtime/flags/flagSetting.hpp"
  36 #include "runtime/stubCodeGenerator.hpp"
  37 #include "utilities/align.hpp"
  38 #include "utilities/checkedCast.hpp"
  39 #include "utilities/copy.hpp"
  40 
  41 #include <new>
  42 #include <type_traits>
  43 
  44 const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
  45 
  46 
  47 // Implementation of relocInfo
  48 
  49 #ifdef ASSERT
  50 relocInfo::relocType relocInfo::check_relocType(relocType type) {

 157   _addr    = cs->start();
 158   _code    = nullptr; // Not cb->blob();
 159 
 160   CodeBuffer* cb = cs->outer();
 161   assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
 162   for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
 163     CodeSection* cs = cb->code_section(n);
 164     _section_start[n] = cs->start();
 165     _section_end  [n] = cs->end();
 166   }
 167 
 168   assert(!has_current(), "just checking");
 169 
 170   assert(begin == nullptr || begin >= cs->start(), "in bounds");
 171   assert(limit == nullptr || limit <= cs->end(),   "in bounds");
 172   set_limits(begin, limit);
 173 }
 174 
 175 bool RelocIterator::addr_in_const() const {
 176   const int n = CodeBuffer::SECT_CONSTS;
 177   if (_section_start[n] == nullptr) {
 178     return false;
 179   }
 180   return section_start(n) <= addr() && addr() < section_end(n);
 181 }
 182 
 183 
 184 void RelocIterator::set_limits(address begin, address limit) {
 185   _limit = limit;
 186 
 187   // the limit affects this next stuff:
 188   if (begin != nullptr) {
 189     relocInfo* backup;
 190     address    backup_addr;
 191     while (true) {
 192       backup      = _current;
 193       backup_addr = _addr;
 194       if (!next() || addr() >= begin) break;
 195     }
 196     // At this point, either we are at the first matching record,
 197     // or else there is no such record, and !has_current().
 198     // In either case, revert to the immediately preceding state.
 199     _current = backup;

 450   jint offset = unpack_1_int();
 451   _static_call = address_from_scaled_offset(offset, base);
 452 }
 453 
 454 void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
 455   short* p = (short*) dest->locs_end();
 456   CodeSection* insts = dest->outer()->insts();
 457   normalize_address(_owner, insts);
 458   p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
 459   dest->set_locs_end((relocInfo*) p);
 460 }
 461 
 462 void trampoline_stub_Relocation::unpack_data() {
 463   address base = binding()->section_start(CodeBuffer::SECT_INSTS);
 464   _owner = address_from_scaled_offset(unpack_1_int(), base);
 465 }
 466 
 467 void external_word_Relocation::pack_data_to(CodeSection* dest) {
 468   short* p = (short*) dest->locs_end();
 469   int index = ExternalsRecorder::find_index(_target);
 470   // Use 4 bytes to store index to be able patch it when
 471   // updating relocations in SCCReader::read_relocations().
 472   p = add_jint(p, index);
 473   dest->set_locs_end((relocInfo*) p);
 474 }
 475 

 476 void external_word_Relocation::unpack_data() {
 477   int index = unpack_1_int();
 478   _target = ExternalsRecorder::at(index);
 479 }
 480 
 481 
 482 void internal_word_Relocation::pack_data_to(CodeSection* dest) {
 483   short* p = (short*) dest->locs_end();
 484   normalize_address(_target, dest, true);
 485 
 486   // Check whether my target address is valid within this section.
 487   // If not, strengthen the relocation type to point to another section.
 488   int sindex = _section;
 489   if (sindex == CodeBuffer::SECT_NONE && _target != nullptr
 490       && (!dest->allocates(_target) || _target == dest->locs_point())) {
 491     sindex = dest->outer()->section_index_of(_target);
 492     guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
 493     relocInfo* base = dest->locs_end() - 1;
 494     assert(base->type() == this->type(), "sanity");
 495     // Change the written type, to be section_word_type instead.

 724 
 725   return nullptr;
 726 }
 727 
 728 void static_stub_Relocation::clear_inline_cache() {
 729   // Call stub is only used when calling the interpreted code.
 730   // It does not really need to be cleared, except that we want to clean out the methodoop.
 731   CompiledDirectCall::set_stub_to_clean(this);
 732 }
 733 
 734 
 735 void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 736   if (_target != nullptr) {
 737     // Probably this reference is absolute,  not relative, so the following is
 738     // probably a no-op.
 739     set_value(_target);
 740   }
 741   // If target is nullptr, this is  an absolute embedded reference to an external
 742   // location, which means  there is nothing to fix here.  In either case, the
 743   // resulting target should be an "external" address.
 744 #ifdef ASSERT
 745   if (SCCache::is_on()) {
 746     // SCA needs relocation info for card table base which may point to CodeCache
 747     if (is_card_table_address(target())) {
 748       return;
 749     }
 750   }
 751 #endif
 752   postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
 753   postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
 754 }
 755 
 756 
 757 address external_word_Relocation::target() {
 758   address target = _target;
 759   if (target == nullptr) {
 760     target = pd_get_address_from_code();
 761   }
 762   return target;
 763 }
 764 
 765 
 766 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 767   address target = _target;
 768   if (target == nullptr) {
 769     target = new_addr_for(this->target(), src, dest);
 770   }
 771   set_value(target);
 772 }
 773 
 774 
 775 address internal_word_Relocation::target() {
 776   address target = _target;
 777   if (target == nullptr) {
 778     if (addr_in_const()) {
 779       target = *(address*)addr();
 780     } else {
 781       target = pd_get_address_from_code();
 782     }
 783   }
 784   return target;
 785 }
 786 
 787 const char* relocInfo::type_name(relocInfo::relocType t) {





 788   switch (t) {
 789   #define EACH_CASE(name) \
 790   case relocInfo::name##_type: \
 791     return #name;
 792 
 793   APPLY_TO_RELOCATIONS(EACH_CASE);
 794   #undef EACH_CASE
 795 
 796   case relocInfo::none:
 797     return "none";
 798   case relocInfo::data_prefix_tag:
 799     return "prefix";
 800   default:
 801     return "UNKNOWN RELOC TYPE";
 802   }
 803 }
 804 
 805 
 806 void RelocIterator::print_current_on(outputStream* st) {
 807   if (!has_current()) {
 808     st->print_cr("(no relocs)");
 809     return;
 810   }
 811   st->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
 812             p2i(_current), type(), relocInfo::type_name(type()), p2i(_addr), _current->addr_offset());
 813   if (current()->format() != 0)
 814     st->print(" format=%d", current()->format());
 815   if (datalen() == 1) {
 816     st->print(" data=%d", data()[0]);
 817   } else if (datalen() > 0) {
 818     st->print(" data={");
 819     for (int i = 0; i < datalen(); i++) {
 820       st->print("%04x", data()[i] & 0xFFFF);
 821     }
 822     st->print("}");
 823   }
 824   st->print("]");
 825   switch (type()) {
 826   case relocInfo::oop_type:
 827     {
 828       oop_Relocation* r = oop_reloc();
 829       oop* oop_addr  = nullptr;
 830       oop  raw_oop   = nullptr;
 831       oop  oop_value = nullptr;
 832       if (code() != nullptr || r->oop_is_immediate()) {
 833         oop_addr  = r->oop_addr();
 834         raw_oop   = *oop_addr;
 835         oop_value = r->oop_value();
 836       }
 837       st->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " index=%d]",
 838                  p2i(oop_addr), p2i(raw_oop), r->oop_index());
 839       // Do not print the oop by default--we want this routine to
 840       // work even during GC or other inconvenient times.
 841       if (WizardMode && oop_value != nullptr) {
 842         st->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
 843         if (oopDesc::is_oop(oop_value)) {
 844           oop_value->print_value_on(st);
 845         }
 846       }
 847       break;
 848     }
 849   case relocInfo::metadata_type:
 850     {
 851       metadata_Relocation* r = metadata_reloc();
 852       Metadata** metadata_addr  = nullptr;
 853       Metadata*    raw_metadata   = nullptr;
 854       Metadata*    metadata_value = nullptr;
 855       if (code() != nullptr || r->metadata_is_immediate()) {
 856         metadata_addr  = r->metadata_addr();
 857         raw_metadata   = *metadata_addr;
 858         metadata_value = r->metadata_value();
 859       }
 860       st->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " index=%d]",
 861                  p2i(metadata_addr), p2i(raw_metadata), r->metadata_index());
 862       if (metadata_value != nullptr) {
 863         st->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
 864         metadata_value->print_value_on(st);
 865       }
 866       break;
 867     }
 868   case relocInfo::external_word_type:
 869   case relocInfo::internal_word_type:
 870   case relocInfo::section_word_type:
 871     {
 872       DataRelocation* r = (DataRelocation*) reloc();
 873       st->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
 874       break;
 875     }
 876   case relocInfo::static_call_type:
 877     {
 878       static_call_Relocation* r = (static_call_Relocation*) reloc();
 879       st->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 880                  p2i(r->destination()), p2i(r->method_value()));
 881       CodeBlob* cb = CodeCache::find_blob(r->destination());
 882       if (cb != nullptr) {
 883         st->print(" Blob::%s", cb->name());
 884       }
 885       break;
 886     }
 887   case relocInfo::runtime_call_type:
 888   case relocInfo::runtime_call_w_cp_type:
 889     {
 890       CallRelocation* r = (CallRelocation*) reloc();
 891       address dest = r->destination();
 892       st->print(" | [destination=" INTPTR_FORMAT "]", p2i(dest));
 893       if (StubRoutines::contains(dest)) {
 894         StubCodeDesc* desc = StubCodeDesc::desc_for(dest);
 895         if (desc == nullptr) {
 896           desc = StubCodeDesc::desc_for(dest + frame::pc_return_offset);
 897         }
 898         if (desc != nullptr) {
 899           st->print(" Stub::%s", desc->name());
 900         }
 901       } else {
 902         CodeBlob* cb = CodeCache::find_blob(dest);
 903         if (cb != nullptr) {
 904           st->print(" Blob::%s", cb->name());
 905         } else {
 906           ResourceMark rm;
 907           const int buflen = 1024;
 908           char* buf = NEW_RESOURCE_ARRAY(char, buflen);
 909           int offset;
 910           if (os::dll_address_to_function_name(dest, buf, buflen, &offset)) {
 911             st->print(" %s", buf);
 912             if (offset != 0) {
 913               st->print("+%d", offset);
 914             }
 915           }
 916         }
 917       }
 918       break;
 919     }
 920   case relocInfo::virtual_call_type:
 921     {
 922       virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
 923       st->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 924                 p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));
 925       CodeBlob* cb = CodeCache::find_blob(r->destination());
 926       if (cb != nullptr) {
 927         st->print(" Blob::%s", cb->name());
 928       }
 929       break;
 930     }
 931   case relocInfo::static_stub_type:
 932     {
 933       static_stub_Relocation* r = (static_stub_Relocation*) reloc();
 934       st->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
 935       break;
 936     }
 937   case relocInfo::trampoline_stub_type:
 938     {
 939       trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
 940       st->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
 941       break;
 942     }
 943   case relocInfo::opt_virtual_call_type:
 944     {
 945       opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();
 946       st->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 947                  p2i(r->destination()), p2i(r->method_value()));
 948       CodeBlob* cb = CodeCache::find_blob(r->destination());
 949       if (cb != nullptr) {
 950         st->print(" Blob::%s", cb->name());
 951       }
 952       break;
 953     }
 954   default:
 955     break;
 956   }
 957   st->cr();
 958 }
 959 
 960 
 961 void RelocIterator::print_on(outputStream* st) {
 962   RelocIterator save_this = (*this);
 963   relocInfo* scan = _current;
 964   if (!has_current())  scan += 1;  // nothing to scan here!
 965 
 966   bool skip_next = has_current();
 967   bool got_next;
 968   while (true) {
 969     got_next = (skip_next || next());
 970     skip_next = false;
 971 
 972     st->print("         @" INTPTR_FORMAT ": ", p2i(scan));
 973     relocInfo* newscan = _current+1;
 974     if (!has_current())  newscan -= 1;  // nothing to scan here!
 975     while (scan < newscan) {
 976       st->print("%04x", *(short*)scan & 0xFFFF);
 977       scan++;
 978     }
 979     st->cr();
 980 
 981     if (!got_next)  break;
 982     print_current_on(st);
 983   }
 984 
 985   (*this) = save_this;
 986 }
 987 
 988 //---------------------------------------------------------------------------------
 989 // Non-product code
 990 
 991 #ifndef PRODUCT
 992 
 993 // For the debugger:
 994 extern "C"
 995 void print_blob_locs(nmethod* nm) {
 996   nm->print();
 997   RelocIterator iter(nm);
 998   iter.print_on(tty);
 999 }
1000 extern "C"
1001 void print_buf_locs(CodeBuffer* cb) {
1002   FlagSetting fs(PrintRelocations, true);
1003   cb->print_on(tty);
1004 }
1005 #endif // !PRODUCT
< prev index next >