changeset 55949:3f8a81f5d1b2

8224965: ZGC: Strengthen ZHeap::is_in() Reviewed-by: eosterlund
author pliden
date Wed, 05 Jun 2019 10:43:45 +0200
parents a5967fd63d9d
children 1de459182903
files src/hotspot/share/gc/z/zAddress.hpp src/hotspot/share/gc/z/zAddress.inline.hpp src/hotspot/share/gc/z/zCollectedHeap.cpp src/hotspot/share/gc/z/zHeap.cpp
diffstat 4 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/z/zAddress.hpp	Wed Jun 05 10:43:44 2019 +0200
+++ b/src/hotspot/share/gc/z/zAddress.hpp	Wed Jun 05 10:43:45 2019 +0200
@@ -49,6 +49,7 @@
   static bool is_finalizable(uintptr_t value);
   static bool is_finalizable_good(uintptr_t value);
   static bool is_remapped(uintptr_t value);
+  static bool is_in(uintptr_t value);
 
   static uintptr_t address(uintptr_t value);
   static uintptr_t offset(uintptr_t value);
--- a/src/hotspot/share/gc/z/zAddress.inline.hpp	Wed Jun 05 10:43:44 2019 +0200
+++ b/src/hotspot/share/gc/z/zAddress.inline.hpp	Wed Jun 05 10:43:45 2019 +0200
@@ -26,6 +26,7 @@
 
 #include "gc/z/zAddress.hpp"
 #include "gc/z/zGlobals.hpp"
+#include "utilities/globalDefinitions.hpp"
 #include "utilities/macros.hpp"
 
 inline bool ZAddress::is_null(uintptr_t value) {
@@ -81,6 +82,16 @@
   return value & ZAddressMetadataRemapped;
 }
 
+inline bool ZAddress::is_in(uintptr_t value) {
+  // Check that exactly one non-offset bit is set
+  if (!is_power_of_2(value & ~ZAddressOffsetMask)) {
+    return false;
+  }
+
+  // Check that one of the non-finalizable metadata is set
+  return value & (ZAddressMetadataMask & ~ZAddressMetadataFinalizable);
+}
+
 inline uintptr_t ZAddress::address(uintptr_t value) {
   return value | ZAddressBase;
 }
--- a/src/hotspot/share/gc/z/zCollectedHeap.cpp	Wed Jun 05 10:43:44 2019 +0200
+++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp	Wed Jun 05 10:43:45 2019 +0200
@@ -109,7 +109,7 @@
 }
 
 bool ZCollectedHeap::is_in(const void* p) const {
-  return is_in_reserved(p) && _heap.is_in((uintptr_t)p);
+  return _heap.is_in((uintptr_t)p);
 }
 
 uint32_t ZCollectedHeap::hash_oop(oop obj) const {
--- a/src/hotspot/share/gc/z/zHeap.cpp	Wed Jun 05 10:43:44 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.cpp	Wed Jun 05 10:43:45 2019 +0200
@@ -177,13 +177,17 @@
 }
 
 bool ZHeap::is_in(uintptr_t addr) const {
-  if (addr < ZAddressReservedStart || addr >= ZAddressReservedEnd) {
-    return false;
-  }
+  // 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
+  // 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".
 
-  const ZPage* const page = _page_table.get(addr);
-  if (page != NULL) {
-    return page->is_in(addr);
+  if (ZAddress::is_in(addr)) {
+    const ZPage* const page = _page_table.get(addr);
+    if (page != NULL) {
+      return page->is_in(addr);
+    }
   }
 
   return false;