changeset 58:2b0645fd51d3

Bug 3104: SEGV in TSnapShotContainer::mergeChildren with Oracle JDK8u92 Reviewed-by: ykubota
author Yasumasa Suenaga <yasuenag@gmail.com>
date Mon, 16 Jan 2017 18:24:50 +0900
parents 55659802313d
children d766054a28ee
files agent/ChangeLog agent/src/snapShotContainer.cpp
diffstat 2 files changed, 44 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/agent/ChangeLog	Thu Nov 24 14:42:03 2016 +0900
+++ b/agent/ChangeLog	Mon Jan 16 18:24:50 2017 +0900
@@ -1,3 +1,7 @@
+2017-01-16 Yasumasa Suenaga  <yasuenag@gmail.com>
+
+	* Bug 3104: SEGV in TSnapShotContainer::mergeChildren with Oracle JDK8u92
+
 2016-11-24  KUBOTA Yuji <kubota.yuji@lab.ntt.co.jp>
 
 	* Bump to 1.1.5
--- a/agent/src/snapShotContainer.cpp	Thu Nov 24 14:42:03 2016 +0900
+++ b/agent/src/snapShotContainer.cpp	Mon Jan 16 18:24:50 2017 +0900
@@ -1,7 +1,7 @@
 /*!
  * \file snapshotContainer.cpp
  * \brief This file is used to add up using size every class.
- * Copyright (C) 2011-2013 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2017 Nippon Telegraph and Telephone Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -593,23 +593,48 @@
                 
                 /* Loop each children class. */
                 TChildClassCounter *counter = srcClsCounter->child;
+                TChildClassCounter *prevCounter = NULL;
                 while (counter != NULL){
-                  /* Search child class. */
-                  TChildClassCounter *childClsData = 
-                    this->findChildClass(clsCounter, counter->objData->klassOop);
-                    
-                  /* Register class as child class. */
-                  if(unlikely(childClsData == NULL)){
-                     childClsData = this->pushNewChildClass(
-                                          clsCounter, counter->objData);
-                  }
-                    
-                  if(likely(childClsData != NULL)){
-                    /* Marge children class heap usage. */
-                    this->addInc(childClsData->counter, counter->counter);
+                  TObjectData *objData = counter->objData;
+
+                  /*
+                   * If the class of objData is already unloaded, we should
+                   * remove reference to it from child object data.
+                   */
+                  if (objData->isRemoved) {
+                    TChildClassCounter *nextCounter = counter->next;
+
+                    if (prevCounter == NULL) {
+                      srcClsCounter->child = nextCounter;
+                    } else {
+                      prevCounter->next = nextCounter;
+                    }
+
+                    /* Deallocate TChildClassCounter. */
+                    free(counter->counter);
+                    free(counter);
+
+		    counter = nextCounter;
+                  } else {
+                    /* Search child class. */
+                    TChildClassCounter *childClsData =
+                            this->findChildClass(clsCounter, objData->klassOop);
+
+                    /* Register class as child class. */
+                    if (unlikely(childClsData == NULL)) {
+                      childClsData =
+                               this->pushNewChildClass(clsCounter, objData);
+                    }
+
+                    if (likely(childClsData != NULL)) {
+                      /* Marge children class heap usage. */
+                      this->addInc(childClsData->counter, counter->counter);
+                    }
+
+                    prevCounter = counter;
+                    counter = counter->next;
                   }
 
-                  counter = counter->next;
                 }
 
             }