8219459: oopDesc::is_valid() is broken
authorcoleenp
Tue, 14 May 2019 08:52:51 -0400
changeset 54842 f9c8e16db3dd
parent 54841 43439afaab4a
child 54843 25c329958c70
8219459: oopDesc::is_valid() is broken Summary: Use Metaspace::contains() to test address ranges. Reviewed-by: mdoerr, stuefe, jiangli
src/hotspot/share/memory/metaspace.cpp
src/hotspot/share/memory/metaspace.hpp
src/hotspot/share/oops/klass.cpp
src/hotspot/share/oops/oop.cpp
--- a/src/hotspot/share/memory/metaspace.cpp	Tue May 14 13:34:49 2019 +0100
+++ b/src/hotspot/share/memory/metaspace.cpp	Tue May 14 08:52:51 2019 -0400
@@ -47,6 +47,7 @@
 #include "utilities/debug.hpp"
 #include "utilities/formatBuffer.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/vmError.hpp"
 
 
 using namespace metaspace;
@@ -917,31 +918,6 @@
 #endif
 }
 
-// Utils to check if a pointer or range is part of a committed metaspace region.
-metaspace::VirtualSpaceNode* MetaspaceUtils::find_enclosing_virtual_space(const void* p) {
-  MutexLocker cl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
-  VirtualSpaceNode* vsn = Metaspace::space_list()->find_enclosing_space(p);
-  if (Metaspace::using_class_space() && vsn == NULL) {
-    vsn = Metaspace::class_space_list()->find_enclosing_space(p);
-  }
-  return vsn;
-}
-
-bool MetaspaceUtils::is_range_in_committed(const void* from, const void* to) {
-#if INCLUDE_CDS
-  if (UseSharedSpaces) {
-    for (int idx = MetaspaceShared::ro; idx <= MetaspaceShared::mc; idx++) {
-      if (FileMapInfo::current_info()->is_in_shared_region(from, idx)) {
-        return FileMapInfo::current_info()->is_in_shared_region(to, idx);
-      }
-    }
-  }
-#endif
-  VirtualSpaceNode* vsn = find_enclosing_virtual_space(from);
-  return (vsn != NULL) && vsn->contains(to);
-}
-
-
 // Metaspace methods
 
 size_t Metaspace::_first_chunk_word_size = 0;
--- a/src/hotspot/share/memory/metaspace.hpp	Tue May 14 13:34:49 2019 +0100
+++ b/src/hotspot/share/memory/metaspace.hpp	Tue May 14 08:52:51 2019 -0400
@@ -329,11 +329,6 @@
   // Helper for print_xx_report.
   static void print_vs(outputStream* out, size_t scale);
 
-  // Utils to check if a pointer or range is part of a committed metaspace region
-  // without acquiring any locks.
-  static metaspace::VirtualSpaceNode* find_enclosing_virtual_space(const void* p);
-  static bool is_range_in_committed(const void* from, const void* to);
-
 public:
 
   // Collect used metaspace statistics. This involves walking the CLDG. The resulting
--- a/src/hotspot/share/oops/klass.cpp	Tue May 14 13:34:49 2019 +0100
+++ b/src/hotspot/share/oops/klass.cpp	Tue May 14 08:52:51 2019 -0400
@@ -813,7 +813,7 @@
   if ((size_t)k < os::min_page_size()) return false;
 
   if (!os::is_readable_range(k, k + 1)) return false;
-  if (!MetaspaceUtils::is_range_in_committed(k, k + 1)) return false;
+  if (!Metaspace::contains(k)) return false;
 
   if (!Symbol::is_valid(k->name())) return false;
   return ClassLoaderDataGraph::is_valid(k->class_loader_data());
--- a/src/hotspot/share/oops/oop.cpp	Tue May 14 13:34:49 2019 +0100
+++ b/src/hotspot/share/oops/oop.cpp	Tue May 14 08:52:51 2019 -0400
@@ -182,9 +182,7 @@
   if (!Universe::heap()->is_in(obj)) return false;
 
   Klass* k = (Klass*)load_klass_raw(obj);
-
-  if (!os::is_readable_range(k, k + 1)) return false;
-  return MetaspaceUtils::is_range_in_committed(k, k + 1);
+  return Klass::is_valid(k);
 }
 
 oop oopDesc::oop_or_null(address addr) {