changeset 51578:31b159f30fb2 jdk-12+9

8180193: Make marking bitmap code available to other GCs Reviewed-by: shade, stefank
author rkennke
date Wed, 29 Aug 2018 20:15:09 +0200
parents 64331e014bc7
children d7fc38d3fc8d
files src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.cpp src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.hpp src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.inline.hpp src/hotspot/share/gc/shared/markBitMap.cpp src/hotspot/share/gc/shared/markBitMap.hpp src/hotspot/share/gc/shared/markBitMap.inline.hpp
diffstat 6 files changed, 247 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.cpp	Wed Aug 29 19:48:28 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.cpp	Wed Aug 29 20:15:09 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,23 +28,8 @@
 #include "gc/g1/heapRegion.hpp"
 #include "memory/virtualspace.hpp"
 
-void G1CMBitMap::print_on_error(outputStream* st, const char* prefix) const {
-  _bm.print_on_error(st, prefix);
-}
-
-size_t G1CMBitMap::compute_size(size_t heap_size) {
-  return ReservedSpace::allocation_align_size_up(heap_size / mark_distance());
-}
-
-size_t G1CMBitMap::mark_distance() {
-  return MinObjAlignmentInBytes * BitsPerByte;
-}
-
 void G1CMBitMap::initialize(MemRegion heap, G1RegionToSpaceMapper* storage) {
-  _covered = heap;
-
-  _bm = BitMapView((BitMap::bm_word_t*) storage->reserved().start(), _covered.word_size() >> _shifter);
-
+  MarkBitMap::initialize(heap, storage->reserved());
   storage->set_mapping_changed_listener(&_listener);
 }
 
@@ -57,19 +42,17 @@
   _bm->clear_range(mr);
 }
 
-void G1CMBitMap::clear_range(MemRegion mr) {
-  MemRegion intersection = mr.intersection(_covered);
-  assert(!intersection.is_empty(),
-         "Given range from " PTR_FORMAT " to " PTR_FORMAT " is completely outside the heap",
-         p2i(mr.start()), p2i(mr.end()));
-  // convert address range into offset range
-  _bm.at_put_range(addr_to_offset(intersection.start()),
-                   addr_to_offset(intersection.end()), false);
-}
-
 void G1CMBitMap::clear_region(HeapRegion* region) {
  if (!region->is_empty()) {
    MemRegion mr(region->bottom(), region->top());
    clear_range(mr);
  }
 }
+
+#ifdef ASSERT
+void G1CMBitMap::check_mark(HeapWord* addr) {
+  assert(G1CollectedHeap::heap()->is_in_exact(addr),
+         "Trying to access bitmap " PTR_FORMAT " for address " PTR_FORMAT " not in the heap.",
+         p2i(this), p2i(addr));
+}
+#endif
--- a/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.hpp	Wed Aug 29 19:48:28 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.hpp	Wed Aug 29 20:15:09 2018 +0200
@@ -26,6 +26,7 @@
 #define SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP
 
 #include "gc/g1/g1RegionToSpaceMapper.hpp"
+#include "gc/shared/markBitMap.hpp"
 #include "memory/memRegion.hpp"
 #include "oops/oopsHierarchy.hpp"
 #include "utilities/bitMap.hpp"
@@ -59,68 +60,24 @@
 
 // A generic mark bitmap for concurrent marking.  This is essentially a wrapper
 // around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords.
-class G1CMBitMap {
-  MemRegion _covered;    // The heap area covered by this bitmap.
-
-  const int _shifter;    // Shift amount from heap index to bit index in the bitmap.
-
-  BitMapView _bm;        // The actual bitmap.
+class G1CMBitMap : public MarkBitMap {
 
   G1CMBitMapMappingChangedListener _listener;
 
-  inline void check_mark(HeapWord* addr) NOT_DEBUG_RETURN;
+protected:
 
-  // Convert from bit offset to address.
-  HeapWord* offset_to_addr(size_t offset) const {
-    return _covered.start() + (offset << _shifter);
-  }
-  // Convert from address to bit offset.
-  size_t addr_to_offset(const HeapWord* addr) const {
-    return pointer_delta(addr, _covered.start()) >> _shifter;
-  }
+  virtual void check_mark(HeapWord* addr) NOT_DEBUG_RETURN;
+
 public:
-  static size_t compute_size(size_t heap_size);
-  // Returns the amount of bytes on the heap between two marks in the bitmap.
-  static size_t mark_distance();
-  // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
-  // mark bitmap corresponds to. This is the same as the mark distance above.
-  static size_t heap_map_factor() {
-    return mark_distance();
-  }
 
-  G1CMBitMap() : _covered(), _shifter(LogMinObjAlignment), _bm(), _listener() { _listener.set_bitmap(this); }
+  G1CMBitMap() : MarkBitMap(), _listener() { _listener.set_bitmap(this); }
 
   // Initializes the underlying BitMap to cover the given area.
   void initialize(MemRegion heap, G1RegionToSpaceMapper* storage);
 
-  // Read marks
-  bool is_marked(oop obj) const;
-  bool is_marked(HeapWord* addr) const {
-    assert(_covered.contains(addr),
-           "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT,
-           p2i(addr), p2i(_covered.start()), p2i(_covered.end()));
-    return _bm.at(addr_to_offset(addr));
-  }
-
   // Apply the closure to the addresses that correspond to marked bits in the bitmap.
   inline bool iterate(G1CMBitMapClosure* cl, MemRegion mr);
 
-  // Return the address corresponding to the next marked bit at or after
-  // "addr", and before "limit", if "limit" is non-NULL.  If there is no
-  // such bit, returns "limit" if that is non-NULL, or else "endWord()".
-  inline HeapWord* get_next_marked_addr(const HeapWord* addr,
-                                        const HeapWord* limit) const;
-
-  void print_on_error(outputStream* st, const char* prefix) const;
-
-  // Write marks.
-  inline void mark(HeapWord* addr);
-  inline void clear(HeapWord* addr);
-  inline void clear(oop obj);
-  inline bool par_mark(HeapWord* addr);
-  inline bool par_mark(oop obj);
-
-  void clear_range(MemRegion mr);
   void clear_region(HeapRegion* hr);
 };
 
--- a/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.inline.hpp	Wed Aug 29 19:48:28 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.inline.hpp	Wed Aug 29 20:15:09 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 #define SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_INLINE_HPP
 
 #include "gc/g1/g1ConcurrentMarkBitMap.hpp"
+#include "gc/shared/markBitMap.inline.hpp"
 #include "memory/memRegion.hpp"
 #include "utilities/align.hpp"
 #include "utilities/bitMap.inline.hpp"
@@ -50,49 +51,4 @@
   return true;
 }
 
-inline HeapWord* G1CMBitMap::get_next_marked_addr(const HeapWord* addr,
-                                                  const HeapWord* limit) const {
-  assert(limit != NULL, "limit must not be NULL");
-  // Round addr up to a possible object boundary to be safe.
-  size_t const addr_offset = addr_to_offset(align_up(addr, HeapWordSize << _shifter));
-  size_t const limit_offset = addr_to_offset(limit);
-  size_t const nextOffset = _bm.get_next_one_offset(addr_offset, limit_offset);
-  return offset_to_addr(nextOffset);
-}
-
-#ifdef ASSERT
-inline void G1CMBitMap::check_mark(HeapWord* addr) {
-  assert(G1CollectedHeap::heap()->is_in_exact(addr),
-         "Trying to access bitmap " PTR_FORMAT " for address " PTR_FORMAT " not in the heap.",
-         p2i(this), p2i(addr));
-}
-#endif
-
-inline void G1CMBitMap::mark(HeapWord* addr) {
-  check_mark(addr);
-  _bm.set_bit(addr_to_offset(addr));
-}
-
-inline void G1CMBitMap::clear(HeapWord* addr) {
-  check_mark(addr);
-  _bm.clear_bit(addr_to_offset(addr));
-}
-
-inline bool G1CMBitMap::par_mark(HeapWord* addr) {
-  check_mark(addr);
-  return _bm.par_set_bit(addr_to_offset(addr));
-}
-
-inline bool G1CMBitMap::par_mark(oop obj) {
-  return par_mark((HeapWord*) obj);
-}
-
-inline bool G1CMBitMap::is_marked(oop obj) const{
-  return is_marked((HeapWord*) obj);
-}
-
-inline void G1CMBitMap::clear(oop obj) {
-  clear((HeapWord*) obj);
-}
-
 #endif // SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_INLINE_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/markBitMap.cpp	Wed Aug 29 20:15:09 2018 +0200
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "gc/shared/markBitMap.inline.hpp"
+#include "memory/virtualspace.hpp"
+
+void MarkBitMap::print_on_error(outputStream* st, const char* prefix) const {
+  _bm.print_on_error(st, prefix);
+}
+
+size_t MarkBitMap::compute_size(size_t heap_size) {
+  return ReservedSpace::allocation_align_size_up(heap_size / mark_distance());
+}
+
+size_t MarkBitMap::mark_distance() {
+  return MinObjAlignmentInBytes * BitsPerByte;
+}
+
+void MarkBitMap::initialize(MemRegion heap, MemRegion storage) {
+  _covered = heap;
+
+  _bm = BitMapView((BitMap::bm_word_t*) storage.start(), _covered.word_size() >> _shifter);
+}
+
+void MarkBitMap::clear_range(MemRegion mr) {
+  MemRegion intersection = mr.intersection(_covered);
+  assert(!intersection.is_empty(),
+         "Given range from " PTR_FORMAT " to " PTR_FORMAT " is completely outside the heap",
+         p2i(mr.start()), p2i(mr.end()));
+  // convert address range into offset range
+  _bm.at_put_range(addr_to_offset(intersection.start()),
+                   addr_to_offset(intersection.end()), false);
+}
+
+#ifdef ASSERT
+void MarkBitMap::check_mark(HeapWord* addr) {
+  assert(Universe::heap()->is_in_reserved(addr),
+         "Trying to access bitmap " PTR_FORMAT " for address " PTR_FORMAT " not in the heap.",
+         p2i(this), p2i(addr));
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/markBitMap.hpp	Wed Aug 29 20:15:09 2018 +0200
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_GC_SHARED_MARKBITMAP_HPP
+#define SHARE_VM_GC_SHARED_MARKBITMAP_HPP
+
+#include "memory/memRegion.hpp"
+#include "oops/oopsHierarchy.hpp"
+#include "utilities/bitMap.hpp"
+
+// A generic mark bitmap for concurrent marking.  This is essentially a wrapper
+// around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords.
+class MarkBitMap {
+protected:
+  MemRegion _covered;    // The heap area covered by this bitmap.
+
+  const int _shifter;    // Shift amount from heap index to bit index in the bitmap.
+
+  BitMapView _bm;        // The actual bitmap.
+
+  virtual void check_mark(HeapWord* addr) NOT_DEBUG_RETURN;
+
+  // Convert from bit offset to address.
+  HeapWord* offset_to_addr(size_t offset) const {
+    return _covered.start() + (offset << _shifter);
+  }
+  // Convert from address to bit offset.
+  size_t addr_to_offset(const HeapWord* addr) const {
+    return pointer_delta(addr, _covered.start()) >> _shifter;
+  }
+public:
+  static size_t compute_size(size_t heap_size);
+  // Returns the amount of bytes on the heap between two marks in the bitmap.
+  static size_t mark_distance();
+  // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
+  // mark bitmap corresponds to. This is the same as the mark distance above.
+  static size_t heap_map_factor() {
+    return mark_distance();
+  }
+
+  MarkBitMap() : _covered(), _shifter(LogMinObjAlignment), _bm() {}
+
+  // Initializes the underlying BitMap to cover the given area.
+  void initialize(MemRegion heap, MemRegion storage);
+
+  // Read marks
+  bool is_marked(oop obj) const;
+  bool is_marked(HeapWord* addr) const {
+    assert(_covered.contains(addr),
+           "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT,
+           p2i(addr), p2i(_covered.start()), p2i(_covered.end()));
+    return _bm.at(addr_to_offset(addr));
+  }
+
+  // Return the address corresponding to the next marked bit at or after
+  // "addr", and before "limit", if "limit" is non-NULL.  If there is no
+  // such bit, returns "limit" if that is non-NULL, or else "endWord()".
+  inline HeapWord* get_next_marked_addr(const HeapWord* addr,
+                                        const HeapWord* limit) const;
+
+  void print_on_error(outputStream* st, const char* prefix) const;
+
+  // Write marks.
+  inline void mark(HeapWord* addr);
+  inline void clear(HeapWord* addr);
+  inline void clear(oop obj);
+  inline bool par_mark(HeapWord* addr);
+  inline bool par_mark(oop obj);
+
+  void clear_range(MemRegion mr);
+};
+
+#endif // SHARE_VM_GC_SHARED_MARKBITMAP_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/markBitMap.inline.hpp	Wed Aug 29 20:15:09 2018 +0200
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_GC_SHARED_MARKBITMAP_INLINE_HPP
+#define SHARE_VM_GC_SHARED_MARKBITMAP_INLINE_HPP
+
+#include "gc/shared/collectedHeap.hpp"
+#include "gc/shared/markBitMap.hpp"
+#include "memory/memRegion.hpp"
+#include "memory/universe.hpp"
+#include "utilities/align.hpp"
+#include "utilities/bitMap.inline.hpp"
+
+inline HeapWord* MarkBitMap::get_next_marked_addr(const HeapWord* addr,
+                                                const HeapWord* limit) const {
+  assert(limit != NULL, "limit must not be NULL");
+  // Round addr up to a possible object boundary to be safe.
+  size_t const addr_offset = addr_to_offset(align_up(addr, HeapWordSize << _shifter));
+  size_t const limit_offset = addr_to_offset(limit);
+  size_t const nextOffset = _bm.get_next_one_offset(addr_offset, limit_offset);
+  return offset_to_addr(nextOffset);
+}
+
+inline void MarkBitMap::mark(HeapWord* addr) {
+  check_mark(addr);
+  _bm.set_bit(addr_to_offset(addr));
+}
+
+inline void MarkBitMap::clear(HeapWord* addr) {
+  check_mark(addr);
+  _bm.clear_bit(addr_to_offset(addr));
+}
+
+inline bool MarkBitMap::par_mark(HeapWord* addr) {
+  check_mark(addr);
+  return _bm.par_set_bit(addr_to_offset(addr));
+}
+
+inline bool MarkBitMap::par_mark(oop obj) {
+  return par_mark((HeapWord*) obj);
+}
+
+inline bool MarkBitMap::is_marked(oop obj) const{
+  return is_marked((HeapWord*) obj);
+}
+
+inline void MarkBitMap::clear(oop obj) {
+  clear((HeapWord*) obj);
+}
+
+#endif // SHARE_VM_GC_SHARED_MARKBITMAP_INLINE_HPP