changeset 7090:3592be0f4f3e

8000456: Add programmatic deadlock detection in SSLEngineDeadlock Reviewed-by: wetmore
author xuelei
date Wed, 19 Jun 2013 02:46:50 -0700
parents f346a2ed2fcb
children c9ab121e737c
files test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLEngineImpl/SSLEngineDeadlock.java
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLEngineImpl/SSLEngineDeadlock.java	Mon Jun 17 11:27:22 2013 +0400
+++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLEngineImpl/SSLEngineDeadlock.java	Wed Jun 19 02:46:50 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -75,6 +75,7 @@
 import java.io.*;
 import java.security.*;
 import java.nio.*;
+import java.lang.management.*;
 
 public class SSLEngineDeadlock {
 
@@ -145,6 +146,8 @@
             }
             SSLEngineDeadlock test = new SSLEngineDeadlock();
             test.runTest();
+
+            detectDeadLock();
         }
         System.out.println("Test Passed.");
     }
@@ -362,6 +365,22 @@
     }
 
     /*
+     * Detect dead lock
+     */
+    private static void detectDeadLock() throws Exception {
+        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
+        long[] threadIds = threadBean.findDeadlockedThreads();
+        if (threadIds != null && threadIds.length != 0) {
+            for (long id : threadIds) {
+                ThreadInfo info =
+                    threadBean.getThreadInfo(id, Integer.MAX_VALUE);
+                System.out.println("Deadlocked ThreadInfo: " + info);
+            }
+            throw new Exception("Found Deadlock!");
+        }
+    }
+
+    /*
      * Logging code
      */
     private static boolean resultOnce = true;