< 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 

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











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

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















































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































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















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















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



















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



















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



















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



















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

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













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






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

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




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

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




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

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




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

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




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

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









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





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





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

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

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

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

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

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

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

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

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

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

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

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

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