Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
1b8ed27a
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
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,发现更多精彩内容 >>
提交
1b8ed27a
编写于
3月 09, 2017
作者:
M
mchung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8175797: (ref) Reference::enqueue method should clear referent before enqueuing
Reviewed-by: alanb, kbarrett, mr
上级
ce6d369e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
78 addition
and
13 deletion
+78
-13
jdk/src/java.base/share/classes/java/lang/ref/FinalReference.java
...java.base/share/classes/java/lang/ref/FinalReference.java
+6
-1
jdk/src/java.base/share/classes/java/lang/ref/Reference.java
jdk/src/java.base/share/classes/java/lang/ref/Reference.java
+17
-9
jdk/test/java/lang/ref/ReferenceEnqueue.java
jdk/test/java/lang/ref/ReferenceEnqueue.java
+55
-3
未找到文件。
jdk/src/java.base/share/classes/java/lang/ref/FinalReference.java
浏览文件 @
1b8ed27a
/*
* Copyright (c) 1997, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
7
, 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
...
...
@@ -33,4 +33,9 @@ class FinalReference<T> extends Reference<T> {
public
FinalReference
(
T
referent
,
ReferenceQueue
<?
super
T
>
q
)
{
super
(
referent
,
q
);
}
@Override
public
boolean
enqueue
()
{
throw
new
InternalError
(
"should never reach here"
);
}
}
jdk/src/java.base/share/classes/java/lang/ref/Reference.java
浏览文件 @
1b8ed27a
/*
* Copyright (c) 1997, 201
6
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
7
, 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
...
...
@@ -140,15 +140,24 @@ public abstract class Reference<T> {
}
}
/* Atomically get and clear (set to null) the VM's pending list.
/*
* system property to disable clearing before enqueuing.
*/
private
static
final
boolean
disableClearBeforeEnqueue
=
Boolean
.
getBoolean
(
"jdk.lang.ref.disableClearBeforeEnqueue"
);
/*
* Atomically get and clear (set to null) the VM's pending list.
*/
private
static
native
Reference
<
Object
>
getAndClearReferencePendingList
();
/* Test whether the VM's pending list contains any entries.
/*
* Test whether the VM's pending list contains any entries.
*/
private
static
native
boolean
hasReferencePendingList
();
/* Wait until the VM's pending list may be non-null.
/*
* Wait until the VM's pending list may be non-null.
*/
private
static
native
void
waitForReferencePendingList
();
...
...
@@ -261,7 +270,6 @@ public abstract class Reference<T> {
this
.
referent
=
null
;
}
/* -- Queue operations -- */
/**
...
...
@@ -278,8 +286,8 @@ public abstract class Reference<T> {
}
/**
*
Adds this reference object to the queue with which it is registered,
* if any.
*
Clears this reference object and adds it to the queue with which
* i
t is registered, i
f any.
*
* <p> This method is invoked only by Java code; when the garbage collector
* enqueues references it does so directly, without invoking this method.
...
...
@@ -289,10 +297,11 @@ public abstract class Reference<T> {
* it was not registered with a queue when it was created
*/
public
boolean
enqueue
()
{
if
(!
disableClearBeforeEnqueue
)
this
.
referent
=
null
;
return
this
.
queue
.
enqueue
(
this
);
}
/* -- Constructors -- */
Reference
(
T
referent
)
{
...
...
@@ -419,5 +428,4 @@ public abstract class Reference<T> {
// HotSpot needs to retain the ref and not GC it before a call to this
// method
}
}
jdk/test/java/lang/ref/ReferenceEnqueue.java
浏览文件 @
1b8ed27a
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011,
2017,
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
...
...
@@ -22,17 +22,23 @@
*/
/* @test
* @bug 4268317 8132306
* @bug 4268317 8132306
8175797
* @summary Test if Reference.enqueue() works properly with GC
* @run main ReferenceEnqueue
* @run main/othervm -Djdk.lang.ref.disableClearAndEnqueue=true ReferenceEnqueue
*/
import
java.lang.ref.*
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
ReferenceEnqueue
{
public
static
void
main
(
String
args
[])
throws
Exception
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
new
WeakRef
().
run
();
new
ExplicitEnqueue
().
run
();
}
System
.
out
.
println
(
"Test passed."
);
}
...
...
@@ -76,4 +82,50 @@ public class ReferenceEnqueue {
}
}
}
static
class
ExplicitEnqueue
{
final
ReferenceQueue
<
Object
>
queue
=
new
ReferenceQueue
<>();
final
List
<
Reference
<
Object
>>
refs
=
new
ArrayList
<>();
final
int
iterations
=
1000
;
final
boolean
disableClearAndEnqueue
=
Boolean
.
parseBoolean
(
"jdk.lang.ref.disableClearAndEnqueue"
);
ExplicitEnqueue
()
{
this
.
refs
.
add
(
new
SoftReference
<>(
new
Object
(),
queue
));
this
.
refs
.
add
(
new
WeakReference
<>(
new
Object
(),
queue
));
this
.
refs
.
add
(
new
PhantomReference
<>(
new
Object
(),
queue
));
}
void
run
()
throws
InterruptedException
{
for
(
Reference
<
Object
>
ref
:
refs
)
{
if
(
ref
.
enqueue
()
==
false
)
{
throw
new
RuntimeException
(
"Error: enqueue failed"
);
}
if
(
disableClearAndEnqueue
&&
ref
.
get
()
==
null
)
{
throw
new
RuntimeException
(
"Error: clearing should be disabled"
);
}
if
(!
disableClearAndEnqueue
&&
ref
.
get
()
!=
null
)
{
throw
new
RuntimeException
(
"Error: referent must be cleared"
);
}
}
System
.
gc
();
for
(
int
i
=
0
;
refs
.
size
()
>
0
&&
i
<
iterations
;
i
++)
{
Reference
<
Object
>
ref
=
(
Reference
<
Object
>)
queue
.
poll
();
if
(
ref
==
null
)
{
System
.
gc
();
Thread
.
sleep
(
100
);
continue
;
}
if
(
refs
.
remove
(
ref
)
==
false
)
{
throw
new
RuntimeException
(
"Error: unknown reference "
+
ref
);
}
}
if
(!
refs
.
isEmpty
())
{
throw
new
RuntimeException
(
"Error: not all references are removed"
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录