Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
Dragonwell11
提交
93fa841f
D
Dragonwell11
项目概览
LinuxSuRen
/
Dragonwell11
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
93fa841f
编写于
2月 15, 2018
作者:
M
martin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8197812: (ref) Data race in Finalizer
Reviewed-by: plevart, mchung
上级
74361b06
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
43 deletion
+32
-43
src/java.base/share/classes/java/lang/ref/Finalizer.java
src/java.base/share/classes/java/lang/ref/Finalizer.java
+32
-43
未找到文件。
src/java.base/share/classes/java/lang/ref/Finalizer.java
浏览文件 @
93fa841f
...
...
@@ -36,18 +36,18 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
class */
private
static
ReferenceQueue
<
Object
>
queue
=
new
ReferenceQueue
<>();
/** Head of doubly linked list of Finalizers awaiting finalization. */
private
static
Finalizer
unfinalized
=
null
;
private
static
final
Object
lock
=
new
Object
();
private
Finalizer
next
=
null
,
prev
=
null
;
/** Lock guarding access to unfinalized list. */
private
static
final
Object
lock
=
new
Object
();
private
boolean
hasBeenFinalized
()
{
return
(
next
==
this
);
}
private
Finalizer
next
,
prev
;
private
void
add
()
{
private
Finalizer
(
Object
finalizee
)
{
super
(
finalizee
,
queue
);
// push onto unfinalized
synchronized
(
lock
)
{
if
(
unfinalized
!=
null
)
{
this
.
next
=
unfinalized
;
...
...
@@ -57,31 +57,6 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
}
}
private
void
remove
()
{
synchronized
(
lock
)
{
if
(
unfinalized
==
this
)
{
if
(
this
.
next
!=
null
)
{
unfinalized
=
this
.
next
;
}
else
{
unfinalized
=
this
.
prev
;
}
}
if
(
this
.
next
!=
null
)
{
this
.
next
.
prev
=
this
.
prev
;
}
if
(
this
.
prev
!=
null
)
{
this
.
prev
.
next
=
this
.
next
;
}
this
.
next
=
this
;
/* Indicates that this has been finalized */
this
.
prev
=
this
;
}
}
private
Finalizer
(
Object
finalizee
)
{
super
(
finalizee
,
queue
);
add
();
}
static
ReferenceQueue
<
Object
>
getQueue
()
{
return
queue
;
}
...
...
@@ -91,11 +66,24 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
new
Finalizer
(
finalizee
);
}
private
void
runFinalizer
(
JavaLangAccess
jla
)
{
synchronized
(
this
)
{
if
(
hasBeenFinalized
())
return
;
remove
();
private
void
deregisterAndRunFinalizer
(
JavaLangAccess
jla
)
{
synchronized
(
lock
)
{
if
(
this
.
next
==
this
)
// already finalized
return
;
// unlink from unfinalized
if
(
unfinalized
==
this
)
unfinalized
=
this
.
next
;
else
this
.
prev
.
next
=
this
.
next
;
if
(
this
.
next
!=
null
)
this
.
next
.
prev
=
this
.
prev
;
this
.
prev
=
null
;
this
.
next
=
this
;
// mark as finalized
}
runFinalizer
(
jla
);
}
private
void
runFinalizer
(
JavaLangAccess
jla
)
{
try
{
Object
finalizee
=
this
.
get
();
if
(
finalizee
!=
null
&&
!(
finalizee
instanceof
java
.
lang
.
Enum
))
{
...
...
@@ -155,11 +143,8 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
return
;
final
JavaLangAccess
jla
=
SharedSecrets
.
getJavaLangAccess
();
running
=
true
;
for
(;;)
{
Finalizer
f
=
(
Finalizer
)
queue
.
poll
();
if
(
f
==
null
)
break
;
f
.
runFinalizer
(
jla
);
}
for
(
Finalizer
f
;
(
f
=
(
Finalizer
)
queue
.
poll
())
!=
null
;
)
f
.
deregisterAndRunFinalizer
(
jla
);
}
});
}
...
...
@@ -179,11 +164,15 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
final
JavaLangAccess
jla
=
SharedSecrets
.
getJavaLangAccess
();
running
=
true
;
for
(;;)
{
// "pollFirst" from unfinalized
Finalizer
f
;
synchronized
(
lock
)
{
f
=
unfinalized
;
if
(
f
==
null
)
break
;
unfinalized
=
f
.
next
;
if
(
unfinalized
!=
null
)
unfinalized
.
prev
=
null
;
f
.
next
=
f
;
// mark as finalized
}
f
.
runFinalizer
(
jla
);
}}});
...
...
@@ -214,7 +203,7 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
for
(;;)
{
try
{
Finalizer
f
=
(
Finalizer
)
queue
.
remove
();
f
.
r
unFinalizer
(
jla
);
f
.
deregisterAndR
unFinalizer
(
jla
);
}
catch
(
InterruptedException
x
)
{
// ignore and continue
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录