< prev index next >

src/java.base/share/classes/jdk/internal/misc/Unsafe.java

Print this page

 160      * The first two parameters are interpreted exactly as with
 161      * {@link #getInt(Object, long)} to refer to a specific
 162      * Java variable (field or array element).  The given value
 163      * is stored into that variable.
 164      * <p>
 165      * The variable must be of the same type as the method
 166      * parameter {@code x}.
 167      *
 168      * @param o Java heap object in which the variable resides, if any, else
 169      *        null
 170      * @param offset indication of where the variable resides in a Java heap
 171      *        object, if any, else a memory address locating the variable
 172      *        statically
 173      * @param x the value to store into the indicated Java variable
 174      * @throws RuntimeException No defined exceptions are thrown, not even
 175      *         {@link NullPointerException}
 176      */
 177     @IntrinsicCandidate
 178     public native void putInt(Object o, long offset, int x);
 179 
















































 180     /**
 181      * Fetches a reference value from a given Java variable.



 182      * @see #getInt(Object, long)
 183      */
 184     @IntrinsicCandidate
 185     public native Object getReference(Object o, long offset);
 186 
 187     /**
 188      * Stores a reference value into a given Java variable.


 189      * <p>
 190      * Unless the reference {@code x} being stored is either null
 191      * or matches the field type, the results are undefined.
 192      * If the reference {@code o} is non-null, card marks or
 193      * other store barriers for that object (if the VM requires them)
 194      * are updated.
 195      * @see #putInt(Object, long, int)
 196      */
 197     @IntrinsicCandidate
 198     public native void putReference(Object o, long offset, Object x);
 199 









































































 200     /** @see #getInt(Object, long) */
 201     @IntrinsicCandidate
 202     public native boolean getBoolean(Object o, long offset);
 203 
 204     /** @see #putInt(Object, long, int) */
 205     @IntrinsicCandidate
 206     public native void    putBoolean(Object o, long offset, boolean x);
 207 
 208     /** @see #getInt(Object, long) */
 209     @IntrinsicCandidate
 210     public native byte    getByte(Object o, long offset);
 211 
 212     /** @see #putInt(Object, long, int) */
 213     @IntrinsicCandidate
 214     public native void    putByte(Object o, long offset, byte x);
 215 
 216     /** @see #getInt(Object, long) */
 217     @IntrinsicCandidate
 218     public native short   getShort(Object o, long offset);
 219 

1218 
1219     /**
1220      * Reports the scale factor for addressing elements in the storage
1221      * allocation of a given array class.  However, arrays of "narrow" types
1222      * will generally not work properly with accessors like {@link
1223      * #getByte(Object, long)}, so the scale factor for such classes is reported
1224      * as zero.
1225      *
1226      * @see #arrayBaseOffset
1227      * @see #getInt(Object, long)
1228      * @see #putInt(Object, long, int)
1229      */
1230     public int arrayIndexScale(Class<?> arrayClass) {
1231         if (arrayClass == null) {
1232             throw new NullPointerException();
1233         }
1234 
1235         return arrayIndexScale0(arrayClass);
1236     }
1237 











1238 
1239     /** The value of {@code arrayIndexScale(boolean[].class)} */
1240     public static final int ARRAY_BOOLEAN_INDEX_SCALE
1241             = theUnsafe.arrayIndexScale(boolean[].class);
1242 
1243     /** The value of {@code arrayIndexScale(byte[].class)} */
1244     public static final int ARRAY_BYTE_INDEX_SCALE
1245             = theUnsafe.arrayIndexScale(byte[].class);
1246 
1247     /** The value of {@code arrayIndexScale(short[].class)} */
1248     public static final int ARRAY_SHORT_INDEX_SCALE
1249             = theUnsafe.arrayIndexScale(short[].class);
1250 
1251     /** The value of {@code arrayIndexScale(char[].class)} */
1252     public static final int ARRAY_CHAR_INDEX_SCALE
1253             = theUnsafe.arrayIndexScale(char[].class);
1254 
1255     /** The value of {@code arrayIndexScale(int[].class)} */
1256     public static final int ARRAY_INT_INDEX_SCALE
1257             = theUnsafe.arrayIndexScale(int[].class);

1396        return null;
1397     }
1398 
1399     /** Throws the exception without telling the verifier. */
1400     public native void throwException(Throwable ee);
1401 
1402     /**
1403      * Atomically updates Java variable to {@code x} if it is currently
1404      * holding {@code expected}.
1405      *
1406      * <p>This operation has memory semantics of a {@code volatile} read
1407      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1408      *
1409      * @return {@code true} if successful
1410      */
1411     @IntrinsicCandidate
1412     public final native boolean compareAndSetReference(Object o, long offset,
1413                                                        Object expected,
1414                                                        Object x);
1415 















































1416     @IntrinsicCandidate
1417     public final native Object compareAndExchangeReference(Object o, long offset,
1418                                                            Object expected,
1419                                                            Object x);
1420 































1421     @IntrinsicCandidate
1422     public final Object compareAndExchangeReferenceAcquire(Object o, long offset,
1423                                                            Object expected,
1424                                                            Object x) {
1425         return compareAndExchangeReference(o, offset, expected, x);
1426     }
1427 















1428     @IntrinsicCandidate
1429     public final Object compareAndExchangeReferenceRelease(Object o, long offset,
1430                                                            Object expected,
1431                                                            Object x) {
1432         return compareAndExchangeReference(o, offset, expected, x);
1433     }
1434 















1435     @IntrinsicCandidate
1436     public final boolean weakCompareAndSetReferencePlain(Object o, long offset,
1437                                                          Object expected,
1438                                                          Object x) {
1439         return compareAndSetReference(o, offset, expected, x);
1440     }
1441 



















1442     @IntrinsicCandidate
1443     public final boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
1444                                                            Object expected,
1445                                                            Object x) {
1446         return compareAndSetReference(o, offset, expected, x);
1447     }
1448 



















1449     @IntrinsicCandidate
1450     public final boolean weakCompareAndSetReferenceRelease(Object o, long offset,
1451                                                            Object expected,
1452                                                            Object x) {
1453         return compareAndSetReference(o, offset, expected, x);
1454     }
1455 



















1456     @IntrinsicCandidate
1457     public final boolean weakCompareAndSetReference(Object o, long offset,
1458                                                     Object expected,
1459                                                     Object x) {
1460         return compareAndSetReference(o, offset, expected, x);
1461     }
1462 



















1463     /**
1464      * Atomically updates Java variable to {@code x} if it is currently
1465      * holding {@code expected}.
1466      *
1467      * <p>This operation has memory semantics of a {@code volatile} read
1468      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1469      *
1470      * @return {@code true} if successful
1471      */
1472     @IntrinsicCandidate
1473     public final native boolean compareAndSetInt(Object o, long offset,
1474                                                  int expected,
1475                                                  int x);
1476 
1477     @IntrinsicCandidate
1478     public final native int compareAndExchangeInt(Object o, long offset,
1479                                                   int expected,
1480                                                   int x);
1481 
1482     @IntrinsicCandidate

2058     public final boolean weakCompareAndSetLongRelease(Object o, long offset,
2059                                                       long expected,
2060                                                       long x) {
2061         return compareAndSetLong(o, offset, expected, x);
2062     }
2063 
2064     @IntrinsicCandidate
2065     public final boolean weakCompareAndSetLong(Object o, long offset,
2066                                                long expected,
2067                                                long x) {
2068         return compareAndSetLong(o, offset, expected, x);
2069     }
2070 
2071     /**
2072      * Fetches a reference value from a given Java variable, with volatile
2073      * load semantics. Otherwise identical to {@link #getReference(Object, long)}
2074      */
2075     @IntrinsicCandidate
2076     public native Object getReferenceVolatile(Object o, long offset);
2077 













2078     /**
2079      * Stores a reference value into a given Java variable, with
2080      * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
2081      */
2082     @IntrinsicCandidate
2083     public native void putReferenceVolatile(Object o, long offset, Object x);
2084 






2085     /** Volatile version of {@link #getInt(Object, long)}  */
2086     @IntrinsicCandidate
2087     public native int     getIntVolatile(Object o, long offset);
2088 
2089     /** Volatile version of {@link #putInt(Object, long, int)}  */
2090     @IntrinsicCandidate
2091     public native void    putIntVolatile(Object o, long offset, int x);
2092 
2093     /** Volatile version of {@link #getBoolean(Object, long)}  */
2094     @IntrinsicCandidate
2095     public native boolean getBooleanVolatile(Object o, long offset);
2096 
2097     /** Volatile version of {@link #putBoolean(Object, long, boolean)}  */
2098     @IntrinsicCandidate
2099     public native void    putBooleanVolatile(Object o, long offset, boolean x);
2100 
2101     /** Volatile version of {@link #getByte(Object, long)}  */
2102     @IntrinsicCandidate
2103     public native byte    getByteVolatile(Object o, long offset);
2104 

2137     /** Volatile version of {@link #putFloat(Object, long, float)}  */
2138     @IntrinsicCandidate
2139     public native void    putFloatVolatile(Object o, long offset, float x);
2140 
2141     /** Volatile version of {@link #getDouble(Object, long)}  */
2142     @IntrinsicCandidate
2143     public native double  getDoubleVolatile(Object o, long offset);
2144 
2145     /** Volatile version of {@link #putDouble(Object, long, double)}  */
2146     @IntrinsicCandidate
2147     public native void    putDoubleVolatile(Object o, long offset, double x);
2148 
2149 
2150 
2151     /** Acquire version of {@link #getReferenceVolatile(Object, long)} */
2152     @IntrinsicCandidate
2153     public final Object getReferenceAcquire(Object o, long offset) {
2154         return getReferenceVolatile(o, offset);
2155     }
2156 




2157     /** Acquire version of {@link #getBooleanVolatile(Object, long)} */
2158     @IntrinsicCandidate
2159     public final boolean getBooleanAcquire(Object o, long offset) {
2160         return getBooleanVolatile(o, offset);
2161     }
2162 
2163     /** Acquire version of {@link #getByteVolatile(Object, long)} */
2164     @IntrinsicCandidate
2165     public final byte getByteAcquire(Object o, long offset) {
2166         return getByteVolatile(o, offset);
2167     }
2168 
2169     /** Acquire version of {@link #getShortVolatile(Object, long)} */
2170     @IntrinsicCandidate
2171     public final short getShortAcquire(Object o, long offset) {
2172         return getShortVolatile(o, offset);
2173     }
2174 
2175     /** Acquire version of {@link #getCharVolatile(Object, long)} */
2176     @IntrinsicCandidate

2201     public final double getDoubleAcquire(Object o, long offset) {
2202         return getDoubleVolatile(o, offset);
2203     }
2204 
2205     /*
2206      * Versions of {@link #putReferenceVolatile(Object, long, Object)}
2207      * that do not guarantee immediate visibility of the store to
2208      * other threads. This method is generally only useful if the
2209      * underlying field is a Java volatile (or if an array cell, one
2210      * that is otherwise only accessed using volatile accesses).
2211      *
2212      * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
2213      */
2214 
2215     /** Release version of {@link #putReferenceVolatile(Object, long, Object)} */
2216     @IntrinsicCandidate
2217     public final void putReferenceRelease(Object o, long offset, Object x) {
2218         putReferenceVolatile(o, offset, x);
2219     }
2220 




2221     /** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
2222     @IntrinsicCandidate
2223     public final void putBooleanRelease(Object o, long offset, boolean x) {
2224         putBooleanVolatile(o, offset, x);
2225     }
2226 
2227     /** Release version of {@link #putByteVolatile(Object, long, byte)} */
2228     @IntrinsicCandidate
2229     public final void putByteRelease(Object o, long offset, byte x) {
2230         putByteVolatile(o, offset, x);
2231     }
2232 
2233     /** Release version of {@link #putShortVolatile(Object, long, short)} */
2234     @IntrinsicCandidate
2235     public final void putShortRelease(Object o, long offset, short x) {
2236         putShortVolatile(o, offset, x);
2237     }
2238 
2239     /** Release version of {@link #putCharVolatile(Object, long, char)} */
2240     @IntrinsicCandidate

2257     /** Release version of {@link #putLongVolatile(Object, long, long)} */
2258     @IntrinsicCandidate
2259     public final void putLongRelease(Object o, long offset, long x) {
2260         putLongVolatile(o, offset, x);
2261     }
2262 
2263     /** Release version of {@link #putDoubleVolatile(Object, long, double)} */
2264     @IntrinsicCandidate
2265     public final void putDoubleRelease(Object o, long offset, double x) {
2266         putDoubleVolatile(o, offset, x);
2267     }
2268 
2269     // ------------------------------ Opaque --------------------------------------
2270 
2271     /** Opaque version of {@link #getReferenceVolatile(Object, long)} */
2272     @IntrinsicCandidate
2273     public final Object getReferenceOpaque(Object o, long offset) {
2274         return getReferenceVolatile(o, offset);
2275     }
2276 




2277     /** Opaque version of {@link #getBooleanVolatile(Object, long)} */
2278     @IntrinsicCandidate
2279     public final boolean getBooleanOpaque(Object o, long offset) {
2280         return getBooleanVolatile(o, offset);
2281     }
2282 
2283     /** Opaque version of {@link #getByteVolatile(Object, long)} */
2284     @IntrinsicCandidate
2285     public final byte getByteOpaque(Object o, long offset) {
2286         return getByteVolatile(o, offset);
2287     }
2288 
2289     /** Opaque version of {@link #getShortVolatile(Object, long)} */
2290     @IntrinsicCandidate
2291     public final short getShortOpaque(Object o, long offset) {
2292         return getShortVolatile(o, offset);
2293     }
2294 
2295     /** Opaque version of {@link #getCharVolatile(Object, long)} */
2296     @IntrinsicCandidate

2311     }
2312 
2313     /** Opaque version of {@link #getLongVolatile(Object, long)} */
2314     @IntrinsicCandidate
2315     public final long getLongOpaque(Object o, long offset) {
2316         return getLongVolatile(o, offset);
2317     }
2318 
2319     /** Opaque version of {@link #getDoubleVolatile(Object, long)} */
2320     @IntrinsicCandidate
2321     public final double getDoubleOpaque(Object o, long offset) {
2322         return getDoubleVolatile(o, offset);
2323     }
2324 
2325     /** Opaque version of {@link #putReferenceVolatile(Object, long, Object)} */
2326     @IntrinsicCandidate
2327     public final void putReferenceOpaque(Object o, long offset, Object x) {
2328         putReferenceVolatile(o, offset, x);
2329     }
2330 




2331     /** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
2332     @IntrinsicCandidate
2333     public final void putBooleanOpaque(Object o, long offset, boolean x) {
2334         putBooleanVolatile(o, offset, x);
2335     }
2336 
2337     /** Opaque version of {@link #putByteVolatile(Object, long, byte)} */
2338     @IntrinsicCandidate
2339     public final void putByteOpaque(Object o, long offset, byte x) {
2340         putByteVolatile(o, offset, x);
2341     }
2342 
2343     /** Opaque version of {@link #putShortVolatile(Object, long, short)} */
2344     @IntrinsicCandidate
2345     public final void putShortOpaque(Object o, long offset, short x) {
2346         putShortVolatile(o, offset, x);
2347     }
2348 
2349     /** Opaque version of {@link #putCharVolatile(Object, long, char)} */
2350     @IntrinsicCandidate

2745     /**
2746      * Atomically exchanges the given reference value with the current
2747      * reference value of a field or array element within the given
2748      * object {@code o} at the given {@code offset}.
2749      *
2750      * @param o object/array to update the field/element in
2751      * @param offset field/element offset
2752      * @param newValue new value
2753      * @return the previous value
2754      * @since 1.8
2755      */
2756     @IntrinsicCandidate
2757     public final Object getAndSetReference(Object o, long offset, Object newValue) {
2758         Object v;
2759         do {
2760             v = getReferenceVolatile(o, offset);
2761         } while (!weakCompareAndSetReference(o, offset, v, newValue));
2762         return v;
2763     }
2764 









2765     @ForceInline
2766     public final Object getAndSetReferenceRelease(Object o, long offset, Object newValue) {
2767         Object v;
2768         do {
2769             v = getReference(o, offset);
2770         } while (!weakCompareAndSetReferenceRelease(o, offset, v, newValue));
2771         return v;
2772     }
2773 





2774     @ForceInline
2775     public final Object getAndSetReferenceAcquire(Object o, long offset, Object newValue) {
2776         Object v;
2777         do {
2778             v = getReferenceAcquire(o, offset);
2779         } while (!weakCompareAndSetReferenceAcquire(o, offset, v, newValue));
2780         return v;
2781     }
2782 





2783     @IntrinsicCandidate
2784     public final byte getAndSetByte(Object o, long offset, byte newValue) {
2785         byte v;
2786         do {
2787             v = getByteVolatile(o, offset);
2788         } while (!weakCompareAndSetByte(o, offset, v, newValue));
2789         return v;
2790     }
2791 
2792     @ForceInline
2793     public final byte getAndSetByteRelease(Object o, long offset, byte newValue) {
2794         byte v;
2795         do {
2796             v = getByte(o, offset);
2797         } while (!weakCompareAndSetByteRelease(o, offset, v, newValue));
2798         return v;
2799     }
2800 
2801     @ForceInline
2802     public final byte getAndSetByteAcquire(Object o, long offset, byte newValue) {

3820     private static long convEndian(boolean big, long n)   { return big == BIG_ENDIAN ? n : Long.reverseBytes(n)     ; }
3821 
3822 
3823 
3824     private native long allocateMemory0(long bytes);
3825     private native long reallocateMemory0(long address, long bytes);
3826     private native void freeMemory0(long address);
3827     @IntrinsicCandidate
3828     private native void setMemory0(Object o, long offset, long bytes, byte value);
3829     @IntrinsicCandidate
3830     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
3831     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
3832     private native long objectFieldOffset0(Field f);
3833     private native long objectFieldOffset1(Class<?> c, String name);
3834     private native long staticFieldOffset0(Field f);
3835     private native Object staticFieldBase0(Field f);
3836     private native boolean shouldBeInitialized0(Class<?> c);
3837     private native void ensureClassInitialized0(Class<?> c);
3838     private native int arrayBaseOffset0(Class<?> arrayClass);
3839     private native int arrayIndexScale0(Class<?> arrayClass);

3840     private native int getLoadAverage0(double[] loadavg, int nelems);
3841 
3842 
3843     /**
3844      * Invokes the given direct byte buffer's cleaner, if any.
3845      *
3846      * @param directBuffer a direct byte buffer
3847      * @throws NullPointerException     if {@code directBuffer} is null
3848      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
3849      *                                  or is a {@link java.nio.Buffer#slice slice}, or is a
3850      *                                  {@link java.nio.Buffer#duplicate duplicate}
3851      */
3852     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
3853         if (!directBuffer.isDirect())
3854             throw new IllegalArgumentException("buffer is non-direct");
3855 
3856         DirectBuffer db = (DirectBuffer) directBuffer;
3857         if (db.attachment() != null)
3858             throw new IllegalArgumentException("duplicate or slice");
3859 

 160      * The first two parameters are interpreted exactly as with
 161      * {@link #getInt(Object, long)} to refer to a specific
 162      * Java variable (field or array element).  The given value
 163      * is stored into that variable.
 164      * <p>
 165      * The variable must be of the same type as the method
 166      * parameter {@code x}.
 167      *
 168      * @param o Java heap object in which the variable resides, if any, else
 169      *        null
 170      * @param offset indication of where the variable resides in a Java heap
 171      *        object, if any, else a memory address locating the variable
 172      *        statically
 173      * @param x the value to store into the indicated Java variable
 174      * @throws RuntimeException No defined exceptions are thrown, not even
 175      *         {@link NullPointerException}
 176      */
 177     @IntrinsicCandidate
 178     public native void putInt(Object o, long offset, int x);
 179 
 180 
 181     /**
 182      * Returns true if the given field is flattened.
 183      */
 184     public boolean isFlatField(Field f) {
 185         if (f == null) {
 186             throw new NullPointerException();
 187         }
 188         return isFlatField0(f);
 189     }
 190 
 191     private native boolean isFlatField0(Object o);
 192 
 193     /* Returns true if the given field has a null marker
 194      * <p>
 195      * Nullable flat fields are stored in a flattened representation
 196      * and have an associated null marker to indicate if the the field value is
 197      * null or the one stored with the flat representation
 198      */
 199 
 200      public boolean hasNullMarker(Field f) {
 201         if (f == null) {
 202             throw new NullPointerException();
 203         }
 204         return hasNullMarker0(f);
 205      }
 206 
 207      private native boolean hasNullMarker0(Object o);
 208 
 209      /* Returns the offset of the null marker of the field,
 210       * or -1 if the field doesn't have a null marker
 211       */
 212 
 213      public int nullMarkerOffset(Field f) {
 214         if (f == null) {
 215             throw new NullPointerException();
 216         }
 217         return nullMarkerOffset0(f);
 218      }
 219 
 220      private native int nullMarkerOffset0(Object o);
 221 
 222     /**
 223      * Returns true if the given class is a flattened array.
 224      */
 225     @IntrinsicCandidate
 226     public native boolean isFlatArray(Class<?> arrayClass);
 227 
 228     /**
 229      * Fetches a reference value from a given Java variable.
 230      * This method can return a reference to either an object or value
 231      * or a null reference.
 232      *
 233      * @see #getInt(Object, long)
 234      */
 235     @IntrinsicCandidate
 236     public native Object getReference(Object o, long offset);
 237 
 238     /**
 239      * Stores a reference value into a given Java variable.
 240      * This method can store a reference to either an object or value
 241      * or a null reference.
 242      * <p>
 243      * Unless the reference {@code x} being stored is either null
 244      * or matches the field type, the results are undefined.
 245      * If the reference {@code o} is non-null, card marks or
 246      * other store barriers for that object (if the VM requires them)
 247      * are updated.
 248      * @see #putInt(Object, long, int)
 249      */
 250     @IntrinsicCandidate
 251     public native void putReference(Object o, long offset, Object x);
 252 
 253     /**
 254      * Fetches a value of type {@code <V>} from a given Java variable.
 255      * More specifically, fetches a field or array element within the given
 256      * {@code o} object at the given offset, or (if {@code o} is null)
 257      * from the memory address whose numerical value is the given offset.
 258      *
 259      * @param o Java heap object in which the variable resides, if any, else
 260      *        null
 261      * @param offset indication of where the variable resides in a Java heap
 262      *        object, if any, else a memory address locating the variable
 263      *        statically
 264      * @param valueType value type
 265      * @param <V> the type of a value
 266      * @return the value fetched from the indicated Java variable
 267      * @throws RuntimeException No defined exceptions are thrown, not even
 268      *         {@link NullPointerException}
 269      */
 270     @IntrinsicCandidate
 271     public native <V> V getValue(Object o, long offset, Class<?> valueType);
 272 
 273     /**
 274      * Stores the given value into a given Java variable.
 275      *
 276      * Unless the reference {@code o} being stored is either null
 277      * or matches the field type, the results are undefined.
 278      *
 279      * @param o Java heap object in which the variable resides, if any, else
 280      *        null
 281      * @param offset indication of where the variable resides in a Java heap
 282      *        object, if any, else a memory address locating the variable
 283      *        statically
 284      * @param valueType value type
 285      * @param v the value to store into the indicated Java variable
 286      * @param <V> the type of a value
 287      * @throws RuntimeException No defined exceptions are thrown, not even
 288      *         {@link NullPointerException}
 289      */
 290     @IntrinsicCandidate
 291     public native <V> void putValue(Object o, long offset, Class<?> valueType, V v);
 292 
 293     /**
 294      * Returns an uninitialized default instance of the given value class.
 295      */
 296     public native <V> V uninitializedDefaultValue(Class<?> type);
 297 
 298     /**
 299      * Returns an object instance with a private buffered value whose layout
 300      * and contents is exactly the given value instance.  The return object
 301      * is in the larval state that can be updated using the unsafe put operation.
 302      *
 303      * @param value a value instance
 304      * @param <V> the type of the given value instance
 305      */
 306     @IntrinsicCandidate
 307     public native <V> V makePrivateBuffer(V value);
 308 
 309     /**
 310      * Exits the larval state and returns a value instance.
 311      *
 312      * @param value a value instance
 313      * @param <V> the type of the given value instance
 314      */
 315     @IntrinsicCandidate
 316     public native <V> V finishPrivateBuffer(V value);
 317 
 318     /**
 319      * Returns the header size of the given value type.
 320      *
 321      * @param valueType value type
 322      * @return the header size of the value type
 323      */
 324     public native <V> long valueHeaderSize(Class<V> valueType);
 325 
 326     /** @see #getInt(Object, long) */
 327     @IntrinsicCandidate
 328     public native boolean getBoolean(Object o, long offset);
 329 
 330     /** @see #putInt(Object, long, int) */
 331     @IntrinsicCandidate
 332     public native void    putBoolean(Object o, long offset, boolean x);
 333 
 334     /** @see #getInt(Object, long) */
 335     @IntrinsicCandidate
 336     public native byte    getByte(Object o, long offset);
 337 
 338     /** @see #putInt(Object, long, int) */
 339     @IntrinsicCandidate
 340     public native void    putByte(Object o, long offset, byte x);
 341 
 342     /** @see #getInt(Object, long) */
 343     @IntrinsicCandidate
 344     public native short   getShort(Object o, long offset);
 345 

1344 
1345     /**
1346      * Reports the scale factor for addressing elements in the storage
1347      * allocation of a given array class.  However, arrays of "narrow" types
1348      * will generally not work properly with accessors like {@link
1349      * #getByte(Object, long)}, so the scale factor for such classes is reported
1350      * as zero.
1351      *
1352      * @see #arrayBaseOffset
1353      * @see #getInt(Object, long)
1354      * @see #putInt(Object, long, int)
1355      */
1356     public int arrayIndexScale(Class<?> arrayClass) {
1357         if (arrayClass == null) {
1358             throw new NullPointerException();
1359         }
1360 
1361         return arrayIndexScale0(arrayClass);
1362     }
1363 
1364     /**
1365      * Return the size of the object in the heap.
1366      * @param o an object
1367      * @return the objects's size
1368      * @since Valhalla
1369      */
1370     public long getObjectSize(Object o) {
1371         if (o == null)
1372             throw new NullPointerException();
1373         return getObjectSize0(o);
1374     }
1375 
1376     /** The value of {@code arrayIndexScale(boolean[].class)} */
1377     public static final int ARRAY_BOOLEAN_INDEX_SCALE
1378             = theUnsafe.arrayIndexScale(boolean[].class);
1379 
1380     /** The value of {@code arrayIndexScale(byte[].class)} */
1381     public static final int ARRAY_BYTE_INDEX_SCALE
1382             = theUnsafe.arrayIndexScale(byte[].class);
1383 
1384     /** The value of {@code arrayIndexScale(short[].class)} */
1385     public static final int ARRAY_SHORT_INDEX_SCALE
1386             = theUnsafe.arrayIndexScale(short[].class);
1387 
1388     /** The value of {@code arrayIndexScale(char[].class)} */
1389     public static final int ARRAY_CHAR_INDEX_SCALE
1390             = theUnsafe.arrayIndexScale(char[].class);
1391 
1392     /** The value of {@code arrayIndexScale(int[].class)} */
1393     public static final int ARRAY_INT_INDEX_SCALE
1394             = theUnsafe.arrayIndexScale(int[].class);

1533        return null;
1534     }
1535 
1536     /** Throws the exception without telling the verifier. */
1537     public native void throwException(Throwable ee);
1538 
1539     /**
1540      * Atomically updates Java variable to {@code x} if it is currently
1541      * holding {@code expected}.
1542      *
1543      * <p>This operation has memory semantics of a {@code volatile} read
1544      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1545      *
1546      * @return {@code true} if successful
1547      */
1548     @IntrinsicCandidate
1549     public final native boolean compareAndSetReference(Object o, long offset,
1550                                                        Object expected,
1551                                                        Object x);
1552 
1553     private final boolean isValueObject(Object o) {
1554         return o != null && o.getClass().isValue();
1555     }
1556 
1557     /*
1558      * For value type, CAS should do substitutability test as opposed
1559      * to two pointers comparison.
1560      *
1561      * TODO: replace global lock workaround with the proper support for
1562      * atomic access to value objects and loosely consistent values.
1563      */
1564     public final <V> boolean compareAndSetReference(Object o, long offset,
1565                                                     Class<?> type,
1566                                                     V expected,
1567                                                     V x) {
1568         if (type.isValue() || isValueObject(expected)) {
1569             synchronized (valueLock) {
1570                 Object witness = getReference(o, offset);
1571                 if (witness == expected) {
1572                     putReference(o, offset, x);
1573                     return true;
1574                 } else {
1575                     return false;
1576                 }
1577             }
1578         } else {
1579             return compareAndSetReference(o, offset, expected, x);
1580         }
1581     }
1582 
1583     @ForceInline
1584     public final <V> boolean compareAndSetValue(Object o, long offset,
1585                                                 Class<?> valueType,
1586                                                 V expected,
1587                                                 V x) {
1588         synchronized (valueLock) {
1589             Object witness = getValue(o, offset, valueType);
1590             if (witness == expected) {
1591                 putValue(o, offset, valueType, x);
1592                 return true;
1593             }
1594             else {
1595                 return false;
1596             }
1597         }
1598     }
1599 
1600     @IntrinsicCandidate
1601     public final native Object compareAndExchangeReference(Object o, long offset,
1602                                                            Object expected,
1603                                                            Object x);
1604 
1605     public final <V> Object compareAndExchangeReference(Object o, long offset,
1606                                                         Class<?> valueType,
1607                                                         V expected,
1608                                                         V x) {
1609         if (valueType.isValue() || isValueObject(expected)) {
1610             synchronized (valueLock) {
1611                 Object witness = getReference(o, offset);
1612                 if (witness == expected) {
1613                     putReference(o, offset, x);
1614                 }
1615                 return witness;
1616             }
1617         } else {
1618             return compareAndExchangeReference(o, offset, expected, x);
1619         }
1620     }
1621 
1622     @ForceInline
1623     public final <V> Object compareAndExchangeValue(Object o, long offset,
1624                                                     Class<?> valueType,
1625                                                     V expected,
1626                                                     V x) {
1627         synchronized (valueLock) {
1628             Object witness = getValue(o, offset, valueType);
1629             if (witness == expected) {
1630                 putValue(o, offset, valueType, x);
1631             }
1632             return witness;
1633         }
1634     }
1635 
1636     @IntrinsicCandidate
1637     public final Object compareAndExchangeReferenceAcquire(Object o, long offset,
1638                                                            Object expected,
1639                                                            Object x) {
1640         return compareAndExchangeReference(o, offset, expected, x);
1641     }
1642 
1643     public final <V> Object compareAndExchangeReferenceAcquire(Object o, long offset,
1644                                                                Class<?> valueType,
1645                                                                V expected,
1646                                                                V x) {
1647         return compareAndExchangeReference(o, offset, valueType, expected, x);
1648     }
1649 
1650     @ForceInline
1651     public final <V> Object compareAndExchangeValueAcquire(Object o, long offset,
1652                                                            Class<?> valueType,
1653                                                            V expected,
1654                                                            V x) {
1655         return compareAndExchangeValue(o, offset, valueType, expected, x);
1656     }
1657 
1658     @IntrinsicCandidate
1659     public final Object compareAndExchangeReferenceRelease(Object o, long offset,
1660                                                            Object expected,
1661                                                            Object x) {
1662         return compareAndExchangeReference(o, offset, expected, x);
1663     }
1664 
1665     public final <V> Object compareAndExchangeReferenceRelease(Object o, long offset,
1666                                                                Class<?> valueType,
1667                                                                V expected,
1668                                                                V x) {
1669         return compareAndExchangeReference(o, offset, valueType, expected, x);
1670     }
1671 
1672     @ForceInline
1673     public final <V> Object compareAndExchangeValueRelease(Object o, long offset,
1674                                                            Class<?> valueType,
1675                                                            V expected,
1676                                                            V x) {
1677         return compareAndExchangeValue(o, offset, valueType, expected, x);
1678     }
1679 
1680     @IntrinsicCandidate
1681     public final boolean weakCompareAndSetReferencePlain(Object o, long offset,
1682                                                          Object expected,
1683                                                          Object x) {
1684         return compareAndSetReference(o, offset, expected, x);
1685     }
1686 
1687     public final <V> boolean weakCompareAndSetReferencePlain(Object o, long offset,
1688                                                              Class<?> valueType,
1689                                                              V expected,
1690                                                              V x) {
1691         if (valueType.isValue() || isValueObject(expected)) {
1692             return compareAndSetReference(o, offset, valueType, expected, x);
1693         } else {
1694             return weakCompareAndSetReferencePlain(o, offset, expected, x);
1695         }
1696     }
1697 
1698     @ForceInline
1699     public final <V> boolean weakCompareAndSetValuePlain(Object o, long offset,
1700                                                          Class<?> valueType,
1701                                                          V expected,
1702                                                          V x) {
1703         return compareAndSetValue(o, offset, valueType, expected, x);
1704     }
1705 
1706     @IntrinsicCandidate
1707     public final boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
1708                                                            Object expected,
1709                                                            Object x) {
1710         return compareAndSetReference(o, offset, expected, x);
1711     }
1712 
1713     public final <V> boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
1714                                                                Class<?> valueType,
1715                                                                V expected,
1716                                                                V x) {
1717         if (valueType.isValue() || isValueObject(expected)) {
1718             return compareAndSetReference(o, offset, valueType, expected, x);
1719         } else {
1720             return weakCompareAndSetReferencePlain(o, offset, expected, x);
1721         }
1722     }
1723 
1724     @ForceInline
1725     public final <V> boolean weakCompareAndSetValueAcquire(Object o, long offset,
1726                                                            Class<?> valueType,
1727                                                            V expected,
1728                                                            V x) {
1729         return compareAndSetValue(o, offset, valueType, expected, x);
1730     }
1731 
1732     @IntrinsicCandidate
1733     public final boolean weakCompareAndSetReferenceRelease(Object o, long offset,
1734                                                            Object expected,
1735                                                            Object x) {
1736         return compareAndSetReference(o, offset, expected, x);
1737     }
1738 
1739     public final <V> boolean weakCompareAndSetReferenceRelease(Object o, long offset,
1740                                                                Class<?> valueType,
1741                                                                V expected,
1742                                                                V x) {
1743         if (valueType.isValue() || isValueObject(expected)) {
1744             return compareAndSetReference(o, offset, valueType, expected, x);
1745         } else {
1746             return weakCompareAndSetReferencePlain(o, offset, expected, x);
1747         }
1748     }
1749 
1750     @ForceInline
1751     public final <V> boolean weakCompareAndSetValueRelease(Object o, long offset,
1752                                                            Class<?> valueType,
1753                                                            V expected,
1754                                                            V x) {
1755         return compareAndSetValue(o, offset, valueType, expected, x);
1756     }
1757 
1758     @IntrinsicCandidate
1759     public final boolean weakCompareAndSetReference(Object o, long offset,
1760                                                     Object expected,
1761                                                     Object x) {
1762         return compareAndSetReference(o, offset, expected, x);
1763     }
1764 
1765     public final <V> boolean weakCompareAndSetReference(Object o, long offset,
1766                                                         Class<?> valueType,
1767                                                         V expected,
1768                                                         V x) {
1769         if (valueType.isValue() || isValueObject(expected)) {
1770             return compareAndSetReference(o, offset, valueType, expected, x);
1771         } else {
1772             return weakCompareAndSetReferencePlain(o, offset, expected, x);
1773         }
1774     }
1775 
1776     @ForceInline
1777     public final <V> boolean weakCompareAndSetValue(Object o, long offset,
1778                                                     Class<?> valueType,
1779                                                     V expected,
1780                                                     V x) {
1781         return compareAndSetValue(o, offset, valueType, expected, x);
1782     }
1783 
1784     /**
1785      * Atomically updates Java variable to {@code x} if it is currently
1786      * holding {@code expected}.
1787      *
1788      * <p>This operation has memory semantics of a {@code volatile} read
1789      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1790      *
1791      * @return {@code true} if successful
1792      */
1793     @IntrinsicCandidate
1794     public final native boolean compareAndSetInt(Object o, long offset,
1795                                                  int expected,
1796                                                  int x);
1797 
1798     @IntrinsicCandidate
1799     public final native int compareAndExchangeInt(Object o, long offset,
1800                                                   int expected,
1801                                                   int x);
1802 
1803     @IntrinsicCandidate

2379     public final boolean weakCompareAndSetLongRelease(Object o, long offset,
2380                                                       long expected,
2381                                                       long x) {
2382         return compareAndSetLong(o, offset, expected, x);
2383     }
2384 
2385     @IntrinsicCandidate
2386     public final boolean weakCompareAndSetLong(Object o, long offset,
2387                                                long expected,
2388                                                long x) {
2389         return compareAndSetLong(o, offset, expected, x);
2390     }
2391 
2392     /**
2393      * Fetches a reference value from a given Java variable, with volatile
2394      * load semantics. Otherwise identical to {@link #getReference(Object, long)}
2395      */
2396     @IntrinsicCandidate
2397     public native Object getReferenceVolatile(Object o, long offset);
2398 
2399     /**
2400      * Global lock for atomic and volatile strength access to any value of
2401      * a value type.  This is a temporary workaround until better localized
2402      * atomic access mechanisms are supported for value class and primitive class.
2403      */
2404     private static final Object valueLock = new Object();
2405 
2406     public final <V> Object getValueVolatile(Object base, long offset, Class<?> valueType) {
2407         synchronized (valueLock) {
2408             return getValue(base, offset, valueType);
2409         }
2410     }
2411 
2412     /**
2413      * Stores a reference value into a given Java variable, with
2414      * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
2415      */
2416     @IntrinsicCandidate
2417     public native void putReferenceVolatile(Object o, long offset, Object x);
2418 
2419     public final <V> void putValueVolatile(Object o, long offset, Class<?> valueType, V x) {
2420         synchronized (valueLock) {
2421             putValue(o, offset, valueType, x);
2422         }
2423     }
2424 
2425     /** Volatile version of {@link #getInt(Object, long)}  */
2426     @IntrinsicCandidate
2427     public native int     getIntVolatile(Object o, long offset);
2428 
2429     /** Volatile version of {@link #putInt(Object, long, int)}  */
2430     @IntrinsicCandidate
2431     public native void    putIntVolatile(Object o, long offset, int x);
2432 
2433     /** Volatile version of {@link #getBoolean(Object, long)}  */
2434     @IntrinsicCandidate
2435     public native boolean getBooleanVolatile(Object o, long offset);
2436 
2437     /** Volatile version of {@link #putBoolean(Object, long, boolean)}  */
2438     @IntrinsicCandidate
2439     public native void    putBooleanVolatile(Object o, long offset, boolean x);
2440 
2441     /** Volatile version of {@link #getByte(Object, long)}  */
2442     @IntrinsicCandidate
2443     public native byte    getByteVolatile(Object o, long offset);
2444 

2477     /** Volatile version of {@link #putFloat(Object, long, float)}  */
2478     @IntrinsicCandidate
2479     public native void    putFloatVolatile(Object o, long offset, float x);
2480 
2481     /** Volatile version of {@link #getDouble(Object, long)}  */
2482     @IntrinsicCandidate
2483     public native double  getDoubleVolatile(Object o, long offset);
2484 
2485     /** Volatile version of {@link #putDouble(Object, long, double)}  */
2486     @IntrinsicCandidate
2487     public native void    putDoubleVolatile(Object o, long offset, double x);
2488 
2489 
2490 
2491     /** Acquire version of {@link #getReferenceVolatile(Object, long)} */
2492     @IntrinsicCandidate
2493     public final Object getReferenceAcquire(Object o, long offset) {
2494         return getReferenceVolatile(o, offset);
2495     }
2496 
2497     public final <V> Object getValueAcquire(Object base, long offset, Class<?> valueType) {
2498         return getValueVolatile(base, offset, valueType);
2499     }
2500 
2501     /** Acquire version of {@link #getBooleanVolatile(Object, long)} */
2502     @IntrinsicCandidate
2503     public final boolean getBooleanAcquire(Object o, long offset) {
2504         return getBooleanVolatile(o, offset);
2505     }
2506 
2507     /** Acquire version of {@link #getByteVolatile(Object, long)} */
2508     @IntrinsicCandidate
2509     public final byte getByteAcquire(Object o, long offset) {
2510         return getByteVolatile(o, offset);
2511     }
2512 
2513     /** Acquire version of {@link #getShortVolatile(Object, long)} */
2514     @IntrinsicCandidate
2515     public final short getShortAcquire(Object o, long offset) {
2516         return getShortVolatile(o, offset);
2517     }
2518 
2519     /** Acquire version of {@link #getCharVolatile(Object, long)} */
2520     @IntrinsicCandidate

2545     public final double getDoubleAcquire(Object o, long offset) {
2546         return getDoubleVolatile(o, offset);
2547     }
2548 
2549     /*
2550      * Versions of {@link #putReferenceVolatile(Object, long, Object)}
2551      * that do not guarantee immediate visibility of the store to
2552      * other threads. This method is generally only useful if the
2553      * underlying field is a Java volatile (or if an array cell, one
2554      * that is otherwise only accessed using volatile accesses).
2555      *
2556      * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
2557      */
2558 
2559     /** Release version of {@link #putReferenceVolatile(Object, long, Object)} */
2560     @IntrinsicCandidate
2561     public final void putReferenceRelease(Object o, long offset, Object x) {
2562         putReferenceVolatile(o, offset, x);
2563     }
2564 
2565     public final <V> void putValueRelease(Object o, long offset, Class<?> valueType, V x) {
2566         putValueVolatile(o, offset, valueType, x);
2567     }
2568 
2569     /** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
2570     @IntrinsicCandidate
2571     public final void putBooleanRelease(Object o, long offset, boolean x) {
2572         putBooleanVolatile(o, offset, x);
2573     }
2574 
2575     /** Release version of {@link #putByteVolatile(Object, long, byte)} */
2576     @IntrinsicCandidate
2577     public final void putByteRelease(Object o, long offset, byte x) {
2578         putByteVolatile(o, offset, x);
2579     }
2580 
2581     /** Release version of {@link #putShortVolatile(Object, long, short)} */
2582     @IntrinsicCandidate
2583     public final void putShortRelease(Object o, long offset, short x) {
2584         putShortVolatile(o, offset, x);
2585     }
2586 
2587     /** Release version of {@link #putCharVolatile(Object, long, char)} */
2588     @IntrinsicCandidate

2605     /** Release version of {@link #putLongVolatile(Object, long, long)} */
2606     @IntrinsicCandidate
2607     public final void putLongRelease(Object o, long offset, long x) {
2608         putLongVolatile(o, offset, x);
2609     }
2610 
2611     /** Release version of {@link #putDoubleVolatile(Object, long, double)} */
2612     @IntrinsicCandidate
2613     public final void putDoubleRelease(Object o, long offset, double x) {
2614         putDoubleVolatile(o, offset, x);
2615     }
2616 
2617     // ------------------------------ Opaque --------------------------------------
2618 
2619     /** Opaque version of {@link #getReferenceVolatile(Object, long)} */
2620     @IntrinsicCandidate
2621     public final Object getReferenceOpaque(Object o, long offset) {
2622         return getReferenceVolatile(o, offset);
2623     }
2624 
2625     public final <V> Object getValueOpaque(Object base, long offset, Class<?> valueType) {
2626         return getValueVolatile(base, offset, valueType);
2627     }
2628 
2629     /** Opaque version of {@link #getBooleanVolatile(Object, long)} */
2630     @IntrinsicCandidate
2631     public final boolean getBooleanOpaque(Object o, long offset) {
2632         return getBooleanVolatile(o, offset);
2633     }
2634 
2635     /** Opaque version of {@link #getByteVolatile(Object, long)} */
2636     @IntrinsicCandidate
2637     public final byte getByteOpaque(Object o, long offset) {
2638         return getByteVolatile(o, offset);
2639     }
2640 
2641     /** Opaque version of {@link #getShortVolatile(Object, long)} */
2642     @IntrinsicCandidate
2643     public final short getShortOpaque(Object o, long offset) {
2644         return getShortVolatile(o, offset);
2645     }
2646 
2647     /** Opaque version of {@link #getCharVolatile(Object, long)} */
2648     @IntrinsicCandidate

2663     }
2664 
2665     /** Opaque version of {@link #getLongVolatile(Object, long)} */
2666     @IntrinsicCandidate
2667     public final long getLongOpaque(Object o, long offset) {
2668         return getLongVolatile(o, offset);
2669     }
2670 
2671     /** Opaque version of {@link #getDoubleVolatile(Object, long)} */
2672     @IntrinsicCandidate
2673     public final double getDoubleOpaque(Object o, long offset) {
2674         return getDoubleVolatile(o, offset);
2675     }
2676 
2677     /** Opaque version of {@link #putReferenceVolatile(Object, long, Object)} */
2678     @IntrinsicCandidate
2679     public final void putReferenceOpaque(Object o, long offset, Object x) {
2680         putReferenceVolatile(o, offset, x);
2681     }
2682 
2683     public final <V> void putValueOpaque(Object o, long offset, Class<?> valueType, V x) {
2684         putValueVolatile(o, offset, valueType, x);
2685     }
2686 
2687     /** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
2688     @IntrinsicCandidate
2689     public final void putBooleanOpaque(Object o, long offset, boolean x) {
2690         putBooleanVolatile(o, offset, x);
2691     }
2692 
2693     /** Opaque version of {@link #putByteVolatile(Object, long, byte)} */
2694     @IntrinsicCandidate
2695     public final void putByteOpaque(Object o, long offset, byte x) {
2696         putByteVolatile(o, offset, x);
2697     }
2698 
2699     /** Opaque version of {@link #putShortVolatile(Object, long, short)} */
2700     @IntrinsicCandidate
2701     public final void putShortOpaque(Object o, long offset, short x) {
2702         putShortVolatile(o, offset, x);
2703     }
2704 
2705     /** Opaque version of {@link #putCharVolatile(Object, long, char)} */
2706     @IntrinsicCandidate

3101     /**
3102      * Atomically exchanges the given reference value with the current
3103      * reference value of a field or array element within the given
3104      * object {@code o} at the given {@code offset}.
3105      *
3106      * @param o object/array to update the field/element in
3107      * @param offset field/element offset
3108      * @param newValue new value
3109      * @return the previous value
3110      * @since 1.8
3111      */
3112     @IntrinsicCandidate
3113     public final Object getAndSetReference(Object o, long offset, Object newValue) {
3114         Object v;
3115         do {
3116             v = getReferenceVolatile(o, offset);
3117         } while (!weakCompareAndSetReference(o, offset, v, newValue));
3118         return v;
3119     }
3120 
3121     @SuppressWarnings("unchecked")
3122     public final <V> Object getAndSetValue(Object o, long offset, Class<?> valueType, V newValue) {
3123         synchronized (valueLock) {
3124             Object oldValue = getValue(o, offset, valueType);
3125             putValue(o, offset, valueType, newValue);
3126             return oldValue;
3127         }
3128     }
3129 
3130     @ForceInline
3131     public final Object getAndSetReferenceRelease(Object o, long offset, Object newValue) {
3132         Object v;
3133         do {
3134             v = getReference(o, offset);
3135         } while (!weakCompareAndSetReferenceRelease(o, offset, v, newValue));
3136         return v;
3137     }
3138 
3139     @ForceInline
3140     public final <V> Object getAndSetValueRelease(Object o, long offset, Class<?> valueType, V newValue) {
3141         return getAndSetValue(o, offset, valueType, newValue);
3142     }
3143 
3144     @ForceInline
3145     public final Object getAndSetReferenceAcquire(Object o, long offset, Object newValue) {
3146         Object v;
3147         do {
3148             v = getReferenceAcquire(o, offset);
3149         } while (!weakCompareAndSetReferenceAcquire(o, offset, v, newValue));
3150         return v;
3151     }
3152 
3153     @ForceInline
3154     public final <V> Object getAndSetValueAcquire(Object o, long offset, Class<?> valueType, V newValue) {
3155         return getAndSetValue(o, offset, valueType, newValue);
3156     }
3157 
3158     @IntrinsicCandidate
3159     public final byte getAndSetByte(Object o, long offset, byte newValue) {
3160         byte v;
3161         do {
3162             v = getByteVolatile(o, offset);
3163         } while (!weakCompareAndSetByte(o, offset, v, newValue));
3164         return v;
3165     }
3166 
3167     @ForceInline
3168     public final byte getAndSetByteRelease(Object o, long offset, byte newValue) {
3169         byte v;
3170         do {
3171             v = getByte(o, offset);
3172         } while (!weakCompareAndSetByteRelease(o, offset, v, newValue));
3173         return v;
3174     }
3175 
3176     @ForceInline
3177     public final byte getAndSetByteAcquire(Object o, long offset, byte newValue) {

4195     private static long convEndian(boolean big, long n)   { return big == BIG_ENDIAN ? n : Long.reverseBytes(n)     ; }
4196 
4197 
4198 
4199     private native long allocateMemory0(long bytes);
4200     private native long reallocateMemory0(long address, long bytes);
4201     private native void freeMemory0(long address);
4202     @IntrinsicCandidate
4203     private native void setMemory0(Object o, long offset, long bytes, byte value);
4204     @IntrinsicCandidate
4205     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
4206     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
4207     private native long objectFieldOffset0(Field f);
4208     private native long objectFieldOffset1(Class<?> c, String name);
4209     private native long staticFieldOffset0(Field f);
4210     private native Object staticFieldBase0(Field f);
4211     private native boolean shouldBeInitialized0(Class<?> c);
4212     private native void ensureClassInitialized0(Class<?> c);
4213     private native int arrayBaseOffset0(Class<?> arrayClass);
4214     private native int arrayIndexScale0(Class<?> arrayClass);
4215     private native long getObjectSize0(Object o);
4216     private native int getLoadAverage0(double[] loadavg, int nelems);
4217 
4218 
4219     /**
4220      * Invokes the given direct byte buffer's cleaner, if any.
4221      *
4222      * @param directBuffer a direct byte buffer
4223      * @throws NullPointerException     if {@code directBuffer} is null
4224      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
4225      *                                  or is a {@link java.nio.Buffer#slice slice}, or is a
4226      *                                  {@link java.nio.Buffer#duplicate duplicate}
4227      */
4228     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
4229         if (!directBuffer.isDirect())
4230             throw new IllegalArgumentException("buffer is non-direct");
4231 
4232         DirectBuffer db = (DirectBuffer) directBuffer;
4233         if (db.attachment() != null)
4234             throw new IllegalArgumentException("duplicate or slice");
4235 
< prev index next >