Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f211a4ab
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
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看板
提交
f211a4ab
编写于
4月 03, 2015
作者:
J
jbachorik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids
Reviewed-by: mchung
上级
6f254023
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
12 deletion
+77
-12
src/share/classes/sun/management/ThreadImpl.java
src/share/classes/sun/management/ThreadImpl.java
+9
-1
test/java/lang/management/ThreadMXBean/ThreadInfoArray.java
test/java/lang/management/ThreadMXBean/ThreadInfoArray.java
+68
-11
未找到文件。
src/share/classes/sun/management/ThreadImpl.java
浏览文件 @
f211a4ab
/*
* Copyright (c) 2003, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 201
5
, Oracle and/or its affiliates. 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
...
...
@@ -165,6 +165,10 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
"Invalid maxDepth parameter: "
+
maxDepth
);
}
// ids has been verified to be non-null
// an empty array of ids should return an empty array of ThreadInfos
if
(
ids
.
length
==
0
)
return
new
ThreadInfo
[
0
];
Util
.
checkMonitorAccess
();
ThreadInfo
[]
infos
=
new
ThreadInfo
[
ids
.
length
];
// nulls
...
...
@@ -436,6 +440,10 @@ class ThreadImpl implements com.sun.management.ThreadMXBean {
boolean
lockedMonitors
,
boolean
lockedSynchronizers
)
{
verifyThreadIds
(
ids
);
// ids has been verified to be non-null
// an empty array of ids should return an empty array of ThreadInfos
if
(
ids
.
length
==
0
)
return
new
ThreadInfo
[
0
];
verifyDumpThreads
(
lockedMonitors
,
lockedSynchronizers
);
return
dumpThreads0
(
ids
,
lockedMonitors
,
lockedSynchronizers
);
}
...
...
test/java/lang/management/ThreadMXBean/ThreadInfoArray.java
浏览文件 @
f211a4ab
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004,
2015,
Oracle and/or its affiliates. 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
...
...
@@ -23,11 +23,12 @@
/*
* @test
* @bug 5058327
* @summary Test
if getThreadInfo(long[]) returns a ThreadInfo[]
*
with null elements with no exception
.
* @bug 5058327
8074368
* @summary Test
s the correct behaviour of getThreadInfo(long[]) for non-existent
*
thread IDs and the empty thread id array
.
*
* @author Mandy Chung
* @author Jaroslav Bachorik
*
* @build ThreadInfoArray
* @run main ThreadInfoArray
...
...
@@ -35,15 +36,30 @@
import
java.lang.management.*
;
import
javax.management.*
;
import
java.util.*
;
import
static
java
.
lang
.
management
.
ManagementFactory
.*;
public
class
ThreadInfoArray
{
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
MBeanServer
mbs
=
ManagementFactory
.
getPlatformMBeanServer
();
ObjectName
on
=
new
ObjectName
(
THREAD_MXBEAN_NAME
);
ThreadMXBean
mbean
=
ManagementFactory
.
getThreadMXBean
();
ThreadMXBean
proxy
=
newPlatformMXBeanProxy
(
mbs
,
on
.
toString
(),
ThreadMXBean
.
class
);
checkNullElement
(
mbean
,
proxy
,
mbs
,
on
);
checkEmptyArray
(
mbean
,
proxy
,
mbs
,
on
);
System
.
out
.
println
(
"Test passed"
);
}
private
static
void
checkNullElement
(
ThreadMXBean
mbean
,
ThreadMXBean
proxy
,
MBeanServer
mbs
,
ObjectName
on
)
throws
Exception
{
System
.
out
.
println
(
"--- Check null element"
);
// ID for a new thread
long
[]
ids
=
{
new
Thread
().
getId
()};
// direct call
ThreadInfo
[]
tinfos
=
mbean
.
getThreadInfo
(
ids
);
if
(
tinfos
[
0
]
!=
null
)
{
...
...
@@ -52,8 +68,6 @@ public class ThreadInfoArray {
}
// call getThreadInfo through MBeanServer
MBeanServer
mbs
=
ManagementFactory
.
getPlatformMBeanServer
();
ObjectName
on
=
new
ObjectName
(
THREAD_MXBEAN_NAME
);
Object
[]
params
=
{
ids
};
String
[]
sigs
=
{
"[J"
};
Object
[]
result
=
(
Object
[])
mbs
.
invoke
(
on
,
"getThreadInfo"
,
params
,
sigs
);
...
...
@@ -64,14 +78,57 @@ public class ThreadInfoArray {
}
// call getThreadInfo through proxy
ThreadMXBean
proxy
=
newPlatformMXBeanProxy
(
mbs
,
on
.
toString
(),
ThreadMXBean
.
class
);
tinfos
=
proxy
.
getThreadInfo
(
ids
);
if
(
tinfos
[
0
]
!=
null
)
{
throw
new
RuntimeException
(
"TEST FAILED: "
+
"Expected to have a null element"
);
}
System
.
out
.
println
(
"Test passed"
);
System
.
out
.
println
(
"--- PASSED"
);
}
private
static
void
checkEmptyArray
(
ThreadMXBean
mbean
,
ThreadMXBean
proxy
,
MBeanServer
mbs
,
ObjectName
on
)
throws
Exception
{
System
.
out
.
println
(
"--- Check empty TID array"
);
long
[]
ids
=
new
long
[
0
];
// direct call
assertEmptyArray
(
mbean
.
getThreadInfo
(
ids
),
"Expected empty ThreadInfo array"
);
assertEmptyArray
(
mbean
.
getThreadInfo
(
ids
,
1
),
"Expected empty ThreadInfo array"
);
assertEmptyArray
(
mbean
.
getThreadInfo
(
ids
,
true
,
true
),
"Expected empty ThreadInfo array"
);
// call getThreadInfo through MBeanServer
assertEmptyArray
(
(
Object
[])
mbs
.
invoke
(
on
,
"getThreadInfo"
,
new
Object
[]{
ids
},
new
String
[]{
"[J"
}
),
"Expected empty ThreadInfo array via MBeanServer"
);
assertEmptyArray
(
(
Object
[])
mbs
.
invoke
(
on
,
"getThreadInfo"
,
new
Object
[]{
ids
,
1
},
new
String
[]{
"[J"
,
"int"
}
),
"Expected empty ThreadInfo array via MBeanServer"
);
assertEmptyArray
(
(
Object
[])
mbs
.
invoke
(
on
,
"getThreadInfo"
,
new
Object
[]{
ids
,
true
,
true
},
new
String
[]{
"[J"
,
"boolean"
,
"boolean"
}
),
"Expected empty ThreadInfo array via MBeanServer"
);
// call getThreadInfo through proxy
assertEmptyArray
(
proxy
.
getThreadInfo
(
ids
),
"Expected empty ThreadInfo array"
);
assertEmptyArray
(
proxy
.
getThreadInfo
(
ids
,
1
),
"Expected empty ThreadInfo array"
);
assertEmptyArray
(
proxy
.
getThreadInfo
(
ids
,
true
,
true
),
"Expected empty ThreadInfo array"
);
System
.
out
.
println
(
"--- PASSED"
);
}
private
static
void
assertEmptyArray
(
Object
[]
arr
,
String
message
)
throws
Exception
{
if
(
arr
.
length
>
0
)
{
throw
new
RuntimeException
(
"TEST FAILED: "
+
message
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录