< prev index next >

src/hotspot/share/cds/metaspaceShared.cpp

Print this page

  57 #include "classfile/symbolTable.hpp"
  58 #include "classfile/systemDictionary.hpp"
  59 #include "classfile/systemDictionaryShared.hpp"
  60 #include "classfile/vmClasses.hpp"
  61 #include "classfile/vmSymbols.hpp"
  62 #include "code/codeCache.hpp"
  63 #include "gc/shared/gcVMOperations.hpp"
  64 #include "interpreter/bytecodeStream.hpp"
  65 #include "interpreter/bytecodes.hpp"
  66 #include "jvm_io.h"
  67 #include "logging/log.hpp"
  68 #include "logging/logMessage.hpp"
  69 #include "logging/logStream.hpp"
  70 #include "memory/memoryReserver.hpp"
  71 #include "memory/metaspace.hpp"
  72 #include "memory/metaspaceClosure.hpp"
  73 #include "memory/resourceArea.hpp"
  74 #include "memory/universe.hpp"
  75 #include "nmt/memTracker.hpp"
  76 #include "oops/compressedKlass.hpp"


  77 #include "oops/instanceMirrorKlass.hpp"
  78 #include "oops/klass.inline.hpp"
  79 #include "oops/objArrayOop.hpp"
  80 #include "oops/oop.inline.hpp"
  81 #include "oops/oopHandle.hpp"
  82 #include "prims/jvmtiExport.hpp"
  83 #include "runtime/arguments.hpp"
  84 #include "runtime/globals.hpp"
  85 #include "runtime/globals_extension.hpp"
  86 #include "runtime/handles.inline.hpp"
  87 #include "runtime/javaCalls.hpp"
  88 #include "runtime/os.inline.hpp"
  89 #include "runtime/safepointVerifiers.hpp"
  90 #include "runtime/sharedRuntime.hpp"
  91 #include "runtime/vmOperations.hpp"
  92 #include "runtime/vmThread.hpp"
  93 #include "sanitizers/leak.hpp"
  94 #include "utilities/align.hpp"
  95 #include "utilities/bitMap.inline.hpp"
  96 #include "utilities/defaultStream.hpp"

 103 ReservedSpace MetaspaceShared::_symbol_rs;
 104 VirtualSpace MetaspaceShared::_symbol_vs;
 105 bool MetaspaceShared::_archive_loading_failed = false;
 106 bool MetaspaceShared::_remapped_readwrite = false;
 107 void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
 108 intx MetaspaceShared::_relocation_delta;
 109 char* MetaspaceShared::_requested_base_address;
 110 Array<Method*>* MetaspaceShared::_archived_method_handle_intrinsics = nullptr;
 111 bool MetaspaceShared::_use_optimized_module_handling = true;
 112 
 113 // The CDS archive is divided into the following regions:
 114 //     rw  - read-write metadata
 115 //     ro  - read-only metadata and read-only tables
 116 //     hp  - heap region
 117 //     bm  - bitmap for relocating the above 7 regions.
 118 //
 119 // The rw and ro regions are linearly allocated, in the order of rw->ro.
 120 // These regions are aligned with MetaspaceShared::core_region_alignment().
 121 //
 122 // These 2 regions are populated in the following steps:
 123 // [0] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are
 124 //     temporarily allocated outside of the shared regions.
 125 // [1] We enter a safepoint and allocate a buffer for the rw/ro regions.
 126 // [2] C++ vtables are copied into the rw region.
 127 // [3] ArchiveBuilder copies RW metadata into the rw region.
 128 // [4] ArchiveBuilder copies RO metadata into the ro region.
 129 // [5] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
 130 //     are copied into the ro region as read-only tables.
 131 //
 132 // The heap region is written by HeapShared::write_heap().
 133 //
 134 // The bitmap region is used to relocate the ro/rw/hp regions.
 135 
 136 static DumpRegion _symbol_region("symbols");
 137 
 138 char* MetaspaceShared::symbol_space_alloc(size_t num_bytes) {
 139   return _symbol_region.allocate(num_bytes);
 140 }
 141 
 142 // os::vm_allocation_granularity() is usually 4K for most OSes. However, some platforms
 143 // such as linux-aarch64 and macos-x64 ...

 842     log_debug(cds)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
 843     FLAG_SET_ERGO(MinHeapSize, max_heap_size);
 844   }
 845   if (InitialHeapSize > max_heap_size) {
 846     log_debug(cds)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
 847     FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
 848   }
 849   if (MaxHeapSize > max_heap_size) {
 850     log_debug(cds)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
 851     FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
 852   }
 853 }
 854 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
 855 
 856 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
 857   const char* filesep = os::file_separator();
 858   jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
 859                Arguments::get_java_home(), filesep, filesep);
 860 }
 861 
 862 void MetaspaceShared::preload_classes(TRAPS) {
 863   char default_classlist[JVM_MAXPATHLEN];
 864   const char* classlist_path;
 865 
 866   get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 867   if (SharedClassListFile == nullptr) {
 868     classlist_path = default_classlist;
 869   } else {
 870     classlist_path = SharedClassListFile;
 871   }
 872 
 873   log_info(cds)("Loading classes to share ...");
 874   ClassListParser::parse_classlist(classlist_path,
 875                                    ClassListParser::_parse_all, CHECK);
 876   if (ExtraSharedClassListFile) {
 877     ClassListParser::parse_classlist(ExtraSharedClassListFile,
 878                                      ClassListParser::_parse_all, CHECK);
 879   }
 880   if (classlist_path != default_classlist) {
 881     struct stat statbuf;
 882     if (os::stat(default_classlist, &statbuf) == 0) {

 889   // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
 890   // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
 891   // are archived.
 892   exercise_runtime_cds_code(CHECK);
 893 
 894   log_info(cds)("Loading classes to share: done.");
 895 }
 896 
 897 void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
 898   // Exercise the manifest processing code
 899   const char* dummy = "Manifest-Version: 1.0\n";
 900   CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
 901 
 902   // Exercise FileSystem and URL code
 903   CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
 904 }
 905 
 906 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
 907   if (CDSConfig::is_dumping_classic_static_archive()) {
 908     // We are running with -Xshare:dump
 909     preload_classes(CHECK);
 910 
 911     if (SharedArchiveConfigFile) {
 912       log_info(cds)("Reading extra data from %s ...", SharedArchiveConfigFile);
 913       read_extra_data(THREAD, SharedArchiveConfigFile);
 914       log_info(cds)("Reading extra data: done.");
 915     }
 916   }
 917 
 918   if (CDSConfig::is_dumping_preimage_static_archive()) {
 919     log_info(cds)("Reading lambda form invokers from JDK default classlist ...");
 920     char default_classlist[JVM_MAXPATHLEN];
 921     get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 922     struct stat statbuf;
 923     if (os::stat(default_classlist, &statbuf) == 0) {
 924       ClassListParser::parse_classlist(default_classlist,
 925                                        ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
 926     }
 927   }
 928 
 929 #if INCLUDE_CDS_JAVA_HEAP

1047     }
1048     ik->link_class(THREAD);
1049     if (HAS_PENDING_EXCEPTION) {
1050       ResourceMark rm(THREAD);
1051       log_warning(cds)("Preload Warning: Verification failed for %s",
1052                     ik->external_name());
1053       CLEAR_PENDING_EXCEPTION;
1054       SystemDictionaryShared::set_class_has_failed_verification(ik);
1055     } else {
1056       assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1057       ik->compute_has_loops_flag_for_methods();
1058     }
1059     BytecodeVerificationLocal = saved;
1060     return true;
1061   } else {
1062     return false;
1063   }
1064 }
1065 
1066 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {





1067   if (CDSConfig::is_dumping_heap()) {
1068     HeapShared::write_heap(&_heap_info);
1069   } else {
1070     CDSConfig::log_reasons_for_not_dumping_heap();
1071   }
1072 }
1073 
1074 void MetaspaceShared::set_shared_metaspace_range(void* base, void *static_top, void* top) {
1075   assert(base <= static_top && static_top <= top, "must be");
1076   _shared_metaspace_static_top = static_top;
1077   MetaspaceObj::set_shared_metaspace_range(base, top);
1078 }
1079 
1080 bool MetaspaceShared::is_shared_dynamic(void* p) {
1081   if ((p < MetaspaceObj::shared_metaspace_top()) &&
1082       (p >= _shared_metaspace_static_top)) {
1083     return true;
1084   } else {
1085     return false;
1086   }

  57 #include "classfile/symbolTable.hpp"
  58 #include "classfile/systemDictionary.hpp"
  59 #include "classfile/systemDictionaryShared.hpp"
  60 #include "classfile/vmClasses.hpp"
  61 #include "classfile/vmSymbols.hpp"
  62 #include "code/codeCache.hpp"
  63 #include "gc/shared/gcVMOperations.hpp"
  64 #include "interpreter/bytecodeStream.hpp"
  65 #include "interpreter/bytecodes.hpp"
  66 #include "jvm_io.h"
  67 #include "logging/log.hpp"
  68 #include "logging/logMessage.hpp"
  69 #include "logging/logStream.hpp"
  70 #include "memory/memoryReserver.hpp"
  71 #include "memory/metaspace.hpp"
  72 #include "memory/metaspaceClosure.hpp"
  73 #include "memory/resourceArea.hpp"
  74 #include "memory/universe.hpp"
  75 #include "nmt/memTracker.hpp"
  76 #include "oops/compressedKlass.hpp"
  77 #include "oops/flatArrayKlass.hpp"
  78 #include "oops/inlineKlass.hpp"
  79 #include "oops/instanceMirrorKlass.hpp"
  80 #include "oops/klass.inline.hpp"
  81 #include "oops/objArrayOop.hpp"
  82 #include "oops/oop.inline.hpp"
  83 #include "oops/oopHandle.hpp"
  84 #include "prims/jvmtiExport.hpp"
  85 #include "runtime/arguments.hpp"
  86 #include "runtime/globals.hpp"
  87 #include "runtime/globals_extension.hpp"
  88 #include "runtime/handles.inline.hpp"
  89 #include "runtime/javaCalls.hpp"
  90 #include "runtime/os.inline.hpp"
  91 #include "runtime/safepointVerifiers.hpp"
  92 #include "runtime/sharedRuntime.hpp"
  93 #include "runtime/vmOperations.hpp"
  94 #include "runtime/vmThread.hpp"
  95 #include "sanitizers/leak.hpp"
  96 #include "utilities/align.hpp"
  97 #include "utilities/bitMap.inline.hpp"
  98 #include "utilities/defaultStream.hpp"

 105 ReservedSpace MetaspaceShared::_symbol_rs;
 106 VirtualSpace MetaspaceShared::_symbol_vs;
 107 bool MetaspaceShared::_archive_loading_failed = false;
 108 bool MetaspaceShared::_remapped_readwrite = false;
 109 void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
 110 intx MetaspaceShared::_relocation_delta;
 111 char* MetaspaceShared::_requested_base_address;
 112 Array<Method*>* MetaspaceShared::_archived_method_handle_intrinsics = nullptr;
 113 bool MetaspaceShared::_use_optimized_module_handling = true;
 114 
 115 // The CDS archive is divided into the following regions:
 116 //     rw  - read-write metadata
 117 //     ro  - read-only metadata and read-only tables
 118 //     hp  - heap region
 119 //     bm  - bitmap for relocating the above 7 regions.
 120 //
 121 // The rw and ro regions are linearly allocated, in the order of rw->ro.
 122 // These regions are aligned with MetaspaceShared::core_region_alignment().
 123 //
 124 // These 2 regions are populated in the following steps:
 125 // [0] All classes are loaded in MetaspaceShared::loadable_descriptors(). All metadata are
 126 //     temporarily allocated outside of the shared regions.
 127 // [1] We enter a safepoint and allocate a buffer for the rw/ro regions.
 128 // [2] C++ vtables are copied into the rw region.
 129 // [3] ArchiveBuilder copies RW metadata into the rw region.
 130 // [4] ArchiveBuilder copies RO metadata into the ro region.
 131 // [5] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
 132 //     are copied into the ro region as read-only tables.
 133 //
 134 // The heap region is written by HeapShared::write_heap().
 135 //
 136 // The bitmap region is used to relocate the ro/rw/hp regions.
 137 
 138 static DumpRegion _symbol_region("symbols");
 139 
 140 char* MetaspaceShared::symbol_space_alloc(size_t num_bytes) {
 141   return _symbol_region.allocate(num_bytes);
 142 }
 143 
 144 // os::vm_allocation_granularity() is usually 4K for most OSes. However, some platforms
 145 // such as linux-aarch64 and macos-x64 ...

 844     log_debug(cds)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
 845     FLAG_SET_ERGO(MinHeapSize, max_heap_size);
 846   }
 847   if (InitialHeapSize > max_heap_size) {
 848     log_debug(cds)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
 849     FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
 850   }
 851   if (MaxHeapSize > max_heap_size) {
 852     log_debug(cds)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
 853     FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
 854   }
 855 }
 856 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
 857 
 858 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
 859   const char* filesep = os::file_separator();
 860   jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
 861                Arguments::get_java_home(), filesep, filesep);
 862 }
 863 
 864 void MetaspaceShared::loadable_descriptors(TRAPS) {
 865   char default_classlist[JVM_MAXPATHLEN];
 866   const char* classlist_path;
 867 
 868   get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 869   if (SharedClassListFile == nullptr) {
 870     classlist_path = default_classlist;
 871   } else {
 872     classlist_path = SharedClassListFile;
 873   }
 874 
 875   log_info(cds)("Loading classes to share ...");
 876   ClassListParser::parse_classlist(classlist_path,
 877                                    ClassListParser::_parse_all, CHECK);
 878   if (ExtraSharedClassListFile) {
 879     ClassListParser::parse_classlist(ExtraSharedClassListFile,
 880                                      ClassListParser::_parse_all, CHECK);
 881   }
 882   if (classlist_path != default_classlist) {
 883     struct stat statbuf;
 884     if (os::stat(default_classlist, &statbuf) == 0) {

 891   // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
 892   // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
 893   // are archived.
 894   exercise_runtime_cds_code(CHECK);
 895 
 896   log_info(cds)("Loading classes to share: done.");
 897 }
 898 
 899 void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
 900   // Exercise the manifest processing code
 901   const char* dummy = "Manifest-Version: 1.0\n";
 902   CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
 903 
 904   // Exercise FileSystem and URL code
 905   CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
 906 }
 907 
 908 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
 909   if (CDSConfig::is_dumping_classic_static_archive()) {
 910     // We are running with -Xshare:dump
 911     loadable_descriptors(CHECK);
 912 
 913     if (SharedArchiveConfigFile) {
 914       log_info(cds)("Reading extra data from %s ...", SharedArchiveConfigFile);
 915       read_extra_data(THREAD, SharedArchiveConfigFile);
 916       log_info(cds)("Reading extra data: done.");
 917     }
 918   }
 919 
 920   if (CDSConfig::is_dumping_preimage_static_archive()) {
 921     log_info(cds)("Reading lambda form invokers from JDK default classlist ...");
 922     char default_classlist[JVM_MAXPATHLEN];
 923     get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 924     struct stat statbuf;
 925     if (os::stat(default_classlist, &statbuf) == 0) {
 926       ClassListParser::parse_classlist(default_classlist,
 927                                        ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
 928     }
 929   }
 930 
 931 #if INCLUDE_CDS_JAVA_HEAP

1049     }
1050     ik->link_class(THREAD);
1051     if (HAS_PENDING_EXCEPTION) {
1052       ResourceMark rm(THREAD);
1053       log_warning(cds)("Preload Warning: Verification failed for %s",
1054                     ik->external_name());
1055       CLEAR_PENDING_EXCEPTION;
1056       SystemDictionaryShared::set_class_has_failed_verification(ik);
1057     } else {
1058       assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1059       ik->compute_has_loops_flag_for_methods();
1060     }
1061     BytecodeVerificationLocal = saved;
1062     return true;
1063   } else {
1064     return false;
1065   }
1066 }
1067 
1068 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1069   if (CDSConfig::is_valhalla_preview()) {
1070     log_info(cds)("Archived java heap is not yet supported with Valhalla preview");
1071     return;
1072   }
1073 
1074   if (CDSConfig::is_dumping_heap()) {
1075     HeapShared::write_heap(&_heap_info);
1076   } else {
1077     CDSConfig::log_reasons_for_not_dumping_heap();
1078   }
1079 }
1080 
1081 void MetaspaceShared::set_shared_metaspace_range(void* base, void *static_top, void* top) {
1082   assert(base <= static_top && static_top <= top, "must be");
1083   _shared_metaspace_static_top = static_top;
1084   MetaspaceObj::set_shared_metaspace_range(base, top);
1085 }
1086 
1087 bool MetaspaceShared::is_shared_dynamic(void* p) {
1088   if ((p < MetaspaceObj::shared_metaspace_top()) &&
1089       (p >= _shared_metaspace_static_top)) {
1090     return true;
1091   } else {
1092     return false;
1093   }
< prev index next >