< prev index next >
src/java.base/share/classes/jdk/internal/misc/Unsafe.java
Print this page
rev 52850 : imported patch method-var-handles
@@ -172,23 +172,36 @@
* {@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);
- public native Object getValue(Object base, long offset, Class<?> valueType);
-
/**
* 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,11 +209,48 @@
* @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);
+ /**
+ * 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,14 +1356,14 @@
public final native boolean compareAndSetObject(Object o, long offset,
Object expected,
Object x);
@ForceInline
- public final boolean compareAndSetValue(Object o, long offset,
+ public final <V> boolean compareAndSetValue(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
synchronized (valueLock) {
Object witness = getValue(o, offset, valueType);
if (witness.equals(expected)) {
putValue(o, offset, valueType, x);
return true;
@@ -1326,16 +1376,15 @@
@HotSpotIntrinsicCandidate
public final native Object compareAndExchangeObject(Object o, long offset,
Object expected,
Object x);
-
@ForceInline
- public final Object compareAndExchangeValue(Object o, long offset,
+ public final <V> Object compareAndExchangeValue(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
synchronized (valueLock) {
Object witness = getValue(o, offset, valueType);
if (witness.equals(expected)) {
putValue(o, offset, valueType, x);
}
@@ -1349,14 +1398,14 @@
Object x) {
return compareAndExchangeObject(o, offset, expected, x);
}
@ForceInline
- public final Object compareAndExchangeValueAcquire(Object o, long offset,
+ public final <V> Object compareAndExchangeValueAcquire(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
return compareAndExchangeValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final Object compareAndExchangeObjectRelease(Object o, long offset,
@@ -1364,14 +1413,14 @@
Object x) {
return compareAndExchangeObject(o, offset, expected, x);
}
@ForceInline
- public final Object compareAndExchangeValueRelease(Object o, long offset,
+ public final <V> Object compareAndExchangeValueRelease(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
return compareAndExchangeValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectPlain(Object o, long offset,
@@ -1379,14 +1428,14 @@
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
- public final boolean weakCompareAndSetValuePlain(Object o, long offset,
+ public final <V> boolean weakCompareAndSetValuePlain(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectAcquire(Object o, long offset,
@@ -1394,14 +1443,14 @@
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
- public final boolean weakCompareAndSetValueAcquire(Object o, long offset,
+ public final <V> boolean weakCompareAndSetValueAcquire(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObjectRelease(Object o, long offset,
@@ -1409,14 +1458,14 @@
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
- public final boolean weakCompareAndSetValueRelease(Object o, long offset,
+ public final <V> boolean weakCompareAndSetValueRelease(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSetObject(Object o, long offset,
@@ -1424,14 +1473,14 @@
Object x) {
return compareAndSetObject(o, offset, expected, x);
}
@ForceInline
- public final boolean weakCompareAndSetValue(Object o, long offset,
+ public final <V> boolean weakCompareAndSetValue(Object o, long offset,
Class<?> valueType,
- Object expected,
- Object x) {
+ V expected,
+ V x) {
return compareAndSetValue(o, offset, valueType, expected, x);
}
/**
* Atomically updates Java variable to {@code x} if it is currently
@@ -2053,11 +2102,11 @@
* 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) {
+ public final <V> Object getValueVolatile(Object base, long offset, Class<?> valueType) {
synchronized (valueLock) {
return getValue(base, offset, valueType);
}
}
@@ -2066,11 +2115,11 @@
* 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) {
+ public final <V> void putValueVolatile(Object o, long offset, Class<?> valueType, V x) {
synchronized (valueLock) {
putValue(o, offset, valueType, x);
}
}
@@ -2144,11 +2193,11 @@
@HotSpotIntrinsicCandidate
public final Object getObjectAcquire(Object o, long offset) {
return getObjectVolatile(o, offset);
}
- public final Object getValueAcquire(Object base, long offset, Class<?> valueType) {
+ 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,11 +2261,11 @@
@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) {
+ 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,11 +2321,11 @@
@HotSpotIntrinsicCandidate
public final Object getObjectOpaque(Object o, long offset) {
return getObjectVolatile(o, offset);
}
- public final Object getValueOpaque(Object base, long offset, Class<?> valueType) {
+ 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,11 +2379,11 @@
@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) {
+ 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,11 +2817,12 @@
v = getObjectVolatile(o, offset);
} while (!weakCompareAndSetObject(o, offset, v, newValue));
return v;
}
- public final Object getAndSetValue(Object o, long offset, Class<?> valueType, Object newValue) {
+ @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,11 +2836,11 @@
} while (!weakCompareAndSetObjectRelease(o, offset, v, newValue));
return v;
}
@ForceInline
- public final Object getAndSetValueRelease(Object o, long offset, Class<?> valueType, Object newValue) {
+ 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,11 +2850,11 @@
} while (!weakCompareAndSetObjectAcquire(o, offset, v, newValue));
return v;
}
@ForceInline
- public final Object getAndSetValueAcquire(Object o, long offset, Class<?> valueType, Object newValue) {
+ 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 >