changeset 56364:f2bd6a3993a7

8231266: ZGC: Minor cleanups in ZCollectedHeap and ZHeap Reviewed-by: stefank, eosterlund
author pliden
date Tue, 24 Sep 2019 17:08:18 +0200
parents a8f06f2b84b0
children 872465abbfe3
files src/hotspot/share/gc/z/zCollectedHeap.cpp src/hotspot/share/gc/z/zHeap.cpp src/hotspot/share/gc/z/zHeap.hpp src/hotspot/share/gc/z/zHeap.inline.hpp
diffstat 4 files changed, 23 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/z/zCollectedHeap.cpp	Tue Sep 24 17:08:18 2019 +0200
+++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp	Tue Sep 24 17:08:18 2019 +0200
@@ -23,13 +23,13 @@
 
 #include "precompiled.hpp"
 #include "gc/shared/gcHeapSummary.hpp"
-#include "gc/shared/locationPrinter.hpp"
 #include "gc/shared/suspendibleThreadSet.hpp"
 #include "gc/z/zCollectedHeap.hpp"
 #include "gc/z/zGlobals.hpp"
 #include "gc/z/zHeap.inline.hpp"
 #include "gc/z/zNMethod.hpp"
 #include "gc/z/zObjArrayAllocator.hpp"
+#include "gc/z/zOop.inline.hpp"
 #include "gc/z/zServiceability.hpp"
 #include "gc/z/zStat.hpp"
 #include "gc/z/zUtils.inline.hpp"
@@ -116,7 +116,7 @@
 }
 
 uint32_t ZCollectedHeap::hash_oop(oop obj) const {
-  return _heap.hash_oop(obj);
+  return _heap.hash_oop(ZOop::to_address(obj));
 }
 
 HeapWord* ZCollectedHeap::allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) {
@@ -352,13 +352,7 @@
 }
 
 bool ZCollectedHeap::print_location(outputStream* st, void* addr) const {
-  if (LocationPrinter::is_valid_obj(addr)) {
-    st->print(INTPTR_FORMAT " is a %s oop: ", p2i(addr),
-              ZAddress::is_good(reinterpret_cast<uintptr_t>(addr)) ? "good" : "bad");
-    cast_to_oop(addr)->print_on(st);
-    return true;
-  }
-  return false;
+  return _heap.print_location(st, (uintptr_t)addr);
 }
 
 void ZCollectedHeap::verify(VerifyOption option /* ignored */) {
@@ -366,5 +360,5 @@
 }
 
 bool ZCollectedHeap::is_oop(oop object) const {
-  return CollectedHeap::is_oop(object) && _heap.is_oop(object);
+  return _heap.is_oop(ZOop::to_address(object));
 }
--- a/src/hotspot/share/gc/z/zHeap.cpp	Tue Sep 24 17:08:18 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.cpp	Tue Sep 24 17:08:18 2019 +0200
@@ -22,6 +22,7 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/shared/locationPrinter.hpp"
 #include "gc/z/zAddress.inline.hpp"
 #include "gc/z/zGlobals.hpp"
 #include "gc/z/zHeap.inline.hpp"
@@ -169,7 +170,7 @@
 
 bool ZHeap::is_in(uintptr_t addr) const {
   // An address is considered to be "in the heap" if it points into
-  // the allocated part of a pages, regardless of which heap view is
+  // the allocated part of a page, regardless of which heap view is
   // used. Note that an address with the finalizable metadata bit set
   // is not pointing into a heap view, and therefore not considered
   // to be "in the heap".
@@ -502,6 +503,16 @@
   st->cr();
 }
 
+bool ZHeap::print_location(outputStream* st, uintptr_t addr) const {
+  if (LocationPrinter::is_valid_obj((void*)addr)) {
+    st->print(PTR_FORMAT " is a %s oop: ", addr, ZAddress::is_good(addr) ? "good" : "bad");
+    ZOop::from_address(addr)->print_on(st);
+    return true;
+  }
+
+  return false;
+}
+
 void ZHeap::verify() {
   // Heap verification can only be done between mark end and
   // relocate start. This is the only window where all oop are
--- a/src/hotspot/share/gc/z/zHeap.hpp	Tue Sep 24 17:08:18 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.hpp	Tue Sep 24 17:08:18 2019 +0200
@@ -98,7 +98,7 @@
   size_t unsafe_max_tlab_alloc() const;
 
   bool is_in(uintptr_t addr) const;
-  uint32_t hash_oop(oop obj) const;
+  uint32_t hash_oop(uintptr_t addr) const;
 
   // Workers
   uint nconcurrent_worker_threads() const;
@@ -161,9 +161,10 @@
   // Printing
   void print_on(outputStream* st) const;
   void print_extended_on(outputStream* st) const;
+  bool print_location(outputStream* st, uintptr_t addr) const;
 
   // Verification
-  bool is_oop(oop object) const;
+  bool is_oop(uintptr_t addr) const;
   void verify();
 };
 
--- a/src/hotspot/share/gc/z/zHeap.inline.hpp	Tue Sep 24 17:08:18 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.inline.hpp	Tue Sep 24 17:08:18 2019 +0200
@@ -44,8 +44,8 @@
   return &_reference_processor;
 }
 
-inline uint32_t ZHeap::hash_oop(oop obj) const {
-  const uintptr_t offset = ZAddress::offset(ZOop::to_address(obj));
+inline uint32_t ZHeap::hash_oop(uintptr_t addr) const {
+  const uintptr_t offset = ZAddress::offset(addr);
   return ZHash::address_to_uint32(offset);
 }
 
@@ -133,12 +133,8 @@
   _page_allocator.check_out_of_memory();
 }
 
-inline bool ZHeap::is_oop(oop object) const {
-  // Verify that we have a good address. Note that ZAddress::is_good()
-  // would not be a strong enough verification, since it only verifies
-  // that the metadata bits are good.
-  const uintptr_t addr = ZOop::to_address(object);
-  return ZAddress::good(addr) == addr;
+inline bool ZHeap::is_oop(uintptr_t addr) const {
+  return ZAddress::is_good(addr) && is_object_aligned(addr) && is_in(addr);
 }
 
 #endif // SHARE_GC_Z_ZHEAP_INLINE_HPP