return lock.getClass().getName() + '@' +
Integer.toHexString(System.identityHashCode(lock));
}
private static void checkLockInfo(Thread t, Thread.State state, Object lock, Thread owner) {
ThreadInfo info = tm.getThreadInfo(t.getId());
if (info == null) {
throw new RuntimeException(t.getName() +
" expected to have ThreadInfo " +
" but got null.");
}
if (info.getThreadState() != state) {
throw new RuntimeException(t.getName() + " expected to be in " +
state + " state but got " + info.getThreadState());
}
if (lock == null && info.getLockName() != null) {
throw new RuntimeException(t.getName() +
" expected not to be blocked on any lock" +
" but got " + info.getLockName());
}
String expectedLockName = getLockName(lock);
if (lock != null && info.getLockName() == null) {
throw new RuntimeException(t.getName() +
" expected to be blocked on lock [" + expectedLockName +
"] but got null.");
}
if (lock != null && !expectedLockName.equals(info.getLockName())) {
throw new RuntimeException(t.getName() +
" expected to be blocked on lock [" + expectedLockName +
"] but got [" + info.getLockName() + "].");
}
if (owner == null && info.getLockOwnerName() != null) {
throw new RuntimeException("Lock owner is expected " +
" to be null but got " + info.getLockOwnerName());
}
if (owner != null && info.getLockOwnerName() == null) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() +
" but got null.");
}
if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() +
" but got " + owner.getName());
}
if (owner == null && info.getLockOwnerId() != -1) {
throw new RuntimeException("Lock owner is expected " +
" to be -1 but got " + info.getLockOwnerId());
}
if (owner != null && info.getLockOwnerId() <= 0) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() + "(id = " + owner.getId() +
") but got " + info.getLockOwnerId());
}
if (owner != null && info.getLockOwnerId() != owner.getId()) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() + "(id = " + owner.getId() +
") but got " + info.getLockOwnerId());
}
if (info.isSuspended()) {
throw new RuntimeException(t.getName() +
" isSuspended() returns " + info.isSuspended());
}
}