jdk/test/java/lang/management/ManagementFactory/ThreadMXBeanProxy.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 13803 889df16bef60
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13803
diff changeset
     2
 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
    26
 * @bug     5086470 6358247 7193302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test type conversion when invoking ThreadMXBean.dumpAllThreads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          through proxy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main ThreadMXBeanProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import static java.lang.management.ManagementFactory.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.concurrent.locks.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.concurrent.TimeUnit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class ThreadMXBeanProxy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static MBeanServer server =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static ThreadMXBean mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static Mutex mutex = new Mutex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static MyThread thread = new MyThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static void main(String[] argv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        mbean = newPlatformMXBeanProxy(server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                       THREAD_MXBEAN_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                       ThreadMXBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (!mbean.isSynchronizerUsageSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            System.out.println("Monitoring of synchronizer usage not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        thread.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        thread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
    63
        // wait until myThread acquires mutex and lock owner is set.
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
    64
        while (!(mutex.isLocked() && mutex.getLockOwner() == thread)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
           try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
               Thread.sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
           } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
               throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        long[] ids = new long[] { thread.getId() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        // validate the local access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        ThreadInfo[] infos = getThreadMXBean().getThreadInfo(ids, true, true);
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
    76
        if (infos.length != 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            throw new RuntimeException("Returned ThreadInfo[] of length=" +
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
    78
                infos.length + ". Expected to be 1.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        thread.checkThreadInfo(infos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // validate the remote access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        infos = mbean.getThreadInfo(ids, true, true);
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
    84
        if (infos.length != 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new RuntimeException("Returned ThreadInfo[] of length=" +
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
    86
                infos.length + ". Expected to be 1.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        thread.checkThreadInfo(infos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        infos = mbean.dumpAllThreads(true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        for (ThreadInfo ti : infos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (ti.getThreadId() == thread.getId()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                thread.checkThreadInfo(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new RuntimeException("No ThreadInfo found for MyThread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    static class MyThread extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        public MyThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            super("MyThread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                mutex.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                Object o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                synchronized(o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                        o.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        int OWNED_MONITORS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        int OWNED_SYNCS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        void checkThreadInfo(ThreadInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (!getName().equals(info.getThreadName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                throw new RuntimeException("Name: " + info.getThreadName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    " not matched. Expected: " + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            MonitorInfo[] monitors = info.getLockedMonitors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (monitors.length != OWNED_MONITORS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                throw new RuntimeException("Number of locked monitors = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    monitors.length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    " not matched. Expected: " + OWNED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            MonitorInfo m = monitors[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            StackTraceElement ste = m.getLockedStackFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            int depth = m.getLockedStackDepth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            StackTraceElement[] stacktrace = info.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if (!ste.equals(stacktrace[depth])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                System.out.println("LockedStackFrame:- " + ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                System.out.println("StackTrace at " + depth + " :-" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    stacktrace[depth]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                throw new RuntimeException("LockedStackFrame does not match " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    "stack frame in ThreadInfo.getStackTrace");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
           String className = lock.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
           int hcode = System.identityHashCode(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
           if (!className.equals(m.getClassName()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                   hcode != m.getIdentityHashCode() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                   !m.getLockedStackFrame().getMethodName().equals("run")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                System.out.println(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                throw new RuntimeException("MonitorInfo " + m +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                   " doesn't match.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            LockInfo[] syncs = info.getLockedSynchronizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (syncs.length != OWNED_SYNCS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                throw new RuntimeException("Number of locked syncs = " +
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   163
                        syncs.length + " not matched. Expected: " + OWNED_SYNCS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            AbstractOwnableSynchronizer s = mutex.getSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            String lockName = s.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            hcode = System.identityHashCode(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (!lockName.equals(syncs[0].getClassName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                throw new RuntimeException("LockInfo : " + syncs[0] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    " class name not matched. Expected: " + lockName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (hcode != syncs[0].getIdentityHashCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                throw new RuntimeException("LockInfo: " + syncs[0] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    " IdentityHashCode not matched. Expected: " + hcode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   176
            LockInfo li = info.getLockInfo();
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   177
            if (li == null) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   178
                throw new RuntimeException("Expected non-null LockInfo");
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   179
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    static class Mutex implements Lock, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // Our internal helper class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        class Sync extends AbstractQueuedSynchronizer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // Report whether in locked state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            protected boolean isHeldExclusively() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                return getState() == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // Acquire the lock if state is zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            public boolean tryAcquire(int acquires) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                assert acquires == 1; // Otherwise unused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                if (compareAndSetState(0, 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    setExclusiveOwnerThread(Thread.currentThread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // Release the lock by setting state to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            protected boolean tryRelease(int releases) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                assert releases == 1; // Otherwise unused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                if (getState() == 0) throw new IllegalMonitorStateException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                setExclusiveOwnerThread(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                setState(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // Provide a Condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            Condition newCondition() { return new ConditionObject(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            // Deserialize properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                setState(0); // reset to unlocked state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   219
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   220
            protected Thread getLockOwner() {
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   221
                return getExclusiveOwnerThread();
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   222
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // The sync object does all the hard work. We just forward to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        private final Sync sync = new Sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        public void lock()                { sync.acquire(1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        public boolean tryLock()          { return sync.tryAcquire(1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        public void unlock()              { sync.release(1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        public Condition newCondition()   { return sync.newCondition(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        public boolean isLocked()         { return sync.isHeldExclusively(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public void lockInterruptibly() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            sync.acquireInterruptibly(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return sync.tryAcquireNanos(1, unit.toNanos(timeout));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
1012
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   241
        public Thread getLockOwner()     { return sync.getLockOwner(); }
c3c2f8023df1 6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
swamyv
parents: 2
diff changeset
   242
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public AbstractOwnableSynchronizer getSync() { return sync; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}