897 // Map the shared string objects and open archive heap objects to the runtime 898 // java heap. 899 // 900 // The shared strings are mapped close to the end of the java heap top in 901 // closed archive regions. The mapped strings contain no out-going references 902 // to any other java heap regions. GC does not write into the mapped shared strings. 903 // 904 // The open archive heap objects are mapped below the shared strings in 905 // the runtime java heap. The mapped open archive heap data only contain 906 // references to the shared strings and open archive objects initially. 907 // During runtime execution, out-going references to any other java heap 908 // regions may be added. GC may mark and update references in the mapped 909 // open archive objects. 910 void FileMapInfo::map_heap_regions_impl() { 911 if (!HeapShared::is_heap_object_archiving_allowed()) { 912 log_info(cds)("CDS heap data is being ignored. UseG1GC, " 913 "UseCompressedOops and UseCompressedClassPointers are required."); 914 return; 915 } 916 917 MemRegion heap_reserved = Universe::heap()->reserved_region(); 918 919 log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:", 920 max_heap_size()/M); 921 log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", 922 p2i(narrow_klass_base()), narrow_klass_shift()); 923 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", 924 narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift()); 925 926 log_info(cds)("The current max heap size = " SIZE_FORMAT "M, HeapRegion::GrainBytes = " SIZE_FORMAT, 927 heap_reserved.byte_size()/M, HeapRegion::GrainBytes); 928 log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", 929 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); 930 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", 931 Universe::narrow_oop_mode(), p2i(Universe::narrow_oop_base()), Universe::narrow_oop_shift()); 932 933 if (narrow_klass_base() != Universe::narrow_klass_base() || 934 narrow_klass_shift() != Universe::narrow_klass_shift()) { 935 log_info(cds)("CDS heap data cannot be used because the archive was created with an incompatible narrow klass encoding mode."); 936 return; 1206 1207 FileMapInfo* FileMapInfo::_current_info = NULL; 1208 bool FileMapInfo::_heap_pointers_need_patching = false; 1209 Array<u8>* FileMapInfo::_shared_path_table = NULL; 1210 int FileMapInfo::_shared_path_table_size = 0; 1211 size_t FileMapInfo::_shared_path_entry_size = 0x1234baad; 1212 bool FileMapInfo::_validating_shared_path_table = false; 1213 1214 // Open the shared archive file, read and validate the header 1215 // information (version, boot classpath, etc.). If initialization 1216 // fails, shared spaces are disabled and the file is closed. [See 1217 // fail_continue.] 1218 // 1219 // Validation of the archive is done in two steps: 1220 // 1221 // [1] validate_header() - done here. This checks the header, including _paths_misc_info. 1222 // [2] validate_shared_path_table - this is done later, because the table is in the RW 1223 // region of the archive, which is not mapped yet. 1224 bool FileMapInfo::initialize() { 1225 assert(UseSharedSpaces, "UseSharedSpaces expected."); 1226 1227 if (!open_for_read()) { 1228 return false; 1229 } 1230 1231 init_from_file(_fd); 1232 if (!validate_header()) { 1233 return false; 1234 } 1235 return true; 1236 } 1237 1238 char* FileMapInfo::region_addr(int idx) { 1239 CDSFileMapRegion* si = space_at(idx); 1240 if (MetaspaceShared::is_heap_region(idx)) { 1241 assert(DumpSharedSpaces, "The following doesn't work at runtime"); 1242 return si->_used > 0 ? 1243 (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL; 1244 } else { 1245 return si->_addr._base; | 897 // Map the shared string objects and open archive heap objects to the runtime 898 // java heap. 899 // 900 // The shared strings are mapped close to the end of the java heap top in 901 // closed archive regions. The mapped strings contain no out-going references 902 // to any other java heap regions. GC does not write into the mapped shared strings. 903 // 904 // The open archive heap objects are mapped below the shared strings in 905 // the runtime java heap. The mapped open archive heap data only contain 906 // references to the shared strings and open archive objects initially. 907 // During runtime execution, out-going references to any other java heap 908 // regions may be added. GC may mark and update references in the mapped 909 // open archive objects. 910 void FileMapInfo::map_heap_regions_impl() { 911 if (!HeapShared::is_heap_object_archiving_allowed()) { 912 log_info(cds)("CDS heap data is being ignored. UseG1GC, " 913 "UseCompressedOops and UseCompressedClassPointers are required."); 914 return; 915 } 916 917 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::early_class_hook_env()) { 918 ShouldNotReachHere(); // CDS should have been disabled. 919 // The archived objects are mapped at JVM start-up, but we don't know if 920 // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook, 921 // which would make the archived String or mirror objects invalid. Let's be safe and not 922 // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage 923 // (aka JVMTI_PHASE_PRIMORDIAL). 924 // 925 // If JvmtiExport::early_class_hook_env() is false, the classes of some objects 926 // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK 927 // because we won't install an archived object subgraph if the klass of any of the 928 // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph(). 929 } 930 931 MemRegion heap_reserved = Universe::heap()->reserved_region(); 932 933 log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:", 934 max_heap_size()/M); 935 log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", 936 p2i(narrow_klass_base()), narrow_klass_shift()); 937 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", 938 narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift()); 939 940 log_info(cds)("The current max heap size = " SIZE_FORMAT "M, HeapRegion::GrainBytes = " SIZE_FORMAT, 941 heap_reserved.byte_size()/M, HeapRegion::GrainBytes); 942 log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", 943 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); 944 log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", 945 Universe::narrow_oop_mode(), p2i(Universe::narrow_oop_base()), Universe::narrow_oop_shift()); 946 947 if (narrow_klass_base() != Universe::narrow_klass_base() || 948 narrow_klass_shift() != Universe::narrow_klass_shift()) { 949 log_info(cds)("CDS heap data cannot be used because the archive was created with an incompatible narrow klass encoding mode."); 950 return; 1220 1221 FileMapInfo* FileMapInfo::_current_info = NULL; 1222 bool FileMapInfo::_heap_pointers_need_patching = false; 1223 Array<u8>* FileMapInfo::_shared_path_table = NULL; 1224 int FileMapInfo::_shared_path_table_size = 0; 1225 size_t FileMapInfo::_shared_path_entry_size = 0x1234baad; 1226 bool FileMapInfo::_validating_shared_path_table = false; 1227 1228 // Open the shared archive file, read and validate the header 1229 // information (version, boot classpath, etc.). If initialization 1230 // fails, shared spaces are disabled and the file is closed. [See 1231 // fail_continue.] 1232 // 1233 // Validation of the archive is done in two steps: 1234 // 1235 // [1] validate_header() - done here. This checks the header, including _paths_misc_info. 1236 // [2] validate_shared_path_table - this is done later, because the table is in the RW 1237 // region of the archive, which is not mapped yet. 1238 bool FileMapInfo::initialize() { 1239 assert(UseSharedSpaces, "UseSharedSpaces expected."); 1240 1241 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::early_class_hook_env()) { 1242 // CDS assumes that no classes resolved in SystemDictionary::resolve_well_known_classes 1243 // are replaced at runtime by JVMTI ClassFileLoadHook. All of those classes are resolved 1244 // during the JVMTI "early" stage (JVMTI_PHASE_PRIMORDIAL), so we're OK if 1245 // JvmtiExport::early_class_hook_env() is not requested by native agent(s). 1246 FileMapInfo::fail_continue("CDS is disabled because early JVMTI ClassFileLoadHook is in use."); 1247 return false; 1248 } 1249 1250 if (!open_for_read()) { 1251 return false; 1252 } 1253 1254 init_from_file(_fd); 1255 if (!validate_header()) { 1256 return false; 1257 } 1258 return true; 1259 } 1260 1261 char* FileMapInfo::region_addr(int idx) { 1262 CDSFileMapRegion* si = space_at(idx); 1263 if (MetaspaceShared::is_heap_region(idx)) { 1264 assert(DumpSharedSpaces, "The following doesn't work at runtime"); 1265 return si->_used > 0 ? 1266 (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL; 1267 } else { 1268 return si->_addr._base; |