# HG changeset patch # User KUBOTA Yuji # Date 1432263507 -32400 # Node ID f2b28c1246052ab33e3a8ebcf66031a433892c8c # Parent 6075e5707a9be6db45c47987ca4b515a8b225dbc Bug 2376: Deadlock finder needs to return a original _thread_state to HotSpot VM. reviewed-by: yasuenag diff -r 6075e5707a9b -r f2b28c124605 agent/ChangeLog --- 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 + + * Bug 2376: Deadlock finder needs to return a original _thread_state to HotSpot VM. + 2015-05-19 KUBOTA Yuji * Bug 2370: Change bugs.sun.com to bugs.openjdk.java.net diff -r 6075e5707a9b -r f2b28c124605 agent/src/deadlockFinder.cpp --- 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. */ diff -r 6075e5707a9b -r f2b28c124605 agent/src/oopUtil.hpp --- 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); }