< 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) {

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

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

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

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

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

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

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

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

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

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

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

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