Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
b22391ba
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看板
提交
b22391ba
编写于
9月 25, 2013
作者:
M
malenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8023310: Thread contention in the method Beans.IsDesignTime()
Reviewed-by: art, sfriberg
上级
6b21a48b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
72 deletion
+77
-72
src/share/classes/java/beans/ThreadGroupContext.java
src/share/classes/java/beans/ThreadGroupContext.java
+7
-11
src/share/classes/java/beans/WeakIdentityMap.java
src/share/classes/java/beans/WeakIdentityMap.java
+70
-61
未找到文件。
src/share/classes/java/beans/ThreadGroupContext.java
浏览文件 @
b22391ba
...
...
@@ -41,24 +41,20 @@ import java.util.WeakHashMap;
*/
final
class
ThreadGroupContext
{
private
static
final
WeakIdentityMap
<
ThreadGroupContext
>
contexts
=
new
WeakIdentityMap
<>();
private
static
final
WeakIdentityMap
<
ThreadGroupContext
>
contexts
=
new
WeakIdentityMap
<
ThreadGroupContext
>()
{
protected
ThreadGroupContext
create
(
Object
key
)
{
return
new
ThreadGroupContext
();
}
};
/**
* Returns the appropriate {@code
Ap
pContext} for the caller,
* Returns the appropriate {@code
ThreadGrou
pContext} for the caller,
* as determined by its {@code ThreadGroup}.
*
* @return the application-dependent context
*/
static
ThreadGroupContext
getContext
()
{
ThreadGroup
group
=
Thread
.
currentThread
().
getThreadGroup
();
synchronized
(
contexts
)
{
ThreadGroupContext
context
=
contexts
.
get
(
group
);
if
(
context
==
null
)
{
context
=
new
ThreadGroupContext
();
contexts
.
put
(
group
,
context
);
}
return
context
;
}
return
contexts
.
get
(
Thread
.
currentThread
().
getThreadGroup
());
}
private
volatile
boolean
isDesignTime
;
...
...
src/share/classes/java/beans/WeakIdentityMap.java
浏览文件 @
b22391ba
...
...
@@ -33,18 +33,22 @@ import java.lang.ref.WeakReference;
* and reference-equality in place of object-equality to compare them.
* An entry will automatically be removed when its key is no longer
* in ordinary use. Both null values and the null key are supported.
* This class does not require additional synchronization.
* A thread-safety is provided by a fragile combination
* of synchronized blocks and volatile fields.
* Be very careful during editing!
*
* @see java.util.IdentityHashMap
* @see java.util.WeakHashMap
*/
final
class
WeakIdentityMap
<
T
>
{
abstract
class
WeakIdentityMap
<
T
>
{
private
static
final
int
MAXIMUM_CAPACITY
=
1
<<
30
;
// it MUST be a power of two
private
static
final
Object
NULL
=
new
Object
();
// special object for null key
private
final
ReferenceQueue
<
Object
>
queue
=
new
ReferenceQueue
<
Object
>();
private
Entry
<
T
>[]
table
=
newTable
(
1
<<
3
);
// table's length MUST be a power of two
private
volatile
Entry
<
T
>[]
table
=
newTable
(
1
<<
3
);
// table's length MUST be a power of two
private
int
threshold
=
6
;
// the next size value at which to resize
private
int
size
=
0
;
// the number of key-value mappings
...
...
@@ -54,78 +58,83 @@ final class WeakIdentityMap<T> {
key
=
NULL
;
}
int
hash
=
key
.
hashCode
();
int
index
=
getIndex
(
this
.
table
,
hash
);
for
(
Entry
<
T
>
entry
=
this
.
table
[
index
];
entry
!=
null
;
entry
=
entry
.
next
)
{
Entry
<
T
>[]
table
=
this
.
table
;
// unsynchronized search improves performance
// the null value does not mean that there are no needed entry
int
index
=
getIndex
(
table
,
hash
);
for
(
Entry
<
T
>
entry
=
table
[
index
];
entry
!=
null
;
entry
=
entry
.
next
)
{
if
(
entry
.
isMatched
(
key
,
hash
))
{
return
entry
.
value
;
}
}
return
null
;
}
public
T
put
(
Object
key
,
T
value
)
{
removeStaleEntries
();
if
(
key
==
null
)
{
key
=
NULL
;
}
int
hash
=
key
.
hashCode
();
int
index
=
getIndex
(
this
.
table
,
hash
);
for
(
Entry
<
T
>
entry
=
this
.
table
[
index
];
entry
!=
null
;
entry
=
entry
.
next
)
{
if
(
entry
.
isMatched
(
key
,
hash
))
{
T
oldValue
=
entry
.
value
;
entry
.
value
=
value
;
return
oldValue
;
}
}
this
.
table
[
index
]
=
new
Entry
<
T
>(
key
,
hash
,
value
,
this
.
queue
,
this
.
table
[
index
]);
if
(++
this
.
size
>=
this
.
threshold
)
{
if
(
this
.
table
.
length
==
MAXIMUM_CAPACITY
)
{
this
.
threshold
=
Integer
.
MAX_VALUE
;
synchronized
(
NULL
)
{
// synchronized search improves stability
// we must create and add new value if there are no needed entry
index
=
getIndex
(
this
.
table
,
hash
);
for
(
Entry
<
T
>
entry
=
this
.
table
[
index
];
entry
!=
null
;
entry
=
entry
.
next
)
{
if
(
entry
.
isMatched
(
key
,
hash
))
{
return
entry
.
value
;
}
}
else
{
removeStaleEntries
();
Entry
<
T
>[]
table
=
newTable
(
this
.
table
.
length
*
2
);
transfer
(
this
.
table
,
table
);
// If ignoring null elements and processing ref queue caused massive
// shrinkage, then restore old table. This should be rare, but avoids
// unbounded expansion of garbage-filled tables.
if
(
this
.
size
>=
this
.
threshold
/
2
)
{
this
.
table
=
table
;
this
.
threshold
*=
2
;
T
value
=
create
(
key
);
this
.
table
[
index
]
=
new
Entry
<
T
>(
key
,
hash
,
value
,
this
.
queue
,
this
.
table
[
index
]);
if
(++
this
.
size
>=
this
.
threshold
)
{
if
(
this
.
table
.
length
==
MAXIMUM_CAPACITY
)
{
this
.
threshold
=
Integer
.
MAX_VALUE
;
}
else
{
transfer
(
table
,
this
.
table
);
removeStaleEntries
();
table
=
newTable
(
this
.
table
.
length
*
2
);
transfer
(
this
.
table
,
table
);
// If ignoring null elements and processing ref queue caused massive
// shrinkage, then restore old table. This should be rare, but avoids
// unbounded expansion of garbage-filled tables.
if
(
this
.
size
>=
this
.
threshold
/
2
)
{
this
.
table
=
table
;
this
.
threshold
*=
2
;
}
else
{
transfer
(
table
,
this
.
table
);
}
}
}
return
value
;
}
return
null
;
}
protected
abstract
T
create
(
Object
key
);
private
void
removeStaleEntries
()
{
for
(
Object
ref
=
this
.
queue
.
poll
();
ref
!=
null
;
ref
=
this
.
queue
.
poll
())
{
@SuppressWarnings
(
"unchecked"
)
Entry
<
T
>
entry
=
(
Entry
<
T
>)
ref
;
int
index
=
getIndex
(
this
.
table
,
entry
.
hash
);
Entry
<
T
>
prev
=
this
.
table
[
index
];
Entry
<
T
>
current
=
prev
;
while
(
current
!=
null
)
{
Entry
<
T
>
next
=
current
.
next
;
if
(
current
==
entry
)
{
if
(
prev
==
entry
)
{
this
.
table
[
index
]
=
next
;
Object
ref
=
this
.
queue
.
poll
();
if
(
ref
!=
null
)
{
synchronized
(
NULL
)
{
do
{
@SuppressWarnings
(
"unchecked"
)
Entry
<
T
>
entry
=
(
Entry
<
T
>)
ref
;
int
index
=
getIndex
(
this
.
table
,
entry
.
hash
);
Entry
<
T
>
prev
=
this
.
table
[
index
];
Entry
<
T
>
current
=
prev
;
while
(
current
!=
null
)
{
Entry
<
T
>
next
=
current
.
next
;
if
(
current
==
entry
)
{
if
(
prev
==
entry
)
{
this
.
table
[
index
]
=
next
;
}
else
{
prev
.
next
=
next
;
}
entry
.
value
=
null
;
// Help GC
entry
.
next
=
null
;
// Help GC
this
.
size
--;
break
;
}
prev
=
current
;
current
=
next
;
}
else
{
prev
.
next
=
next
;
}
entry
.
value
=
null
;
// Help GC
entry
.
next
=
null
;
// Help GC
this
.
size
--;
break
;
ref
=
this
.
queue
.
poll
();
}
prev
=
current
;
current
=
next
;
while
(
ref
!=
null
);
}
}
}
...
...
@@ -164,8 +173,8 @@ final class WeakIdentityMap<T> {
private
static
class
Entry
<
T
>
extends
WeakReference
<
Object
>
{
private
final
int
hash
;
private
T
value
;
private
Entry
<
T
>
next
;
private
volatile
T
value
;
private
volatile
Entry
<
T
>
next
;
Entry
(
Object
key
,
int
hash
,
T
value
,
ReferenceQueue
<
Object
>
queue
,
Entry
<
T
>
next
)
{
super
(
key
,
queue
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录