RFR (M): 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
Roland Westrelin
roland.westrelin at oracle.com
Tue May 15 09:10:06 PDT 2012
http://cr.openjdk.java.net/~roland/7023898/
This change provides intrinsics when optimized instruction sequences for the new Unsafe methods below exist (the change to the libraries will get in as a separate piece of work).
Roland.
/**
* 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(obj, offset);
int next = current + delta;
if (compareAndSwapInt(obj, 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(obj, offset);
long next = current + delta;
if (compareAndSwapLong(obj, 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 obj An object whose field to get and set
* @param newValue the new value
* @return the previous value
*/
int getAndSet(Object o, long offset, int newValue) {
for (;;) {
int current = getInt(obj, offset);
if (compareAndSwapInt(obj, 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 obj An object whose field to get and set
* @param newValue the new value
* @return the previous value
*/
long getAndSet(Object o, long offset, long newValue) {
for (;;) {
long current = getLongVolatile(obj, offset);
if (compareAndSwapLong(obj, 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 obj An object whose field to get and set
* @param newValue the new value
* @return the previous value
*/
Object getAndSet(Object o, long offset, Object newValue) {
for (;;) {
Object current = getObject(obj, offset);
if (compareAndSwapObject(obj, offset, current, newValue)) {
return current;
}
}
}
More information about the hotspot-compiler-dev
mailing list