< prev index next >

src/hotspot/share/code/relocInfo.cpp

Print this page

   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 "precompiled.hpp"

  26 #include "code/codeCache.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/nmethod.hpp"
  29 #include "code/relocInfo.hpp"

  30 #include "memory/resourceArea.hpp"
  31 #include "memory/universe.hpp"
  32 #include "oops/compressedOops.inline.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/flags/flagSetting.hpp"
  35 #include "runtime/stubCodeGenerator.hpp"
  36 #include "utilities/align.hpp"
  37 #include "utilities/checkedCast.hpp"
  38 #include "utilities/copy.hpp"
  39 
  40 #include <new>
  41 #include <type_traits>
  42 
  43 const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
  44 
  45 
  46 // Implementation of relocInfo
  47 
  48 #ifdef ASSERT
  49 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   return section_start(n) <= addr() && addr() < section_end(n);
 178 }
 179 
 180 
 181 void RelocIterator::set_limits(address begin, address limit) {
 182   _limit = limit;
 183 
 184   // the limit affects this next stuff:
 185   if (begin != nullptr) {
 186     relocInfo* backup;
 187     address    backup_addr;
 188     while (true) {
 189       backup      = _current;
 190       backup_addr = _addr;
 191       if (!next() || addr() >= begin) break;
 192     }
 193     // At this point, either we are at the first matching record,
 194     // or else there is no such record, and !has_current().
 195     // In either case, revert to the immediately preceding state.
 196     _current = backup;

 436 
 437 void static_stub_Relocation::unpack_data() {
 438   address base = binding()->section_start(CodeBuffer::SECT_INSTS);
 439   jint offset = unpack_1_int();
 440   _static_call = address_from_scaled_offset(offset, base);
 441 }
 442 
 443 void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
 444   short* p = (short*) dest->locs_end();
 445   CodeSection* insts = dest->outer()->insts();
 446   normalize_address(_owner, insts);
 447   p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
 448   dest->set_locs_end((relocInfo*) p);
 449 }
 450 
 451 void trampoline_stub_Relocation::unpack_data() {
 452   address base = binding()->section_start(CodeBuffer::SECT_INSTS);
 453   _owner = address_from_scaled_offset(unpack_1_int(), base);
 454 }
 455 
 456 void external_word_Relocation::pack_data_to(CodeSection* dest) {
 457   short* p = (short*) dest->locs_end();
 458 #ifndef _LP64
 459   p = pack_1_int_to(p, (int32_t) (intptr_t)_target);
 460 #else
 461   jlong t = (jlong) _target;
 462   int32_t lo = low(t);
 463   int32_t hi = high(t);
 464   p = pack_2_ints_to(p, lo, hi);
 465 #endif /* _LP64 */
 466   dest->set_locs_end((relocInfo*) p);
 467 }
 468 




 469 
 470 void external_word_Relocation::unpack_data() {
 471 #ifndef _LP64
 472   _target = (address) (intptr_t)unpack_1_int();
 473 #else
 474   jint lo, hi;
 475   unpack_2_ints(lo, hi);
 476   jlong t = jlong_from(hi, lo);;
 477   _target = (address) t;
 478 #endif /* _LP64 */
 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;

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




 878       break;
 879     }
 880   case relocInfo::runtime_call_type:
 881   case relocInfo::runtime_call_w_cp_type:
 882     {
 883       CallRelocation* r = (CallRelocation*) reloc();
 884       tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));


























 885       break;
 886     }
 887   case relocInfo::virtual_call_type:
 888     {
 889       virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
 890       tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 891                  p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));




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




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





 947 // For the debugger:
 948 extern "C"
 949 void print_blob_locs(nmethod* nm) {
 950   nm->print();
 951   RelocIterator iter(nm);
 952   iter.print();
 953 }
 954 extern "C"
 955 void print_buf_locs(CodeBuffer* cb) {
 956   FlagSetting fs(PrintRelocations, true);
 957   cb->print();
 958 }
 959 #endif // !PRODUCT

   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 "precompiled.hpp"
  26 #include "ci/ciUtilities.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/relocInfo.hpp"
  31 #include "code/SCCache.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/compressedOops.inline.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "runtime/flags/flagSetting.hpp"
  37 #include "runtime/stubCodeGenerator.hpp"
  38 #include "utilities/align.hpp"
  39 #include "utilities/checkedCast.hpp"
  40 #include "utilities/copy.hpp"
  41 
  42 #include <new>
  43 #include <type_traits>
  44 
  45 const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
  46 
  47 
  48 // Implementation of relocInfo
  49 
  50 #ifdef ASSERT
  51 relocInfo::relocType relocInfo::check_relocType(relocType type) {

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

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

 462 #ifndef _LP64
 463   return pack_1_int_to(p, (int32_t) (intptr_t)_target);
 464 #else
 465   jlong t = (jlong) _target;
 466   int32_t lo = low(t);
 467   int32_t hi = high(t);
 468   return pack_2_ints_to(p, lo, hi);
 469 #endif /* _LP64 */

 470 }
 471 
 472 void external_word_Relocation::pack_data_to(CodeSection* dest) {
 473   short* p = (short*) dest->locs_end();
 474   dest->set_locs_end((relocInfo*)pack_data_to(p));
 475 }
 476 
 477 void external_word_Relocation::unpack_data() {
 478 #ifndef _LP64
 479   _target = (address) (intptr_t)unpack_1_int();
 480 #else
 481   jint lo, hi;
 482   unpack_2_ints(lo, hi);
 483   jlong t = jlong_from(hi, lo);;
 484   _target = (address) t;
 485 #endif /* _LP64 */
 486 }
 487 
 488 
 489 void internal_word_Relocation::pack_data_to(CodeSection* dest) {
 490   short* p = (short*) dest->locs_end();
 491   normalize_address(_target, dest, true);
 492 
 493   // Check whether my target address is valid within this section.
 494   // If not, strengthen the relocation type to point to another section.
 495   int sindex = _section;

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





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