This class may be removed in the future. Consider the replacements in JEP 193 'Variable Handles': http://openjdk.java.net/jeps/193
@Override public void set(U obj, M newValue) { unsafe.putObjectVolatile(obj, offset, newValue); }
public static void putObjectVolatile( Object obj, long offset, Object value ) { unsafe.putObjectVolatile( obj, offset, value ); }
/** * Stores reference value with volatile semantic. * * @param obj Object. * @param off Offset. * @param val Value. */ public static void putObjectVolatile(Object obj, long off, Object val) { UNSAFE.putObjectVolatile(obj, off, val); }
static final <K, V> void setTabAt(final Node<K, V>[] tab, final int i, final Node<K, V> v) { U.putObjectVolatile(tab, ((long) i << ASHIFT) + ABASE, v); }
static final <K, V> void setTabAt(final Node<K, V>[] tab, final int i, final Node<K, V> v) { U.putObjectVolatile(tab, ((long) i << ASHIFT) + ABASE, v); }
private static void setArrayAt(Object[] array, int index, Object newValue) { UNSAFE.putObjectVolatile(array, ((long) index << OBJECT_ARRAY_SHIFT) + OBJECT_ARRAY_BASE, newValue); }
protected final void svElement(E[] buffer, long offset, E e) { UNSAFE.putObjectVolatile(buffer, offset, e); }
protected final void svElement(E[] buffer, long offset, Object e) { UNSAFE.putObjectVolatile(buffer, offset, e); }
protected final void svElement(long offset, E e) { UNSAFE.putObjectVolatile(buffer, offset, e); }
private void setMap(ConcurrentNavigableMap<E,Object> map) { UNSAFE.putObjectVolatile(this, mapOffset, map); }
private final void setEnq(Node<T> n) { Unsafe.instance.putObjectVolatile(this, enqOffset, n); }
private final void setDeq(Node<T> n) { Unsafe.instance.putObjectVolatile(this, deqOffset, n); }
@Override public void set(U obj, W newValue) { unsafe.putObjectVolatile(obj, offset, newValue); }
private final void setDeq(Node<T> n) { Unsafe.instance.putObjectVolatile(this, deqOffset, n); }
private final void setEnq(Node<T> n) { Unsafe.instance.putObjectVolatile(this, enqOffset, n); }
/** * Sets the element at position {@code i} to the given value. * * @param i the index * @param newValue the new value */ public final void set(int i, E newValue) { unsafe.putObjectVolatile(array, checkedByteOffset(i), newValue); }
public void set(T obj, V newValue) { if (obj == null || obj.getClass() != tclass || cclass != null || (newValue != null && vclass != null && vclass != newValue.getClass())) updateCheck(obj, newValue); unsafe.putObjectVolatile(obj, offset, newValue); }
@SuppressWarnings({"sunapi", "all"}) private void disableJava9SillyWarning() { // JVM9 complains about using reflection to access packages from a module that aren't exported. This makes no sense; the whole point of reflection // is to get past such issues. The only comment from the jigsaw team lead on this was some unspecified mumbling about security which makes no sense, // as the SecurityManager is invoked to check such things. Therefore this warning is a bug, so we shall patch java to fix it. try { Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafe.setAccessible(true); Unsafe u = (Unsafe) theUnsafe.get(null); Class<?> cls = Class.forName("jdk.internal.module.IllegalAccessLogger"); Field logger = cls.getDeclaredField("logger"); u.putObjectVolatile(cls, u.staticFieldOffset(logger), null); } catch (Throwable t) { // We shall ignore it; the effect of this code failing is that the user gets to see a warning they remove with various --add-opens magic. } }
@SuppressWarnings("unchecked") public static void disableWarning() { try { Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafe.setAccessible(true); Unsafe u = (Unsafe) theUnsafe.get(null); Class cls = Class.forName("jdk.internal.module.IllegalAccessLogger"); Field logger = cls.getDeclaredField("logger"); u.putObjectVolatile(cls, u.staticFieldOffset(logger), null); } catch (Exception e) { // ignore } }
/** * Reconstitutes the instance from a stream (that is, deserializes it). */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException, java.io.InvalidObjectException { // Note: This must be changed if any additional fields are defined Object a = s.readFields().get("array", null); if (a == null || !a.getClass().isArray()) throw new java.io.InvalidObjectException("Not array type"); if (a.getClass() != Object[].class) a = Arrays.copyOf((Object[])a, Array.getLength(a), Object[].class); unsafe.putObjectVolatile(this, arrayFieldOffset, a); }