8017478: Kitchensink crashed with SIGSEGV in BaselineReporter::diff_callsites
authorzgu
Tue, 25 Jun 2013 17:22:04 -0400
changeset 18479 d14275b3c52d
parent 18438 9ea6bbfe0b83
child 18480 cd9896dfe725
8017478: Kitchensink crashed with SIGSEGV in BaselineReporter::diff_callsites Summary: Fixed possible NULL pointer that caused SIGSEGV Reviewed-by: coleenp, acorn, ctornqvi
hotspot/src/share/vm/services/memReporter.cpp
--- a/hotspot/src/share/vm/services/memReporter.cpp	Sun Jun 23 22:08:28 2013 -0700
+++ b/hotspot/src/share/vm/services/memReporter.cpp	Tue Jun 25 17:22:04 2013 -0400
@@ -188,8 +188,8 @@
                   (MallocCallsitePointer*)prev_malloc_itr.current();
 
   while (cur_malloc_callsite != NULL || prev_malloc_callsite != NULL) {
-    if (prev_malloc_callsite == NULL ||
-        cur_malloc_callsite->addr() < prev_malloc_callsite->addr()) {
+    if (prev_malloc_callsite == NULL) {
+      assert(cur_malloc_callsite != NULL, "sanity check");
       // this is a new callsite
       _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
         amount_in_current_scale(cur_malloc_callsite->amount()),
@@ -197,22 +197,42 @@
         diff_in_current_scale(cur_malloc_callsite->amount(), 0),
         diff(cur_malloc_callsite->count(), 0));
       cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
-    } else if (cur_malloc_callsite == NULL ||
-               cur_malloc_callsite->addr() > prev_malloc_callsite->addr()) {
+    } else if (cur_malloc_callsite == NULL) {
+      assert(prev_malloc_callsite != NULL, "Sanity check");
       // this callsite is already gone
       _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(),
-        amount_in_current_scale(0), 0,
+        0, 0,
         diff_in_current_scale(0, prev_malloc_callsite->amount()),
         diff(0, prev_malloc_callsite->count()));
       prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
-    } else {  // the same callsite
-      _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
-        amount_in_current_scale(cur_malloc_callsite->amount()),
-        cur_malloc_callsite->count(),
-        diff_in_current_scale(cur_malloc_callsite->amount(), prev_malloc_callsite->amount()),
-        diff(cur_malloc_callsite->count(), prev_malloc_callsite->count()));
-      cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
-      prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
+    } else {
+      assert(cur_malloc_callsite  != NULL,  "Sanity check");
+      assert(prev_malloc_callsite != NULL,  "Sanity check");
+      if (cur_malloc_callsite->addr() < prev_malloc_callsite->addr()) {
+        // this is a new callsite
+        _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
+          amount_in_current_scale(cur_malloc_callsite->amount()),
+          cur_malloc_callsite->count(),
+          diff_in_current_scale(cur_malloc_callsite->amount(), 0),
+          diff(cur_malloc_callsite->count(), 0));
+          cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
+      } else if (cur_malloc_callsite->addr() > prev_malloc_callsite->addr()) {
+        // this callsite is already gone
+        _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(),
+          0, 0,
+          diff_in_current_scale(0, prev_malloc_callsite->amount()),
+          diff(0, prev_malloc_callsite->count()));
+        prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
+      } else {
+        // the same callsite
+        _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
+          amount_in_current_scale(cur_malloc_callsite->amount()),
+          cur_malloc_callsite->count(),
+          diff_in_current_scale(cur_malloc_callsite->amount(), prev_malloc_callsite->amount()),
+          diff(cur_malloc_callsite->count(), prev_malloc_callsite->count()));
+        cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
+        prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
+      }
     }
   }