Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
6decff94
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6decff94
编写于
5月 26, 2009
作者:
M
mchung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6798842: TEST_BUG: ThreadStackTrace.java fails intermittently with unexpected thread status.
Summary: remove @ignore Reviewed-by: swamyv
上级
2dee6671
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
93 addition
and
53 deletion
+93
-53
test/java/lang/management/ThreadMXBean/ThreadStackTrace.java
test/java/lang/management/ThreadMXBean/ThreadStackTrace.java
+14
-53
test/java/lang/management/ThreadMXBean/Utils.java
test/java/lang/management/ThreadMXBean/Utils.java
+79
-0
未找到文件。
test/java/lang/management/ThreadMXBean/ThreadStackTrace.java
浏览文件 @
6decff94
...
@@ -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
()
{
...
...
test/java/lang/management/ThreadMXBean/Utils.java
0 → 100644
浏览文件 @
6decff94
/*
* 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
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录