Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
ec5059f2
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看板
提交
ec5059f2
编写于
10月 12, 2011
作者:
D
dl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7082299: AtomicReferenceArray should ensure that array is Object[]
Reviewed-by: chegar, dholmes, alanb
上级
687fc027
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
8 deletion
+35
-8
src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java
...ses/java/util/concurrent/atomic/AtomicReferenceArray.java
+35
-8
未找到文件。
src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java
浏览文件 @
ec5059f2
...
...
@@ -34,8 +34,10 @@
*/
package
java.util.concurrent.atomic
;
import
java.lang.reflect.Array
;
import
java.util.Arrays
;
import
sun.misc.Unsafe
;
import
java.util.*
;
/**
* An array of object references in which elements may be updated
...
...
@@ -49,13 +51,23 @@ import java.util.*;
public
class
AtomicReferenceArray
<
E
>
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
-
6209656149925076980L
;
private
static
final
Unsafe
unsafe
=
Unsafe
.
getUnsafe
()
;
private
static
final
int
base
=
unsafe
.
arrayBaseOffset
(
Object
[].
class
)
;
private
static
final
Unsafe
unsafe
;
private
static
final
int
base
;
private
static
final
int
shift
;
private
final
Object
[]
array
;
private
static
final
long
arrayFieldOffset
;
private
final
Object
[]
array
;
// must have exact type Object[]
static
{
int
scale
=
unsafe
.
arrayIndexScale
(
Object
[].
class
);
int
scale
;
try
{
unsafe
=
Unsafe
.
getUnsafe
();
arrayFieldOffset
=
unsafe
.
objectFieldOffset
(
AtomicReferenceArray
.
class
.
getDeclaredField
(
"array"
));
base
=
unsafe
.
arrayBaseOffset
(
Object
[].
class
);
scale
=
unsafe
.
arrayIndexScale
(
Object
[].
class
);
}
catch
(
Exception
e
)
{
throw
new
Error
(
e
);
}
if
((
scale
&
(
scale
-
1
))
!=
0
)
throw
new
Error
(
"data type scale not a power of two"
);
shift
=
31
-
Integer
.
numberOfLeadingZeros
(
scale
);
...
...
@@ -91,7 +103,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
*/
public
AtomicReferenceArray
(
E
[]
array
)
{
// Visibility guaranteed by final field guarantees
this
.
array
=
array
.
clone
(
);
this
.
array
=
Arrays
.
copyOf
(
array
,
array
.
length
,
Object
[].
class
);
}
/**
...
...
@@ -150,7 +162,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
public
final
E
getAndSet
(
int
i
,
E
newValue
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
E
current
=
(
E
)
getRaw
(
offset
);
E
current
=
getRaw
(
offset
);
if
(
compareAndSetRaw
(
offset
,
current
,
newValue
))
return
current
;
}
...
...
@@ -196,7 +208,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* @return the String representation of the current values of array
*/
public
String
toString
()
{
int
iMax
=
array
.
length
-
1
;
int
iMax
=
array
.
length
-
1
;
if
(
iMax
==
-
1
)
return
"[]"
;
...
...
@@ -210,4 +222,19 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
}
}
/**
* Reconstitutes the instance from a stream (that is, deserializes it).
* @param s the stream
*/
private
void
readObject
(
java
.
io
.
ObjectInputStream
s
)
throws
java
.
io
.
IOException
,
ClassNotFoundException
{
// Note: This must be changed if any additional fields are defined
Object
a
=
s
.
readFields
().
get
(
"array"
,
null
);
if
(
a
==
null
||
!
a
.
getClass
().
isArray
())
throw
new
java
.
io
.
InvalidObjectException
(
"Not array type"
);
if
(
a
.
getClass
()
!=
Object
[].
class
)
a
=
Arrays
.
copyOf
((
Object
[])
a
,
Array
.
getLength
(
a
),
Object
[].
class
);
unsafe
.
putObjectVolatile
(
this
,
arrayFieldOffset
,
a
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录