-
Enhancement
-
Resolution: Fixed
-
P3
-
hs21
-
b03
-
x86
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8000388 | 8 | Roland Westrelin | P3 | Resolved | Fixed | b59 |
JDK-8017998 | 7u45 | Roland Westrelin | P3 | Closed | Fixed | b01 |
JDK-8002894 | 7u40 | Roland Westrelin | P3 | Resolved | Fixed | b01 |
JDK-8001719 | hs24 | Roland Westrelin | P3 | Resolved | Fixed | master |
implemented as CAS loops. On x86/x64, these could be intrinsified into lock:xadd.
The latter is far less heavy-weight than cmpxchg.
After discussions with Doug Lea and Dave Dice, we should extend Unsafe a bit to provide intrinsifiable operations to take advantage of xadd and xchg. Here's the rough interface addition. These are slightly different than normal Unsafe since they start with Java implementations which are always valid. They can be replaced with intrinsics if the platform provides a fast implementation.
/**
* Atomically update Java variable by <tt>delta</tt> returning
* the previous value.
* @return the previous value
*/
public int getAndAddInt(Object o, long offset, int delta) {
for (;;) {
int current = getInt(o, offset);
int next = current + delta;
if (compareAndSwapInt(o, offset, current, next)) {
return current;
}
}
}
/**
* Atomically update Java variable by <tt>delta</tt> returning
* the previous value.
* @return the previous value
*/
public long getAndAddLong(Object o, long offset, long delta) {
for (;;) {
long current = getLongVolatile(o, offset);
long next = current + delta;
if (compareAndSwapLong(o, offset, current, next)) {
return current;
}
}
}
/**
* Atomically sets the field of the given object at the given offset
* to the given value and returns the old value.
*
* @param o An object whose field to get and set
* @param newValue the new value
* @return the previous value
*/
public int getAndSet(Object o, long offset, int newValue) {
for (;;) {
int current = getInt(o, offset);
if (compareAndSwapInt(o, offset, current, newValue)) {
return current;
}
}
}
/**
* Atomically sets the field of the given object at the given offset
* to the given value and returns the old value.
*
* @param o An object whose field to get and set
* @param newValue the new value
* @return the previous value
*/
public long getAndSet(Object o, long offset, long newValue) {
for (;;) {
long current = getLongVolatile(o, offset);
if (compareAndSwapLong(o, offset, current, newValue)) {
return current;
}
}
}
/**
* Atomically sets the field of the given object at the given offset
* to the given value and returns the old value.
*
* @param o An object whose field to get and set
* @param newValue the new value
* @return the previous value
*/
public Object getAndSet(Object o, long offset, Object newValue) {
for (;;) {
Object current = getObject(o, offset);
if (compareAndSwapObject(o, offset, current, newValue)) {
return current;
}
}
}
- backported by
-
JDK-8000388 Intrinsify AtomicLongFieldUpdater.getAndIncrement()
- Resolved
-
JDK-8001719 Intrinsify AtomicLongFieldUpdater.getAndIncrement()
- Resolved
-
JDK-8002894 Intrinsify AtomicLongFieldUpdater.getAndIncrement()
- Resolved
-
JDK-8002895 Intrinsify AtomicLongFieldUpdater.getAndIncrement()
- Closed
-
JDK-8002896 Intrinsify AtomicLongFieldUpdater.getAndIncrement()
- Closed
-
JDK-8017998 Intrinsify AtomicLongFieldUpdater.getAndIncrement()
- Closed
- relates to
-
JDK-8273020 LibraryCallKit::sharpen_unsafe_type does not handle narrow oop array
- Resolved
-
JDK-8011901 Unsafe.getAndAddLong(obj, off, delta) does not work properly with long deltas
- Closed
-
JDK-7172640 C2: instrinsic implementations in LibraryCallKit should use argument() instead of pop()
- Resolved
-
JDK-8004330 Add missing Unsafe entry points for addAndGet() family
- Resolved