changeset 24013:fde446cb8e19

8147451: Crash in Method::checked_resolve_jmethod_id(_jmethodID*) Summary: VisualVM's memory profiling with allocation stacktraces crashes JVM in Method::checked_resolve_jmethod_id() Reviewed-by: coleenp, sspitsyn, jiangli
author shshahma
date Fri, 10 Jun 2016 15:34:32 +0530
parents b857e4abb00c
children cf1faa9100dd
files src/share/vm/oops/method.cpp src/share/vm/prims/jniCheck.cpp
diffstat 2 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/method.cpp	Mon May 30 15:24:37 2016 +0530
+++ b/src/share/vm/oops/method.cpp	Fri Jun 10 15:34:32 2016 +0530
@@ -1778,7 +1778,7 @@
   void clear_all_methods() {
     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
       for (int i = 0; i< number_of_methods; i++) {
-        _methods[i] = NULL;
+        b->_methods[i] = NULL;
       }
     }
   }
@@ -1788,7 +1788,7 @@
     int count = 0;
     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
       for (int i = 0; i< number_of_methods; i++) {
-        if (_methods[i] != _free_method) count++;
+        if (b->_methods[i] != _free_method) count++;
       }
     }
     return count;
@@ -1846,6 +1846,9 @@
   Method* m = resolve_jmethod_id(mid);
   assert(m != NULL, "should be called with non-null method");
   InstanceKlass* ik = m->method_holder();
+  if (ik == NULL) {
+    return false;
+  }
   ClassLoaderData* cld = ik->class_loader_data();
   if (cld->jmethod_ids() == NULL) return false;
   return (cld->jmethod_ids()->contains((Method**)mid));
@@ -1853,6 +1856,9 @@
 
 Method* Method::checked_resolve_jmethod_id(jmethodID mid) {
   if (mid == NULL) return NULL;
+  if (!Method::is_method_id(mid)) {
+    return NULL;
+  }
   Method* o = resolve_jmethod_id(mid);
   if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) {
     return NULL;
--- a/src/share/vm/prims/jniCheck.cpp	Mon May 30 15:24:37 2016 +0530
+++ b/src/share/vm/prims/jniCheck.cpp	Fri Jun 10 15:34:32 2016 +0530
@@ -461,16 +461,11 @@
 
 Method* jniCheck::validate_jmethod_id(JavaThread* thr, jmethodID method_id) {
   ASSERT_OOPS_ALLOWED;
-  // do the fast jmethodID check first
+  // Do the jmethodID check
   Method* moop = Method::checked_resolve_jmethod_id(method_id);
   if (moop == NULL) {
     ReportJNIFatalError(thr, fatal_wrong_class_or_method);
   }
-  // jmethodIDs are supposed to be weak handles in the class loader data,
-  // but that can be expensive so check it last
-  else if (!Method::is_method_id(method_id)) {
-    ReportJNIFatalError(thr, fatal_non_weak_method);
-  }
   return moop;
 }