From 1fedab332926262a2ef8a641ea0d55d7fab5d5e1 Mon Sep 17 00:00:00 2001 From: shshahma Date: Fri, 10 Jun 2016 15:34:32 +0530 Subject: [PATCH] 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 --- src/share/vm/oops/method.cpp | 10 ++++++++-- src/share/vm/prims/jniCheck.cpp | 7 +------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/share/vm/oops/method.cpp b/src/share/vm/oops/method.cpp index ffc9e9cd0..94085afba 100644 --- a/src/share/vm/oops/method.cpp +++ b/src/share/vm/oops/method.cpp @@ -1778,7 +1778,7 @@ class JNIMethodBlock : public CHeapObj { 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 @@ class JNIMethodBlock : public CHeapObj { 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 @@ bool Method::is_method_id(jmethodID mid) { 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 @@ bool Method::is_method_id(jmethodID mid) { 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; diff --git a/src/share/vm/prims/jniCheck.cpp b/src/share/vm/prims/jniCheck.cpp index e95937ae9..07e40ae2a 100644 --- a/src/share/vm/prims/jniCheck.cpp +++ b/src/share/vm/prims/jniCheck.cpp @@ -461,16 +461,11 @@ oop jniCheck::validate_handle(JavaThread* thr, jobject obj) { 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; } -- GitLab