Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
b8a7c6dc
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看板
体验新版 GitCode,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
b8a7c6dc
编写于
1月 10, 2013
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8006007: j.u.c.atomic classes should use intrinsic getAndXXX provided by 7023898
Reviewed-by: dl, shade
上级
5abc5d76
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
204 addition
and
242 deletion
+204
-242
src/share/classes/java/util/concurrent/atomic/AtomicBoolean.java
...re/classes/java/util/concurrent/atomic/AtomicBoolean.java
+7
-7
src/share/classes/java/util/concurrent/atomic/AtomicInteger.java
...re/classes/java/util/concurrent/atomic/AtomicInteger.java
+9
-43
src/share/classes/java/util/concurrent/atomic/AtomicIntegerArray.java
...asses/java/util/concurrent/atomic/AtomicIntegerArray.java
+6
-22
src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
...ava/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
+71
-41
src/share/classes/java/util/concurrent/atomic/AtomicLong.java
...share/classes/java/util/concurrent/atomic/AtomicLong.java
+9
-43
src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java
.../classes/java/util/concurrent/atomic/AtomicLongArray.java
+6
-22
src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
...s/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
+73
-43
src/share/classes/java/util/concurrent/atomic/AtomicReference.java
.../classes/java/util/concurrent/atomic/AtomicReference.java
+4
-7
src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java
...ses/java/util/concurrent/atomic/AtomicReferenceArray.java
+3
-7
src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
...a/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
+16
-7
未找到文件。
src/share/classes/java/util/concurrent/atomic/AtomicBoolean.java
浏览文件 @
b8a7c6dc
...
...
@@ -111,7 +111,7 @@ public class AtomicBoolean implements java.io.Serializable {
*
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
boolean
weakCompareAndSet
(
boolean
expect
,
boolean
update
)
{
int
e
=
expect
?
1
:
0
;
...
...
@@ -146,16 +146,16 @@ public class AtomicBoolean implements java.io.Serializable {
* @return the previous value
*/
public
final
boolean
getAndSet
(
boolean
newValue
)
{
for
(;;)
{
boolean
current
=
get
();
if
(
compareAndSet
(
current
,
newValue
))
return
current
;
}
boolean
prev
;
do
{
prev
=
get
();
}
while
(!
compareAndSet
(
prev
,
newValue
))
;
return
prev
;
}
/**
* Returns the String representation of the current value.
* @return the String representation of the current value
.
* @return the String representation of the current value
*/
public
String
toString
()
{
return
Boolean
.
toString
(
get
());
...
...
src/share/classes/java/util/concurrent/atomic/AtomicInteger.java
浏览文件 @
b8a7c6dc
...
...
@@ -115,11 +115,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
int
getAndSet
(
int
newValue
)
{
for
(;;)
{
int
current
=
get
();
if
(
compareAndSet
(
current
,
newValue
))
return
current
;
}
return
unsafe
.
getAndSetInt
(
this
,
valueOffset
,
newValue
);
}
/**
...
...
@@ -145,7 +141,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
*
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
final
boolean
weakCompareAndSet
(
int
expect
,
int
update
)
{
return
unsafe
.
compareAndSwapInt
(
this
,
valueOffset
,
expect
,
update
);
...
...
@@ -157,12 +153,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
int
getAndIncrement
()
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
+
1
;
if
(
compareAndSet
(
current
,
next
))
return
current
;
}
return
getAndAdd
(
1
);
}
/**
...
...
@@ -171,12 +162,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
int
getAndDecrement
()
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
-
1
;
if
(
compareAndSet
(
current
,
next
))
return
current
;
}
return
getAndAdd
(-
1
);
}
/**
...
...
@@ -186,12 +172,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
int
getAndAdd
(
int
delta
)
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
+
delta
;
if
(
compareAndSet
(
current
,
next
))
return
current
;
}
return
unsafe
.
getAndAddInt
(
this
,
valueOffset
,
delta
);
}
/**
...
...
@@ -200,12 +181,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value
*/
public
final
int
incrementAndGet
()
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
+
1
;
if
(
compareAndSet
(
current
,
next
))
return
next
;
}
return
getAndAdd
(
1
)
+
1
;
}
/**
...
...
@@ -214,12 +190,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value
*/
public
final
int
decrementAndGet
()
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
-
1
;
if
(
compareAndSet
(
current
,
next
))
return
next
;
}
return
getAndAdd
(-
1
)
-
1
;
}
/**
...
...
@@ -229,17 +200,12 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value
*/
public
final
int
addAndGet
(
int
delta
)
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
+
delta
;
if
(
compareAndSet
(
current
,
next
))
return
next
;
}
return
getAndAdd
(
delta
)
+
delta
;
}
/**
* Returns the String representation of the current value.
* @return the String representation of the current value
.
* @return the String representation of the current value
*/
public
String
toString
()
{
return
Integer
.
toString
(
get
());
...
...
src/share/classes/java/util/concurrent/atomic/AtomicIntegerArray.java
浏览文件 @
b8a7c6dc
...
...
@@ -145,12 +145,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the previous value
*/
public
final
int
getAndSet
(
int
i
,
int
newValue
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
int
current
=
getRaw
(
offset
);
if
(
compareAndSetRaw
(
offset
,
current
,
newValue
))
return
current
;
}
return
unsafe
.
getAndSetInt
(
array
,
checkedByteOffset
(
i
),
newValue
);
}
/**
...
...
@@ -182,7 +177,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @param i the index
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
final
boolean
weakCompareAndSet
(
int
i
,
int
expect
,
int
update
)
{
return
compareAndSet
(
i
,
expect
,
update
);
...
...
@@ -216,12 +211,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the previous value
*/
public
final
int
getAndAdd
(
int
i
,
int
delta
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
int
current
=
getRaw
(
offset
);
if
(
compareAndSetRaw
(
offset
,
current
,
current
+
delta
))
return
current
;
}
return
unsafe
.
getAndAddInt
(
array
,
checkedByteOffset
(
i
),
delta
);
}
/**
...
...
@@ -231,7 +221,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the updated value
*/
public
final
int
incrementAndGet
(
int
i
)
{
return
addAndGet
(
i
,
1
)
;
return
getAndAdd
(
i
,
1
)
+
1
;
}
/**
...
...
@@ -241,7 +231,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the updated value
*/
public
final
int
decrementAndGet
(
int
i
)
{
return
addAndGet
(
i
,
-
1
)
;
return
getAndAdd
(
i
,
-
1
)
-
1
;
}
/**
...
...
@@ -252,13 +242,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the updated value
*/
public
final
int
addAndGet
(
int
i
,
int
delta
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
int
current
=
getRaw
(
offset
);
int
next
=
current
+
delta
;
if
(
compareAndSetRaw
(
offset
,
current
,
next
))
return
next
;
}
return
getAndAdd
(
i
,
delta
)
+
delta
;
}
/**
...
...
src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
浏览文件 @
b8a7c6dc
...
...
@@ -159,11 +159,11 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value
*/
public
int
getAndSet
(
T
obj
,
int
newValue
)
{
for
(;;)
{
int
current
=
get
(
obj
);
if
(
compareAndSet
(
obj
,
current
,
newValue
))
return
current
;
}
int
prev
;
do
{
prev
=
get
(
obj
);
}
while
(!
compareAndSet
(
obj
,
prev
,
newValue
))
;
return
prev
;
}
/**
...
...
@@ -174,12 +174,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value
*/
public
int
getAndIncrement
(
T
obj
)
{
for
(;;)
{
int
current
=
get
(
obj
);
int
next
=
current
+
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
current
;
}
int
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
prev
;
}
/**
...
...
@@ -190,12 +190,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value
*/
public
int
getAndDecrement
(
T
obj
)
{
for
(;;)
{
int
current
=
get
(
obj
);
int
next
=
current
-
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
current
;
}
int
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
-
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
prev
;
}
/**
...
...
@@ -207,12 +207,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value
*/
public
int
getAndAdd
(
T
obj
,
int
delta
)
{
for
(;;)
{
int
current
=
get
(
obj
);
int
next
=
current
+
delta
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
current
;
}
int
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
delta
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
prev
;
}
/**
...
...
@@ -223,12 +223,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the updated value
*/
public
int
incrementAndGet
(
T
obj
)
{
for
(;;)
{
int
current
=
get
(
obj
);
int
next
=
current
+
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
next
;
}
int
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
next
;
}
/**
...
...
@@ -239,12 +239,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the updated value
*/
public
int
decrementAndGet
(
T
obj
)
{
for
(;;)
{
int
current
=
get
(
obj
);
int
next
=
current
-
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
next
;
}
int
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
-
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
next
;
}
/**
...
...
@@ -256,12 +256,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the updated value
*/
public
int
addAndGet
(
T
obj
,
int
delta
)
{
for
(;;)
{
int
current
=
get
(
obj
);
int
next
=
current
+
delta
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
next
;
}
int
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
delta
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
next
;
}
/**
...
...
@@ -361,6 +361,36 @@ public abstract class AtomicIntegerFieldUpdater<T> {
return
unsafe
.
getIntVolatile
(
obj
,
offset
);
}
public
int
getAndSet
(
T
obj
,
int
newValue
)
{
if
(
obj
==
null
||
obj
.
getClass
()
!=
tclass
||
cclass
!=
null
)
fullCheck
(
obj
);
return
unsafe
.
getAndSetInt
(
obj
,
offset
,
newValue
);
}
public
int
getAndIncrement
(
T
obj
)
{
return
getAndAdd
(
obj
,
1
);
}
public
int
getAndDecrement
(
T
obj
)
{
return
getAndAdd
(
obj
,
-
1
);
}
public
int
getAndAdd
(
T
obj
,
int
delta
)
{
if
(
obj
==
null
||
obj
.
getClass
()
!=
tclass
||
cclass
!=
null
)
fullCheck
(
obj
);
return
unsafe
.
getAndAddInt
(
obj
,
offset
,
delta
);
}
public
int
incrementAndGet
(
T
obj
)
{
return
getAndAdd
(
obj
,
1
)
+
1
;
}
public
int
decrementAndGet
(
T
obj
)
{
return
getAndAdd
(
obj
,
-
1
)
-
1
;
}
public
int
addAndGet
(
T
obj
,
int
delta
)
{
return
getAndAdd
(
obj
,
delta
)
+
delta
;
}
private
void
ensureProtectedAccess
(
T
obj
)
{
if
(
cclass
.
isInstance
(
obj
))
{
return
;
...
...
src/share/classes/java/util/concurrent/atomic/AtomicLong.java
浏览文件 @
b8a7c6dc
...
...
@@ -129,11 +129,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
long
getAndSet
(
long
newValue
)
{
while
(
true
)
{
long
current
=
get
();
if
(
compareAndSet
(
current
,
newValue
))
return
current
;
}
return
unsafe
.
getAndSetLong
(
this
,
valueOffset
,
newValue
);
}
/**
...
...
@@ -159,7 +155,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
*
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
final
boolean
weakCompareAndSet
(
long
expect
,
long
update
)
{
return
unsafe
.
compareAndSwapLong
(
this
,
valueOffset
,
expect
,
update
);
...
...
@@ -171,12 +167,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
long
getAndIncrement
()
{
while
(
true
)
{
long
current
=
get
();
long
next
=
current
+
1
;
if
(
compareAndSet
(
current
,
next
))
return
current
;
}
return
getAndAdd
(
1
);
}
/**
...
...
@@ -185,12 +176,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
long
getAndDecrement
()
{
while
(
true
)
{
long
current
=
get
();
long
next
=
current
-
1
;
if
(
compareAndSet
(
current
,
next
))
return
current
;
}
return
getAndAdd
(-
1
);
}
/**
...
...
@@ -200,12 +186,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value
*/
public
final
long
getAndAdd
(
long
delta
)
{
while
(
true
)
{
long
current
=
get
();
long
next
=
current
+
delta
;
if
(
compareAndSet
(
current
,
next
))
return
current
;
}
return
unsafe
.
getAndAddLong
(
this
,
valueOffset
,
delta
);
}
/**
...
...
@@ -214,12 +195,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value
*/
public
final
long
incrementAndGet
()
{
for
(;;)
{
long
current
=
get
();
long
next
=
current
+
1
;
if
(
compareAndSet
(
current
,
next
))
return
next
;
}
return
getAndAdd
(
1
)
+
1
;
}
/**
...
...
@@ -228,12 +204,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value
*/
public
final
long
decrementAndGet
()
{
for
(;;)
{
long
current
=
get
();
long
next
=
current
-
1
;
if
(
compareAndSet
(
current
,
next
))
return
next
;
}
return
getAndAdd
(-
1
)
-
1
;
}
/**
...
...
@@ -243,17 +214,12 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value
*/
public
final
long
addAndGet
(
long
delta
)
{
for
(;;)
{
long
current
=
get
();
long
next
=
current
+
delta
;
if
(
compareAndSet
(
current
,
next
))
return
next
;
}
return
getAndAdd
(
delta
)
+
delta
;
}
/**
* Returns the String representation of the current value.
* @return the String representation of the current value
.
* @return the String representation of the current value
*/
public
String
toString
()
{
return
Long
.
toString
(
get
());
...
...
src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java
浏览文件 @
b8a7c6dc
...
...
@@ -144,12 +144,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the previous value
*/
public
final
long
getAndSet
(
int
i
,
long
newValue
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
long
current
=
getRaw
(
offset
);
if
(
compareAndSetRaw
(
offset
,
current
,
newValue
))
return
current
;
}
return
unsafe
.
getAndSetLong
(
array
,
checkedByteOffset
(
i
),
newValue
);
}
/**
...
...
@@ -181,7 +176,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @param i the index
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
final
boolean
weakCompareAndSet
(
int
i
,
long
expect
,
long
update
)
{
return
compareAndSet
(
i
,
expect
,
update
);
...
...
@@ -215,12 +210,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the previous value
*/
public
final
long
getAndAdd
(
int
i
,
long
delta
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
long
current
=
getRaw
(
offset
);
if
(
compareAndSetRaw
(
offset
,
current
,
current
+
delta
))
return
current
;
}
return
unsafe
.
getAndAddLong
(
array
,
checkedByteOffset
(
i
),
delta
);
}
/**
...
...
@@ -230,7 +220,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the updated value
*/
public
final
long
incrementAndGet
(
int
i
)
{
return
addAndGet
(
i
,
1
)
;
return
getAndAdd
(
i
,
1
)
+
1
;
}
/**
...
...
@@ -240,7 +230,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the updated value
*/
public
final
long
decrementAndGet
(
int
i
)
{
return
addAndGet
(
i
,
-
1
)
;
return
getAndAdd
(
i
,
-
1
)
-
1
;
}
/**
...
...
@@ -251,13 +241,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the updated value
*/
public
long
addAndGet
(
int
i
,
long
delta
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
long
current
=
getRaw
(
offset
);
long
next
=
current
+
delta
;
if
(
compareAndSetRaw
(
offset
,
current
,
next
))
return
next
;
}
return
getAndAdd
(
i
,
delta
)
+
delta
;
}
/**
...
...
src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
浏览文件 @
b8a7c6dc
...
...
@@ -98,7 +98,7 @@ public abstract class AtomicLongFieldUpdater<T> {
* @param obj An object whose field to conditionally set
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
* @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor.
*/
...
...
@@ -118,7 +118,7 @@ public abstract class AtomicLongFieldUpdater<T> {
* @param obj An object whose field to conditionally set
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
* @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor.
*/
...
...
@@ -162,11 +162,11 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value
*/
public
long
getAndSet
(
T
obj
,
long
newValue
)
{
for
(;;)
{
long
current
=
get
(
obj
);
if
(
compareAndSet
(
obj
,
current
,
newValue
))
return
current
;
}
long
prev
;
do
{
prev
=
get
(
obj
);
}
while
(!
compareAndSet
(
obj
,
prev
,
newValue
))
;
return
prev
;
}
/**
...
...
@@ -177,12 +177,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value
*/
public
long
getAndIncrement
(
T
obj
)
{
for
(;;)
{
long
current
=
get
(
obj
);
long
next
=
current
+
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
current
;
}
long
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
prev
;
}
/**
...
...
@@ -193,12 +193,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value
*/
public
long
getAndDecrement
(
T
obj
)
{
for
(;;)
{
long
current
=
get
(
obj
);
long
next
=
current
-
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
current
;
}
long
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
-
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
prev
;
}
/**
...
...
@@ -210,12 +210,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value
*/
public
long
getAndAdd
(
T
obj
,
long
delta
)
{
for
(;;)
{
long
current
=
get
(
obj
);
long
next
=
current
+
delta
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
current
;
}
long
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
delta
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
prev
;
}
/**
...
...
@@ -226,12 +226,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the updated value
*/
public
long
incrementAndGet
(
T
obj
)
{
for
(;;)
{
long
current
=
get
(
obj
);
long
next
=
current
+
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
next
;
}
long
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
next
;
}
/**
...
...
@@ -242,12 +242,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the updated value
*/
public
long
decrementAndGet
(
T
obj
)
{
for
(;;)
{
long
current
=
get
(
obj
);
long
next
=
current
-
1
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
next
;
}
long
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
-
1
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
next
;
}
/**
...
...
@@ -259,12 +259,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the updated value
*/
public
long
addAndGet
(
T
obj
,
long
delta
)
{
for
(;;)
{
long
current
=
get
(
obj
);
long
next
=
current
+
delta
;
if
(
compareAndSet
(
obj
,
current
,
next
))
return
next
;
}
long
prev
,
next
;
do
{
prev
=
get
(
obj
)
;
next
=
prev
+
delta
;
}
while
(!
compareAndSet
(
obj
,
prev
,
next
))
;
return
next
;
}
private
static
class
CASUpdater
<
T
>
extends
AtomicLongFieldUpdater
<
T
>
{
...
...
@@ -345,6 +345,36 @@ public abstract class AtomicLongFieldUpdater<T> {
return
unsafe
.
getLongVolatile
(
obj
,
offset
);
}
public
long
getAndSet
(
T
obj
,
long
newValue
)
{
if
(
obj
==
null
||
obj
.
getClass
()
!=
tclass
||
cclass
!=
null
)
fullCheck
(
obj
);
return
unsafe
.
getAndSetLong
(
obj
,
offset
,
newValue
);
}
public
long
getAndIncrement
(
T
obj
)
{
return
getAndAdd
(
obj
,
1
);
}
public
long
getAndDecrement
(
T
obj
)
{
return
getAndAdd
(
obj
,
-
1
);
}
public
long
getAndAdd
(
T
obj
,
long
delta
)
{
if
(
obj
==
null
||
obj
.
getClass
()
!=
tclass
||
cclass
!=
null
)
fullCheck
(
obj
);
return
unsafe
.
getAndAddLong
(
obj
,
offset
,
delta
);
}
public
long
incrementAndGet
(
T
obj
)
{
return
getAndAdd
(
obj
,
1
)
+
1
;
}
public
long
decrementAndGet
(
T
obj
)
{
return
getAndAdd
(
obj
,
-
1
)
-
1
;
}
public
long
addAndGet
(
T
obj
,
long
delta
)
{
return
getAndAdd
(
obj
,
delta
)
+
delta
;
}
private
void
ensureProtectedAccess
(
T
obj
)
{
if
(
cclass
.
isInstance
(
obj
))
{
return
;
...
...
src/share/classes/java/util/concurrent/atomic/AtomicReference.java
浏览文件 @
b8a7c6dc
...
...
@@ -124,7 +124,7 @@ public class AtomicReference<V> implements java.io.Serializable {
*
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
final
boolean
weakCompareAndSet
(
V
expect
,
V
update
)
{
return
unsafe
.
compareAndSwapObject
(
this
,
valueOffset
,
expect
,
update
);
...
...
@@ -136,17 +136,14 @@ public class AtomicReference<V> implements java.io.Serializable {
* @param newValue the new value
* @return the previous value
*/
@SuppressWarnings
(
"unchecked"
)
public
final
V
getAndSet
(
V
newValue
)
{
while
(
true
)
{
V
x
=
get
();
if
(
compareAndSet
(
x
,
newValue
))
return
x
;
}
return
(
V
)
unsafe
.
getAndSetObject
(
this
,
valueOffset
,
newValue
);
}
/**
* Returns the String representation of the current value.
* @return the String representation of the current value
.
* @return the String representation of the current value
*/
public
String
toString
()
{
return
String
.
valueOf
(
get
());
...
...
src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java
浏览文件 @
b8a7c6dc
...
...
@@ -159,13 +159,9 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* @param newValue the new value
* @return the previous value
*/
@SuppressWarnings
(
"unchecked"
)
public
final
E
getAndSet
(
int
i
,
E
newValue
)
{
long
offset
=
checkedByteOffset
(
i
);
while
(
true
)
{
E
current
=
getRaw
(
offset
);
if
(
compareAndSetRaw
(
offset
,
current
,
newValue
))
return
current
;
}
return
(
E
)
unsafe
.
getAndSetObject
(
array
,
checkedByteOffset
(
i
),
newValue
);
}
/**
...
...
@@ -197,7 +193,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* @param i the index
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
final
boolean
weakCompareAndSet
(
int
i
,
E
expect
,
E
update
)
{
return
compareAndSet
(
i
,
expect
,
update
);
...
...
src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
浏览文件 @
b8a7c6dc
...
...
@@ -116,7 +116,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @param obj An object whose field to conditionally set
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
abstract
boolean
compareAndSet
(
T
obj
,
V
expect
,
V
update
);
...
...
@@ -134,7 +134,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @param obj An object whose field to conditionally set
* @param expect the expected value
* @param update the new value
* @return true if successful
.
* @return true if successful
*/
public
abstract
boolean
weakCompareAndSet
(
T
obj
,
V
expect
,
V
update
);
...
...
@@ -176,11 +176,11 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @return the previous value
*/
public
V
getAndSet
(
T
obj
,
V
newValue
)
{
for
(;;)
{
V
current
=
get
(
obj
);
if
(
compareAndSet
(
obj
,
current
,
newValue
))
return
current
;
}
V
prev
;
do
{
prev
=
get
(
obj
);
}
while
(!
compareAndSet
(
obj
,
prev
,
newValue
))
;
return
prev
;
}
private
static
final
class
AtomicReferenceFieldUpdaterImpl
<
T
,
V
>
...
...
@@ -321,6 +321,15 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
return
(
V
)
unsafe
.
getObjectVolatile
(
obj
,
offset
);
}
@SuppressWarnings
(
"unchecked"
)
public
V
getAndSet
(
T
obj
,
V
newValue
)
{
if
(
obj
==
null
||
obj
.
getClass
()
!=
tclass
||
cclass
!=
null
||
(
newValue
!=
null
&&
vclass
!=
null
&&
vclass
!=
newValue
.
getClass
()))
updateCheck
(
obj
,
newValue
);
return
(
V
)
unsafe
.
getAndSetObject
(
obj
,
offset
,
newValue
);
}
private
void
ensureProtectedAccess
(
T
obj
)
{
if
(
cclass
.
isInstance
(
obj
))
{
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录