< prev index next >

src/hotspot/share/cds/archiveBuilder.cpp

Print this page

  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "cds/archiveBuilder.hpp"
  27 #include "cds/archiveUtils.hpp"
  28 #include "cds/cppVtables.hpp"
  29 #include "cds/dumpAllocStats.hpp"
  30 #include "cds/metaspaceShared.hpp"
  31 #include "classfile/classLoaderDataShared.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "classfile/systemDictionaryShared.hpp"
  34 #include "classfile/vmClasses.hpp"
  35 #include "interpreter/abstractInterpreter.hpp"
  36 #include "logging/log.hpp"
  37 #include "logging/logStream.hpp"
  38 #include "memory/allStatic.hpp"
  39 #include "memory/memRegion.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "oops/instanceKlass.hpp"

  42 #include "oops/objArrayKlass.hpp"
  43 #include "oops/oopHandle.inline.hpp"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/globals_extension.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/thread.hpp"
  48 #include "utilities/align.hpp"
  49 #include "utilities/bitMap.inline.hpp"
  50 #include "utilities/formatBuffer.hpp"
  51 #include "utilities/hashtable.inline.hpp"
  52 
  53 ArchiveBuilder* ArchiveBuilder::_current = NULL;
  54 
  55 ArchiveBuilder::OtherROAllocMark::~OtherROAllocMark() {
  56   char* newtop = ArchiveBuilder::current()->_ro_region.top();
  57   ArchiveBuilder::alloc_stats()->record_other_type(int(newtop - _oldtop), true);
  58 }
  59 
  60 ArchiveBuilder::SourceObjList::SourceObjList() : _ptrmap(16 * K) {
  61   _total_bytes = 0;

 714   log_info(cds)("Relocating embedded pointers in core regions ... ");
 715   relocate_embedded_pointers(&_rw_src_objs);
 716   relocate_embedded_pointers(&_ro_src_objs);
 717   update_special_refs();
 718 }
 719 
 720 // We must relocate vmClasses::_klasses[] only after we have copied the
 721 // java objects in during dump_java_heap_objects(): during the object copy, we operate on
 722 // old objects which assert that their klass is the original klass.
 723 void ArchiveBuilder::relocate_vm_classes() {
 724   log_info(cds)("Relocating vmClasses::_klasses[] ... ");
 725   ResourceMark rm;
 726   RefRelocator doit(this);
 727   vmClasses::metaspace_pointers_do(&doit);
 728 }
 729 
 730 void ArchiveBuilder::make_klasses_shareable() {
 731   for (int i = 0; i < klasses()->length(); i++) {
 732     Klass* k = klasses()->at(i);
 733     k->remove_java_mirror();







 734     if (k->is_objArray_klass()) {
 735       // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
 736       // on their array classes.
 737     } else if (k->is_typeArray_klass()) {
 738       k->remove_unshareable_info();
 739     } else {
 740       assert(k->is_instance_klass(), " must be");
 741       InstanceKlass* ik = InstanceKlass::cast(k);
 742       if (DynamicDumpSharedSpaces) {
 743         // For static dump, class loader type are already set.
 744         ik->assign_class_loader_type();
 745       }
 746 
 747       MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread::current(), ik);
 748       ik->remove_unshareable_info();
 749 
 750       if (log_is_enabled(Debug, cds, class)) {
 751         ResourceMark rm;
 752         log_debug(cds, class)("klasses[%4d] = " PTR_FORMAT " %s", i, p2i(to_requested(ik)), ik->external_name());
 753       }

 755   }
 756 }
 757 
 758 uintx ArchiveBuilder::buffer_to_offset(address p) const {
 759   address requested_p = to_requested(p);
 760   assert(requested_p >= _requested_static_archive_bottom, "must be");
 761   return requested_p - _requested_static_archive_bottom;
 762 }
 763 
 764 uintx ArchiveBuilder::any_to_offset(address p) const {
 765   if (is_in_mapped_static_archive(p)) {
 766     assert(DynamicDumpSharedSpaces, "must be");
 767     return p - _mapped_static_archive_bottom;
 768   }
 769   return buffer_to_offset(p);
 770 }
 771 
 772 // Update a Java object to point its Klass* to the new location after
 773 // shared archive has been compacted.
 774 void ArchiveBuilder::relocate_klass_ptr(oop o) {

 775   assert(DumpSharedSpaces, "sanity");
 776   Klass* k = get_relocated_klass(o->klass());
 777   Klass* requested_k = to_requested(k);
 778   narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);
 779   o->set_narrow_klass(nk);





 780 }
 781 
 782 // RelocateBufferToRequested --- Relocate all the pointers in rw/ro,
 783 // so that the archive can be mapped to the "requested" location without runtime relocation.
 784 //
 785 // - See ArchiveBuilder header for the definition of "buffer", "mapped" and "requested"
 786 // - ArchivePtrMarker::ptrmap() marks all the pointers in the rw/ro regions
 787 // - Every pointer must have one of the following values:
 788 //   [a] NULL:
 789 //       No relocation is needed. Remove this pointer from ptrmap so we don't need to
 790 //       consider it at runtime.
 791 //   [b] Points into an object X which is inside the buffer:
 792 //       Adjust this pointer by _buffer_to_requested_delta, so it points to X
 793 //       when the archive is mapped at the requested location.
 794 //   [c] Points into an object Y which is inside mapped static archive:
 795 //       - This happens only during dynamic dump
 796 //       - Adjust this pointer by _mapped_to_requested_static_archive_delta,
 797 //         so it points to Y when the static archive is mapped at the requested location.
 798 template <bool STATIC_DUMP>
 799 class RelocateBufferToRequested : public BitMapClosure {

  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "cds/archiveBuilder.hpp"
  27 #include "cds/archiveUtils.hpp"
  28 #include "cds/cppVtables.hpp"
  29 #include "cds/dumpAllocStats.hpp"
  30 #include "cds/metaspaceShared.hpp"
  31 #include "classfile/classLoaderDataShared.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "classfile/systemDictionaryShared.hpp"
  34 #include "classfile/vmClasses.hpp"
  35 #include "interpreter/abstractInterpreter.hpp"
  36 #include "logging/log.hpp"
  37 #include "logging/logStream.hpp"
  38 #include "memory/allStatic.hpp"
  39 #include "memory/memRegion.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "oops/instanceKlass.hpp"
  42 #include "oops/klass.inline.hpp"
  43 #include "oops/objArrayKlass.hpp"
  44 #include "oops/oopHandle.inline.hpp"
  45 #include "runtime/arguments.hpp"
  46 #include "runtime/globals_extension.hpp"
  47 #include "runtime/sharedRuntime.hpp"
  48 #include "runtime/thread.hpp"
  49 #include "utilities/align.hpp"
  50 #include "utilities/bitMap.inline.hpp"
  51 #include "utilities/formatBuffer.hpp"
  52 #include "utilities/hashtable.inline.hpp"
  53 
  54 ArchiveBuilder* ArchiveBuilder::_current = NULL;
  55 
  56 ArchiveBuilder::OtherROAllocMark::~OtherROAllocMark() {
  57   char* newtop = ArchiveBuilder::current()->_ro_region.top();
  58   ArchiveBuilder::alloc_stats()->record_other_type(int(newtop - _oldtop), true);
  59 }
  60 
  61 ArchiveBuilder::SourceObjList::SourceObjList() : _ptrmap(16 * K) {
  62   _total_bytes = 0;

 715   log_info(cds)("Relocating embedded pointers in core regions ... ");
 716   relocate_embedded_pointers(&_rw_src_objs);
 717   relocate_embedded_pointers(&_ro_src_objs);
 718   update_special_refs();
 719 }
 720 
 721 // We must relocate vmClasses::_klasses[] only after we have copied the
 722 // java objects in during dump_java_heap_objects(): during the object copy, we operate on
 723 // old objects which assert that their klass is the original klass.
 724 void ArchiveBuilder::relocate_vm_classes() {
 725   log_info(cds)("Relocating vmClasses::_klasses[] ... ");
 726   ResourceMark rm;
 727   RefRelocator doit(this);
 728   vmClasses::metaspace_pointers_do(&doit);
 729 }
 730 
 731 void ArchiveBuilder::make_klasses_shareable() {
 732   for (int i = 0; i < klasses()->length(); i++) {
 733     Klass* k = klasses()->at(i);
 734     k->remove_java_mirror();
 735 #ifdef _LP64
 736     if (UseCompactObjectHeaders) {
 737       Klass* requested_k = to_requested(k);
 738       narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);
 739       k->set_prototype_header(markWord::prototype().set_narrow_klass(nk));
 740     }
 741 #endif //_LP64
 742     if (k->is_objArray_klass()) {
 743       // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
 744       // on their array classes.
 745     } else if (k->is_typeArray_klass()) {
 746       k->remove_unshareable_info();
 747     } else {
 748       assert(k->is_instance_klass(), " must be");
 749       InstanceKlass* ik = InstanceKlass::cast(k);
 750       if (DynamicDumpSharedSpaces) {
 751         // For static dump, class loader type are already set.
 752         ik->assign_class_loader_type();
 753       }
 754 
 755       MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread::current(), ik);
 756       ik->remove_unshareable_info();
 757 
 758       if (log_is_enabled(Debug, cds, class)) {
 759         ResourceMark rm;
 760         log_debug(cds, class)("klasses[%4d] = " PTR_FORMAT " %s", i, p2i(to_requested(ik)), ik->external_name());
 761       }

 763   }
 764 }
 765 
 766 uintx ArchiveBuilder::buffer_to_offset(address p) const {
 767   address requested_p = to_requested(p);
 768   assert(requested_p >= _requested_static_archive_bottom, "must be");
 769   return requested_p - _requested_static_archive_bottom;
 770 }
 771 
 772 uintx ArchiveBuilder::any_to_offset(address p) const {
 773   if (is_in_mapped_static_archive(p)) {
 774     assert(DynamicDumpSharedSpaces, "must be");
 775     return p - _mapped_static_archive_bottom;
 776   }
 777   return buffer_to_offset(p);
 778 }
 779 
 780 // Update a Java object to point its Klass* to the new location after
 781 // shared archive has been compacted.
 782 void ArchiveBuilder::relocate_klass_ptr(oop o) {
 783 #ifdef _LP64
 784   assert(DumpSharedSpaces, "sanity");
 785   Klass* k = get_relocated_klass(o->klass());
 786   Klass* requested_k = to_requested(k);
 787   narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);
 788   if (UseCompactObjectHeaders) {
 789     o->set_mark(o->mark().set_narrow_klass(nk));
 790   } else {
 791     o->set_narrow_klass(nk);
 792   }
 793 #endif // _LP64
 794 }
 795 
 796 // RelocateBufferToRequested --- Relocate all the pointers in rw/ro,
 797 // so that the archive can be mapped to the "requested" location without runtime relocation.
 798 //
 799 // - See ArchiveBuilder header for the definition of "buffer", "mapped" and "requested"
 800 // - ArchivePtrMarker::ptrmap() marks all the pointers in the rw/ro regions
 801 // - Every pointer must have one of the following values:
 802 //   [a] NULL:
 803 //       No relocation is needed. Remove this pointer from ptrmap so we don't need to
 804 //       consider it at runtime.
 805 //   [b] Points into an object X which is inside the buffer:
 806 //       Adjust this pointer by _buffer_to_requested_delta, so it points to X
 807 //       when the archive is mapped at the requested location.
 808 //   [c] Points into an object Y which is inside mapped static archive:
 809 //       - This happens only during dynamic dump
 810 //       - Adjust this pointer by _mapped_to_requested_static_archive_delta,
 811 //         so it points to Y when the static archive is mapped at the requested location.
 812 template <bool STATIC_DUMP>
 813 class RelocateBufferToRequested : public BitMapClosure {
< prev index next >