< 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 

 755 
 756   return nullptr;
 757 }
 758 
 759 void static_stub_Relocation::clear_inline_cache() {
 760   // Call stub is only used when calling the interpreted code.
 761   // It does not really need to be cleared, except that we want to clean out the methodoop.
 762   CompiledDirectCall::set_stub_to_clean(this);
 763 }
 764 
 765 
 766 void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 767   if (_target != nullptr) {
 768     // Probably this reference is absolute,  not relative, so the following is
 769     // probably a no-op.
 770     set_value(_target);
 771   }
 772   // If target is nullptr, this is  an absolute embedded reference to an external
 773   // location, which means  there is nothing to fix here.  In either case, the
 774   // resulting target should be an "external" address.








 775   postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
 776   postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
 777 }
 778 
 779 
 780 address external_word_Relocation::target() {
 781   address target = _target;
 782   if (target == nullptr) {
 783     target = pd_get_address_from_code();
 784   }
 785   return target;
 786 }
 787 
 788 
 789 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 790   address target = _target;
 791   if (target == nullptr) {
 792     target = new_addr_for(this->target(), src, dest);
 793   }
 794   set_value(target);

 847   } else if (datalen() > 0) {
 848     st->print(" data={");
 849     for (int i = 0; i < datalen(); i++) {
 850       st->print("%04x", data()[i] & 0xFFFF);
 851     }
 852     st->print("}");
 853   }
 854   st->print("]");
 855   switch (type()) {
 856   case relocInfo::oop_type:
 857     {
 858       oop_Relocation* r = oop_reloc();
 859       oop* oop_addr  = nullptr;
 860       oop  raw_oop   = nullptr;
 861       oop  oop_value = nullptr;
 862       if (code() != nullptr || r->oop_is_immediate()) {
 863         oop_addr  = r->oop_addr();
 864         raw_oop   = *oop_addr;
 865         oop_value = r->oop_value();
 866       }
 867       st->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
 868                  p2i(oop_addr), p2i(raw_oop));
 869       // Do not print the oop by default--we want this routine to
 870       // work even during GC or other inconvenient times.
 871       if (WizardMode && oop_value != nullptr) {
 872         st->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
 873         if (oopDesc::is_oop(oop_value)) {
 874           oop_value->print_value_on(st);
 875         }
 876       }
 877       break;
 878     }
 879   case relocInfo::metadata_type:
 880     {
 881       metadata_Relocation* r = metadata_reloc();
 882       Metadata** metadata_addr  = nullptr;
 883       Metadata*    raw_metadata   = nullptr;
 884       Metadata*    metadata_value = nullptr;
 885       if (code() != nullptr || r->metadata_is_immediate()) {
 886         metadata_addr  = r->metadata_addr();
 887         raw_metadata   = *metadata_addr;
 888         metadata_value = r->metadata_value();
 889       }
 890       st->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT "]",
 891                  p2i(metadata_addr), p2i(raw_metadata));
 892       if (metadata_value != nullptr) {
 893         st->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
 894         metadata_value->print_value_on(st);
 895       }
 896       break;
 897     }
 898   case relocInfo::external_word_type:
 899   case relocInfo::internal_word_type:
 900   case relocInfo::section_word_type:
 901     {
 902       DataRelocation* r = (DataRelocation*) reloc();
 903       st->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
 904       break;
 905     }
 906   case relocInfo::static_call_type:
 907     {
 908       static_call_Relocation* r = (static_call_Relocation*) reloc();
 909       st->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 910                  p2i(r->destination()), p2i(r->method_value()));
 911       CodeBlob* cb = CodeCache::find_blob(r->destination());

 914       }
 915       break;
 916     }
 917   case relocInfo::runtime_call_type:
 918   case relocInfo::runtime_call_w_cp_type:
 919     {
 920       CallRelocation* r = (CallRelocation*) reloc();
 921       address dest = r->destination();
 922       st->print(" | [destination=" INTPTR_FORMAT "]", p2i(dest));
 923       if (StubRoutines::contains(dest)) {
 924         StubCodeDesc* desc = StubCodeDesc::desc_for(dest);
 925         if (desc == nullptr) {
 926           desc = StubCodeDesc::desc_for(dest + frame::pc_return_offset);
 927         }
 928         if (desc != nullptr) {
 929           st->print(" Stub::%s", desc->name());
 930         }
 931       } else {
 932         CodeBlob* cb = CodeCache::find_blob(dest);
 933         if (cb != nullptr) {
 934           st->print(" %s", cb->name());
 935         } else {
 936           ResourceMark rm;
 937           const int buflen = 1024;
 938           char* buf = NEW_RESOURCE_ARRAY(char, buflen);
 939           int offset;
 940           if (os::dll_address_to_function_name(dest, buf, buflen, &offset)) {
 941             st->print(" %s", buf);
 942             if (offset != 0) {
 943               st->print("+%d", offset);
 944             }
 945           }
 946         }
 947       }
 948       break;
 949     }
 950   case relocInfo::virtual_call_type:
 951     {
 952       virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
 953       st->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 954                  p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));

   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/aotCodeCache.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/nmethod.hpp"
  30 #include "code/relocInfo.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 

 757 
 758   return nullptr;
 759 }
 760 
 761 void static_stub_Relocation::clear_inline_cache() {
 762   // Call stub is only used when calling the interpreted code.
 763   // It does not really need to be cleared, except that we want to clean out the methodoop.
 764   CompiledDirectCall::set_stub_to_clean(this);
 765 }
 766 
 767 
 768 void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 769   if (_target != nullptr) {
 770     // Probably this reference is absolute,  not relative, so the following is
 771     // probably a no-op.
 772     set_value(_target);
 773   }
 774   // If target is nullptr, this is  an absolute embedded reference to an external
 775   // location, which means  there is nothing to fix here.  In either case, the
 776   // resulting target should be an "external" address.
 777 #ifdef ASSERT
 778   if (AOTCodeCache::is_on()) {
 779     // AOTCode needs relocation info for card table base which may point to CodeCache
 780     if (is_card_table_address(target())) {
 781       return;
 782     }
 783   }
 784 #endif
 785   postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);
 786   postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);
 787 }
 788 
 789 
 790 address external_word_Relocation::target() {
 791   address target = _target;
 792   if (target == nullptr) {
 793     target = pd_get_address_from_code();
 794   }
 795   return target;
 796 }
 797 
 798 
 799 void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 800   address target = _target;
 801   if (target == nullptr) {
 802     target = new_addr_for(this->target(), src, dest);
 803   }
 804   set_value(target);

 857   } else if (datalen() > 0) {
 858     st->print(" data={");
 859     for (int i = 0; i < datalen(); i++) {
 860       st->print("%04x", data()[i] & 0xFFFF);
 861     }
 862     st->print("}");
 863   }
 864   st->print("]");
 865   switch (type()) {
 866   case relocInfo::oop_type:
 867     {
 868       oop_Relocation* r = oop_reloc();
 869       oop* oop_addr  = nullptr;
 870       oop  raw_oop   = nullptr;
 871       oop  oop_value = nullptr;
 872       if (code() != nullptr || r->oop_is_immediate()) {
 873         oop_addr  = r->oop_addr();
 874         raw_oop   = *oop_addr;
 875         oop_value = r->oop_value();
 876       }
 877       st->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " index=%d]",
 878                  p2i(oop_addr), p2i(raw_oop), r->oop_index());
 879       // Do not print the oop by default--we want this routine to
 880       // work even during GC or other inconvenient times.
 881       if (WizardMode && oop_value != nullptr) {
 882         st->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
 883         if (oopDesc::is_oop(oop_value)) {
 884           oop_value->print_value_on(st);
 885         }
 886       }
 887       break;
 888     }
 889   case relocInfo::metadata_type:
 890     {
 891       metadata_Relocation* r = metadata_reloc();
 892       Metadata** metadata_addr  = nullptr;
 893       Metadata*    raw_metadata   = nullptr;
 894       Metadata*    metadata_value = nullptr;
 895       if (code() != nullptr || r->metadata_is_immediate()) {
 896         metadata_addr  = r->metadata_addr();
 897         raw_metadata   = *metadata_addr;
 898         metadata_value = r->metadata_value();
 899       }
 900       st->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " index=%d]",
 901                  p2i(metadata_addr), p2i(raw_metadata), r->metadata_index());
 902       if (metadata_value != nullptr) {
 903         st->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
 904         metadata_value->print_value_on(st);
 905       }
 906       break;
 907     }
 908   case relocInfo::external_word_type:
 909   case relocInfo::internal_word_type:
 910   case relocInfo::section_word_type:
 911     {
 912       DataRelocation* r = (DataRelocation*) reloc();
 913       st->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
 914       break;
 915     }
 916   case relocInfo::static_call_type:
 917     {
 918       static_call_Relocation* r = (static_call_Relocation*) reloc();
 919       st->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 920                  p2i(r->destination()), p2i(r->method_value()));
 921       CodeBlob* cb = CodeCache::find_blob(r->destination());

 924       }
 925       break;
 926     }
 927   case relocInfo::runtime_call_type:
 928   case relocInfo::runtime_call_w_cp_type:
 929     {
 930       CallRelocation* r = (CallRelocation*) reloc();
 931       address dest = r->destination();
 932       st->print(" | [destination=" INTPTR_FORMAT "]", p2i(dest));
 933       if (StubRoutines::contains(dest)) {
 934         StubCodeDesc* desc = StubCodeDesc::desc_for(dest);
 935         if (desc == nullptr) {
 936           desc = StubCodeDesc::desc_for(dest + frame::pc_return_offset);
 937         }
 938         if (desc != nullptr) {
 939           st->print(" Stub::%s", desc->name());
 940         }
 941       } else {
 942         CodeBlob* cb = CodeCache::find_blob(dest);
 943         if (cb != nullptr) {
 944           st->print(" Blob::%s", cb->name());
 945         } else {
 946           ResourceMark rm;
 947           const int buflen = 1024;
 948           char* buf = NEW_RESOURCE_ARRAY(char, buflen);
 949           int offset;
 950           if (os::dll_address_to_function_name(dest, buf, buflen, &offset)) {
 951             st->print(" %s", buf);
 952             if (offset != 0) {
 953               st->print("+%d", offset);
 954             }
 955           }
 956         }
 957       }
 958       break;
 959     }
 960   case relocInfo::virtual_call_type:
 961     {
 962       virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
 963       st->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",
 964                  p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));
< prev index next >