< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page


  47 #include "memory/resourceArea.hpp"
  48 #include "oops/compressedOops.inline.hpp"
  49 #include "oops/instanceClassLoaderKlass.hpp"
  50 #include "oops/instanceMirrorKlass.hpp"
  51 #include "oops/instanceRefKlass.hpp"
  52 #include "oops/objArrayKlass.hpp"
  53 #include "oops/objArrayOop.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/typeArrayKlass.hpp"
  56 #include "prims/jvmtiRedefineClasses.hpp"
  57 #include "runtime/handles.inline.hpp"
  58 #include "runtime/os.hpp"
  59 #include "runtime/safepointVerifiers.hpp"
  60 #include "runtime/signature.hpp"
  61 #include "runtime/timerTrace.hpp"
  62 #include "runtime/vmThread.hpp"
  63 #include "runtime/vm_operations.hpp"
  64 #include "utilities/align.hpp"
  65 #include "utilities/bitMap.hpp"
  66 #include "utilities/defaultStream.hpp"

  67 #include "utilities/hashtable.inline.hpp"
  68 #if INCLUDE_G1GC
  69 #include "gc/g1/g1CollectedHeap.hpp"
  70 #endif
  71 
  72 ReservedSpace MetaspaceShared::_shared_rs;
  73 VirtualSpace MetaspaceShared::_shared_vs;
  74 MetaspaceSharedStats MetaspaceShared::_stats;
  75 bool MetaspaceShared::_has_error_classes;
  76 bool MetaspaceShared::_archive_loading_failed = false;
  77 bool MetaspaceShared::_remapped_readwrite = false;
  78 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
  79 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
  80 size_t MetaspaceShared::_core_spaces_size = 0;
  81 
  82 // The CDS archive is divided into the following regions:
  83 //     mc  - misc code (the method entry trampolines)
  84 //     rw  - read-write metadata
  85 //     ro  - read-only metadata and read-only tables
  86 //     md  - misc data (the c++ vtables)


1061 public:
1062   SortedSymbolClosure() {
1063     SymbolTable::symbols_do(this);
1064     _symbols.sort(compare_symbols_by_address);
1065   }
1066   GrowableArray<Symbol*>* get_sorted_symbols() {
1067     return &_symbols;
1068   }
1069 };
1070 
1071 // ArchiveCompactor --
1072 //
1073 // This class is the central piece of shared archive compaction -- all metaspace data are
1074 // initially allocated outside of the shared regions. ArchiveCompactor copies the
1075 // metaspace data into their final location in the shared regions.
1076 
1077 class ArchiveCompactor : AllStatic {
1078   static DumpAllocStats* _alloc_stats;
1079   static SortedSymbolClosure* _ssc;
1080 

1081   static unsigned my_hash(const address& a) {
1082     return primitive_hash<address>(a);
1083   }
1084   static bool my_equals(const address& a0, const address& a1) {
1085     return primitive_equals<address>(a0, a1);
1086   }
1087   typedef ResourceHashtable<

1088       address, address,
1089       ArchiveCompactor::my_hash,   // solaris compiler doesn't like: primitive_hash<address>
1090       ArchiveCompactor::my_equals, // solaris compiler doesn't like: primitive_equals<address>
1091       16384, ResourceObj::C_HEAP> RelocationTable;
1092   static RelocationTable* _new_loc_table;
1093 
1094 public:
1095   static void initialize() {
1096     _alloc_stats = new(ResourceObj::C_HEAP, mtInternal)DumpAllocStats;
1097     _new_loc_table = new(ResourceObj::C_HEAP, mtInternal)RelocationTable;
1098   }
1099   static DumpAllocStats* alloc_stats() {
1100     return _alloc_stats;
1101   }
1102 
1103   // Use this when you allocate space with MetaspaceShare::read_only_space_alloc()
1104   // outside of ArchiveCompactor::allocate(). These are usually for misc tables
1105   // that are allocated in the RO space.
1106   class OtherROAllocMark {
1107     char* _oldtop;
1108   public:
1109     OtherROAllocMark() {
1110       _oldtop = _ro_region.top();
1111     }


1367   // shared classes at runtime, where constraints were previously created.
1368   guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
1369             "loader constraints are not saved");
1370   guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
1371           "placeholders are not saved");
1372   // Revisit and implement this if we prelink method handle call sites:
1373   guarantee(SystemDictionary::invoke_method_table() == NULL ||
1374             SystemDictionary::invoke_method_table()->number_of_entries() == 0,
1375             "invoke method table is not saved");
1376 
1377   // At this point, many classes have been loaded.
1378   // Gather systemDictionary classes in a global array and do everything to
1379   // that so we don't have to walk the SystemDictionary again.
1380   _global_klass_objects = new GrowableArray<Klass*>(1000);
1381   CollectClassesClosure collect_classes;
1382   ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
1383 
1384   tty->print_cr("Number of classes %d", _global_klass_objects->length());
1385   {
1386     int num_type_array = 0, num_obj_array = 0, num_inst = 0;

1387     for (int i = 0; i < _global_klass_objects->length(); i++) {
1388       Klass* k = _global_klass_objects->at(i);
1389       if (k->is_instance_klass()) {
1390         num_inst ++;










1391       } else if (k->is_objArray_klass()) {
1392         num_obj_array ++;
1393       } else {
1394         assert(k->is_typeArray_klass(), "sanity");
1395         num_type_array ++;
1396       }
1397     }
1398     tty->print_cr("    instance classes   = %5d", num_inst);




1399     tty->print_cr("    obj array classes  = %5d", num_obj_array);
1400     tty->print_cr("    type array classes = %5d", num_type_array);
1401   }
1402 
1403   // Ensure the ConstMethods won't be modified at run-time
1404   tty->print("Updating ConstMethods ... ");
1405   rewrite_nofast_bytecodes_and_calculate_fingerprints();
1406   tty->print_cr("done. ");
1407 
1408   // Move classes from platform/system dictionaries into the boot dictionary
1409   SystemDictionary::combine_shared_dictionaries();
1410 
1411   // Make sure all classes have a correct loader type.
1412   ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(MetaspaceShared::check_shared_class_loader_type);
1413 
1414   // Remove all references outside the metadata
1415   tty->print("Removing unshareable information ... ");
1416   remove_unshareable_in_classes();
1417   tty->print_cr("done. ");
1418 




  47 #include "memory/resourceArea.hpp"
  48 #include "oops/compressedOops.inline.hpp"
  49 #include "oops/instanceClassLoaderKlass.hpp"
  50 #include "oops/instanceMirrorKlass.hpp"
  51 #include "oops/instanceRefKlass.hpp"
  52 #include "oops/objArrayKlass.hpp"
  53 #include "oops/objArrayOop.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/typeArrayKlass.hpp"
  56 #include "prims/jvmtiRedefineClasses.hpp"
  57 #include "runtime/handles.inline.hpp"
  58 #include "runtime/os.hpp"
  59 #include "runtime/safepointVerifiers.hpp"
  60 #include "runtime/signature.hpp"
  61 #include "runtime/timerTrace.hpp"
  62 #include "runtime/vmThread.hpp"
  63 #include "runtime/vm_operations.hpp"
  64 #include "utilities/align.hpp"
  65 #include "utilities/bitMap.hpp"
  66 #include "utilities/defaultStream.hpp"
  67 #include "utilities/expandableResourceHash.hpp"
  68 #include "utilities/hashtable.inline.hpp"
  69 #if INCLUDE_G1GC
  70 #include "gc/g1/g1CollectedHeap.hpp"
  71 #endif
  72 
  73 ReservedSpace MetaspaceShared::_shared_rs;
  74 VirtualSpace MetaspaceShared::_shared_vs;
  75 MetaspaceSharedStats MetaspaceShared::_stats;
  76 bool MetaspaceShared::_has_error_classes;
  77 bool MetaspaceShared::_archive_loading_failed = false;
  78 bool MetaspaceShared::_remapped_readwrite = false;
  79 address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
  80 size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
  81 size_t MetaspaceShared::_core_spaces_size = 0;
  82 
  83 // The CDS archive is divided into the following regions:
  84 //     mc  - misc code (the method entry trampolines)
  85 //     rw  - read-write metadata
  86 //     ro  - read-only metadata and read-only tables
  87 //     md  - misc data (the c++ vtables)


1062 public:
1063   SortedSymbolClosure() {
1064     SymbolTable::symbols_do(this);
1065     _symbols.sort(compare_symbols_by_address);
1066   }
1067   GrowableArray<Symbol*>* get_sorted_symbols() {
1068     return &_symbols;
1069   }
1070 };
1071 
1072 // ArchiveCompactor --
1073 //
1074 // This class is the central piece of shared archive compaction -- all metaspace data are
1075 // initially allocated outside of the shared regions. ArchiveCompactor copies the
1076 // metaspace data into their final location in the shared regions.
1077 
1078 class ArchiveCompactor : AllStatic {
1079   static DumpAllocStats* _alloc_stats;
1080   static SortedSymbolClosure* _ssc;
1081 
1082 public: // <-- solaris compiler wants this
1083   static unsigned my_hash(const address& a) {
1084     return primitive_hash<address>(a);
1085   }
1086   static bool my_equals(const address& a0, const address& a1) {
1087     return primitive_equals<address>(a0, a1);
1088   }
1089 private:
1090   typedef ExpandableResourceHashtable<
1091       address, address,
1092       ArchiveCompactor::my_hash,   // solaris compiler doesn't like: primitive_hash<address>
1093       ArchiveCompactor::my_equals, // solaris compiler doesn't like: primitive_equals<address>
1094       8087, 8, ResourceObj::C_HEAP> RelocationTable;
1095   static RelocationTable* _new_loc_table;
1096 
1097 public:
1098   static void initialize() {
1099     _alloc_stats = new(ResourceObj::C_HEAP, mtInternal)DumpAllocStats;
1100     _new_loc_table = new(ResourceObj::C_HEAP, mtInternal)RelocationTable;
1101   }
1102   static DumpAllocStats* alloc_stats() {
1103     return _alloc_stats;
1104   }
1105 
1106   // Use this when you allocate space with MetaspaceShare::read_only_space_alloc()
1107   // outside of ArchiveCompactor::allocate(). These are usually for misc tables
1108   // that are allocated in the RO space.
1109   class OtherROAllocMark {
1110     char* _oldtop;
1111   public:
1112     OtherROAllocMark() {
1113       _oldtop = _ro_region.top();
1114     }


1370   // shared classes at runtime, where constraints were previously created.
1371   guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
1372             "loader constraints are not saved");
1373   guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
1374           "placeholders are not saved");
1375   // Revisit and implement this if we prelink method handle call sites:
1376   guarantee(SystemDictionary::invoke_method_table() == NULL ||
1377             SystemDictionary::invoke_method_table()->number_of_entries() == 0,
1378             "invoke method table is not saved");
1379 
1380   // At this point, many classes have been loaded.
1381   // Gather systemDictionary classes in a global array and do everything to
1382   // that so we don't have to walk the SystemDictionary again.
1383   _global_klass_objects = new GrowableArray<Klass*>(1000);
1384   CollectClassesClosure collect_classes;
1385   ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
1386 
1387   tty->print_cr("Number of classes %d", _global_klass_objects->length());
1388   {
1389     int num_type_array = 0, num_obj_array = 0, num_inst = 0;
1390     int num_boot = 0, num_platform = 0, num_app = 0, num_unregistered = 0;
1391     for (int i = 0; i < _global_klass_objects->length(); i++) {
1392       Klass* k = _global_klass_objects->at(i);
1393       if (k->is_instance_klass()) {
1394         num_inst ++;
1395         InstanceKlass* ik = InstanceKlass::cast(k);
1396         if (ik->shared_classpath_index() == UNREGISTERED_INDEX) {
1397           num_unregistered ++;
1398         } else if (ik->is_shared_boot_class()) {
1399           num_boot ++;
1400         } else if (ik->is_shared_platform_class()) {
1401           num_platform ++;
1402         } else if (ik->is_shared_app_class()) {
1403           num_app ++;
1404         }
1405       } else if (k->is_objArray_klass()) {
1406         num_obj_array ++;
1407       } else {
1408         assert(k->is_typeArray_klass(), "sanity");
1409         num_type_array ++;
1410       }
1411     }
1412     tty->print_cr("    instance classes   = %5d", num_inst);
1413     tty->print_cr("       boot            = %5d", num_boot);
1414     tty->print_cr("       platform        = %5d", num_platform);
1415     tty->print_cr("       app             = %5d", num_app);
1416     tty->print_cr("       unregistered    = %5d", num_unregistered);
1417     tty->print_cr("    obj array classes  = %5d", num_obj_array);
1418     tty->print_cr("    type array classes = %5d", num_type_array);
1419   }
1420 
1421   // Ensure the ConstMethods won't be modified at run-time
1422   tty->print("Updating ConstMethods ... ");
1423   rewrite_nofast_bytecodes_and_calculate_fingerprints();
1424   tty->print_cr("done. ");
1425 
1426   // Move classes from platform/system dictionaries into the boot dictionary
1427   SystemDictionary::combine_shared_dictionaries();
1428 
1429   // Make sure all classes have a correct loader type.
1430   ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(MetaspaceShared::check_shared_class_loader_type);
1431 
1432   // Remove all references outside the metadata
1433   tty->print("Removing unshareable information ... ");
1434   remove_unshareable_in_classes();
1435   tty->print_cr("done. ");
1436 


< prev index next >