< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page

@@ -88,10 +88,11 @@
 size_t MetaspaceShared::_i2i_entry_code_buffers_size = 0;
 void* MetaspaceShared::_shared_metaspace_static_top = NULL;
 intx MetaspaceShared::_relocation_delta;
 char* MetaspaceShared::_requested_base_address;
 bool MetaspaceShared::_use_optimized_module_handling = true;
+bool MetaspaceShared::_use_full_module_graph = true;
 
 // The CDS archive is divided into the following regions:
 //     mc  - misc code (the method entry trampolines, c++ vtables)
 //     rw  - read-write metadata
 //     ro  - read-only metadata and read-only tables

@@ -238,10 +239,14 @@
 
 char* MetaspaceShared::read_only_space_alloc(size_t num_bytes) {
   return _ro_region.allocate(num_bytes);
 }
 
+char* MetaspaceShared::read_write_space_alloc(size_t num_bytes) {
+  return _rw_region.allocate(num_bytes);
+}
+
 size_t MetaspaceShared::reserved_space_alignment() { return os::vm_allocation_granularity(); }
 
 static bool shared_base_valid(char* shared_base) {
 #ifdef _LP64
   return CompressedKlassPointers::is_valid_base((address)shared_base);

@@ -587,10 +592,12 @@
   soc->do_tag(--tag);
 
   serialize_cloned_cpp_vtptrs(soc);
   soc->do_tag(--tag);
 
+  CDS_JAVA_HEAP_ONLY(ClassLoaderData::serialize(soc));
+
   soc->do_tag(666);
 }
 
 address MetaspaceShared::i2i_entry_code_buffers(size_t total_size) {
   if (DumpSharedSpaces) {

@@ -1094,10 +1101,11 @@
   METASPACE_OBJ_TYPES_DO(f) \
   f(SymbolHashentry) \
   f(SymbolBucket) \
   f(StringHashentry) \
   f(StringBucket) \
+  f(ModulesNatives) \
   f(Other)
 
   enum Type {
     // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
     SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE)

@@ -1129,10 +1137,15 @@
     int which = (read_only) ? RO : RW;
     _counts[which][type] ++;
     _bytes [which][type] += byte_size;
   }
 
+  void record_modules(int byte_size, bool read_only) {
+    int which = (read_only) ? RO : RW;
+    _bytes [which][ModulesNativesType] += byte_size;
+  }
+
   void record_other_type(int byte_size, bool read_only) {
     int which = (read_only) ? RO : RW;
     _bytes [which][OtherType] += byte_size;
   }
   void print_stats(int ro_all, int rw_all, int mc_all);

@@ -1418,19 +1431,31 @@
       _mc_region.pack(&_rw_region);
 
       ResourceMark rm;
       ShallowCopier rw_copier(false);
       iterate_roots(&rw_copier);
+
+#if INCLUDE_CDS_JAVA_HEAP
+      // Archive the ModuleEntry's and PackageEntry's of the 3 built-in loaders
+      char* start = _rw_region.top();
+      ClassLoaderData::allocate_archived_tables();
+      ArchiveCompactor::alloc_stats()->record_modules(_rw_region.top() - start, /*read_only*/false);
+#endif
     }
     {
       // allocate and shallow-copy of RO object, immediately following the RW region
       log_info(cds)("Allocating RO objects ... ");
       _rw_region.pack(&_ro_region);
 
       ResourceMark rm;
       ShallowCopier ro_copier(true);
       iterate_roots(&ro_copier);
+#if INCLUDE_CDS_JAVA_HEAP
+      char* start = _ro_region.top();
+      ClassLoaderData::init_archived_tables();
+      ArchiveCompactor::alloc_stats()->record_modules(_ro_region.top() - start, /*read_only*/true);
+#endif
     }
     {
       log_info(cds)("Relocating embedded pointers ... ");
       ResourceMark rm;
       ShallowCopyEmbeddedRefRelocator emb_reloc;

@@ -1521,10 +1546,17 @@
     assert(pp != NULL, "must be");
     Klass* klass = (Klass*)(*pp);
     assert(klass->is_klass(), "must be");
     return klass;
   }
+
+  static Symbol* get_relocated_symbol(Symbol* orig_symbol) {
+    assert(DumpSharedSpaces, "dump time only");
+    address* pp = _new_loc_table->lookup((address)orig_symbol);
+    assert(pp != NULL, "must be");
+    return (Symbol*)(*pp);
+  }
 };
 
 DumpAllocStats* ArchiveCompactor::_alloc_stats;
 ArchiveCompactor::RelocationTable* ArchiveCompactor::_new_loc_table;
 

@@ -1825,10 +1857,14 @@
     k = (Klass*)(address(k) + final_delta());
   }
   return k;
 }
 
+Symbol* MetaspaceShared::get_relocated_symbol(Symbol* orig_symbol) {
+  return ArchiveCompactor::get_relocated_symbol(orig_symbol);
+}
+
 class LinkSharedClassesClosure : public KlassClosure {
   Thread* THREAD;
   bool    _made_progress;
  public:
   LinkSharedClassesClosure(Thread* thread) : THREAD(thread), _made_progress(false) {}

@@ -1939,10 +1975,16 @@
     // fails verification, all other interfaces that were not specified in the classlist but
     // are implemented by K are not verified.
     link_and_cleanup_shared_classes(CATCH);
     log_info(cds)("Rewriting and linking classes: done");
 
+#if INCLUDE_CDS_JAVA_HEAP
+    if (use_full_module_graph()) {
+      HeapShared::reset_archived_object_states(THREAD);
+    }
+#endif
+
     VM_PopulateDumpSharedSpace op;
     MutexLocker ml(THREAD, HeapShared::is_heap_object_archiving_allowed() ?
                    Heap_lock : NULL);     // needed by HeapShared::run_gc()
     VMThread::execute(&op);
   }

@@ -2356,11 +2398,12 @@
           // map_heap_regions() compares the current narrow oop and klass encodings
           // with the archived ones, so it must be done after all encodings are determined.
           static_mapinfo->map_heap_regions();
         }
       });
-    log_info(cds)("Using optimized module handling %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled");
+    log_info(cds)("optimized module handling: %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled");
+    log_info(cds)("full module graph: %s", MetaspaceShared::use_full_module_graph() ? "enabled" : "disabled");
   } else {
     unmap_archive(static_mapinfo);
     unmap_archive(dynamic_mapinfo);
     release_reserved_spaces(archive_space_rs, class_space_rs);
   }

@@ -2681,10 +2724,15 @@
 intx MetaspaceShared::final_delta() {
   return intx(MetaspaceShared::requested_base_address())  // We want the base archive to be mapped to here at runtime
        - intx(SharedBaseAddress);                         // .. but the base archive is mapped at here at dump time
 }
 
+bool MetaspaceShared::use_full_module_graph() {
+  return _use_optimized_module_handling && _use_full_module_graph &&
+    (UseSharedSpaces || DumpSharedSpaces) && HeapShared::is_heap_object_archiving_allowed();
+}
+
 void MetaspaceShared::print_on(outputStream* st) {
   if (UseSharedSpaces || DumpSharedSpaces) {
     st->print("CDS archive(s) mapped at: ");
     address base;
     address top;

@@ -2703,10 +2751,5 @@
   } else {
     st->print("CDS disabled.");
   }
   st->cr();
 }
-
-
-
-
-
< prev index next >