changeset 52697:c9325aa887da

8214118: HeapRegions marked as archive even if CDS mapping fails Reviewed-by: tschatzl, jiangli
author sjohanss
date Fri, 23 Nov 2018 10:57:07 +0100
parents 61b3b58a1d1d
children 7d3cde494494
files src/hotspot/share/gc/g1/g1Allocator.hpp src/hotspot/share/gc/g1/g1Allocator.inline.hpp src/hotspot/share/gc/g1/g1CollectedHeap.cpp src/hotspot/share/gc/g1/g1CollectedHeap.hpp src/hotspot/share/memory/filemap.cpp src/hotspot/share/memory/filemap.hpp
diffstat 6 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/g1/g1Allocator.hpp	Fri Nov 23 11:07:54 2018 +0100
+++ b/src/hotspot/share/gc/g1/g1Allocator.hpp	Fri Nov 23 10:57:07 2018 +0100
@@ -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);
--- a/src/hotspot/share/gc/g1/g1Allocator.inline.hpp	Fri Nov 23 11:07:54 2018 +0100
+++ b/src/hotspot/share/gc/g1/g1Allocator.inline.hpp	Fri Nov 23 10:57:07 2018 +0100
@@ -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
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Fri Nov 23 11:07:54 2018 +0100
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Fri Nov 23 10:57:07 2018 +0100
@@ -753,7 +753,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");
@@ -815,7 +815,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) {
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Fri Nov 23 11:07:54 2018 +0100
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Fri Nov 23 10:57:07 2018 +0100
@@ -683,7 +683,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);
 
--- a/src/hotspot/share/memory/filemap.cpp	Fri Nov 23 11:07:54 2018 +0100
+++ b/src/hotspot/share/memory/filemap.cpp	Fri Nov 23 10:57:07 2018 +0100
@@ -1096,7 +1096,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. "
                     INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
                     p2i(addr), regions[i].byte_size());
@@ -1106,7 +1106,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;
   }
@@ -1171,10 +1171,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
@@ -1428,9 +1428,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);
+                                           num_open_archive_heap_ranges,
+                                           true);
     map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
-                                           num_closed_archive_heap_ranges);
+                                           num_closed_archive_heap_ranges,
+                                           false);
   } else if (DumpSharedSpaces) {
     fail_stop("%s", msg);
   }
--- a/src/hotspot/share/memory/filemap.hpp	Fri Nov 23 11:07:54 2018 +0100
+++ b/src/hotspot/share/memory/filemap.hpp	Fri Nov 23 10:57:07 2018 +0100
@@ -327,7 +327,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;
 
   CDSFileMapRegion* space_at(int i) {
     return _header->space_at(i);