# HG changeset patch # User sjohanss # Date 1542967027 -3600 # Fri Nov 23 10:57:07 2018 +0100 # Node ID 8bde95b1f6791b37346c0076bdcbf9088de9f17b # Parent b3483fbaf2360c8a9fae598ac9f1a2d955f4e916 8214118: HeapRegions marked as archive even if CDS mapping fails Reviewed-by: tschatzl, jiangli diff --git a/src/hotspot/share/gc/g1/g1Allocator.hpp b/src/hotspot/share/gc/g1/g1Allocator.hpp --- a/src/hotspot/share/gc/g1/g1Allocator.hpp +++ b/src/hotspot/share/gc/g1/g1Allocator.hpp @@ -262,8 +262,9 @@ // Create the _archive_region_map which is used to identify archive objects. 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 clear_range_archive(MemRegion range, bool open); // Check if the object is in closed archive static inline bool is_closed_archive_object(oop object); diff --git a/src/hotspot/share/gc/g1/g1Allocator.inline.hpp b/src/hotspot/share/gc/g1/g1Allocator.inline.hpp --- a/src/hotspot/share/gc/g1/g1Allocator.inline.hpp +++ b/src/hotspot/share/gc/g1/g1Allocator.inline.hpp @@ -109,6 +109,10 @@ // Set the regions containing the specified address range as archive. inline void G1ArchiveAllocator::set_range_archive(MemRegion range, bool open) { 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) { _open_archive_region_map.set_by_address(range, true); } else { @@ -116,6 +120,20 @@ } } +// 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. inline bool G1ArchiveAllocator::in_closed_archive_range(oop object) { // This is the out-of-line part of is_closed_archive_object test, done separately diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -752,7 +752,7 @@ 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(ranges != NULL, "MemRegion array NULL"); assert(count != 0, "No MemRegions provided"); @@ -814,7 +814,7 @@ } // 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) { diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -697,7 +697,7 @@ // 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 // 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); diff --git a/src/hotspot/share/memory/filemap.cpp b/src/hotspot/share/memory/filemap.cpp --- a/src/hotspot/share/memory/filemap.cpp +++ b/src/hotspot/share/memory/filemap.cpp @@ -974,7 +974,7 @@ si->_allow_exec); if (base == NULL || base != addr) { // 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."); return false; } @@ -982,7 +982,7 @@ if (!verify_mapped_heap_regions(first, region_num)) { // 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"); return false; } @@ -1020,10 +1020,10 @@ } // 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) { 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 @@ -1258,8 +1258,11 @@ // 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. map_info->dealloc_archive_heap_regions(open_archive_heap_ranges, - num_open_archive_heap_ranges); - map_info->dealloc_archive_heap_regions(string_ranges, num_string_ranges); + num_open_archive_heap_ranges, + true); + map_info->dealloc_archive_heap_regions(string_ranges, + num_string_ranges, + false); } else if (DumpSharedSpaces) { fail_stop("%s", msg); } diff --git a/src/hotspot/share/memory/filemap.hpp b/src/hotspot/share/memory/filemap.hpp --- a/src/hotspot/share/memory/filemap.hpp +++ b/src/hotspot/share/memory/filemap.hpp @@ -328,7 +328,7 @@ bool map_heap_data(MemRegion **heap_mem, int first, int max, int* num, 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); - 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; }; #endif // SHARE_VM_MEMORY_FILEMAP_HPP