< prev index next >
src/java.base/share/classes/jdk/internal/misc/Unsafe.java
Print this page
rev 52850 : imported patch method-var-handles
*** 172,194 ****
* {@link NullPointerException}
*/
@HotSpotIntrinsicCandidate
public native void putInt(Object o, long offset, int x);
public native boolean isFlattenedArray(Class<?> arrayClass);
/**
* Fetches a reference value from a given Java variable.
* @see #getInt(Object, long)
*/
@HotSpotIntrinsicCandidate
public native Object getObject(Object o, long offset);
- public native Object getValue(Object base, long offset, Class<?> valueType);
-
/**
* Stores a reference value into a given Java variable.
* <p>
* Unless the reference {@code x} being stored is either null
* or matches the field type, the results are undefined.
* If the reference {@code o} is non-null, card marks or
* other store barriers for that object (if the VM requires them)
--- 172,207 ----
* {@link NullPointerException}
*/
@HotSpotIntrinsicCandidate
public native void putInt(Object o, long offset, int x);
+ /**
+ * Returns true if the given class is a regular value type.
+ */
+ public boolean isValueType(Class<?> c) {
+ return c.isValue() && c == c.asValueType();
+ }
+
+ /**
+ * Returns true if the given class is a flattened array.
+ */
public native boolean isFlattenedArray(Class<?> arrayClass);
/**
* Fetches a reference value from a given Java variable.
+ * This method can return a reference to either an object or value
+ * or a null reference.
+ *
* @see #getInt(Object, long)
*/
@HotSpotIntrinsicCandidate
public native Object getObject(Object o, long offset);
/**
* Stores a reference value into a given Java variable.
+ * This method can store a reference to either an object or value
+ * or a null reference.
* <p>
* Unless the reference {@code x} being stored is either null
* or matches the field type, the results are undefined.
* If the reference {@code o} is non-null, card marks or
* other store barriers for that object (if the VM requires them)
*** 196,206 ****
* @see #putInt(Object, long, int)
*/
@HotSpotIntrinsicCandidate
public native void putObject(Object o, long offset, Object x);
! public native void putValue(Object base, long offset, Class<?> valueType, Object value);
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native boolean getBoolean(Object o, long offset);
--- 209,256 ----
* @see #putInt(Object, long, int)
*/
@HotSpotIntrinsicCandidate
public native void putObject(Object o, long offset, Object x);
! /**
! * Fetches a value of type {@code <V>} from a given Java variable.
! * More specifically, fetches a field or array element within the given
! * {@code o} object at the given offset, or (if {@code o} is null)
! * from the memory address whose numerical value is the given offset.
! *
! * @param o Java heap object in which the variable resides, if any, else
! * null
! * @param offset indication of where the variable resides in a Java heap
! * object, if any, else a memory address locating the variable
! * statically
! * @param vc value class
! * @param <V> the type of a value
! * @return the value fetched from the indicated Java variable
! * @throws RuntimeException No defined exceptions are thrown, not even
! * {@link NullPointerException}
! */
! public native <V> V getValue(Object o, long offset, Class<?> vc);
!
! /**
! * Stores the given value into a given Java variable.
! *
! * Unless the reference {@code o} being stored is either null
! * or matches the field type and not in a value container,
! * the results are undefined.
! *
! * @param o Java heap object in which the variable resides, if any, else
! * null
! * @param offset indication of where the variable resides in a Java heap
! * object, if any, else a memory address locating the variable
! * statically
! * @param vc value class
! * @param v the value to store into the indicated Java variable
! * @param <V> the type of a value
! * @throws RuntimeException No defined exceptions are thrown, not even
! * {@link NullPointerException}
! */
! public native <V> void putValue(Object o, long offset, Class<?> vc, V v);
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native boolean getBoolean(Object o, long offset);
*** 1306,1319 ****
public final native boolean compareAndSetObject(Object o, long offset,
Object expected,
Object x);
@ForceInline
! public final boolean compareAndSetValue(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
synchronized (valueLock) {
Object witness = getValue(o, offset, valueType);
if (witness.equals(expected)) {
putValue(o, offset, valueType, x);
return true;
--- 1356,1369 ----
public final native boolean compareAndSetObject(Object o, long offset,
Object expected,
Object x);
@ForceInline
! public final <V> boolean compareAndSetValue(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
synchronized (valueLock) {
Object witness = getValue(o, offset, valueType);
if (witness.equals(expected)) {
putValue(o, offset, valueType, x);
return true;
*** 1326,1341 ****
@HotSpotIntrinsicCandidate
public final native Object compareAndExchangeObject(Object o, long offset,
Object expected,
Object x);
-
@ForceInline
! public final Object compareAndExchangeValue(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
synchronized (valueLock) {
Object witness = getValue(o, offset, valueType);
if (witness.equals(expected)) {
putValue(o, offset, valueType, x);
}
--- 1376,1390 ----
@HotSpotIntrinsicCandidate
public final native Object compareAndExchangeObject(Object o, long offset,
Object expected,
Object x);
@ForceInline
! public final <V> Object compareAndExchangeValue(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
synchronized (valueLock) {
Object witness = getValue(o, offset, valueType);
if (witness.equals(expected)) {
putValue(o, offset, valueType, x);
}
*** 1349,1362 ****
Object x) {
return compareAndExchangeObject(o, offset, expected, x);
}
@ForceInline
! public final Object compareAndExchangeValueAcquire(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
return compareAndExchangeValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final Object compareAndExchangeObjectRelease(Object o, long offset,
--- 1398,1411 ----
Object x) {
return compareAndExchangeObject(o, offset, expected, x);
}
@ForceInline
! public final <V> Object compareAndExchangeValueAcquire(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
return compareAndExchangeValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final Object compareAndExchangeObjectRelease(Object o, long offset,
*** 1364,1377 ****
Object x) {
return compareAndExchangeObject(o, offset, expected, x);
}
@ForceInline
! public final Object compareAndExchangeValueRelease(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
return compareAndExchangeValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectPlain(Object o, long offset,
--- 1413,1426 ----
Object x) {
return compareAndExchangeObject(o, offset, expected, x);
}
@ForceInline
! public final <V> Object compareAndExchangeValueRelease(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
return compareAndExchangeValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectPlain(Object o, long offset,
*** 1379,1392 ****
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final boolean weakCompareAndSetValuePlain(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectAcquire(Object o, long offset,
--- 1428,1441 ----
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final <V> boolean weakCompareAndSetValuePlain(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectAcquire(Object o, long offset,
*** 1394,1407 ****
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final boolean weakCompareAndSetValueAcquire(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectRelease(Object o, long offset,
--- 1443,1456 ----
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final <V> boolean weakCompareAndSetValueAcquire(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectRelease(Object o, long offset,
*** 1409,1422 ****
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final boolean weakCompareAndSetValueRelease(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObject(Object o, long offset,
--- 1458,1471 ----
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final <V> boolean weakCompareAndSetValueRelease(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObject(Object o, long offset,
*** 1424,1437 ****
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final boolean weakCompareAndSetValue(Object o, long offset,
Class<?> valueType,
! Object expected,
! Object x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
/**
* Atomically updates Java variable to {@code x} if it is currently
--- 1473,1486 ----
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
! public final <V> boolean weakCompareAndSetValue(Object o, long offset,
Class<?> valueType,
! V expected,
! V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
/**
* Atomically updates Java variable to {@code x} if it is currently
*** 2053,2063 ****
* a value type. This is a temporary workaround until better localized
* atomic access mechanisms are supported for value types.
*/
private static final Object valueLock = new Object();
! public final Object getValueVolatile(Object base, long offset, Class<?> valueType) {
synchronized (valueLock) {
return getValue(base, offset, valueType);
}
}
--- 2102,2112 ----
* a value type. This is a temporary workaround until better localized
* atomic access mechanisms are supported for value types.
*/
private static final Object valueLock = new Object();
! public final <V> Object getValueVolatile(Object base, long offset, Class<?> valueType) {
synchronized (valueLock) {
return getValue(base, offset, valueType);
}
}
*** 2066,2076 ****
* volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)}
*/
@HotSpotIntrinsicCandidate
public native void putObjectVolatile(Object o, long offset, Object x);
! public final void putValueVolatile(Object o, long offset, Class<?> valueType, Object x) {
synchronized (valueLock) {
putValue(o, offset, valueType, x);
}
}
--- 2115,2125 ----
* volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)}
*/
@HotSpotIntrinsicCandidate
public native void putObjectVolatile(Object o, long offset, Object x);
! public final <V> void putValueVolatile(Object o, long offset, Class<?> valueType, V x) {
synchronized (valueLock) {
putValue(o, offset, valueType, x);
}
}
*** 2144,2154 ****
@HotSpotIntrinsicCandidate
public final Object getObjectAcquire(Object o, long offset) {
return getObjectVolatile(o, offset);
}
! public final Object getValueAcquire(Object base, long offset, Class<?> valueType) {
return getValueVolatile(base, offset, valueType);
}
/** Acquire version of {@link #getBooleanVolatile(Object, long)} */
@HotSpotIntrinsicCandidate
--- 2193,2203 ----
@HotSpotIntrinsicCandidate
public final Object getObjectAcquire(Object o, long offset) {
return getObjectVolatile(o, offset);
}
! public final <V> Object getValueAcquire(Object base, long offset, Class<?> valueType) {
return getValueVolatile(base, offset, valueType);
}
/** Acquire version of {@link #getBooleanVolatile(Object, long)} */
@HotSpotIntrinsicCandidate
*** 2212,2222 ****
@HotSpotIntrinsicCandidate
public final void putObjectRelease(Object o, long offset, Object x) {
putObjectVolatile(o, offset, x);
}
! public final void putValueRelease(Object o, long offset, Class<?> valueType, Object x) {
putValueVolatile(o, offset, valueType, x);
}
/** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
@HotSpotIntrinsicCandidate
--- 2261,2271 ----
@HotSpotIntrinsicCandidate
public final void putObjectRelease(Object o, long offset, Object x) {
putObjectVolatile(o, offset, x);
}
! public final <V> void putValueRelease(Object o, long offset, Class<?> valueType, V x) {
putValueVolatile(o, offset, valueType, x);
}
/** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
@HotSpotIntrinsicCandidate
*** 2272,2282 ****
@HotSpotIntrinsicCandidate
public final Object getObjectOpaque(Object o, long offset) {
return getObjectVolatile(o, offset);
}
! public final Object getValueOpaque(Object base, long offset, Class<?> valueType) {
return getValueVolatile(base, offset, valueType);
}
/** Opaque version of {@link #getBooleanVolatile(Object, long)} */
@HotSpotIntrinsicCandidate
--- 2321,2331 ----
@HotSpotIntrinsicCandidate
public final Object getObjectOpaque(Object o, long offset) {
return getObjectVolatile(o, offset);
}
! public final <V> Object getValueOpaque(Object base, long offset, Class<?> valueType) {
return getValueVolatile(base, offset, valueType);
}
/** Opaque version of {@link #getBooleanVolatile(Object, long)} */
@HotSpotIntrinsicCandidate
*** 2330,2340 ****
@HotSpotIntrinsicCandidate
public final void putObjectOpaque(Object o, long offset, Object x) {
putObjectVolatile(o, offset, x);
}
! public final void putValueOpaque(Object o, long offset, Class<?> valueType, Object x) {
putValueVolatile(o, offset, valueType, x);
}
/** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
@HotSpotIntrinsicCandidate
--- 2379,2389 ----
@HotSpotIntrinsicCandidate
public final void putObjectOpaque(Object o, long offset, Object x) {
putObjectVolatile(o, offset, x);
}
! public final <V> void putValueOpaque(Object o, long offset, Class<?> valueType, V x) {
putValueVolatile(o, offset, valueType, x);
}
/** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
@HotSpotIntrinsicCandidate
*** 2768,2778 ****
v = getObjectVolatile(o, offset);
} while (!weakCompareAndSetObject(o, offset, v, newValue));
return v;
}
! public final Object getAndSetValue(Object o, long offset, Class<?> valueType, Object newValue) {
synchronized (valueLock) {
Object oldValue = getValue(o, offset, valueType);
putValue(o, offset, valueType, newValue);
return oldValue;
}
--- 2817,2828 ----
v = getObjectVolatile(o, offset);
} while (!weakCompareAndSetObject(o, offset, v, newValue));
return v;
}
! @SuppressWarnings("unchecked")
! public final <V> Object getAndSetValue(Object o, long offset, Class<?> valueType, V newValue) {
synchronized (valueLock) {
Object oldValue = getValue(o, offset, valueType);
putValue(o, offset, valueType, newValue);
return oldValue;
}
*** 2786,2796 ****
} while (!weakCompareAndSetObjectRelease(o, offset, v, newValue));
return v;
}
@ForceInline
! public final Object getAndSetValueRelease(Object o, long offset, Class<?> valueType, Object newValue) {
return getAndSetValue(o, offset, valueType, newValue);
}
@ForceInline
public final Object getAndSetObjectAcquire(Object o, long offset, Object newValue) {
--- 2836,2846 ----
} while (!weakCompareAndSetObjectRelease(o, offset, v, newValue));
return v;
}
@ForceInline
! public final <V> Object getAndSetValueRelease(Object o, long offset, Class<?> valueType, V newValue) {
return getAndSetValue(o, offset, valueType, newValue);
}
@ForceInline
public final Object getAndSetObjectAcquire(Object o, long offset, Object newValue) {
*** 2800,2810 ****
} while (!weakCompareAndSetObjectAcquire(o, offset, v, newValue));
return v;
}
@ForceInline
! public final Object getAndSetValueAcquire(Object o, long offset, Class<?> valueType, Object newValue) {
return getAndSetValue(o, offset, valueType, newValue);
}
@HotSpotIntrinsicCandidate
public final byte getAndSetByte(Object o, long offset, byte newValue) {
--- 2850,2860 ----
} while (!weakCompareAndSetObjectAcquire(o, offset, v, newValue));
return v;
}
@ForceInline
! public final <V> Object getAndSetValueAcquire(Object o, long offset, Class<?> valueType, V newValue) {
return getAndSetValue(o, offset, valueType, newValue);
}
@HotSpotIntrinsicCandidate
public final byte getAndSetByte(Object o, long offset, byte newValue) {
< prev index next >