< prev index next >

src/hotspot/share/cds/metaspaceShared.cpp

Print this page

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


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

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

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





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

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

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

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