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;
446 jint offset = unpack_1_int();
447 _static_call = address_from_scaled_offset(offset, base);
448 }
449
450 void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
451 short* p = (short*) dest->locs_end();
452 CodeSection* insts = dest->outer()->insts();
453 normalize_address(_owner, insts);
454 p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
455 dest->set_locs_end((relocInfo*) p);
456 }
457
458 void trampoline_stub_Relocation::unpack_data() {
459 address base = binding()->section_start(CodeBuffer::SECT_INSTS);
460 _owner = address_from_scaled_offset(unpack_1_int(), base);
461 }
462
463 void external_word_Relocation::pack_data_to(CodeSection* dest) {
464 short* p = (short*) dest->locs_end();
465 int index = ExternalsRecorder::find_index(_target);
466 p = pack_1_int_to(p, index);
467 dest->set_locs_end((relocInfo*) p);
468 }
469
470
471 void external_word_Relocation::unpack_data() {
472 int index = unpack_1_int();
473 _target = ExternalsRecorder::at(index);
474 }
475
476
477 void internal_word_Relocation::pack_data_to(CodeSection* dest) {
478 short* p = (short*) dest->locs_end();
479 normalize_address(_target, dest, true);
480
481 // Check whether my target address is valid within this section.
482 // If not, strengthen the relocation type to point to another section.
483 int sindex = _section;
484 if (sindex == CodeBuffer::SECT_NONE && _target != nullptr
485 && (!dest->allocates(_target) || _target == dest->locs_point())) {
486 sindex = dest->outer()->section_index_of(_target);
487 guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
488 relocInfo* base = dest->locs_end() - 1;
489 assert(base->type() == this->type(), "sanity");
490 // Change the written type, to be section_word_type instead.
719
720 return nullptr;
721 }
722
723 void static_stub_Relocation::clear_inline_cache() {
724 // Call stub is only used when calling the interpreted code.
725 // It does not really need to be cleared, except that we want to clean out the methodoop.
726 CompiledDirectCall::set_stub_to_clean(this);
727 }
728
729
730 void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
731 if (_target != nullptr) {
732 // Probably this reference is absolute, not relative, so the following is
733 // probably a no-op.
734 set_value(_target);
735 }
736 // If target is nullptr, this is an absolute embedded reference to an external
737 // location, which means there is nothing to fix here. In either case, the
738 // resulting target should be an "external" address.
739 postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
740 postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
741 }
742
743
744 address external_word_Relocation::target() {
745 address target = _target;
746 if (target == nullptr) {
747 target = pd_get_address_from_code();
748 }
749 return target;
750 }
751
752
753 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
754 address target = _target;
755 if (target == nullptr) {
756 target = new_addr_for(this->target(), src, dest);
757 }
758 set_value(target);
759 }
760
761
762 address internal_word_Relocation::target() {
763 address target = _target;
764 if (target == nullptr) {
765 if (addr_in_const()) {
766 target = *(address*)addr();
767 } else {
768 target = pd_get_address_from_code();
769 }
770 }
771 return target;
772 }
773
774 //---------------------------------------------------------------------------------
775 // Non-product code
776
777 #ifndef PRODUCT
778
779 static const char* reloc_type_string(relocInfo::relocType t) {
780 switch (t) {
781 #define EACH_CASE(name) \
782 case relocInfo::name##_type: \
783 return #name;
784
785 APPLY_TO_RELOCATIONS(EACH_CASE);
786 #undef EACH_CASE
787
788 case relocInfo::none:
789 return "none";
790 case relocInfo::data_prefix_tag:
791 return "prefix";
792 default:
793 return "UNKNOWN RELOC TYPE";
794 }
795 }
796
797
798 void RelocIterator::print_current() {
799 if (!has_current()) {
800 tty->print_cr("(no relocs)");
801 return;
802 }
803 tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
804 p2i(_current), type(), reloc_type_string((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset());
805 if (current()->format() != 0)
806 tty->print(" format=%d", current()->format());
807 if (datalen() == 1) {
808 tty->print(" data=%d", data()[0]);
809 } else if (datalen() > 0) {
810 tty->print(" data={");
811 for (int i = 0; i < datalen(); i++) {
812 tty->print("%04x", data()[i] & 0xFFFF);
813 }
814 tty->print("}");
815 }
816 tty->print("]");
817 switch (type()) {
818 case relocInfo::oop_type:
819 {
820 oop_Relocation* r = oop_reloc();
821 oop* oop_addr = nullptr;
822 oop raw_oop = nullptr;
823 oop oop_value = nullptr;
824 if (code() != nullptr || r->oop_is_immediate()) {
825 oop_addr = r->oop_addr();
826 raw_oop = *oop_addr;
827 oop_value = r->oop_value();
828 }
829 tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
830 p2i(oop_addr), p2i(raw_oop));
831 // Do not print the oop by default--we want this routine to
832 // work even during GC or other inconvenient times.
833 if (WizardMode && oop_value != nullptr) {
834 tty->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
835 if (oopDesc::is_oop(oop_value)) {
836 oop_value->print_value_on(tty);
837 }
838 }
839 break;
840 }
841 case relocInfo::metadata_type:
842 {
843 metadata_Relocation* r = metadata_reloc();
844 Metadata** metadata_addr = nullptr;
845 Metadata* raw_metadata = nullptr;
846 Metadata* metadata_value = nullptr;
847 if (code() != nullptr || r->metadata_is_immediate()) {
848 metadata_addr = r->metadata_addr();
849 raw_metadata = *metadata_addr;
850 metadata_value = r->metadata_value();
851 }
852 tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
853 p2i(metadata_addr), p2i(raw_metadata));
854 if (metadata_value != nullptr) {
855 tty->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
856 metadata_value->print_value_on(tty);
857 }
858 break;
859 }
860 case relocInfo::external_word_type:
861 case relocInfo::internal_word_type:
862 case relocInfo::section_word_type:
863 {
864 DataRelocation* r = (DataRelocation*) reloc();
865 tty->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
866 break;
867 }
868 case relocInfo::static_call_type:
869 {
870 static_call_Relocation* r = (static_call_Relocation*) reloc();
871 tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
872 p2i(r->destination()), p2i(r->method_value()));
873 break;
874 }
875 case relocInfo::runtime_call_type:
876 case relocInfo::runtime_call_w_cp_type:
877 {
878 CallRelocation* r = (CallRelocation*) reloc();
879 tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));
880 break;
881 }
882 case relocInfo::virtual_call_type:
883 {
884 virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
885 tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
886 p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));
887 break;
888 }
889 case relocInfo::static_stub_type:
890 {
891 static_stub_Relocation* r = (static_stub_Relocation*) reloc();
892 tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
893 break;
894 }
895 case relocInfo::trampoline_stub_type:
896 {
897 trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
898 tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
899 break;
900 }
901 case relocInfo::opt_virtual_call_type:
902 {
903 opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();
904 tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
905 p2i(r->destination()), p2i(r->method_value()));
906 break;
907 }
908 default:
909 break;
910 }
911 tty->cr();
912 }
913
914
915 void RelocIterator::print() {
916 RelocIterator save_this = (*this);
917 relocInfo* scan = _current;
918 if (!has_current()) scan += 1; // nothing to scan here!
919
920 bool skip_next = has_current();
921 bool got_next;
922 while (true) {
923 got_next = (skip_next || next());
924 skip_next = false;
925
926 tty->print(" @" INTPTR_FORMAT ": ", p2i(scan));
927 relocInfo* newscan = _current+1;
928 if (!has_current()) newscan -= 1; // nothing to scan here!
929 while (scan < newscan) {
930 tty->print("%04x", *(short*)scan & 0xFFFF);
931 scan++;
932 }
933 tty->cr();
934
935 if (!got_next) break;
936 print_current();
937 }
938
939 (*this) = save_this;
940 }
941
942 // For the debugger:
943 extern "C"
944 void print_blob_locs(nmethod* nm) {
945 nm->print();
946 RelocIterator iter(nm);
947 iter.print();
948 }
949 extern "C"
950 void print_buf_locs(CodeBuffer* cb) {
951 FlagSetting fs(PrintRelocations, true);
952 cb->print();
953 }
954 #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;
451 jint offset = unpack_1_int();
452 _static_call = address_from_scaled_offset(offset, base);
453 }
454
455 void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
456 short* p = (short*) dest->locs_end();
457 CodeSection* insts = dest->outer()->insts();
458 normalize_address(_owner, insts);
459 p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
460 dest->set_locs_end((relocInfo*) p);
461 }
462
463 void trampoline_stub_Relocation::unpack_data() {
464 address base = binding()->section_start(CodeBuffer::SECT_INSTS);
465 _owner = address_from_scaled_offset(unpack_1_int(), base);
466 }
467
468 void external_word_Relocation::pack_data_to(CodeSection* dest) {
469 short* p = (short*) dest->locs_end();
470 int index = ExternalsRecorder::find_index(_target);
471 // Use 4 bytes to store index to be able patch it when
472 // updating relocations in SCCReader::read_relocations().
473 p = add_jint(p, index);
474 dest->set_locs_end((relocInfo*) p);
475 }
476
477 void external_word_Relocation::unpack_data() {
478 int index = unpack_1_int();
479 _target = ExternalsRecorder::at(index);
480 }
481
482
483 void internal_word_Relocation::pack_data_to(CodeSection* dest) {
484 short* p = (short*) dest->locs_end();
485 normalize_address(_target, dest, true);
486
487 // Check whether my target address is valid within this section.
488 // If not, strengthen the relocation type to point to another section.
489 int sindex = _section;
490 if (sindex == CodeBuffer::SECT_NONE && _target != nullptr
491 && (!dest->allocates(_target) || _target == dest->locs_point())) {
492 sindex = dest->outer()->section_index_of(_target);
493 guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
494 relocInfo* base = dest->locs_end() - 1;
495 assert(base->type() == this->type(), "sanity");
496 // Change the written type, to be section_word_type instead.
725
726 return nullptr;
727 }
728
729 void static_stub_Relocation::clear_inline_cache() {
730 // Call stub is only used when calling the interpreted code.
731 // It does not really need to be cleared, except that we want to clean out the methodoop.
732 CompiledDirectCall::set_stub_to_clean(this);
733 }
734
735
736 void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
737 if (_target != nullptr) {
738 // Probably this reference is absolute, not relative, so the following is
739 // probably a no-op.
740 set_value(_target);
741 }
742 // If target is nullptr, this is an absolute embedded reference to an external
743 // location, which means there is nothing to fix here. In either case, the
744 // resulting target should be an "external" address.
745 #ifdef ASSERT
746 if (SCCache::is_on()) {
747 // SCA needs relocation info for card table base which may point to CodeCache
748 if (is_card_table_address(target())) {
749 return;
750 }
751 }
752 #endif
753 postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
754 postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
755 }
756
757
758 address external_word_Relocation::target() {
759 address target = _target;
760 if (target == nullptr) {
761 target = pd_get_address_from_code();
762 }
763 return target;
764 }
765
766
767 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
768 address target = _target;
769 if (target == nullptr) {
770 target = new_addr_for(this->target(), src, dest);
771 }
772 set_value(target);
773 }
774
775
776 address internal_word_Relocation::target() {
777 address target = _target;
778 if (target == nullptr) {
779 if (addr_in_const()) {
780 target = *(address*)addr();
781 } else {
782 target = pd_get_address_from_code();
783 }
784 }
785 return target;
786 }
787
788 const char* relocInfo::type_name(relocInfo::relocType t) {
789 switch (t) {
790 #define EACH_CASE(name) \
791 case relocInfo::name##_type: \
792 return #name;
793
794 APPLY_TO_RELOCATIONS(EACH_CASE);
795 #undef EACH_CASE
796
797 case relocInfo::none:
798 return "none";
799 case relocInfo::data_prefix_tag:
800 return "prefix";
801 default:
802 return "UNKNOWN RELOC TYPE";
803 }
804 }
805
806
807 void RelocIterator::print_current_on(outputStream* st) {
808 if (!has_current()) {
809 st->print_cr("(no relocs)");
810 return;
811 }
812 st->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
813 p2i(_current), type(), relocInfo::type_name(type()), p2i(_addr), _current->addr_offset());
814 if (current()->format() != 0)
815 st->print(" format=%d", current()->format());
816 if (datalen() == 1) {
817 st->print(" data=%d", data()[0]);
818 } else if (datalen() > 0) {
819 st->print(" data={");
820 for (int i = 0; i < datalen(); i++) {
821 st->print("%04x", data()[i] & 0xFFFF);
822 }
823 st->print("}");
824 }
825 st->print("]");
826 switch (type()) {
827 case relocInfo::oop_type:
828 {
829 oop_Relocation* r = oop_reloc();
830 oop* oop_addr = nullptr;
831 oop raw_oop = nullptr;
832 oop oop_value = nullptr;
833 if (code() != nullptr || r->oop_is_immediate()) {
834 oop_addr = r->oop_addr();
835 raw_oop = *oop_addr;
836 oop_value = r->oop_value();
837 }
838 st->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " index=%d]",
839 p2i(oop_addr), p2i(raw_oop), r->oop_index());
840 // Do not print the oop by default--we want this routine to
841 // work even during GC or other inconvenient times.
842 if (WizardMode && oop_value != nullptr) {
843 st->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
844 if (oopDesc::is_oop(oop_value)) {
845 oop_value->print_value_on(st);
846 }
847 }
848 break;
849 }
850 case relocInfo::metadata_type:
851 {
852 metadata_Relocation* r = metadata_reloc();
853 Metadata** metadata_addr = nullptr;
854 Metadata* raw_metadata = nullptr;
855 Metadata* metadata_value = nullptr;
856 if (code() != nullptr || r->metadata_is_immediate()) {
857 metadata_addr = r->metadata_addr();
858 raw_metadata = *metadata_addr;
859 metadata_value = r->metadata_value();
860 }
861 st->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " index=%d]",
862 p2i(metadata_addr), p2i(raw_metadata), r->metadata_index());
863 if (metadata_value != nullptr) {
864 st->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
865 metadata_value->print_value_on(st);
866 }
867 break;
868 }
869 case relocInfo::external_word_type:
870 case relocInfo::internal_word_type:
871 case relocInfo::section_word_type:
872 {
873 DataRelocation* r = (DataRelocation*) reloc();
874 st->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
875 break;
876 }
877 case relocInfo::static_call_type:
878 {
879 static_call_Relocation* r = (static_call_Relocation*) reloc();
880 st->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
881 p2i(r->destination()), p2i(r->method_value()));
882 CodeBlob* cb = CodeCache::find_blob(r->destination());
883 if (cb != nullptr) {
884 st->print(" Blob::%s", cb->name());
885 }
886 break;
887 }
888 case relocInfo::runtime_call_type:
889 case relocInfo::runtime_call_w_cp_type:
890 {
891 CallRelocation* r = (CallRelocation*) reloc();
892 address dest = r->destination();
893 st->print(" | [destination=" INTPTR_FORMAT "]", p2i(dest));
894 if (StubRoutines::contains(dest)) {
895 StubCodeDesc* desc = StubCodeDesc::desc_for(dest);
896 if (desc == nullptr) {
897 desc = StubCodeDesc::desc_for(dest + frame::pc_return_offset);
898 }
899 if (desc != nullptr) {
900 st->print(" Stub::%s", desc->name());
901 }
902 } else {
903 CodeBlob* cb = CodeCache::find_blob(dest);
904 if (cb != nullptr) {
905 st->print(" Blob::%s", cb->name());
906 } else {
907 ResourceMark rm;
908 const int buflen = 1024;
909 char* buf = NEW_RESOURCE_ARRAY(char, buflen);
910 int offset;
911 if (os::dll_address_to_function_name(dest, buf, buflen, &offset)) {
912 st->print(" %s", buf);
913 if (offset != 0) {
914 st->print("+%d", offset);
915 }
916 }
917 }
918 }
919 break;
920 }
921 case relocInfo::virtual_call_type:
922 {
923 virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
924 st->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
925 p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));
926 CodeBlob* cb = CodeCache::find_blob(r->destination());
927 if (cb != nullptr) {
928 st->print(" Blob::%s", cb->name());
929 }
930 break;
931 }
932 case relocInfo::static_stub_type:
933 {
934 static_stub_Relocation* r = (static_stub_Relocation*) reloc();
935 st->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
936 break;
937 }
938 case relocInfo::trampoline_stub_type:
939 {
940 trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
941 st->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
942 break;
943 }
944 case relocInfo::opt_virtual_call_type:
945 {
946 opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();
947 st->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
948 p2i(r->destination()), p2i(r->method_value()));
949 CodeBlob* cb = CodeCache::find_blob(r->destination());
950 if (cb != nullptr) {
951 st->print(" Blob::%s", cb->name());
952 }
953 break;
954 }
955 default:
956 break;
957 }
958 st->cr();
959 }
960
961
962 void RelocIterator::print_on(outputStream* st) {
963 RelocIterator save_this = (*this);
964 relocInfo* scan = _current;
965 if (!has_current()) scan += 1; // nothing to scan here!
966
967 bool skip_next = has_current();
968 bool got_next;
969 while (true) {
970 got_next = (skip_next || next());
971 skip_next = false;
972
973 st->print(" @" INTPTR_FORMAT ": ", p2i(scan));
974 relocInfo* newscan = _current+1;
975 if (!has_current()) newscan -= 1; // nothing to scan here!
976 while (scan < newscan) {
977 st->print("%04x", *(short*)scan & 0xFFFF);
978 scan++;
979 }
980 st->cr();
981
982 if (!got_next) break;
983 print_current_on(st);
984 }
985
986 (*this) = save_this;
987 }
988
989 //---------------------------------------------------------------------------------
990 // Non-product code
991
992 #ifndef PRODUCT
993
994 // For the debugger:
995 extern "C"
996 void print_blob_locs(nmethod* nm) {
997 nm->print();
998 RelocIterator iter(nm);
999 iter.print_on(tty);
1000 }
1001 extern "C"
1002 void print_buf_locs(CodeBuffer* cb) {
1003 FlagSetting fs(PrintRelocations, true);
1004 cb->print_on(tty);
1005 }
1006 #endif // !PRODUCT
|