< 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;

 709   vmClasses::metaspace_pointers_do(&doit);
 710 }
 711 
 712 void ArchiveBuilder::make_klasses_shareable() {
 713   int num_instance_klasses = 0;
 714   int num_boot_klasses = 0;
 715   int num_platform_klasses = 0;
 716   int num_app_klasses = 0;
 717   int num_hidden_klasses = 0;
 718   int num_unlinked_klasses = 0;
 719   int num_unregistered_klasses = 0;
 720   int num_obj_array_klasses = 0;
 721   int num_type_array_klasses = 0;
 722 
 723   for (int i = 0; i < klasses()->length(); i++) {
 724     const char* type;
 725     const char* unlinked = "";
 726     const char* hidden = "";
 727     Klass* k = klasses()->at(i);
 728     k->remove_java_mirror();



 729     if (k->is_objArray_klass()) {
 730       // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
 731       // on their array classes.
 732       num_obj_array_klasses ++;
 733       type = "array";
 734     } else if (k->is_typeArray_klass()) {
 735       num_type_array_klasses ++;
 736       type = "array";
 737       k->remove_unshareable_info();
 738     } else {
 739       assert(k->is_instance_klass(), " must be");
 740       num_instance_klasses ++;
 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       if (ik->is_shared_boot_class()) {
 747         type = "boot";
 748         num_boot_klasses ++;

 795   address requested_p = to_requested(p);
 796   assert(requested_p >= _requested_static_archive_bottom, "must be");
 797   return requested_p - _requested_static_archive_bottom;
 798 }
 799 
 800 uintx ArchiveBuilder::any_to_offset(address p) const {
 801   if (is_in_mapped_static_archive(p)) {
 802     assert(DynamicDumpSharedSpaces, "must be");
 803     return p - _mapped_static_archive_bottom;
 804   }
 805   return buffer_to_offset(p);
 806 }
 807 
 808 // Update a Java object to point its Klass* to the new location after
 809 // shared archive has been compacted.
 810 void ArchiveBuilder::relocate_klass_ptr(oop o) {
 811   assert(DumpSharedSpaces, "sanity");
 812   Klass* k = get_relocated_klass(o->klass());
 813   Klass* requested_k = to_requested(k);
 814   narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);



 815   o->set_narrow_klass(nk);
 816 }
 817 
 818 // RelocateBufferToRequested --- Relocate all the pointers in rw/ro,
 819 // so that the archive can be mapped to the "requested" location without runtime relocation.
 820 //
 821 // - See ArchiveBuilder header for the definition of "buffer", "mapped" and "requested"
 822 // - ArchivePtrMarker::ptrmap() marks all the pointers in the rw/ro regions
 823 // - Every pointer must have one of the following values:
 824 //   [a] NULL:
 825 //       No relocation is needed. Remove this pointer from ptrmap so we don't need to
 826 //       consider it at runtime.
 827 //   [b] Points into an object X which is inside the buffer:
 828 //       Adjust this pointer by _buffer_to_requested_delta, so it points to X
 829 //       when the archive is mapped at the requested location.
 830 //   [c] Points into an object Y which is inside mapped static archive:
 831 //       - This happens only during dynamic dump
 832 //       - Adjust this pointer by _mapped_to_requested_static_archive_delta,
 833 //         so it points to Y when the static archive is mapped at the requested location.
 834 template <bool STATIC_DUMP>

  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;

 710   vmClasses::metaspace_pointers_do(&doit);
 711 }
 712 
 713 void ArchiveBuilder::make_klasses_shareable() {
 714   int num_instance_klasses = 0;
 715   int num_boot_klasses = 0;
 716   int num_platform_klasses = 0;
 717   int num_app_klasses = 0;
 718   int num_hidden_klasses = 0;
 719   int num_unlinked_klasses = 0;
 720   int num_unregistered_klasses = 0;
 721   int num_obj_array_klasses = 0;
 722   int num_type_array_klasses = 0;
 723 
 724   for (int i = 0; i < klasses()->length(); i++) {
 725     const char* type;
 726     const char* unlinked = "";
 727     const char* hidden = "";
 728     Klass* k = klasses()->at(i);
 729     k->remove_java_mirror();
 730     Klass* requested_k = to_requested(k);
 731     narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);
 732     k->set_prototype_header(markWord::prototype() LP64_ONLY(.set_narrow_klass(nk)));
 733     if (k->is_objArray_klass()) {
 734       // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
 735       // on their array classes.
 736       num_obj_array_klasses ++;
 737       type = "array";
 738     } else if (k->is_typeArray_klass()) {
 739       num_type_array_klasses ++;
 740       type = "array";
 741       k->remove_unshareable_info();
 742     } else {
 743       assert(k->is_instance_klass(), " must be");
 744       num_instance_klasses ++;
 745       InstanceKlass* ik = InstanceKlass::cast(k);
 746       if (DynamicDumpSharedSpaces) {
 747         // For static dump, class loader type are already set.
 748         ik->assign_class_loader_type();
 749       }
 750       if (ik->is_shared_boot_class()) {
 751         type = "boot";
 752         num_boot_klasses ++;

 799   address requested_p = to_requested(p);
 800   assert(requested_p >= _requested_static_archive_bottom, "must be");
 801   return requested_p - _requested_static_archive_bottom;
 802 }
 803 
 804 uintx ArchiveBuilder::any_to_offset(address p) const {
 805   if (is_in_mapped_static_archive(p)) {
 806     assert(DynamicDumpSharedSpaces, "must be");
 807     return p - _mapped_static_archive_bottom;
 808   }
 809   return buffer_to_offset(p);
 810 }
 811 
 812 // Update a Java object to point its Klass* to the new location after
 813 // shared archive has been compacted.
 814 void ArchiveBuilder::relocate_klass_ptr(oop o) {
 815   assert(DumpSharedSpaces, "sanity");
 816   Klass* k = get_relocated_klass(o->klass());
 817   Klass* requested_k = to_requested(k);
 818   narrowKlass nk = CompressedKlassPointers::encode_not_null(requested_k, _requested_static_archive_bottom);
 819 #ifdef _LP64
 820   o->set_mark(o->mark().set_narrow_klass(nk));
 821 #endif
 822   o->set_narrow_klass(nk);
 823 }
 824 
 825 // RelocateBufferToRequested --- Relocate all the pointers in rw/ro,
 826 // so that the archive can be mapped to the "requested" location without runtime relocation.
 827 //
 828 // - See ArchiveBuilder header for the definition of "buffer", "mapped" and "requested"
 829 // - ArchivePtrMarker::ptrmap() marks all the pointers in the rw/ro regions
 830 // - Every pointer must have one of the following values:
 831 //   [a] NULL:
 832 //       No relocation is needed. Remove this pointer from ptrmap so we don't need to
 833 //       consider it at runtime.
 834 //   [b] Points into an object X which is inside the buffer:
 835 //       Adjust this pointer by _buffer_to_requested_delta, so it points to X
 836 //       when the archive is mapped at the requested location.
 837 //   [c] Points into an object Y which is inside mapped static archive:
 838 //       - This happens only during dynamic dump
 839 //       - Adjust this pointer by _mapped_to_requested_static_archive_delta,
 840 //         so it points to Y when the static archive is mapped at the requested location.
 841 template <bool STATIC_DUMP>
< prev index next >