957
958 // allocate from java heap
959 if (!G1CollectedHeap::heap()->alloc_archive_regions(
960 regions, region_num, is_open_archive)) {
961 log_info(cds)("UseSharedSpaces: Unable to allocate region, "
962 "java heap range is already in use.");
963 return false;
964 }
965
966 // Map the archived heap data. No need to call MemTracker::record_virtual_memory_type()
967 // for mapped regions as they are part of the reserved java heap, which is
968 // already recorded.
969 for (int i = 0; i < region_num; i++) {
970 si = &_header->_space[first + i];
971 char* addr = (char*)regions[i].start();
972 char* base = os::map_memory(_fd, _full_path, si->_file_offset,
973 addr, regions[i].byte_size(), si->_read_only,
974 si->_allow_exec);
975 if (base == NULL || base != addr) {
976 // dealloc the regions from java heap
977 dealloc_archive_heap_regions(regions, region_num);
978 log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap.");
979 return false;
980 }
981 }
982
983 if (!verify_mapped_heap_regions(first, region_num)) {
984 // dealloc the regions from java heap
985 dealloc_archive_heap_regions(regions, region_num);
986 log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
987 return false;
988 }
989
990 // the shared heap data is mapped successfully
991 *heap_mem = regions;
992 *num = region_num;
993 return true;
994 }
995
996 bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
997 assert(num > 0, "sanity");
998 for (int i = first; i < first + num; i++) {
999 if (!verify_region_checksum(i)) {
1000 return false;
1001 }
1002 }
1003 return true;
1004 }
1005
1006 void FileMapInfo::fixup_mapped_heap_regions() {
1007 // If any string regions were found, call the fill routine to make them parseable.
1008 // Note that string_ranges may be non-NULL even if no ranges were found.
1009 if (num_string_ranges != 0) {
1010 assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
1011 G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_string_ranges);
1012 }
1013
1014 // do the same for mapped open archive heap regions
1015 if (num_open_archive_heap_ranges != 0) {
1016 assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
1017 G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges,
1018 num_open_archive_heap_ranges);
1019 }
1020 }
1021
1022 // dealloc the archive regions from java heap
1023 void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num) {
1024 if (num > 0) {
1025 assert(regions != NULL, "Null archive ranges array with non-zero count");
1026 G1CollectedHeap::heap()->dealloc_archive_regions(regions, num);
1027 }
1028 }
1029 #endif // INCLUDE_CDS_JAVA_HEAP
1030
1031 bool FileMapInfo::verify_region_checksum(int i) {
1032 assert(i >= 0 && i < MetaspaceShared::n_regions, "invalid region");
1033 if (!VerifySharedSpaces) {
1034 return true;
1035 }
1036
1037 size_t sz = _header->_space[i]._used;
1038
1039 if (sz == 0) {
1040 return true; // no data
1041 }
1042 if ((MetaspaceShared::is_string_region(i) &&
1043 !StringTable::shared_string_mapped()) ||
1044 (MetaspaceShared::is_open_archive_heap_region(i) &&
1045 !MetaspaceShared::open_archive_heap_region_mapped())) {
1046 return true; // archived heap data is not mapped
1241 shared_region_name[i],
1242 p2i(base), p2i(base + si->_used));
1243 }
1244 }
1245
1246 // Unmap mapped regions of shared space.
1247 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
1248 FileMapInfo *map_info = FileMapInfo::current_info();
1249 if (map_info) {
1250 map_info->fail_continue("%s", msg);
1251 for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
1252 char *addr = map_info->_header->region_addr(i);
1253 if (addr != NULL && !MetaspaceShared::is_heap_region(i)) {
1254 map_info->unmap_region(i);
1255 map_info->_header->_space[i]._addr._base = NULL;
1256 }
1257 }
1258 // Dealloc the archive heap regions only without unmapping. The regions are part
1259 // of the java heap. Unmapping of the heap regions are managed by GC.
1260 map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1261 num_open_archive_heap_ranges);
1262 map_info->dealloc_archive_heap_regions(string_ranges, num_string_ranges);
1263 } else if (DumpSharedSpaces) {
1264 fail_stop("%s", msg);
1265 }
1266 }
|
957
958 // allocate from java heap
959 if (!G1CollectedHeap::heap()->alloc_archive_regions(
960 regions, region_num, is_open_archive)) {
961 log_info(cds)("UseSharedSpaces: Unable to allocate region, "
962 "java heap range is already in use.");
963 return false;
964 }
965
966 // Map the archived heap data. No need to call MemTracker::record_virtual_memory_type()
967 // for mapped regions as they are part of the reserved java heap, which is
968 // already recorded.
969 for (int i = 0; i < region_num; i++) {
970 si = &_header->_space[first + i];
971 char* addr = (char*)regions[i].start();
972 char* base = os::map_memory(_fd, _full_path, si->_file_offset,
973 addr, regions[i].byte_size(), si->_read_only,
974 si->_allow_exec);
975 if (base == NULL || base != addr) {
976 // dealloc the regions from java heap
977 dealloc_archive_heap_regions(regions, region_num, is_open_archive);
978 log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap.");
979 return false;
980 }
981 }
982
983 if (!verify_mapped_heap_regions(first, region_num)) {
984 // dealloc the regions from java heap
985 dealloc_archive_heap_regions(regions, region_num, is_open_archive);
986 log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
987 return false;
988 }
989
990 // the shared heap data is mapped successfully
991 *heap_mem = regions;
992 *num = region_num;
993 return true;
994 }
995
996 bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
997 assert(num > 0, "sanity");
998 for (int i = first; i < first + num; i++) {
999 if (!verify_region_checksum(i)) {
1000 return false;
1001 }
1002 }
1003 return true;
1004 }
1005
1006 void FileMapInfo::fixup_mapped_heap_regions() {
1007 // If any string regions were found, call the fill routine to make them parseable.
1008 // Note that string_ranges may be non-NULL even if no ranges were found.
1009 if (num_string_ranges != 0) {
1010 assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
1011 G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_string_ranges);
1012 }
1013
1014 // do the same for mapped open archive heap regions
1015 if (num_open_archive_heap_ranges != 0) {
1016 assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
1017 G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges,
1018 num_open_archive_heap_ranges);
1019 }
1020 }
1021
1022 // dealloc the archive regions from java heap
1023 void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) {
1024 if (num > 0) {
1025 assert(regions != NULL, "Null archive ranges array with non-zero count");
1026 G1CollectedHeap::heap()->dealloc_archive_regions(regions, num, is_open);
1027 }
1028 }
1029 #endif // INCLUDE_CDS_JAVA_HEAP
1030
1031 bool FileMapInfo::verify_region_checksum(int i) {
1032 assert(i >= 0 && i < MetaspaceShared::n_regions, "invalid region");
1033 if (!VerifySharedSpaces) {
1034 return true;
1035 }
1036
1037 size_t sz = _header->_space[i]._used;
1038
1039 if (sz == 0) {
1040 return true; // no data
1041 }
1042 if ((MetaspaceShared::is_string_region(i) &&
1043 !StringTable::shared_string_mapped()) ||
1044 (MetaspaceShared::is_open_archive_heap_region(i) &&
1045 !MetaspaceShared::open_archive_heap_region_mapped())) {
1046 return true; // archived heap data is not mapped
1241 shared_region_name[i],
1242 p2i(base), p2i(base + si->_used));
1243 }
1244 }
1245
1246 // Unmap mapped regions of shared space.
1247 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
1248 FileMapInfo *map_info = FileMapInfo::current_info();
1249 if (map_info) {
1250 map_info->fail_continue("%s", msg);
1251 for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
1252 char *addr = map_info->_header->region_addr(i);
1253 if (addr != NULL && !MetaspaceShared::is_heap_region(i)) {
1254 map_info->unmap_region(i);
1255 map_info->_header->_space[i]._addr._base = NULL;
1256 }
1257 }
1258 // Dealloc the archive heap regions only without unmapping. The regions are part
1259 // of the java heap. Unmapping of the heap regions are managed by GC.
1260 map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1261 num_open_archive_heap_ranges,
1262 true);
1263 map_info->dealloc_archive_heap_regions(string_ranges,
1264 num_string_ranges,
1265 false);
1266 } else if (DumpSharedSpaces) {
1267 fail_stop("%s", msg);
1268 }
1269 }
|