提交 7d9fc750 编写于 作者: K kamg

Merge

...@@ -1237,7 +1237,6 @@ public abstract class URLConnection { ...@@ -1237,7 +1237,6 @@ public abstract class URLConnection {
} }
private static Hashtable handlers = new Hashtable(); private static Hashtable handlers = new Hashtable();
private static final ContentHandler UnknownContentHandlerP = new UnknownContentHandler();
/** /**
* Gets the Content Handler appropriate for this connection. * Gets the Content Handler appropriate for this connection.
...@@ -1264,7 +1263,7 @@ public abstract class URLConnection { ...@@ -1264,7 +1263,7 @@ public abstract class URLConnection {
handler = lookupContentHandlerClassFor(contentType); handler = lookupContentHandlerClassFor(contentType);
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
handler = UnknownContentHandlerP; handler = UnknownContentHandler.INSTANCE;
} }
handlers.put(contentType, handler); handlers.put(contentType, handler);
} }
...@@ -1335,7 +1334,7 @@ public abstract class URLConnection { ...@@ -1335,7 +1334,7 @@ public abstract class URLConnection {
} }
} }
return UnknownContentHandlerP; return UnknownContentHandler.INSTANCE;
} }
/** /**
...@@ -1761,6 +1760,8 @@ public abstract class URLConnection { ...@@ -1761,6 +1760,8 @@ public abstract class URLConnection {
class UnknownContentHandler extends ContentHandler { class UnknownContentHandler extends ContentHandler {
static final ContentHandler INSTANCE = new UnknownContentHandler();
public Object getContent(URLConnection uc) throws IOException { public Object getContent(URLConnection uc) throws IOException {
return uc.getInputStream(); return uc.getInputStream();
} }
......
...@@ -228,6 +228,25 @@ PHONY_LIST += packtest packtest_stress ...@@ -228,6 +228,25 @@ PHONY_LIST += packtest packtest_stress
################################################################ ################################################################
# perftest to collect statistics
# Expect JPRT to set JPRT_PACKTEST_HOME.
PERFTEST_HOME = ${TEST_ROOT}/perf
ifdef JPRT_PERFTEST_HOME
PERFTEST_HOME = $(JPRT_PERFTEST_HOME)
endif
perftest: ( $(PERFTEST_HOME)/perftest \
-t $(shell $(GETMIXEDPATH) "$(PRODUCT_HOME)") \
-w $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)") \
-h $(PERFTEST_HOME) \
) ; $(BUNDLE_UP_AND_EXIT)
PHONY_LIST += perftest
################################################################
# vmsqe tests # vmsqe tests
# Expect JPRT to set JPRT_VMSQE_HOME. # Expect JPRT to set JPRT_VMSQE_HOME.
......
...@@ -66,6 +66,8 @@ public class LockingThread extends Thread { ...@@ -66,6 +66,8 @@ public class LockingThread extends Thread {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
Utils.waitForBlockWaitingState(t1);
Utils.waitForBlockWaitingState(t2);
} }
static long[] getThreadIds() { static long[] getThreadIds() {
return new long[] {t1.getId(), t2.getId()}; return new long[] {t1.getId(), t2.getId()};
......
...@@ -83,11 +83,24 @@ public class MonitorDeadlock { ...@@ -83,11 +83,24 @@ public class MonitorDeadlock {
void waitUntilDeadlock() { void waitUntilDeadlock() {
barr.await(); barr.await();
// sleep a little while to wait until threads are blocked.
try { for (int i=0; i < 100; i++) {
Thread.sleep(100); // sleep a little while to wait until threads are blocked.
} catch (InterruptedException e) { try {
// ignore Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
boolean retry = false;
for (Thread t: dThreads) {
if (t.getState() == Thread.State.RUNNABLE) {
retry = true;
break;
}
}
if (!retry) {
break;
}
} }
} }
......
...@@ -83,11 +83,24 @@ public class SynchronizerDeadlock { ...@@ -83,11 +83,24 @@ public class SynchronizerDeadlock {
void waitUntilDeadlock() { void waitUntilDeadlock() {
barr.await(); barr.await();
// sleep a little while to wait until threads are blocked.
try { for (int i=0; i < 100; i++) {
Thread.sleep(100); // sleep a little while to wait until threads are blocked.
} catch (InterruptedException e) { try {
// ignore Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
boolean retry = false;
for (Thread t: dThreads) {
if (t.getState() == Thread.State.RUNNABLE) {
retry = true;
break;
}
}
if (!retry) {
break;
}
} }
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* monitors. * monitors.
* @author Mandy Chung * @author Mandy Chung
* *
* @build ThreadDump * @build ThreadDump Utils
*/ */
import java.lang.management.*; import java.lang.management.*;
...@@ -63,6 +63,9 @@ public class SynchronizerLockingThread extends Thread { ...@@ -63,6 +63,9 @@ public class SynchronizerLockingThread extends Thread {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
Utils.waitForBlockWaitingState(t1);
Utils.waitForBlockWaitingState(t2);
} }
static long[] getThreadIds() { static long[] getThreadIds() {
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* ThreadInfo.getThreadState() * ThreadInfo.getThreadState()
* @author Mandy Chung * @author Mandy Chung
* *
* @run build Semaphore * @run build Semaphore Utils
* @run main ThreadStackTrace * @run main ThreadStackTrace
*/ */
...@@ -48,16 +48,6 @@ public class ThreadStackTrace { ...@@ -48,16 +48,6 @@ public class ThreadStackTrace {
private static int esDepth = 3; private static int esDepth = 3;
private static int methodExamine1= 2; private static int methodExamine1= 2;
private static void goSleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("Unexpected exception.");
testFailed = true;
}
}
private static void checkNullThreadInfo(Thread t) throws Exception { private static void checkNullThreadInfo(Thread t) throws Exception {
ThreadInfo ti = mbean.getThreadInfo(t.getId()); ThreadInfo ti = mbean.getThreadInfo(t.getId());
if (ti != null) { if (ti != null) {
...@@ -96,7 +86,7 @@ public class ThreadStackTrace { ...@@ -96,7 +86,7 @@ public class ThreadStackTrace {
"is waiting to begin."); "is waiting to begin.");
// The Examiner should be waiting to be notified by the BlockedThread // The Examiner should be waiting to be notified by the BlockedThread
checkThreadState(examiner, Thread.State.WAITING); Utils.checkThreadState(examiner, Thread.State.WAITING);
// Check that the stack is returned correctly for a new thread // Check that the stack is returned correctly for a new thread
checkStack(examiner, examinerStack, esDepth); checkStack(examiner, examinerStack, esDepth);
...@@ -135,35 +125,6 @@ public class ThreadStackTrace { ...@@ -135,35 +125,6 @@ public class ThreadStackTrace {
} }
} }
private static void checkThreadState(Thread thread, Thread.State s)
throws Exception {
ThreadInfo ti = mbean.getThreadInfo(thread.getId());
if (ti.getThreadState() != s) {
ThreadInfo info =
mbean.getThreadInfo(thread.getId(), Integer.MAX_VALUE);
System.out.println(INDENT + "TEST FAILED:");
printStack(thread, info.getStackTrace());
System.out.println(INDENT + "Thread state: " + info.getThreadState());
throw new RuntimeException("TEST FAILED: " +
"Thread state for " + thread + " returns " + ti.getThreadState() +
". Expected to be " + s);
}
}
private static void checkThreadState(Thread thread,
Thread.State s1, Thread.State s2)
throws Exception {
ThreadInfo ti = mbean.getThreadInfo(thread.getId());
if (ti.getThreadState() != s1 && ti.getThreadState() != s2) {
throw new RuntimeException("TEST FAILED: " +
"Thread state for " + thread + " returns " + ti.getThreadState() +
". Expected to be " + s1 + " or " + s2);
}
}
private static void checkStack(Thread t, String[] expectedStack, private static void checkStack(Thread t, String[] expectedStack,
int depth) throws Exception { int depth) throws Exception {
ThreadInfo ti = mbean.getThreadInfo(t.getId(), Integer.MAX_VALUE); ThreadInfo ti = mbean.getThreadInfo(t.getId(), Integer.MAX_VALUE);
...@@ -197,20 +158,20 @@ public class ThreadStackTrace { ...@@ -197,20 +158,20 @@ public class ThreadStackTrace {
handshake.semaP(); handshake.semaP();
// give a chance for the examiner thread to really wait // give a chance for the examiner thread to really wait
goSleep(20); Utils.goSleep(20);
} }
void waitUntilLockAReleased() { void waitUntilLockAReleased() {
handshake.semaP(); handshake.semaP();
// give a chance for the examiner thread to really wait // give a chance for the examiner thread to really wait
goSleep(50); Utils.goSleep(50);
} }
private void notifyWaiter() { private void notifyWaiter() {
// wait until the examiner waits on the semaphore // wait until the examiner waits on the semaphore
while (handshake.getWaiterCount() == 0) { while (handshake.getWaiterCount() == 0) {
goSleep(20); Utils.goSleep(20);
} }
handshake.semaV(); handshake.semaV();
} }
...@@ -278,10 +239,10 @@ public class ThreadStackTrace { ...@@ -278,10 +239,10 @@ public class ThreadStackTrace {
// wait until the examiner is waiting for blockedThread's notification // wait until the examiner is waiting for blockedThread's notification
while (!blockedThread.hasWaitersForBlocked()) { while (!blockedThread.hasWaitersForBlocked()) {
goSleep(50); Utils.goSleep(50);
} }
// give a chance for the examiner thread to really wait // give a chance for the examiner thread to really wait
goSleep(20); Utils.goSleep(20);
} }
private Thread itself; private Thread itself;
...@@ -290,7 +251,7 @@ public class ThreadStackTrace { ...@@ -290,7 +251,7 @@ public class ThreadStackTrace {
examine2(); examine2();
try { try {
System.out.println("Checking examiner's its own stack trace"); System.out.println("Checking examiner's its own stack trace");
checkThreadState(itself, Thread.State.RUNNABLE); Utils.checkThreadState(itself, Thread.State.RUNNABLE);
checkStack(itself, examinerStack, methodExamine1); checkStack(itself, examinerStack, methodExamine1);
// wait until blockedThread is blocked on lockB // wait until blockedThread is blocked on lockB
...@@ -298,7 +259,7 @@ public class ThreadStackTrace { ...@@ -298,7 +259,7 @@ public class ThreadStackTrace {
System.out.println("Checking stack trace for " + System.out.println("Checking stack trace for " +
"BlockedThread - should be blocked on lockB."); "BlockedThread - should be blocked on lockB.");
checkThreadState(blockedThread, Thread.State.BLOCKED); Utils.checkThreadState(blockedThread, Thread.State.BLOCKED);
checkStack(blockedThread, blockedStack, methodB); checkStack(blockedThread, blockedStack, methodB);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -312,7 +273,7 @@ public class ThreadStackTrace { ...@@ -312,7 +273,7 @@ public class ThreadStackTrace {
synchronized (lockA) { synchronized (lockA) {
// wait until main thread gets signalled of the semaphore // wait until main thread gets signalled of the semaphore
while (handshake.getWaiterCount() == 0) { while (handshake.getWaiterCount() == 0) {
goSleep(20); Utils.goSleep(20);
} }
handshake.semaV(); // notify the main thread handshake.semaV(); // notify the main thread
...@@ -321,12 +282,12 @@ public class ThreadStackTrace { ...@@ -321,12 +282,12 @@ public class ThreadStackTrace {
blockedThread.waitUntilBlocked(); blockedThread.waitUntilBlocked();
System.out.println("Checking examiner's its own stack trace"); System.out.println("Checking examiner's its own stack trace");
checkThreadState(itself, Thread.State.RUNNABLE); Utils.checkThreadState(itself, Thread.State.RUNNABLE);
checkStack(itself, examinerStack, esDepth); checkStack(itself, examinerStack, esDepth);
System.out.println("Checking stack trace for " + System.out.println("Checking stack trace for " +
"BlockedThread - should be blocked on lockA."); "BlockedThread - should be blocked on lockA.");
checkThreadState(blockedThread, Thread.State.BLOCKED); Utils.checkThreadState(blockedThread, Thread.State.BLOCKED);
checkStack(blockedThread, blockedStack, bsDepth); checkStack(blockedThread, blockedStack, bsDepth);
} catch (Exception e) { } catch (Exception e) {
...@@ -344,7 +305,7 @@ public class ThreadStackTrace { ...@@ -344,7 +305,7 @@ public class ThreadStackTrace {
try { try {
System.out.println("Checking stack trace for " + System.out.println("Checking stack trace for " +
"BlockedThread - should be waiting on lockA."); "BlockedThread - should be waiting on lockA.");
checkThreadState(blockedThread, Thread.State.WAITING); Utils.checkThreadState(blockedThread, Thread.State.WAITING);
checkStack(blockedThread, blockedStack, bsDepth); checkStack(blockedThread, blockedStack, bsDepth);
// Let the blocked thread go // Let the blocked thread go
...@@ -357,7 +318,7 @@ public class ThreadStackTrace { ...@@ -357,7 +318,7 @@ public class ThreadStackTrace {
} }
} }
// give some time for BlockedThread to proceed // give some time for BlockedThread to proceed
goSleep(50); Utils.goSleep(50);
} // examine2() } // examine2()
public void run() { public void run() {
......
...@@ -24,14 +24,13 @@ ...@@ -24,14 +24,13 @@
/* /*
* @test * @test
* @bug 4967283 5080203 * @bug 4967283 5080203
* @ignore Due to 5080203, cannot rely on this test always passing.
* @summary Basic unit test of thread states returned by * @summary Basic unit test of thread states returned by
* ThreadMXBean.getThreadInfo.getThreadState(). * ThreadMXBean.getThreadInfo.getThreadState().
* It also tests lock information returned by ThreadInfo. * It also tests lock information returned by ThreadInfo.
* *
* @author Mandy Chung * @author Mandy Chung
* *
* @build ThreadExecutionSynchronizer * @build ThreadExecutionSynchronizer Utils
* @run main ThreadStateTest * @run main ThreadStateTest
*/ */
...@@ -43,7 +42,6 @@ import java.util.concurrent.locks.LockSupport; ...@@ -43,7 +42,6 @@ import java.util.concurrent.locks.LockSupport;
public class ThreadStateTest { public class ThreadStateTest {
private static final ThreadMXBean tm = ManagementFactory.getThreadMXBean(); private static final ThreadMXBean tm = ManagementFactory.getThreadMXBean();
private static boolean testFailed = false;
static class Lock { static class Lock {
private String name; private String name;
...@@ -64,32 +62,32 @@ public class ThreadStateTest { ...@@ -64,32 +62,32 @@ public class ThreadStateTest {
MyThread myThread = new MyThread("MyThread"); MyThread myThread = new MyThread("MyThread");
// before myThread starts // before myThread starts
// checkThreadState(myThread, Thread.State.NEW); // Utils.checkThreadState(myThread, Thread.State.NEW);
myThread.start(); myThread.start();
myThread.waitUntilStarted(); myThread.waitUntilStarted();
checkThreadState(myThread, Thread.State.RUNNABLE); Utils.checkThreadState(myThread, Thread.State.RUNNABLE);
checkLockInfo(myThread, Thread.State.RUNNABLE, null, null); checkLockInfo(myThread, Thread.State.RUNNABLE, null, null);
myThread.suspend(); myThread.suspend();
goSleep(10); Utils.goSleep(10);
checkSuspendedThreadState(myThread, Thread.State.RUNNABLE); checkSuspendedThreadState(myThread, Thread.State.RUNNABLE);
myThread.resume(); myThread.resume();
synchronized (globalLock) { synchronized (globalLock) {
myThread.goBlocked(); myThread.goBlocked();
checkThreadState(myThread, Thread.State.BLOCKED); Utils.checkThreadState(myThread, Thread.State.BLOCKED);
checkLockInfo(myThread, Thread.State.BLOCKED, checkLockInfo(myThread, Thread.State.BLOCKED,
globalLock, Thread.currentThread()); globalLock, Thread.currentThread());
} }
myThread.goWaiting(); myThread.goWaiting();
checkThreadState(myThread, Thread.State.WAITING); Utils.checkThreadState(myThread, Thread.State.WAITING);
checkLockInfo(myThread, Thread.State.WAITING, checkLockInfo(myThread, Thread.State.WAITING,
globalLock, null); globalLock, null);
myThread.goTimedWaiting(); myThread.goTimedWaiting();
checkThreadState(myThread, Thread.State.TIMED_WAITING); Utils.checkThreadState(myThread, Thread.State.TIMED_WAITING);
checkLockInfo(myThread, Thread.State.TIMED_WAITING, checkLockInfo(myThread, Thread.State.TIMED_WAITING,
globalLock, null); globalLock, null);
...@@ -102,32 +100,30 @@ public class ThreadStateTest { ...@@ -102,32 +100,30 @@ public class ThreadStateTest {
Bug ID : 5062095 Bug ID : 5062095
*********************************************** ***********************************************
myThread.goParked(); myThread.goParked();
checkThreadState(myThread, Thread.State.WAITING); Utils.checkThreadState(myThread, Thread.State.WAITING);
checkLockInfo(myThread, Thread.State.WAITING, null, null); checkLockInfo(myThread, Thread.State.WAITING, null, null);
myThread.goTimedParked(); myThread.goTimedParked();
checkThreadState(myThread, Thread.State.TIMED_WAITING); Utils.checkThreadState(myThread, Thread.State.TIMED_WAITING);
checkLockInfo(myThread, Thread.State.TIMED_WAITING, null, null); checkLockInfo(myThread, Thread.State.TIMED_WAITING, null, null);
*/ */
myThread.goSleeping(); myThread.goSleeping();
checkThreadState(myThread, Thread.State.TIMED_WAITING); Utils.checkThreadState(myThread, Thread.State.TIMED_WAITING);
checkLockInfo(myThread, Thread.State.TIMED_WAITING, null, null); checkLockInfo(myThread, Thread.State.TIMED_WAITING, null, null);
myThread.terminate(); myThread.terminate();
// checkThreadState(myThread, ThreadState.TERMINATED); // Utils.checkThreadState(myThread, ThreadState.TERMINATED);
try { try {
myThread.join(); myThread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Unexpected exception."); System.out.println("TEST FAILED: Unexpected exception.");
testFailed = true; throw new RuntimeException(e);
} }
if (testFailed)
throw new RuntimeException("TEST FAILED.");
System.out.println("Test passed."); System.out.println("Test passed.");
} }
...@@ -148,32 +144,7 @@ public class ThreadStateTest { ...@@ -148,32 +144,7 @@ public class ThreadStateTest {
throw new RuntimeException(t.getName() + " expected to be suspended " + throw new RuntimeException(t.getName() + " expected to be suspended " +
" but isSuspended() returns " + info.isSuspended()); " but isSuspended() returns " + info.isSuspended());
} }
checkThreadState(t, state); Utils.checkThreadState(t, state);
}
private static void checkThreadState(Thread t, Thread.State expected) {
ThreadInfo ti = tm.getThreadInfo(t.getId());
Thread.State state = ti.getThreadState();
if (state == null) {
throw new RuntimeException(t.getName() + " expected to have " +
expected + " but got null.");
}
if (state != expected) {
if (expected == Thread.State.BLOCKED) {
int retryCount=0;
while (ti.getThreadState() != expected) {
if (retryCount >= 500) {
throw new RuntimeException(t.getName() +
" expected to have " + expected + " but got " + state);
}
goSleep(100);
}
} else {
throw new RuntimeException(t.getName() + " expected to have " +
expected + " but got " + state);
}
}
} }
private static String getLockName(Object lock) { private static String getLockName(Object lock) {
...@@ -250,16 +221,6 @@ public class ThreadStateTest { ...@@ -250,16 +221,6 @@ public class ThreadStateTest {
} }
} }
private static void goSleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("Unexpected exception.");
testFailed = true;
}
}
static class MyThread extends Thread { static class MyThread extends Thread {
private ThreadExecutionSynchronizer thrsync = new ThreadExecutionSynchronizer(); private ThreadExecutionSynchronizer thrsync = new ThreadExecutionSynchronizer();
...@@ -335,7 +296,7 @@ public class ThreadStateTest { ...@@ -335,7 +296,7 @@ public class ThreadStateTest {
LockSupport.park(); LockSupport.park();
// give a chance for the main thread to block // give a chance for the main thread to block
System.out.println(" myThread is going to park."); System.out.println(" myThread is going to park.");
goSleep(10); Utils.goSleep(10);
break; break;
} }
case TIMED_PARKED: { case TIMED_PARKED: {
...@@ -346,7 +307,7 @@ public class ThreadStateTest { ...@@ -346,7 +307,7 @@ public class ThreadStateTest {
LockSupport.parkUntil(deadline); LockSupport.parkUntil(deadline);
// give a chance for the main thread to block // give a chance for the main thread to block
goSleep(10); Utils.goSleep(10);
break; break;
} }
case SLEEPING: { case SLEEPING: {
...@@ -375,7 +336,7 @@ public class ThreadStateTest { ...@@ -375,7 +336,7 @@ public class ThreadStateTest {
public void waitUntilStarted() { public void waitUntilStarted() {
// wait for MyThread. // wait for MyThread.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(10); Utils.goSleep(10);
} }
public void goBlocked() { public void goBlocked() {
...@@ -383,7 +344,7 @@ public class ThreadStateTest { ...@@ -383,7 +344,7 @@ public class ThreadStateTest {
setState(BLOCKED); setState(BLOCKED);
// wait for MyThread to get blocked // wait for MyThread to get blocked
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
public void goWaiting() { public void goWaiting() {
...@@ -391,28 +352,28 @@ public class ThreadStateTest { ...@@ -391,28 +352,28 @@ public class ThreadStateTest {
setState(WAITING); setState(WAITING);
// wait for MyThread to wait on object. // wait for MyThread to wait on object.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
public void goTimedWaiting() { public void goTimedWaiting() {
System.out.println("Waiting myThread to go timed waiting."); System.out.println("Waiting myThread to go timed waiting.");
setState(TIMED_WAITING); setState(TIMED_WAITING);
// wait for MyThread timed wait call. // wait for MyThread timed wait call.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
public void goParked() { public void goParked() {
System.out.println("Waiting myThread to go parked."); System.out.println("Waiting myThread to go parked.");
setState(PARKED); setState(PARKED);
// wait for MyThread state change to PARKED. // wait for MyThread state change to PARKED.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
public void goTimedParked() { public void goTimedParked() {
System.out.println("Waiting myThread to go timed parked."); System.out.println("Waiting myThread to go timed parked.");
setState(TIMED_PARKED); setState(TIMED_PARKED);
// wait for MyThread. // wait for MyThread.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
public void goSleeping() { public void goSleeping() {
...@@ -420,21 +381,21 @@ public class ThreadStateTest { ...@@ -420,21 +381,21 @@ public class ThreadStateTest {
setState(SLEEPING); setState(SLEEPING);
// wait for MyThread. // wait for MyThread.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
public void terminate() { public void terminate() {
System.out.println("Waiting myThread to terminate."); System.out.println("Waiting myThread to terminate.");
setState(TERMINATE); setState(TERMINATE);
// wait for MyThread. // wait for MyThread.
thrsync.waitForSignal(); thrsync.waitForSignal();
goSleep(20); Utils.goSleep(20);
} }
private void setState(int newState) { private void setState(int newState) {
switch (state) { switch (state) {
case BLOCKED: case BLOCKED:
while (state == BLOCKED) { while (state == BLOCKED) {
goSleep(20); Utils.goSleep(20);
} }
state = newState; state = newState;
break; break;
......
/*
* Copyright 2003-2006 Sun Microsystems, Inc. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* Utility class for ThreadMXBean tests
*/
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
public class Utils {
private static final ThreadMXBean tm = ManagementFactory.getThreadMXBean();
private static final int MAX_RETRY = 200;
public static boolean waitForBlockWaitingState(Thread t) {
// wait for the thread to transition to the expected state
int retryCount=0;
while (t.getState() == Thread.State.RUNNABLE && retryCount < MAX_RETRY) {
goSleep(100);
retryCount++;
}
return (t.getState() != Thread.State.RUNNABLE);
}
public static boolean waitForThreadState(Thread t, Thread.State expected) {
// wait for the thread to transition to the expected state
int retryCount=0;
while (t.getState() != expected && retryCount < MAX_RETRY) {
goSleep(100);
retryCount++;
}
return (t.getState() == expected);
}
public static void checkThreadState(Thread t, Thread.State expected) {
waitForThreadState(t, expected);
Thread.State state = tm.getThreadInfo(t.getId()).getThreadState();
if (state == null) {
throw new RuntimeException(t.getName() + " expected to have " +
expected + " but got null.");
}
if (state != expected) {
t.dumpStack();
throw new RuntimeException(t.getName() +
" expected to have " + expected + " but got " + state);
}
}
public static void goSleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("TEST FAILED: Unexpected exception.");
throw new RuntimeException(e);
}
}
}
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
/* /*
* @test * @test
* @bug 6467152 6716076 6829503 * @bug 6467152 6716076 6829503
* @ignore Until made more stable, see 6829636.
* @summary deadlock occurs in LogManager initialization and JVM termination * @summary deadlock occurs in LogManager initialization and JVM termination
* @author Serguei Spitsyn / Hitachi / Martin Buchholz * @author Serguei Spitsyn / Hitachi / Martin Buchholz
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册