8214118: HeapRegions marked as archive even if CDS mapping fails

Reviewed-by: tschatzl, jiangli
This commit is contained in:
Stefan Johansson 2018-11-23 10:57:07 +01:00
parent 751aa57f16
commit bde8307cf9
6 changed files with 32 additions and 11 deletions

View file

@ -262,8 +262,9 @@ public:
// Create the _archive_region_map which is used to identify archive objects. // Create the _archive_region_map which is used to identify archive objects.
static inline void enable_archive_object_check(); static inline void enable_archive_object_check();
// Set the regions containing the specified address range as archive/non-archive. // Mark regions containing the specified address range as archive/non-archive.
static inline void set_range_archive(MemRegion range, bool open); static inline void set_range_archive(MemRegion range, bool open);
static inline void clear_range_archive(MemRegion range, bool open);
// Check if the object is in closed archive // Check if the object is in closed archive
static inline bool is_closed_archive_object(oop object); static inline bool is_closed_archive_object(oop object);

View file

@ -109,6 +109,10 @@ inline void G1ArchiveAllocator::enable_archive_object_check() {
// Set the regions containing the specified address range as archive. // Set the regions containing the specified address range as archive.
inline void G1ArchiveAllocator::set_range_archive(MemRegion range, bool open) { inline void G1ArchiveAllocator::set_range_archive(MemRegion range, bool open) {
assert(_archive_check_enabled, "archive range check not enabled"); assert(_archive_check_enabled, "archive range check not enabled");
log_info(gc, cds)("Mark %s archive regions in map: [" PTR_FORMAT ", " PTR_FORMAT "]",
open ? "open" : "closed",
p2i(range.start()),
p2i(range.last()));
if (open) { if (open) {
_open_archive_region_map.set_by_address(range, true); _open_archive_region_map.set_by_address(range, true);
} else { } else {
@ -116,6 +120,20 @@ inline void G1ArchiveAllocator::set_range_archive(MemRegion range, bool open) {
} }
} }
// Clear the archive regions map containing the specified address range.
inline void G1ArchiveAllocator::clear_range_archive(MemRegion range, bool open) {
assert(_archive_check_enabled, "archive range check not enabled");
log_info(gc, cds)("Clear %s archive regions in map: [" PTR_FORMAT ", " PTR_FORMAT "]",
open ? "open" : "closed",
p2i(range.start()),
p2i(range.last()));
if (open) {
_open_archive_region_map.set_by_address(range, false);
} else {
_closed_archive_region_map.set_by_address(range, false);
}
}
// Check if an object is in a closed archive region using the _archive_region_map. // Check if an object is in a closed archive region using the _archive_region_map.
inline bool G1ArchiveAllocator::in_closed_archive_range(oop object) { inline bool G1ArchiveAllocator::in_closed_archive_range(oop object) {
// This is the out-of-line part of is_closed_archive_object test, done separately // This is the out-of-line part of is_closed_archive_object test, done separately

View file

@ -753,7 +753,7 @@ inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
return result; return result;
} }
void G1CollectedHeap::dealloc_archive_regions(MemRegion* ranges, size_t count) { void G1CollectedHeap::dealloc_archive_regions(MemRegion* ranges, size_t count, bool is_open) {
assert(!is_init_completed(), "Expect to be called at JVM init time"); assert(!is_init_completed(), "Expect to be called at JVM init time");
assert(ranges != NULL, "MemRegion array NULL"); assert(ranges != NULL, "MemRegion array NULL");
assert(count != 0, "No MemRegions provided"); assert(count != 0, "No MemRegions provided");
@ -815,7 +815,7 @@ void G1CollectedHeap::dealloc_archive_regions(MemRegion* ranges, size_t count) {
} }
// Notify mark-sweep that this is no longer an archive range. // Notify mark-sweep that this is no longer an archive range.
G1ArchiveAllocator::set_range_archive(ranges[i], false); G1ArchiveAllocator::clear_range_archive(ranges[i], is_open);
} }
if (uncommitted_regions != 0) { if (uncommitted_regions != 0) {

View file

@ -683,7 +683,7 @@ public:
// which had been allocated by alloc_archive_regions. This should be called // which had been allocated by alloc_archive_regions. This should be called
// rather than fill_archive_regions at JVM init time if the archive file // rather than fill_archive_regions at JVM init time if the archive file
// mapping failed, with the same non-overlapping and sorted MemRegion array. // mapping failed, with the same non-overlapping and sorted MemRegion array.
void dealloc_archive_regions(MemRegion* range, size_t count); void dealloc_archive_regions(MemRegion* range, size_t count, bool is_open);
oop materialize_archived_object(oop obj); oop materialize_archived_object(oop obj);

View file

@ -1096,7 +1096,7 @@ bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
si->_allow_exec); si->_allow_exec);
if (base == NULL || base != addr) { if (base == NULL || base != addr) {
// dealloc the regions from java heap // dealloc the regions from java heap
dealloc_archive_heap_regions(regions, region_num); dealloc_archive_heap_regions(regions, region_num, is_open_archive);
log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. " log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes", INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
p2i(addr), regions[i].byte_size()); p2i(addr), regions[i].byte_size());
@ -1106,7 +1106,7 @@ bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
if (!verify_mapped_heap_regions(first, region_num)) { if (!verify_mapped_heap_regions(first, region_num)) {
// dealloc the regions from java heap // dealloc the regions from java heap
dealloc_archive_heap_regions(regions, region_num); dealloc_archive_heap_regions(regions, region_num, is_open_archive);
log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt"); log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
return false; return false;
} }
@ -1171,10 +1171,10 @@ void FileMapInfo::fixup_mapped_heap_regions() {
} }
// dealloc the archive regions from java heap // dealloc the archive regions from java heap
void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num) { void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) {
if (num > 0) { if (num > 0) {
assert(regions != NULL, "Null archive ranges array with non-zero count"); assert(regions != NULL, "Null archive ranges array with non-zero count");
G1CollectedHeap::heap()->dealloc_archive_regions(regions, num); G1CollectedHeap::heap()->dealloc_archive_regions(regions, num, is_open);
} }
} }
#endif // INCLUDE_CDS_JAVA_HEAP #endif // INCLUDE_CDS_JAVA_HEAP
@ -1428,9 +1428,11 @@ void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
// Dealloc the archive heap regions only without unmapping. The regions are part // Dealloc the archive heap regions only without unmapping. The regions are part
// of the java heap. Unmapping of the heap regions are managed by GC. // of the java heap. Unmapping of the heap regions are managed by GC.
map_info->dealloc_archive_heap_regions(open_archive_heap_ranges, map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
num_open_archive_heap_ranges); num_open_archive_heap_ranges,
true);
map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges, map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
num_closed_archive_heap_ranges); num_closed_archive_heap_ranges,
false);
} else if (DumpSharedSpaces) { } else if (DumpSharedSpaces) {
fail_stop("%s", msg); fail_stop("%s", msg);
} }

View file

@ -327,7 +327,7 @@ public:
bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num, bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num,
bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false); bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false);
bool verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false); bool verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false);
void dealloc_archive_heap_regions(MemRegion* regions, int num) NOT_CDS_JAVA_HEAP_RETURN; void dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN;
CDSFileMapRegion* space_at(int i) { CDSFileMapRegion* space_at(int i) {
return _header->space_at(i); return _header->space_at(i);