changeset 41:0c499e72a72d

Bug 2376: Deadlock finder needs to return a original _thread_state to HotSpot VM. reviewed-by: yasuenag
author KUBOTA Yuji <kubota.yuji@lab.ntt.co.jp>
date Fri, 22 May 2015 11:59:18 +0900
parents 63863f35f1ec
children 6dd54555d3bb
files agent/ChangeLog agent/src/deadlockFinder.cpp agent/src/oopUtil.hpp
diffstat 3 files changed, 28 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/agent/ChangeLog	Tue May 19 20:05:00 2015 +0900
+++ b/agent/ChangeLog	Fri May 22 11:59:18 2015 +0900
@@ -1,3 +1,7 @@
+2015-05-22 KUBOTA Yuji  <kubota.yuji@lab.ntt.co.jp>
+
+	* Bug 2376: Deadlock finder needs to return a original _thread_state to HotSpot VM.
+
 2015-05-19 KUBOTA Yuji  <kubota.yuji@lab.ntt.co.jp>
 
 	* Bug 2371: Fix attacher's message.
--- a/agent/src/deadlockFinder.cpp	Tue May 19 20:05:00 2015 +0900
+++ b/agent/src/deadlockFinder.cpp	Fri May 22 11:59:18 2015 +0900
@@ -1,7 +1,7 @@
 /*!
  * \file deadlockFinder.cpp
  * \brief This file is used by find deadlock.
- * Copyright (C) 2011-2014 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2015 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
@@ -332,24 +332,9 @@
         /* Get self thread id. */
         pid_t threadId = syscall(SYS_gettid);
         
-        /* Check deadlock. */
-        bool foundDeadlock = findDeadLock(threadId, monitor);
-        
-        if (unlikely(foundDeadlock)) {
-            
-            /* Get threads. */
-            getLockedThreads(threadId, monitor, list);
-            
-            /* Count list item. */
-            for (TDeadlockList *item = (*list); item != NULL;
-                item = item->next) {
-                
-                deadlockCount++;
-            }
-        }
-        
         int *status = (int *)incAddress(thisThreadPtr,
             ofsJavaThreadThreadState);
+        int original_status = *status;
         
         /*
          * Normally thread status is "_thread_in_native"
@@ -372,6 +357,24 @@
          * 
          * So thread status reset here by force.
          */
+        *status = THREAD_IN_VM;
+
+        /* Check deadlock. */
+        bool foundDeadlock = findDeadLock(threadId, monitor);
+
+        if (unlikely(foundDeadlock)) {
+
+            /* Get threads. */
+            getLockedThreads(threadId, monitor, list);
+
+            /* Count list item. */
+            for (TDeadlockList *item = (*list); item != NULL;
+                item = item->next) {
+
+                deadlockCount++;
+            }
+        }
+
         if (*status == THREAD_IN_VM) {
             bool needLock = !monitor_owned_by_self(thread_lock);
             
@@ -389,7 +392,7 @@
             }
             
             /* Reset "_thread_state". */
-            *status = THREAD_IN_NATIVE;
+            *status = original_status;
             /* Reset "_safepoint_state". */
             threadSafepointStateDestroy(thisThreadPtr);
             threadSafepointStateCreate(thisThreadPtr);
@@ -515,7 +518,7 @@
     jobject monitorOop     = NULL;
     
     /* Get owner thread of this monitor. */
-    threadPtr = get_lock_owner(monitor, !isInWorkSafepoint());
+    threadPtr = get_lock_owner(monitor, !isAtSafepoint());
     
     /* No deadlock (no owner thread of this monitor). */
     if (unlikely(threadPtr == NULL)) {
@@ -596,7 +599,7 @@
         TDeadlockList *threadRec = NULL;
         
         /* Get owner thread of this monitor. */
-        threadPtr = get_lock_owner(monitor, !isInWorkSafepoint());
+        threadPtr = get_lock_owner(monitor, !isAtSafepoint());
         
         if (unlikely(threadPtr == NULL)) {
             /* Shouldn't reach to here. */
--- a/agent/src/oopUtil.hpp	Tue May 19 20:05:00 2015 +0900
+++ b/agent/src/oopUtil.hpp	Fri May 22 11:59:18 2015 +0900
@@ -1,7 +1,7 @@
 /*!
  * \file oopUtil.hpp
  * \brief This file is used to getting information inner JVM.<br>
- * Copyright (C) 2011-2014 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2015 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
@@ -570,14 +570,6 @@
  * \brief Get safepoint state.
  * \return Is synchronizing or working at safepoint now.
  */
-inline bool isInWorkSafepoint(void) {
-    return (*safePointState != 0);
-}
-
-/*!
- * \brief Get safepoint state.
- * \return Is working at safepoint now.
- */
 inline bool isAtSafepoint(void) {
     return (*safePointState == 2);
 }