< 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) {

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



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

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


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

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








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




865       break;
866     }
867   case relocInfo::runtime_call_type:
868   case relocInfo::runtime_call_w_cp_type:
869     {
870       CallRelocation* r = (CallRelocation*) reloc();
871       tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));


























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




879       break;
880     }
881   case relocInfo::static_stub_type:
882     {
883       static_stub_Relocation* r = (static_stub_Relocation*) reloc();
884       tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
885       break;
886     }
887   case relocInfo::trampoline_stub_type:
888     {
889       trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
890       tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
891       break;
892     }
893   case relocInfo::opt_virtual_call_type:
894     {
895       opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();
896       tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
897                  p2i(r->destination()), p2i(r->method_value()));




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





934 // For the debugger:
935 extern "C"
936 void print_blob_locs(nmethod* nm) {
937   nm->print();
938   RelocIterator iter(nm);
939   iter.print();
940 }
941 extern "C"
942 void print_buf_locs(CodeBuffer* cb) {
943   FlagSetting fs(PrintRelocations, true);
944   cb->print();
945 }
946 #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) {

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

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

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

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





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