< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page
rev 52634 : 8214118: HeapRegions marked as archive even if CDS mapping fails
Reviewed-by:


1079   }
1080 
1081   // allocate from java heap
1082   if (!G1CollectedHeap::heap()->alloc_archive_regions(
1083              regions, region_num, is_open_archive)) {
1084     log_info(cds)("UseSharedSpaces: Unable to allocate region, java heap range is already in use.");
1085     return false;
1086   }
1087 
1088   // Map the archived heap data. No need to call MemTracker::record_virtual_memory_type()
1089   // for mapped regions as they are part of the reserved java heap, which is
1090   // already recorded.
1091   for (int i = 0; i < region_num; i++) {
1092     si = space_at(first + i);
1093     char* addr = (char*)regions[i].start();
1094     char* base = os::map_memory(_fd, _full_path, si->_file_offset,
1095                                 addr, regions[i].byte_size(), si->_read_only,
1096                                 si->_allow_exec);
1097     if (base == NULL || base != addr) {
1098       // dealloc the regions from java heap
1099       dealloc_archive_heap_regions(regions, region_num);
1100       log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
1101                     INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
1102                     p2i(addr), regions[i].byte_size());
1103       return false;
1104     }
1105   }
1106 
1107   if (!verify_mapped_heap_regions(first, region_num)) {
1108     // dealloc the regions from java heap
1109     dealloc_archive_heap_regions(regions, region_num);
1110     log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
1111     return false;
1112   }
1113 
1114   // the shared heap data is mapped successfully
1115   *heap_mem = regions;
1116   *num = region_num;
1117   return true;
1118 }
1119 
1120 bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
1121   assert(num > 0, "sanity");
1122   for (int i = first; i < first + num; i++) {
1123     if (!verify_region_checksum(i)) {
1124       return false;
1125     }
1126   }
1127   return true;
1128 }
1129 


1154 // must be called after the well-known classes are resolved.
1155 void FileMapInfo::fixup_mapped_heap_regions() {
1156   // If any closed regions were found, call the fill routine to make them parseable.
1157   // Note that closed_archive_heap_ranges may be non-NULL even if no ranges were found.
1158   if (num_closed_archive_heap_ranges != 0) {
1159     assert(closed_archive_heap_ranges != NULL,
1160            "Null closed_archive_heap_ranges array with non-zero count");
1161     G1CollectedHeap::heap()->fill_archive_regions(closed_archive_heap_ranges,
1162                                                   num_closed_archive_heap_ranges);
1163   }
1164 
1165   // do the same for mapped open archive heap regions
1166   if (num_open_archive_heap_ranges != 0) {
1167     assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
1168     G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges,
1169                                                   num_open_archive_heap_ranges);
1170   }
1171 }
1172 
1173 // dealloc the archive regions from java heap
1174 void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num) {
1175   if (num > 0) {
1176     assert(regions != NULL, "Null archive ranges array with non-zero count");
1177     G1CollectedHeap::heap()->dealloc_archive_regions(regions, num);
1178   }
1179 }
1180 #endif // INCLUDE_CDS_JAVA_HEAP
1181 
1182 bool FileMapInfo::verify_region_checksum(int i) {
1183   if (!VerifySharedSpaces) {
1184     return true;
1185   }
1186 
1187   size_t sz = space_at(i)->_used;
1188 
1189   if (sz == 0) {
1190     return true; // no data
1191   }
1192   if ((HeapShared::is_closed_archive_heap_region(i) &&
1193        !HeapShared::closed_archive_heap_region_mapped()) ||
1194       (HeapShared::is_open_archive_heap_region(i) &&
1195        !HeapShared::open_archive_heap_region_mapped())) {
1196     return true; // archived heap data is not mapped
1197   }


1411 
1412 // Unmap mapped regions of shared space.
1413 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
1414   MetaspaceObj::set_shared_metaspace_range(NULL, NULL);
1415 
1416   FileMapInfo *map_info = FileMapInfo::current_info();
1417   if (map_info) {
1418     map_info->fail_continue("%s", msg);
1419     for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
1420       if (!HeapShared::is_heap_region(i)) {
1421         char *addr = map_info->region_addr(i);
1422         if (addr != NULL) {
1423           map_info->unmap_region(i);
1424           map_info->space_at(i)->_addr._base = NULL;
1425         }
1426       }
1427     }
1428     // Dealloc the archive heap regions only without unmapping. The regions are part
1429     // of the java heap. Unmapping of the heap regions are managed by GC.
1430     map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1431                                            num_open_archive_heap_ranges);

1432     map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
1433                                            num_closed_archive_heap_ranges);

1434   } else if (DumpSharedSpaces) {
1435     fail_stop("%s", msg);
1436   }
1437 }


1079   }
1080 
1081   // allocate from java heap
1082   if (!G1CollectedHeap::heap()->alloc_archive_regions(
1083              regions, region_num, is_open_archive)) {
1084     log_info(cds)("UseSharedSpaces: Unable to allocate region, java heap range is already in use.");
1085     return false;
1086   }
1087 
1088   // Map the archived heap data. No need to call MemTracker::record_virtual_memory_type()
1089   // for mapped regions as they are part of the reserved java heap, which is
1090   // already recorded.
1091   for (int i = 0; i < region_num; i++) {
1092     si = space_at(first + i);
1093     char* addr = (char*)regions[i].start();
1094     char* base = os::map_memory(_fd, _full_path, si->_file_offset,
1095                                 addr, regions[i].byte_size(), si->_read_only,
1096                                 si->_allow_exec);
1097     if (base == NULL || base != addr) {
1098       // dealloc the regions from java heap
1099       dealloc_archive_heap_regions(regions, region_num, is_open_archive);
1100       log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
1101                     INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
1102                     p2i(addr), regions[i].byte_size());
1103       return false;
1104     }
1105   }
1106 
1107   if (!verify_mapped_heap_regions(first, region_num)) {
1108     // dealloc the regions from java heap
1109     dealloc_archive_heap_regions(regions, region_num, is_open_archive);
1110     log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
1111     return false;
1112   }
1113 
1114   // the shared heap data is mapped successfully
1115   *heap_mem = regions;
1116   *num = region_num;
1117   return true;
1118 }
1119 
1120 bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
1121   assert(num > 0, "sanity");
1122   for (int i = first; i < first + num; i++) {
1123     if (!verify_region_checksum(i)) {
1124       return false;
1125     }
1126   }
1127   return true;
1128 }
1129 


1154 // must be called after the well-known classes are resolved.
1155 void FileMapInfo::fixup_mapped_heap_regions() {
1156   // If any closed regions were found, call the fill routine to make them parseable.
1157   // Note that closed_archive_heap_ranges may be non-NULL even if no ranges were found.
1158   if (num_closed_archive_heap_ranges != 0) {
1159     assert(closed_archive_heap_ranges != NULL,
1160            "Null closed_archive_heap_ranges array with non-zero count");
1161     G1CollectedHeap::heap()->fill_archive_regions(closed_archive_heap_ranges,
1162                                                   num_closed_archive_heap_ranges);
1163   }
1164 
1165   // do the same for mapped open archive heap regions
1166   if (num_open_archive_heap_ranges != 0) {
1167     assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
1168     G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges,
1169                                                   num_open_archive_heap_ranges);
1170   }
1171 }
1172 
1173 // dealloc the archive regions from java heap
1174 void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) {
1175   if (num > 0) {
1176     assert(regions != NULL, "Null archive ranges array with non-zero count");
1177     G1CollectedHeap::heap()->dealloc_archive_regions(regions, num, is_open);
1178   }
1179 }
1180 #endif // INCLUDE_CDS_JAVA_HEAP
1181 
1182 bool FileMapInfo::verify_region_checksum(int i) {
1183   if (!VerifySharedSpaces) {
1184     return true;
1185   }
1186 
1187   size_t sz = space_at(i)->_used;
1188 
1189   if (sz == 0) {
1190     return true; // no data
1191   }
1192   if ((HeapShared::is_closed_archive_heap_region(i) &&
1193        !HeapShared::closed_archive_heap_region_mapped()) ||
1194       (HeapShared::is_open_archive_heap_region(i) &&
1195        !HeapShared::open_archive_heap_region_mapped())) {
1196     return true; // archived heap data is not mapped
1197   }


1411 
1412 // Unmap mapped regions of shared space.
1413 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
1414   MetaspaceObj::set_shared_metaspace_range(NULL, NULL);
1415 
1416   FileMapInfo *map_info = FileMapInfo::current_info();
1417   if (map_info) {
1418     map_info->fail_continue("%s", msg);
1419     for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
1420       if (!HeapShared::is_heap_region(i)) {
1421         char *addr = map_info->region_addr(i);
1422         if (addr != NULL) {
1423           map_info->unmap_region(i);
1424           map_info->space_at(i)->_addr._base = NULL;
1425         }
1426       }
1427     }
1428     // Dealloc the archive heap regions only without unmapping. The regions are part
1429     // of the java heap. Unmapping of the heap regions are managed by GC.
1430     map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1431                                            num_open_archive_heap_ranges,
1432                                            true);
1433     map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
1434                                            num_closed_archive_heap_ranges,
1435                                            false);
1436   } else if (DumpSharedSpaces) {
1437     fail_stop("%s", msg);
1438   }
1439 }
< prev index next >