8209588: SIGSEGV in MethodArityHistogram() with -XX:+CountCompiledCalls
authorlucy
Mon, 20 Aug 2018 17:25:45 +0200
changeset 51446 0fc5fb135f2d
parent 51445 2c4aaa0d56f4
child 51447 8dfed4387312
8209588: SIGSEGV in MethodArityHistogram() with -XX:+CountCompiledCalls Reviewed-by: kvn, goetz
src/hotspot/share/runtime/sharedRuntime.cpp
--- a/src/hotspot/share/runtime/sharedRuntime.cpp	Mon Aug 20 14:25:02 2018 +0200
+++ b/src/hotspot/share/runtime/sharedRuntime.cpp	Mon Aug 20 17:25:45 2018 +0200
@@ -2135,17 +2135,21 @@
   static int _max_size;                       // max. arg size seen
 
   static void add_method_to_histogram(nmethod* nm) {
-    Method* m = nm->method();
-    ArgumentCount args(m->signature());
-    int arity   = args.size() + (m->is_static() ? 0 : 1);
-    int argsize = m->size_of_parameters();
-    arity   = MIN2(arity, MAX_ARITY-1);
-    argsize = MIN2(argsize, MAX_ARITY-1);
-    int count = nm->method()->compiled_invocation_count();
-    _arity_histogram[arity]  += count;
-    _size_histogram[argsize] += count;
-    _max_arity = MAX2(_max_arity, arity);
-    _max_size  = MAX2(_max_size, argsize);
+    // These checks are taken from CodeHeapState::print_names()
+    Method* m = (nm == NULL) ? NULL : nm->method();  // nm->method() may be uninitialized, i.e. != NULL, but invalid
+    if ((nm != NULL) && (m != NULL) && !nm->is_zombie() && !nm->is_not_installed() &&
+        os::is_readable_pointer(m) && os::is_readable_pointer(m->constants())) {
+      ArgumentCount args(m->signature());
+      int arity   = args.size() + (m->is_static() ? 0 : 1);
+      int argsize = m->size_of_parameters();
+      arity   = MIN2(arity, MAX_ARITY-1);
+      argsize = MIN2(argsize, MAX_ARITY-1);
+      int count = nm->method()->compiled_invocation_count();
+      _arity_histogram[arity]  += count;
+      _size_histogram[argsize] += count;
+      _max_arity = MAX2(_max_arity, arity);
+      _max_size  = MAX2(_max_size, argsize);
+    }
   }
 
   void print_histogram_helper(int n, int* histo, const char* name) {