jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java
changeset 28857 20499c662815
parent 25181 216e0899f503
child 30376 2ccf2cf7ea48
equal deleted inserted replaced
28768:30b987a20989 28857:20499c662815
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    73         t.setDaemon(true);
    73         t.setDaemon(true);
    74         return t;
    74         return t;
    75     }
    75     }
    76 
    76 
    77     private static void waitForThreadState(Thread t, Thread.State state) throws InterruptedException {
    77     private static void waitForThreadState(Thread t, Thread.State state) throws InterruptedException {
    78         while (!t.isInterrupted() && t.getState() != state) {
    78         while (t.getState() != state) {
    79             Thread.sleep(3);
    79             Thread.sleep(3);
    80         }
    80         }
    81     }
    81     }
    82 
    82 
    83     /**
    83     /**
   107         ThreadInfo ti = mbean.getThreadInfo(tid);
   107         ThreadInfo ti = mbean.getThreadInfo(tid);
   108         String lockName = null;
   108         String lockName = null;
   109         synchronized(lock1) {
   109         synchronized(lock1) {
   110             p.arriveAndAwaitAdvance(); // phase[1]
   110             p.arriveAndAwaitAdvance(); // phase[1]
   111             waitForThreadState(lt, Thread.State.BLOCKED);
   111             waitForThreadState(lt, Thread.State.BLOCKED);
   112             lockName = mbean.getThreadInfo(tid).getLockName();
   112             do {
       
   113                 lockName = mbean.getThreadInfo(tid).getLockName();
       
   114             } while (lockName == null);
   113         }
   115         }
   114 
   116 
   115         p.arriveAndAwaitAdvance(); // phase[2]
   117         p.arriveAndAwaitAdvance(); // phase[2]
   116         testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock1);
   118         testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock1);
   117         p.arriveAndDeregister(); // phase[3]
   119         p.arriveAndDeregister(); // phase[3]
   157         ThreadInfo ti = mbean.getThreadInfo(tid);
   159         ThreadInfo ti = mbean.getThreadInfo(tid);
   158         String lockName = null;
   160         String lockName = null;
   159         synchronized(lock1) {
   161         synchronized(lock1) {
   160             p.arriveAndAwaitAdvance(); // phase[1]
   162             p.arriveAndAwaitAdvance(); // phase[1]
   161             waitForThreadState(lt, Thread.State.BLOCKED);
   163             waitForThreadState(lt, Thread.State.BLOCKED);
   162             lockName = mbean.getThreadInfo(tid).getLockName();
   164             do {
       
   165                 lockName = mbean.getThreadInfo(tid).getLockName();
       
   166             } while (lockName == null);
   163         }
   167         }
   164         p.arriveAndAwaitAdvance(); // phase[2]
   168         p.arriveAndAwaitAdvance(); // phase[2]
   165 
   169 
   166         ti = testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock1);
   170         ti = testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock1);
   167 
   171 
   168         synchronized(lock2) {
   172         synchronized(lock2) {
   169             p.arriveAndAwaitAdvance(); // phase [3]
   173             p.arriveAndAwaitAdvance(); // phase [3]
   170             waitForThreadState(lt, Thread.State.BLOCKED);
   174             waitForThreadState(lt, Thread.State.BLOCKED);
   171             lockName = mbean.getThreadInfo(tid).getLockName();
   175             do {
       
   176                 lockName = mbean.getThreadInfo(tid).getLockName();
       
   177             } while (lockName == null);
   172         }
   178         }
   173         p.arriveAndAwaitAdvance(); // phase [4]
   179         p.arriveAndAwaitAdvance(); // phase [4]
   174         testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock2);
   180         testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock2);
   175         p.arriveAndDeregister();
   181         p.arriveAndDeregister();
   176 
   182