< 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 

 163   _end     = cs->locs_end();
 164   _addr    = cs->start();
 165   _code    = nullptr; // Not cb->blob();
 166 
 167   CodeBuffer* cb = cs->outer();
 168   assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
 169   for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
 170     CodeSection* cs = cb->code_section(n);
 171     _section_start[n] = cs->start();
 172     _section_end  [n] = cs->end();
 173   }
 174 
 175   assert(!has_current(), "just checking");
 176 
 177   assert(begin == nullptr || begin >= cs->start(), "in bounds");
 178   assert(limit == nullptr || limit <= cs->end(),   "in bounds");
 179   set_limits(begin, limit);
 180 }
 181 
 182 RelocIterator::RelocIterator(CodeBlob* cb) {
 183   initialize_misc();
 184   if (cb->is_nmethod()) {
 185     _code = cb->as_nmethod();
 186   } else {
 187     _code = nullptr;
 188   }


 189   _current = cb->relocation_begin() - 1;
 190   _end     = cb->relocation_end();
 191   _addr    = cb->content_begin();
 192 
 193   _section_start[CodeBuffer::SECT_CONSTS] = cb->content_begin();
 194   _section_start[CodeBuffer::SECT_INSTS ] = cb->code_begin();
 195   _section_start[CodeBuffer::SECT_STUBS ] = cb->code_end();
 196 
 197   _section_end  [CodeBuffer::SECT_CONSTS] = cb->code_begin();
 198   _section_end  [CodeBuffer::SECT_INSTS ] = cb->code_end();
 199   _section_end  [CodeBuffer::SECT_STUBS ] = cb->code_end();
 200 
 201   assert(!has_current(), "just checking");
 202   set_limits(nullptr, nullptr);
 203 }
 204 
 205 bool RelocIterator::addr_in_const() const {
 206   const int n = CodeBuffer::SECT_CONSTS;
 207   if (_section_start[n] == nullptr) {
 208     return false;

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








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

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

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

 165   _end     = cs->locs_end();
 166   _addr    = cs->start();
 167   _code    = nullptr; // Not cb->blob();
 168 
 169   CodeBuffer* cb = cs->outer();
 170   assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
 171   for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
 172     CodeSection* cs = cb->code_section(n);
 173     _section_start[n] = cs->start();
 174     _section_end  [n] = cs->end();
 175   }
 176 
 177   assert(!has_current(), "just checking");
 178 
 179   assert(begin == nullptr || begin >= cs->start(), "in bounds");
 180   assert(limit == nullptr || limit <= cs->end(),   "in bounds");
 181   set_limits(begin, limit);
 182 }
 183 
 184 RelocIterator::RelocIterator(CodeBlob* cb) {

 185   if (cb->is_nmethod()) {
 186     initialize(cb->as_nmethod(), nullptr, nullptr);
 187     return;

 188   }
 189   initialize_misc();
 190   _code = nullptr;
 191   _current = cb->relocation_begin() - 1;
 192   _end     = cb->relocation_end();
 193   _addr    = cb->content_begin();
 194 
 195   _section_start[CodeBuffer::SECT_CONSTS] = cb->content_begin();
 196   _section_start[CodeBuffer::SECT_INSTS ] = cb->code_begin();
 197   _section_start[CodeBuffer::SECT_STUBS ] = cb->code_end();
 198 
 199   _section_end  [CodeBuffer::SECT_CONSTS] = cb->code_begin();
 200   _section_end  [CodeBuffer::SECT_INSTS ] = cb->code_end();
 201   _section_end  [CodeBuffer::SECT_STUBS ] = cb->code_end();
 202 
 203   assert(!has_current(), "just checking");
 204   set_limits(nullptr, nullptr);
 205 }
 206 
 207 bool RelocIterator::addr_in_const() const {
 208   const int n = CodeBuffer::SECT_CONSTS;
 209   if (_section_start[n] == nullptr) {
 210     return false;

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

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

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