Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
9429412d
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,发现更多精彩内容 >>
提交
9429412d
编写于
7月 01, 2014
作者:
J
jbachorik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8038794: java/lang/management/ThreadMXBean/SynchronizationStatistics.java fails intermittently
Reviewed-by: sla
上级
a0504280
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
88 addition
and
45 deletion
+88
-45
test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java
...ng/management/ThreadMXBean/SynchronizationStatistics.java
+88
-45
未找到文件。
test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java
浏览文件 @
9429412d
...
...
@@ -34,6 +34,7 @@
import
java.lang.management.*
;
import
java.util.concurrent.Phaser
;
import
java.util.function.Supplier
;
public
class
SynchronizationStatistics
{
private
static
class
LockerThread
extends
Thread
{
...
...
@@ -86,6 +87,8 @@ public class SynchronizationStatistics {
private
static
void
testBlockingOnSimpleMonitor
()
throws
Exception
{
System
.
out
.
println
(
"testBlockingOnSimpleMonitor"
);
final
Object
lock1
=
new
Object
();
System
.
out
.
println
(
"Lock1 = "
+
lock1
);
final
Phaser
p
=
new
Phaser
(
2
);
LockerThread
lt
=
newLockerThread
(
new
Runnable
()
{
@Override
...
...
@@ -110,12 +113,12 @@ public class SynchronizationStatistics {
}
p
.
arriveAndAwaitAdvance
();
// phase[2]
testBlocked
(
ti
,
mbean
.
getThreadInfo
(
tid
),
lockName
,
lock1
);
testBlocked
(
ti
,
()
->
mbean
.
getThreadInfo
(
tid
),
lockName
,
lock1
);
p
.
arriveAndDeregister
();
// phase[3]
lt
.
join
();
System
.
out
.
println
(
"OK"
);
printok
(
);
}
/**
...
...
@@ -128,6 +131,9 @@ public class SynchronizationStatistics {
final
Object
lock1
=
new
Object
();
final
Object
lock2
=
new
Object
();
System
.
out
.
println
(
"Lock1 = "
+
lock1
);
System
.
out
.
println
(
"Lock2 = "
+
lock2
);
final
Phaser
p
=
new
Phaser
(
2
);
LockerThread
lt
=
newLockerThread
(
new
Runnable
()
{
@Override
...
...
@@ -149,7 +155,6 @@ public class SynchronizationStatistics {
lt
.
start
();
long
tid
=
lt
.
getId
();
ThreadInfo
ti
=
mbean
.
getThreadInfo
(
tid
);
ThreadInfo
ti1
=
null
;
String
lockName
=
null
;
synchronized
(
lock1
)
{
p
.
arriveAndAwaitAdvance
();
// phase[1]
...
...
@@ -158,9 +163,7 @@ public class SynchronizationStatistics {
}
p
.
arriveAndAwaitAdvance
();
// phase[2]
ti1
=
mbean
.
getThreadInfo
(
tid
);
testBlocked
(
ti
,
ti1
,
lockName
,
lock1
);
ti
=
ti1
;
ti
=
testBlocked
(
ti
,
()
->
mbean
.
getThreadInfo
(
tid
),
lockName
,
lock1
);
synchronized
(
lock2
)
{
p
.
arriveAndAwaitAdvance
();
// phase [3]
...
...
@@ -168,12 +171,12 @@ public class SynchronizationStatistics {
lockName
=
mbean
.
getThreadInfo
(
tid
).
getLockName
();
}
p
.
arriveAndAwaitAdvance
();
// phase [4]
testBlocked
(
ti
,
mbean
.
getThreadInfo
(
tid
),
lockName
,
lock2
);
testBlocked
(
ti
,
()
->
mbean
.
getThreadInfo
(
tid
),
lockName
,
lock2
);
p
.
arriveAndDeregister
();
lt
.
join
();
System
.
out
.
println
(
"OK"
);
printok
(
);
}
/**
...
...
@@ -209,13 +212,12 @@ public class SynchronizationStatistics {
}
p
.
arriveAndAwaitAdvance
();
// phase[2]
ThreadInfo
ti2
=
mbean
.
getThreadInfo
(
lt
.
getId
()
);
testWaited
(
ti1
,
()
->
mbean
.
getThreadInfo
(
lt
.
getId
()),
1
);
p
.
arriveAndDeregister
();
// phase[3]
lt
.
join
();
testWaited
(
ti1
,
ti2
,
1
);
System
.
out
.
println
(
"OK"
);
printok
();
}
/**
...
...
@@ -256,12 +258,12 @@ public class SynchronizationStatistics {
int
phase
=
p
.
getPhase
();
while
((
p
.
arriveAndAwaitAdvance
()
-
phase
)
<
3
);
// phase[2-4]
ThreadInfo
ti2
=
mbean
.
getThreadInfo
(
lt
.
getId
()
);
testWaited
(
ti1
,
()
->
mbean
.
getThreadInfo
(
lt
.
getId
()),
3
);
p
.
arriveAndDeregister
();
// phase[5]
lt
.
join
();
testWaited
(
ti1
,
ti2
,
3
);
System
.
out
.
println
(
"OK"
);
printok
(
);
}
/**
...
...
@@ -331,44 +333,85 @@ public class SynchronizationStatistics {
}
p
.
arriveAndAwaitAdvance
();
// phase[4]
ThreadInfo
ti2
=
mbean
.
getThreadInfo
(
lt
.
getId
()
);
testWaited
(
ti1
,
()
->
mbean
.
getThreadInfo
(
lt
.
getId
()),
3
);
p
.
arriveAndDeregister
();
// phase[5]
lt
.
join
();
testWaited
(
ti1
,
ti2
,
3
);
System
.
out
.
println
(
"OK"
);
printok
();
}
private
static
void
testWaited
(
ThreadInfo
ti1
,
ThreadInfo
ti2
,
int
waited
)
throws
Error
{
long
waitCntDiff
=
ti2
.
getWaitedCount
()
-
ti1
.
getWaitedCount
();
long
waitTimeDiff
=
ti2
.
getWaitedTime
()
-
ti1
.
getWaitedTime
();
if
(
waitCntDiff
<
waited
)
{
throw
new
Error
(
"Unexpected diff in waited count. Expecting at least "
+
waited
+
" , got "
+
waitCntDiff
);
}
if
(
waitTimeDiff
<=
0
)
{
throw
new
Error
(
"Unexpected diff in waited time. Expecting increasing "
+
"value, got "
+
waitTimeDiff
+
"ms"
);
}
private
static
void
printok
()
{
System
.
out
.
println
(
"OK\n"
);
}
private
static
void
testBlocked
(
ThreadInfo
ti1
,
ThreadInfo
ti2
,
private
static
void
testWaited
(
ThreadInfo
ti1
,
Supplier
<
ThreadInfo
>
ti2
,
int
waited
)
throws
InterruptedException
{
boolean
error
;
do
{
error
=
false
;
ThreadInfo
ti
=
ti2
.
get
();
long
waitCntDiff
=
ti
.
getWaitedCount
()
-
ti1
.
getWaitedCount
();
long
waitTimeDiff
=
ti
.
getWaitedTime
()
-
ti1
.
getWaitedTime
();
if
(
waitCntDiff
<
waited
)
{
System
.
err
.
println
(
"Unexpected diff in waited count. Expecting at least "
+
waited
+
" , got "
+
waitCntDiff
);
error
=
true
;
}
if
(
waitTimeDiff
<=
0
)
{
System
.
err
.
println
(
"Unexpected diff in waited time. Expecting increasing "
+
"value, got "
+
waitTimeDiff
+
"ms"
);
error
=
true
;
}
if
(
error
)
{
System
.
err
.
println
(
"Retrying in 20ms ..."
);
Thread
.
sleep
(
20
);
}
}
while
(
error
);
}
private
static
ThreadInfo
testBlocked
(
ThreadInfo
ti1
,
Supplier
<
ThreadInfo
>
ti2
,
String
lockName
,
final
Object
lock
)
throws
Error
{
long
blkCntDiff
=
ti2
.
getBlockedCount
()
-
ti1
.
getBlockedCount
();
long
blkTimeDiff
=
ti2
.
getBlockedTime
()
-
ti1
.
getBlockedTime
();
if
(
blkCntDiff
<
1
)
{
throw
new
Error
(
"Unexpected diff in blocked count. Expecting at least 1, "
+
"got "
+
blkCntDiff
);
}
if
(
blkTimeDiff
<
0
)
{
throw
new
Error
(
"Unexpected diff in blocked time. Expecting a positive "
+
"number, got "
+
blkTimeDiff
);
}
if
(!
lockName
.
equals
(
lock
.
toString
()))
{
throw
new
Error
(
"Unexpected blocked monitor name. Expecting "
+
lock
.
toString
()
+
", got "
+
lockName
);
}
throws
InterruptedException
{
boolean
error
;
ThreadInfo
ti
=
null
;
do
{
error
=
false
;
ti
=
ti2
.
get
();
long
blkCntDiff
=
ti
.
getBlockedCount
()
-
ti1
.
getBlockedCount
();
long
blkTimeDiff
=
ti
.
getBlockedTime
()
-
ti1
.
getBlockedTime
();
System
.
out
.
println
(
"testBlocked: ["
+
blkCntDiff
+
", "
+
blkTimeDiff
+
", "
+
lockName
+
"]"
);
if
(
blkCntDiff
<
1
)
{
System
.
err
.
println
(
"Unexpected diff in blocked count. Expecting at least 1, "
+
"got "
+
blkCntDiff
);
error
=
true
;
}
if
(
blkTimeDiff
<
0
)
{
System
.
err
.
println
(
"Unexpected diff in blocked time. Expecting a positive "
+
"number, got "
+
blkTimeDiff
);
error
=
true
;
}
if
(!
lockName
.
equals
(
lock
.
toString
()))
{
System
.
err
.
println
(
"Unexpected blocked monitor name. Expecting "
+
lock
.
toString
()
+
", got "
+
lockName
);
error
=
true
;
}
if
(
error
)
{
System
.
err
.
println
(
"Retrying in 20ms ..."
);
Thread
.
sleep
(
20
);
}
}
while
(
error
);
return
ti
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录