Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
b5100569
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看板
提交
b5100569
编写于
2月 28, 2013
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8006409: ThreadLocalRandom should dropping padding fields from its serialized form
Reviewed-by: dl, martin, alanb, shade
上级
1548b7f0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
48 deletion
+30
-48
src/share/classes/java/util/concurrent/ThreadLocalRandom.java
...share/classes/java/util/concurrent/ThreadLocalRandom.java
+30
-48
未找到文件。
src/share/classes/java/util/concurrent/ThreadLocalRandom.java
浏览文件 @
b5100569
...
...
@@ -83,22 +83,20 @@ public class ThreadLocalRandom extends Random {
* programs.
*
* Because this class is in a different package than class Thread,
* field access methods must use Unsafe to bypass access control
* rules. The base functionality of Random methods is
* conveniently isolated in method next(bits), that just reads and
* writes the Thread field rather than its own field. However, to
* conform to the requirements of the Random constructor, during
* construction, the common static ThreadLocalRandom must maintain
* initialization and value fields, mainly for the sake of
* disabling user calls to setSeed while still allowing a call
* from constructor. For serialization compatibility, these
* fields are left with the same declarations as used in the
* previous ThreadLocal-based version of this class, that used
* them differently. Note that serialization is completely
* unnecessary because there is only a static singleton. But these
* mechanics still ensure compatibility across versions.
* field access methods use Unsafe to bypass access control rules.
* The base functionality of Random methods is conveniently
* isolated in method next(bits), that just reads and writes the
* Thread field rather than its own field. However, to conform to
* the requirements of the Random superclass constructor, the
* common static ThreadLocalRandom maintains an "initialized"
* field for the sake of rejecting user calls to setSeed while
* still allowing a call from constructor. Note that
* serialization is completely unnecessary because there is only a
* static singleton. But we generate a serial form containing
* "rnd" and "initialized" fields to ensure compatibility across
* versions.
*
* Per-
instance
initialization is similar to that in the no-arg
* Per-
thread
initialization is similar to that in the no-arg
* Random constructor, but we avoid correlation among not only
* initial seeds of those created in different threads, but also
* those created using class Random itself; while at the same time
...
...
@@ -132,10 +130,11 @@ public class ThreadLocalRandom extends Random {
private
static
final
ThreadLocal
<
Double
>
nextLocalGaussian
=
new
ThreadLocal
<
Double
>();
/*
* Field used only during singleton initialization
/**
* Field used only during singleton initialization.
* True when constructor completes.
*/
boolean
initialized
;
// true when constructor completes
boolean
initialized
;
/** Constructor used only for static singleton */
private
ThreadLocalRandom
()
{
...
...
@@ -184,7 +183,8 @@ public class ThreadLocalRandom extends Random {
* @throws UnsupportedOperationException always
*/
public
void
setSeed
(
long
seed
)
{
if
(
initialized
)
// allow call from super() constructor
// only allow call from super() constructor
if
(
initialized
)
throw
new
UnsupportedOperationException
();
}
...
...
@@ -357,39 +357,29 @@ public class ThreadLocalRandom extends Random {
r
^=
r
>>>
17
;
r
^=
r
<<
5
;
}
else
if
((
r
=
(
int
)
UNSAFE
.
getLong
(
t
,
SEED
))
==
0
)
r
=
1
;
// avoid zero
else
{
localInit
();
if
((
r
=
(
int
)
UNSAFE
.
getLong
(
t
,
SEED
))
==
0
)
r
=
1
;
// avoid zero
}
UNSAFE
.
putInt
(
t
,
SECONDARY
,
r
);
return
r
;
}
// Serialization support
, maintains original persistent form.
// Serialization support
private
static
final
long
serialVersionUID
=
-
5851777807851030925L
;
/**
* @serialField rnd long
* seed for random computations
* @serialField initialized boolean
* @serialField pad0 long
* @serialField pad1 long
* @serialField pad2 long
* @serialField pad3 long
* @serialField pad4 long
* @serialField pad5 long
* @serialField pad6 long
* @serialField pad7 long
* always true
*/
private
static
final
ObjectStreamField
[]
serialPersistentFields
=
{
new
ObjectStreamField
(
"rnd"
,
long
.
class
),
new
ObjectStreamField
(
"initialized"
,
boolean
.
class
),
new
ObjectStreamField
(
"pad0"
,
long
.
class
),
new
ObjectStreamField
(
"pad1"
,
long
.
class
),
new
ObjectStreamField
(
"pad2"
,
long
.
class
),
new
ObjectStreamField
(
"pad3"
,
long
.
class
),
new
ObjectStreamField
(
"pad4"
,
long
.
class
),
new
ObjectStreamField
(
"pad5"
,
long
.
class
),
new
ObjectStreamField
(
"pad6"
,
long
.
class
),
new
ObjectStreamField
(
"pad7"
,
long
.
class
)
};
new
ObjectStreamField
(
"initialized"
,
boolean
.
class
)
};
/**
* Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it).
...
...
@@ -398,16 +388,8 @@ public class ThreadLocalRandom extends Random {
throws
java
.
io
.
IOException
{
java
.
io
.
ObjectOutputStream
.
PutField
fields
=
out
.
putFields
();
fields
.
put
(
"rnd"
,
0L
);
fields
.
put
(
"rnd"
,
UNSAFE
.
getLong
(
Thread
.
currentThread
(),
SEED
)
);
fields
.
put
(
"initialized"
,
true
);
fields
.
put
(
"pad0"
,
0L
);
fields
.
put
(
"pad1"
,
0L
);
fields
.
put
(
"pad2"
,
0L
);
fields
.
put
(
"pad3"
,
0L
);
fields
.
put
(
"pad4"
,
0L
);
fields
.
put
(
"pad5"
,
0L
);
fields
.
put
(
"pad6"
,
0L
);
fields
.
put
(
"pad7"
,
0L
);
out
.
writeFields
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录