8222558: Rework ResolvedMethodTable verification
authorstefank
Wed, 17 Apr 2019 07:41:09 +0200
changeset 54574 7b74bbe5085b
parent 54573 b73893f7fee3
child 54575 84054d68bf85
8222558: Rework ResolvedMethodTable verification Reviewed-by: coleenp
src/hotspot/share/memory/universe.cpp
src/hotspot/share/memory/universe.hpp
src/hotspot/share/prims/resolvedMethodTable.cpp
src/hotspot/share/prims/resolvedMethodTable.hpp
test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java
--- a/src/hotspot/share/memory/universe.cpp	Thu Apr 18 07:02:07 2019 -0400
+++ b/src/hotspot/share/memory/universe.cpp	Wed Apr 17 07:41:09 2019 +0200
@@ -1151,6 +1151,8 @@
       verify_flags |= Verify_JNIHandles;
     } else if (strcmp(token, "codecache_oops") == 0) {
       verify_flags |= Verify_CodeCacheOops;
+    } else if (strcmp(token, "resolved_method_table") == 0) {
+      verify_flags |= Verify_ResolvedMethodTable;
     } else {
       vm_exit_during_initialization(err_msg("VerifySubSet: \'%s\' memory sub-system is unknown, please correct it", token));
     }
@@ -1230,6 +1232,10 @@
     log_debug(gc, verify)("CodeCache Oops");
     CodeCache::verify_oops();
   }
+  if (should_verify_subset(Verify_ResolvedMethodTable)) {
+    log_debug(gc, verify)("ResolvedMethodTable Oops");
+    ResolvedMethodTable::verify();
+  }
 
   _verify_in_progress = false;
 }
--- a/src/hotspot/share/memory/universe.hpp	Thu Apr 18 07:02:07 2019 -0400
+++ b/src/hotspot/share/memory/universe.hpp	Wed Apr 17 07:41:09 2019 +0200
@@ -478,6 +478,7 @@
     Verify_MetaspaceUtils = 128,
     Verify_JNIHandles = 256,
     Verify_CodeCacheOops = 512,
+    Verify_ResolvedMethodTable = 1024,
     Verify_All = -1
   };
   static void initialize_verify_flags();
--- a/src/hotspot/share/prims/resolvedMethodTable.cpp	Thu Apr 18 07:02:07 2019 -0400
+++ b/src/hotspot/share/prims/resolvedMethodTable.cpp	Wed Apr 17 07:41:09 2019 +0200
@@ -346,16 +346,6 @@
 // cleaning. Note it might trigger a resize instead.
 void ResolvedMethodTable::finish_dead_counter() {
   check_concurrent_work();
-
-#ifdef ASSERT
-  if (SafepointSynchronize::is_at_safepoint()) {
-    size_t fail_cnt = verify_and_compare_entries();
-    if (fail_cnt != 0) {
-      tty->print_cr("ERROR: fail_cnt=" SIZE_FORMAT, fail_cnt);
-      guarantee(fail_cnt == 0, "unexpected ResolvedMethodTable verification failures");
-    }
-  }
-#endif // ASSERT
 }
 
 #if INCLUDE_JVMTI
@@ -402,26 +392,16 @@
 }
 #endif // INCLUDE_JVMTI
 
-// Verification and comp
-class VerifyCompResolvedMethod : StackObj {
-  GrowableArray<oop>* _oops;
+// Verification
+class VerifyResolvedMethod : StackObj {
  public:
-  size_t _errors;
-  VerifyCompResolvedMethod(GrowableArray<oop>* oops) : _oops(oops), _errors(0) {}
   bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
-    oop s = val->peek();
-    if (s == NULL) {
-      return true;
+    oop obj = val->peek();
+    if (obj != NULL) {
+      Method* method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(obj);
+      guarantee(method->is_method(), "Must be");
+      guarantee(!method->is_old(), "Must be");
     }
-    int len = _oops->length();
-    for (int i = 0; i < len; i++) {
-      bool eq = s == _oops->at(i);
-      assert(!eq, "Duplicate entries");
-      if (eq) {
-        _errors++;
-      }
-    }
-    _oops->push(s);
     return true;
   };
 };
@@ -430,16 +410,9 @@
   return _items_count;
 }
 
-size_t ResolvedMethodTable::verify_and_compare_entries() {
-  Thread* thr = Thread::current();
-  GrowableArray<oop>* oops =
-    new (ResourceObj::C_HEAP, mtInternal)
-      GrowableArray<oop>((int)_current_size, true);
-
-  VerifyCompResolvedMethod vcs(oops);
-  if (!_local_table->try_scan(thr, vcs)) {
+void ResolvedMethodTable::verify() {
+  VerifyResolvedMethod vcs;
+  if (!_local_table->try_scan(Thread::current(), vcs)) {
     log_info(membername, table)("verify unavailable at this moment");
   }
-  delete oops;
-  return vcs._errors;
 }
--- a/src/hotspot/share/prims/resolvedMethodTable.hpp	Thu Apr 18 07:02:07 2019 -0400
+++ b/src/hotspot/share/prims/resolvedMethodTable.hpp	Wed Apr 17 07:41:09 2019 +0200
@@ -96,7 +96,7 @@
 
   // Debugging
   static size_t items_count();
-  static size_t verify_and_compare_entries();
+  static void verify();
 };
 
 #endif // SHARE_PRIMS_RESOLVEDMETHODTABLE_HPP
--- a/test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java	Thu Apr 18 07:02:07 2019 -0400
+++ b/test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java	Wed Apr 17 07:41:09 2019 +0200
@@ -103,11 +103,13 @@
         System.err.println("test(" + gc + ", " + doConcurrent + ")");
         // Run this Leak class with logging
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                                      "-Xlog:membername+table=trace",
+                                      "-Xlog:membername+table=trace,gc+verify=debug",
                                       "-XX:+UnlockExperimentalVMOptions",
                                       "-XX:+UnlockDiagnosticVMOptions",
                                       "-XX:+WhiteBoxAPI",
                                       "-Xbootclasspath/a:.",
+                                      "-XX:+VerifyBeforeGC",
+                                      "-XX:+VerifyAfterGC",
                                       doConcurrent ? "-XX:+ExplicitGCInvokesConcurrent" : "-XX:-ExplicitGCInvokesConcurrent",
                                       "-XX:+ClassUnloading",
                                       "-XX:+ClassUnloadingWithConcurrentMark",