changeset 53:f2b28c124605

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:58:27 +0900
parents 6075e5707a9b
children 296461a953ac
files agent/ChangeLog agent/src/deadlockFinder.cpp agent/src/oopUtil.hpp
diffstat 3 files changed, 26 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/agent/ChangeLog	Tue May 19 19:53:37 2015 +0900
+++ b/agent/ChangeLog	Fri May 22 11:58:27 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 2370: Change bugs.sun.com to bugs.openjdk.java.net
--- a/agent/src/deadlockFinder.cpp	Tue May 19 19:53:37 2015 +0900
+++ b/agent/src/deadlockFinder.cpp	Fri May 22 11:58:27 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
@@ -331,22 +331,8 @@
     /* 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"
@@ -369,6 +355,23 @@
      * 
      * 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);
       
@@ -386,7 +389,7 @@
       }
       
       /* Reset "_thread_state". */
-      *status = THREAD_IN_NATIVE;
+      *status = original_status;
       /* Reset "_safepoint_state". */
       threadSafepointStateDestroy(thisThreadPtr);
       threadSafepointStateCreate(thisThreadPtr);
@@ -499,7 +502,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)) {
@@ -579,7 +582,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 19:53:37 2015 +0900
+++ b/agent/src/oopUtil.hpp	Fri May 22 11:58:27 2015 +0900
@@ -532,14 +532,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);
 }