src/share/vm/memory/metaspaceShared.cpp

Print this page




  31 #include "classfile/systemDictionary.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "memory/filemap.hpp"
  34 #include "memory/gcLocker.hpp"
  35 #include "memory/metaspace.hpp"
  36 #include "memory/metaspaceShared.hpp"
  37 #include "oops/objArrayOop.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/os.hpp"
  40 #include "runtime/signature.hpp"
  41 #include "runtime/vm_operations.hpp"
  42 #include "runtime/vmThread.hpp"
  43 #include "utilities/hashtable.inline.hpp"
  44 
  45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  46 
  47 int MetaspaceShared::_max_alignment = 0;
  48 
  49 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
  50 


  51 bool MetaspaceShared::_link_classes_made_progress;
  52 bool MetaspaceShared::_check_classes_made_progress;
  53 bool MetaspaceShared::_has_error_classes;
  54 bool MetaspaceShared::_archive_loading_failed = false;
  55 // Read/write a data stream for restoring/preserving metadata pointers and
  56 // miscellaneous data from/to the shared archive file.
  57 
  58 void MetaspaceShared::serialize(SerializeClosure* soc) {
  59   int tag = 0;
  60   soc->do_tag(--tag);
  61 
  62   // Verify the sizes of various metadata in the system.
  63   soc->do_tag(sizeof(Method));
  64   soc->do_tag(sizeof(ConstMethod));
  65   soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
  66   soc->do_tag(sizeof(ConstantPool));
  67   soc->do_tag(sizeof(ConstantPoolCache));
  68   soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
  69   soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
  70   soc->do_tag(sizeof(Symbol));


 242     while (size > 0) {
 243       *top = *(intptr_t*)start;
 244       ++top;
 245       start += sizeof(intptr_t);
 246       size -= sizeof(intptr_t);
 247     }
 248   }
 249 
 250   bool reading() const { return false; }
 251 };
 252 
 253 // This is for dumping detailed statistics for the allocations
 254 // in the shared spaces.
 255 class DumpAllocClosure : public Metaspace::AllocRecordClosure {
 256 public:
 257 
 258   // Here's poor man's enum inheritance
 259 #define SHAREDSPACE_OBJ_TYPES_DO(f) \
 260   METASPACE_OBJ_TYPES_DO(f) \
 261   f(SymbolHashentry) \
 262   f(SymbolBuckets) \
 263   f(Other)
 264 
 265 #define SHAREDSPACE_OBJ_TYPE_DECLARE(name) name ## Type,
 266 #define SHAREDSPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name;
 267 
 268   enum Type {
 269     // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
 270     SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_DECLARE)
 271     _number_of_types
 272   };
 273 
 274   static const char * type_name(Type type) {
 275     switch(type) {
 276     SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_NAME_CASE)
 277     default:
 278       ShouldNotReachHere();
 279       return NULL;
 280     }
 281   }
 282 


 298   void iterate_metaspace(Metaspace* space, int which) {
 299     assert(which == RO || which == RW, "sanity");
 300     _which = which;
 301     space->iterate(this);
 302   }
 303 
 304   virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) {
 305     assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");
 306     _counts[_which][type] ++;
 307     _bytes [_which][type] += byte_size;
 308   }
 309 
 310   void dump_stats(int ro_all, int rw_all, int md_all, int mc_all);
 311 };
 312 
 313 void DumpAllocClosure::dump_stats(int ro_all, int rw_all, int md_all, int mc_all) {
 314   rw_all += (md_all + mc_all); // md and mc are all mapped Read/Write
 315   int other_bytes = md_all + mc_all;
 316 
 317   // Calculate size of data that was not allocated by Metaspace::allocate()
 318   int symbol_count = _counts[RO][MetaspaceObj::SymbolType];
 319   int symhash_bytes = symbol_count * sizeof (HashtableEntry<Symbol*, mtSymbol>);
 320   int symbuck_count = SymbolTable::the_table()->table_size();
 321   int symbuck_bytes = symbuck_count * sizeof(HashtableBucket<mtSymbol>);
 322 
 323   _counts[RW][SymbolHashentryType] = symbol_count;
 324   _bytes [RW][SymbolHashentryType] = symhash_bytes;
 325   other_bytes -= symhash_bytes;
 326 
 327   _counts[RW][SymbolBucketsType] = symbuck_count;
 328   _bytes [RW][SymbolBucketsType] = symbuck_bytes;
 329   other_bytes -= symbuck_bytes;
 330 
 331   // TODO: count things like dictionary, vtable, etc
 332   _bytes[RW][OtherType] =  other_bytes;
 333 
 334   // prevent divide-by-zero
 335   if (ro_all < 1) {
 336     ro_all = 1;
 337   }
 338   if (rw_all < 1) {
 339     rw_all = 1;
 340   }
 341 
 342   int all_ro_count = 0;
 343   int all_ro_bytes = 0;
 344   int all_rw_count = 0;
 345   int all_rw_bytes = 0;
 346 
 347 // To make fmt_stats be a syntactic constant (for format warnings), use #define.
 348 #define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"
 349   const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";


 407   VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
 408                              GrowableArray<Klass*> *class_promote_order) :
 409     _loader_data(loader_data) {
 410 
 411     // Split up and initialize the misc code and data spaces
 412     ReservedSpace* shared_rs = MetaspaceShared::shared_rs();
 413     int metadata_size = SharedReadOnlySize+SharedReadWriteSize;
 414     ReservedSpace shared_ro_rw = shared_rs->first_part(metadata_size);
 415     ReservedSpace misc_section = shared_rs->last_part(metadata_size);
 416 
 417     // Now split into misc sections.
 418     ReservedSpace md_rs   = misc_section.first_part(SharedMiscDataSize);
 419     ReservedSpace mc_rs   = misc_section.last_part(SharedMiscDataSize);
 420     _md_vs.initialize(md_rs, SharedMiscDataSize);
 421     _mc_vs.initialize(mc_rs, SharedMiscCodeSize);
 422     _class_promote_order = class_promote_order;
 423   }
 424 
 425   VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
 426   void doit();   // outline because gdb sucks











 427 }; // class VM_PopulateDumpSharedSpace
 428 
 429 
 430 void VM_PopulateDumpSharedSpace::doit() {
 431   Thread* THREAD = VMThread::vm_thread();
 432   NOT_PRODUCT(SystemDictionary::verify();)
 433   // The following guarantee is meant to ensure that no loader constraints
 434   // exist yet, since the constraints table is not shared.  This becomes
 435   // more important now that we don't re-initialize vtables/itables for
 436   // shared classes at runtime, where constraints were previously created.
 437   guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
 438             "loader constraints are not saved");
 439   guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
 440           "placeholders are not saved");
 441   // Revisit and implement this if we prelink method handle call sites:
 442   guarantee(SystemDictionary::invoke_method_table() == NULL ||
 443             SystemDictionary::invoke_method_table()->number_of_entries() == 0,
 444             "invoke method table is not saved");
 445 
 446   // At this point, many classes have been loaded.


 500   // Reserve space for a new dummy vtable for klass objects in the
 501   // heap.  Generate self-patching vtable entries.
 502 
 503   MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable,
 504                                      &md_top, md_end,
 505                                      &mc_top, mc_end);
 506 
 507   // Reorder the system dictionary.  (Moving the symbols affects
 508   // how the hash table indices are calculated.)
 509   // Not doing this either.
 510 
 511   SystemDictionary::reorder_dictionary();
 512 
 513   NOT_PRODUCT(SystemDictionary::verify();)
 514 
 515   // Copy the the symbol table, and the system dictionary to the shared
 516   // space in usable form.  Copy the hashtable
 517   // buckets first [read-write], then copy the linked lists of entries
 518   // [read-only].
 519 
 520   SymbolTable::reverse(md_top);
 521   NOT_PRODUCT(SymbolTable::verify());
 522   SymbolTable::copy_buckets(&md_top, md_end);
 523 
 524   SystemDictionary::reverse();
 525   SystemDictionary::copy_buckets(&md_top, md_end);
 526 
 527   ClassLoader::verify();
 528   ClassLoader::copy_package_info_buckets(&md_top, md_end);
 529   ClassLoader::verify();
 530 
 531   SymbolTable::copy_table(&md_top, md_end);
 532   SystemDictionary::copy_table(&md_top, md_end);
 533   ClassLoader::verify();
 534   ClassLoader::copy_package_info_table(&md_top, md_end);
 535   ClassLoader::verify();
 536 
 537   // Write the other data to the output array.
 538   WriteClosure wc(md_top, md_end);
 539   MetaspaceShared::serialize(&wc);
 540   md_top = wc.get_top();
 541 
 542   // Print shared spaces all the time
 543 // To make fmt_space be a syntactic constant (for format warnings), use #define.
 544 #define fmt_space "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " INTPTR_FORMAT
 545   Metaspace* ro_space = _loader_data->ro_metaspace();
 546   Metaspace* rw_space = _loader_data->rw_metaspace();
 547 
 548   // Allocated size of each space (may not be all occupied)
 549   const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
 550   const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
 551   const size_t md_alloced = md_end-md_low;


 983 
 984 void MetaspaceShared::initialize_shared_spaces() {
 985   FileMapInfo *mapinfo = FileMapInfo::current_info();
 986 
 987   char* buffer = mapinfo->region_base(md);
 988 
 989   // Skip over (reserve space for) a list of addresses of C++ vtables
 990   // for Klass objects.  They get filled in later.
 991 
 992   void** vtbl_list = (void**)buffer;
 993   buffer += MetaspaceShared::vtbl_list_size * sizeof(void*);
 994   Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
 995 
 996   // Skip over (reserve space for) dummy C++ vtables Klass objects.
 997   // They are used as is.
 998 
 999   intptr_t vtable_size = *(intptr_t*)buffer;
1000   buffer += sizeof(intptr_t);
1001   buffer += vtable_size;
1002 
1003   // Create the symbol table using the bucket array at this spot in the
1004   // misc data space.  Since the symbol table is often modified, this
1005   // region (of mapped pages) will be copy-on-write.
1006 
1007   int symbolTableLen = *(intptr_t*)buffer;
1008   buffer += sizeof(intptr_t);
1009   int number_of_entries = *(intptr_t*)buffer;
1010   buffer += sizeof(intptr_t);
1011   SymbolTable::create_table((HashtableBucket<mtSymbol>*)buffer, symbolTableLen,
1012                             number_of_entries);
1013   buffer += symbolTableLen;
1014 
1015   // Create the shared dictionary using the bucket array at this spot in
1016   // the misc data space.  Since the shared dictionary table is never
1017   // modified, this region (of mapped pages) will be (effectively, if
1018   // not explicitly) read-only.
1019 
1020   int sharedDictionaryLen = *(intptr_t*)buffer;
1021   buffer += sizeof(intptr_t);
1022   number_of_entries = *(intptr_t*)buffer;
1023   buffer += sizeof(intptr_t);
1024   SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
1025                                           sharedDictionaryLen,
1026                                           number_of_entries);
1027   buffer += sharedDictionaryLen;
1028 
1029   // Create the package info table using the bucket array at this spot in
1030   // the misc data space.  Since the package info table is never
1031   // modified, this region (of mapped pages) will be (effectively, if
1032   // not explicitly) read-only.
1033 
1034   int pkgInfoLen = *(intptr_t*)buffer;
1035   buffer += sizeof(intptr_t);
1036   number_of_entries = *(intptr_t*)buffer;
1037   buffer += sizeof(intptr_t);
1038   ClassLoader::create_package_info_table((HashtableBucket<mtClass>*)buffer, pkgInfoLen,
1039                                          number_of_entries);
1040   buffer += pkgInfoLen;
1041   ClassLoader::verify();
1042 
1043   // The following data in the shared misc data region are the linked
1044   // list elements (HashtableEntry objects) for the symbol table, string
1045   // table, and shared dictionary.  The heap objects referred to by the
1046   // symbol table, string table, and shared dictionary are permanent and
1047   // unmovable.  Since new entries added to the string and symbol tables
1048   // are always added at the beginning of the linked lists, THESE LINKED
1049   // LIST ELEMENTS ARE READ-ONLY.
1050 
1051   int len = *(intptr_t*)buffer; // skip over symbol table entries
1052   buffer += sizeof(intptr_t);
1053   buffer += len;
1054 
1055   len = *(intptr_t*)buffer;     // skip over shared dictionary entries
1056   buffer += sizeof(intptr_t);
1057   buffer += len;
1058 
1059   len = *(intptr_t*)buffer;     // skip over package info table entries
1060   buffer += sizeof(intptr_t);
1061   buffer += len;
1062 
1063   len = *(intptr_t*)buffer;     // skip over package info table char[] arrays.
1064   buffer += sizeof(intptr_t);
1065   buffer += len;
1066 
1067   intptr_t* array = (intptr_t*)buffer;
1068   ReadClosure rc(&array);
1069   serialize(&rc);
1070 
1071   // Close the mapinfo file
1072   mapinfo->close();
1073 
1074   if (PrintSharedArchiveAndExit) {
1075     if (PrintSharedDictionary) {




  31 #include "classfile/systemDictionary.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "memory/filemap.hpp"
  34 #include "memory/gcLocker.hpp"
  35 #include "memory/metaspace.hpp"
  36 #include "memory/metaspaceShared.hpp"
  37 #include "oops/objArrayOop.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/os.hpp"
  40 #include "runtime/signature.hpp"
  41 #include "runtime/vm_operations.hpp"
  42 #include "runtime/vmThread.hpp"
  43 #include "utilities/hashtable.inline.hpp"
  44 
  45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  46 
  47 int MetaspaceShared::_max_alignment = 0;
  48 
  49 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
  50 
  51 MetaspaceSharedStats MetaspaceShared::_stats;
  52 
  53 bool MetaspaceShared::_link_classes_made_progress;
  54 bool MetaspaceShared::_check_classes_made_progress;
  55 bool MetaspaceShared::_has_error_classes;
  56 bool MetaspaceShared::_archive_loading_failed = false;
  57 // Read/write a data stream for restoring/preserving metadata pointers and
  58 // miscellaneous data from/to the shared archive file.
  59 
  60 void MetaspaceShared::serialize(SerializeClosure* soc) {
  61   int tag = 0;
  62   soc->do_tag(--tag);
  63 
  64   // Verify the sizes of various metadata in the system.
  65   soc->do_tag(sizeof(Method));
  66   soc->do_tag(sizeof(ConstMethod));
  67   soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
  68   soc->do_tag(sizeof(ConstantPool));
  69   soc->do_tag(sizeof(ConstantPoolCache));
  70   soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
  71   soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
  72   soc->do_tag(sizeof(Symbol));


 244     while (size > 0) {
 245       *top = *(intptr_t*)start;
 246       ++top;
 247       start += sizeof(intptr_t);
 248       size -= sizeof(intptr_t);
 249     }
 250   }
 251 
 252   bool reading() const { return false; }
 253 };
 254 
 255 // This is for dumping detailed statistics for the allocations
 256 // in the shared spaces.
 257 class DumpAllocClosure : public Metaspace::AllocRecordClosure {
 258 public:
 259 
 260   // Here's poor man's enum inheritance
 261 #define SHAREDSPACE_OBJ_TYPES_DO(f) \
 262   METASPACE_OBJ_TYPES_DO(f) \
 263   f(SymbolHashentry) \
 264   f(SymbolBucket) \
 265   f(Other)
 266 
 267 #define SHAREDSPACE_OBJ_TYPE_DECLARE(name) name ## Type,
 268 #define SHAREDSPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name;
 269 
 270   enum Type {
 271     // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
 272     SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_DECLARE)
 273     _number_of_types
 274   };
 275 
 276   static const char * type_name(Type type) {
 277     switch(type) {
 278     SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_NAME_CASE)
 279     default:
 280       ShouldNotReachHere();
 281       return NULL;
 282     }
 283   }
 284 


 300   void iterate_metaspace(Metaspace* space, int which) {
 301     assert(which == RO || which == RW, "sanity");
 302     _which = which;
 303     space->iterate(this);
 304   }
 305 
 306   virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) {
 307     assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");
 308     _counts[_which][type] ++;
 309     _bytes [_which][type] += byte_size;
 310   }
 311 
 312   void dump_stats(int ro_all, int rw_all, int md_all, int mc_all);
 313 };
 314 
 315 void DumpAllocClosure::dump_stats(int ro_all, int rw_all, int md_all, int mc_all) {
 316   rw_all += (md_all + mc_all); // md and mc are all mapped Read/Write
 317   int other_bytes = md_all + mc_all;
 318 
 319   // Calculate size of data that was not allocated by Metaspace::allocate()
 320   MetaspaceSharedStats *stats = MetaspaceShared::stats();
 321 
 322   // symbols
 323   _counts[RW][SymbolHashentryType] = stats->symbol.hashentry_count;
 324   _bytes [RW][SymbolHashentryType] = stats->symbol.hashentry_bytes;
 325   other_bytes -= stats->symbol.hashentry_bytes;
 326 
 327   _counts[RW][SymbolBucketType] = stats->symbol.bucket_count;
 328   _bytes [RW][SymbolBucketType] = stats->symbol.bucket_bytes;
 329   other_bytes -= stats->symbol.bucket_bytes;


 330 
 331   // TODO: count things like dictionary, vtable, etc
 332   _bytes[RW][OtherType] =  other_bytes;
 333 
 334   // prevent divide-by-zero
 335   if (ro_all < 1) {
 336     ro_all = 1;
 337   }
 338   if (rw_all < 1) {
 339     rw_all = 1;
 340   }
 341 
 342   int all_ro_count = 0;
 343   int all_ro_bytes = 0;
 344   int all_rw_count = 0;
 345   int all_rw_bytes = 0;
 346 
 347 // To make fmt_stats be a syntactic constant (for format warnings), use #define.
 348 #define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"
 349   const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";


 407   VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
 408                              GrowableArray<Klass*> *class_promote_order) :
 409     _loader_data(loader_data) {
 410 
 411     // Split up and initialize the misc code and data spaces
 412     ReservedSpace* shared_rs = MetaspaceShared::shared_rs();
 413     int metadata_size = SharedReadOnlySize+SharedReadWriteSize;
 414     ReservedSpace shared_ro_rw = shared_rs->first_part(metadata_size);
 415     ReservedSpace misc_section = shared_rs->last_part(metadata_size);
 416 
 417     // Now split into misc sections.
 418     ReservedSpace md_rs   = misc_section.first_part(SharedMiscDataSize);
 419     ReservedSpace mc_rs   = misc_section.last_part(SharedMiscDataSize);
 420     _md_vs.initialize(md_rs, SharedMiscDataSize);
 421     _mc_vs.initialize(mc_rs, SharedMiscCodeSize);
 422     _class_promote_order = class_promote_order;
 423   }
 424 
 425   VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
 426   void doit();   // outline because gdb sucks
 427 
 428 private:
 429   void handle_failure(bool success, const char* what) {
 430     if (!success) {
 431       tty->print_cr("Insufficient shared space: please increase -XX:%s= to increase its size", what);
 432       exit(1);
 433     }
 434   }
 435   void handle_misc_data_space_failure(bool success) {
 436     handle_failure(success, "SharedMiscDataSize");
 437   }
 438 }; // class VM_PopulateDumpSharedSpace
 439 
 440 
 441 void VM_PopulateDumpSharedSpace::doit() {
 442   Thread* THREAD = VMThread::vm_thread();
 443   NOT_PRODUCT(SystemDictionary::verify();)
 444   // The following guarantee is meant to ensure that no loader constraints
 445   // exist yet, since the constraints table is not shared.  This becomes
 446   // more important now that we don't re-initialize vtables/itables for
 447   // shared classes at runtime, where constraints were previously created.
 448   guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
 449             "loader constraints are not saved");
 450   guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
 451           "placeholders are not saved");
 452   // Revisit and implement this if we prelink method handle call sites:
 453   guarantee(SystemDictionary::invoke_method_table() == NULL ||
 454             SystemDictionary::invoke_method_table()->number_of_entries() == 0,
 455             "invoke method table is not saved");
 456 
 457   // At this point, many classes have been loaded.


 511   // Reserve space for a new dummy vtable for klass objects in the
 512   // heap.  Generate self-patching vtable entries.
 513 
 514   MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable,
 515                                      &md_top, md_end,
 516                                      &mc_top, mc_end);
 517 
 518   // Reorder the system dictionary.  (Moving the symbols affects
 519   // how the hash table indices are calculated.)
 520   // Not doing this either.
 521 
 522   SystemDictionary::reorder_dictionary();
 523 
 524   NOT_PRODUCT(SystemDictionary::verify();)
 525 
 526   // Copy the the symbol table, and the system dictionary to the shared
 527   // space in usable form.  Copy the hashtable
 528   // buckets first [read-write], then copy the linked lists of entries
 529   // [read-only].
 530 

 531   NOT_PRODUCT(SymbolTable::verify());
 532   handle_misc_data_space_failure(SymbolTable::copy_compact_table(&md_top, md_end));
 533 
 534   SystemDictionary::reverse();
 535   SystemDictionary::copy_buckets(&md_top, md_end);
 536 
 537   ClassLoader::verify();
 538   ClassLoader::copy_package_info_buckets(&md_top, md_end);
 539   ClassLoader::verify();
 540 

 541   SystemDictionary::copy_table(&md_top, md_end);
 542   ClassLoader::verify();
 543   ClassLoader::copy_package_info_table(&md_top, md_end);
 544   ClassLoader::verify();
 545 
 546   // Write the other data to the output array.
 547   WriteClosure wc(md_top, md_end);
 548   MetaspaceShared::serialize(&wc);
 549   md_top = wc.get_top();
 550 
 551   // Print shared spaces all the time
 552 // To make fmt_space be a syntactic constant (for format warnings), use #define.
 553 #define fmt_space "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " INTPTR_FORMAT
 554   Metaspace* ro_space = _loader_data->ro_metaspace();
 555   Metaspace* rw_space = _loader_data->rw_metaspace();
 556 
 557   // Allocated size of each space (may not be all occupied)
 558   const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
 559   const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
 560   const size_t md_alloced = md_end-md_low;


 992 
 993 void MetaspaceShared::initialize_shared_spaces() {
 994   FileMapInfo *mapinfo = FileMapInfo::current_info();
 995 
 996   char* buffer = mapinfo->region_base(md);
 997 
 998   // Skip over (reserve space for) a list of addresses of C++ vtables
 999   // for Klass objects.  They get filled in later.
1000 
1001   void** vtbl_list = (void**)buffer;
1002   buffer += MetaspaceShared::vtbl_list_size * sizeof(void*);
1003   Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
1004 
1005   // Skip over (reserve space for) dummy C++ vtables Klass objects.
1006   // They are used as is.
1007 
1008   intptr_t vtable_size = *(intptr_t*)buffer;
1009   buffer += sizeof(intptr_t);
1010   buffer += vtable_size;
1011 
1012   // Create the shared symbol table using the bucket array at this spot in the
1013   // misc data space. (Todo: move this to read-only space. Currently
1014   // this is mapped copy-on-write but will never be written into).
1015 
1016   buffer = (char*)SymbolTable::init_shared_table(buffer);
1017   SymbolTable::create_table();





1018 
1019   // Create the shared dictionary using the bucket array at this spot in
1020   // the misc data space.  Since the shared dictionary table is never
1021   // modified, this region (of mapped pages) will be (effectively, if
1022   // not explicitly) read-only.
1023 
1024   int sharedDictionaryLen = *(intptr_t*)buffer;
1025   buffer += sizeof(intptr_t);
1026   int number_of_entries = *(intptr_t*)buffer;
1027   buffer += sizeof(intptr_t);
1028   SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
1029                                           sharedDictionaryLen,
1030                                           number_of_entries);
1031   buffer += sharedDictionaryLen;
1032 
1033   // Create the package info table using the bucket array at this spot in
1034   // the misc data space.  Since the package info table is never
1035   // modified, this region (of mapped pages) will be (effectively, if
1036   // not explicitly) read-only.
1037 
1038   int pkgInfoLen = *(intptr_t*)buffer;
1039   buffer += sizeof(intptr_t);
1040   number_of_entries = *(intptr_t*)buffer;
1041   buffer += sizeof(intptr_t);
1042   ClassLoader::create_package_info_table((HashtableBucket<mtClass>*)buffer, pkgInfoLen,
1043                                          number_of_entries);
1044   buffer += pkgInfoLen;
1045   ClassLoader::verify();
1046 
1047   // The following data in the shared misc data region are the linked
1048   // list elements (HashtableEntry objects) for the shared dictionary
1049   // and package info table.








1050 
1051   int len = *(intptr_t*)buffer;     // skip over shared dictionary entries
1052   buffer += sizeof(intptr_t);
1053   buffer += len;
1054 
1055   len = *(intptr_t*)buffer;     // skip over package info table entries
1056   buffer += sizeof(intptr_t);
1057   buffer += len;
1058 
1059   len = *(intptr_t*)buffer;     // skip over package info table char[] arrays.
1060   buffer += sizeof(intptr_t);
1061   buffer += len;
1062 
1063   intptr_t* array = (intptr_t*)buffer;
1064   ReadClosure rc(&array);
1065   serialize(&rc);
1066 
1067   // Close the mapinfo file
1068   mapinfo->close();
1069 
1070   if (PrintSharedArchiveAndExit) {
1071     if (PrintSharedDictionary) {