1 /*
2 * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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
|
1 /*
2 * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
160 * The first two parameters are interpreted exactly as with
161 * {@link #getInt(Object, long)} to refer to a specific
162 * Java variable (field or array element). The given value
163 * is stored into that variable.
164 * <p>
165 * The variable must be of the same type as the method
166 * parameter {@code x}.
167 *
168 * @param o Java heap object in which the variable resides, if any, else
169 * null
170 * @param offset indication of where the variable resides in a Java heap
171 * object, if any, else a memory address locating the variable
172 * statically
173 * @param x the value to store into the indicated Java variable
174 * @throws RuntimeException No defined exceptions are thrown, not even
175 * {@link NullPointerException}
176 */
177 @IntrinsicCandidate
178 public native void putInt(Object o, long offset, int x);
179
180
181 /**
182 * Returns true if the given field is flattened.
183 */
184 public boolean isFlatField(Field f) {
185 if (f == null) {
186 throw new NullPointerException();
187 }
188 return isFlatField0(f);
189 }
190
191 private native boolean isFlatField0(Object o);
192
193 /**
194 * Returns true if the given class is a flattened array.
195 */
196 @IntrinsicCandidate
197 public native boolean isFlatArray(Class<?> arrayClass);
198
199 /**
200 * Fetches a reference value from a given Java variable.
201 * This method can return a reference to either an object or value
202 * or a null reference.
203 *
204 * @see #getInt(Object, long)
205 */
206 @IntrinsicCandidate
207 public native Object getReference(Object o, long offset);
208
209 /**
210 * Stores a reference value into a given Java variable.
211 * This method can store a reference to either an object or value
212 * or a null reference.
213 * <p>
214 * Unless the reference {@code x} being stored is either null
215 * or matches the field type, the results are undefined.
216 * If the reference {@code o} is non-null, card marks or
217 * other store barriers for that object (if the VM requires them)
218 * are updated.
219 * @see #putInt(Object, long, int)
220 */
221 @IntrinsicCandidate
222 public native void putReference(Object o, long offset, Object x);
223
224 /**
225 * Fetches a value of type {@code <V>} from a given Java variable.
226 * More specifically, fetches a field or array element within the given
227 * {@code o} object at the given offset, or (if {@code o} is null)
228 * from the memory address whose numerical value is the given offset.
229 *
230 * @param o Java heap object in which the variable resides, if any, else
231 * null
232 * @param offset indication of where the variable resides in a Java heap
233 * object, if any, else a memory address locating the variable
234 * statically
235 * @param valueType value type
236 * @param <V> the type of a value
237 * @return the value fetched from the indicated Java variable
238 * @throws RuntimeException No defined exceptions are thrown, not even
239 * {@link NullPointerException}
240 */
241 @IntrinsicCandidate
242 public native <V> V getValue(Object o, long offset, Class<?> valueType);
243
244 /**
245 * Stores the given value into a given Java variable.
246 *
247 * Unless the reference {@code o} being stored is either null
248 * or matches the field type, the results are undefined.
249 *
250 * @param o Java heap object in which the variable resides, if any, else
251 * null
252 * @param offset indication of where the variable resides in a Java heap
253 * object, if any, else a memory address locating the variable
254 * statically
255 * @param valueType value type
256 * @param v the value to store into the indicated Java variable
257 * @param <V> the type of a value
258 * @throws RuntimeException No defined exceptions are thrown, not even
259 * {@link NullPointerException}
260 */
261 @IntrinsicCandidate
262 public native <V> void putValue(Object o, long offset, Class<?> valueType, V v);
263
264 /**
265 * Returns an uninitialized default instance of the given value class.
266 */
267 public native <V> V uninitializedDefaultValue(Class<?> type);
268
269 /**
270 * Returns an object instance with a private buffered value whose layout
271 * and contents is exactly the given value instance. The return object
272 * is in the larval state that can be updated using the unsafe put operation.
273 *
274 * @param value a value instance
275 * @param <V> the type of the given value instance
276 */
277 @IntrinsicCandidate
278 public native <V> V makePrivateBuffer(V value);
279
280 /**
281 * Exits the larval state and returns a value instance.
282 *
283 * @param value a value instance
284 * @param <V> the type of the given value instance
285 */
286 @IntrinsicCandidate
287 public native <V> V finishPrivateBuffer(V value);
288
289 /**
290 * Returns the header size of the given value type.
291 *
292 * @param valueType value type
293 * @return the header size of the value type
294 */
295 public native <V> long valueHeaderSize(Class<V> valueType);
296
297 /** @see #getInt(Object, long) */
298 @IntrinsicCandidate
299 public native boolean getBoolean(Object o, long offset);
300
301 /** @see #putInt(Object, long, int) */
302 @IntrinsicCandidate
303 public native void putBoolean(Object o, long offset, boolean x);
304
305 /** @see #getInt(Object, long) */
306 @IntrinsicCandidate
307 public native byte getByte(Object o, long offset);
308
309 /** @see #putInt(Object, long, int) */
310 @IntrinsicCandidate
311 public native void putByte(Object o, long offset, byte x);
312
313 /** @see #getInt(Object, long) */
314 @IntrinsicCandidate
315 public native short getShort(Object o, long offset);
316
1314
1315 /**
1316 * Reports the scale factor for addressing elements in the storage
1317 * allocation of a given array class. However, arrays of "narrow" types
1318 * will generally not work properly with accessors like {@link
1319 * #getByte(Object, long)}, so the scale factor for such classes is reported
1320 * as zero.
1321 *
1322 * @see #arrayBaseOffset
1323 * @see #getInt(Object, long)
1324 * @see #putInt(Object, long, int)
1325 */
1326 public int arrayIndexScale(Class<?> arrayClass) {
1327 if (arrayClass == null) {
1328 throw new NullPointerException();
1329 }
1330
1331 return arrayIndexScale0(arrayClass);
1332 }
1333
1334 /**
1335 * Return the size of the object in the heap.
1336 * @param o an object
1337 * @return the objects's size
1338 * @since Valhalla
1339 */
1340 public long getObjectSize(Object o) {
1341 if (o == null)
1342 throw new NullPointerException();
1343 return getObjectSize0(o);
1344 }
1345
1346 /** The value of {@code arrayIndexScale(boolean[].class)} */
1347 public static final int ARRAY_BOOLEAN_INDEX_SCALE
1348 = theUnsafe.arrayIndexScale(boolean[].class);
1349
1350 /** The value of {@code arrayIndexScale(byte[].class)} */
1351 public static final int ARRAY_BYTE_INDEX_SCALE
1352 = theUnsafe.arrayIndexScale(byte[].class);
1353
1354 /** The value of {@code arrayIndexScale(short[].class)} */
1355 public static final int ARRAY_SHORT_INDEX_SCALE
1356 = theUnsafe.arrayIndexScale(short[].class);
1357
1358 /** The value of {@code arrayIndexScale(char[].class)} */
1359 public static final int ARRAY_CHAR_INDEX_SCALE
1360 = theUnsafe.arrayIndexScale(char[].class);
1361
1362 /** The value of {@code arrayIndexScale(int[].class)} */
1363 public static final int ARRAY_INT_INDEX_SCALE
1364 = theUnsafe.arrayIndexScale(int[].class);
1503 return null;
1504 }
1505
1506 /** Throws the exception without telling the verifier. */
1507 public native void throwException(Throwable ee);
1508
1509 /**
1510 * Atomically updates Java variable to {@code x} if it is currently
1511 * holding {@code expected}.
1512 *
1513 * <p>This operation has memory semantics of a {@code volatile} read
1514 * and write. Corresponds to C11 atomic_compare_exchange_strong.
1515 *
1516 * @return {@code true} if successful
1517 */
1518 @IntrinsicCandidate
1519 public final native boolean compareAndSetReference(Object o, long offset,
1520 Object expected,
1521 Object x);
1522
1523 private final boolean isValueObject(Object o) {
1524 return o != null && o.getClass().isValue();
1525 }
1526
1527 /*
1528 * For primitive type, CAS should do substitutability test as opposed
1529 * to two pointers comparison.
1530 *
1531 * Perhaps we can keep the xxxObject methods for compatibility and
1532 * change the JDK 13 xxxReference method signature freely.
1533 */
1534 public final <V> boolean compareAndSetReference(Object o, long offset,
1535 Class<?> type,
1536 V expected,
1537 V x) {
1538 if (type.isValue() || isValueObject(expected)) {
1539 synchronized (valueLock) {
1540 Object witness = getReference(o, offset);
1541 if (witness == expected) {
1542 putReference(o, offset, x);
1543 return true;
1544 } else {
1545 return false;
1546 }
1547 }
1548 } else {
1549 return compareAndSetReference(o, offset, expected, x);
1550 }
1551 }
1552
1553 @ForceInline
1554 public final <V> boolean compareAndSetValue(Object o, long offset,
1555 Class<?> valueType,
1556 V expected,
1557 V x) {
1558 synchronized (valueLock) {
1559 Object witness = getValue(o, offset, valueType);
1560 if (witness == expected) {
1561 putValue(o, offset, valueType, x);
1562 return true;
1563 }
1564 else {
1565 return false;
1566 }
1567 }
1568 }
1569
1570 @IntrinsicCandidate
1571 public final native Object compareAndExchangeReference(Object o, long offset,
1572 Object expected,
1573 Object x);
1574
1575 public final <V> Object compareAndExchangeReference(Object o, long offset,
1576 Class<?> valueType,
1577 V expected,
1578 V x) {
1579 if (valueType.isValue() || isValueObject(expected)) {
1580 synchronized (valueLock) {
1581 Object witness = getReference(o, offset);
1582 if (witness == expected) {
1583 putReference(o, offset, x);
1584 }
1585 return witness;
1586 }
1587 } else {
1588 return compareAndExchangeReference(o, offset, expected, x);
1589 }
1590 }
1591
1592 @ForceInline
1593 public final <V> Object compareAndExchangeValue(Object o, long offset,
1594 Class<?> valueType,
1595 V expected,
1596 V x) {
1597 synchronized (valueLock) {
1598 Object witness = getValue(o, offset, valueType);
1599 if (witness == expected) {
1600 putValue(o, offset, valueType, x);
1601 }
1602 return witness;
1603 }
1604 }
1605
1606 @IntrinsicCandidate
1607 public final Object compareAndExchangeReferenceAcquire(Object o, long offset,
1608 Object expected,
1609 Object x) {
1610 return compareAndExchangeReference(o, offset, expected, x);
1611 }
1612
1613 public final <V> Object compareAndExchangeReferenceAcquire(Object o, long offset,
1614 Class<?> valueType,
1615 V expected,
1616 V x) {
1617 return compareAndExchangeReference(o, offset, valueType, expected, x);
1618 }
1619
1620 @ForceInline
1621 public final <V> Object compareAndExchangeValueAcquire(Object o, long offset,
1622 Class<?> valueType,
1623 V expected,
1624 V x) {
1625 return compareAndExchangeValue(o, offset, valueType, expected, x);
1626 }
1627
1628 @IntrinsicCandidate
1629 public final Object compareAndExchangeReferenceRelease(Object o, long offset,
1630 Object expected,
1631 Object x) {
1632 return compareAndExchangeReference(o, offset, expected, x);
1633 }
1634
1635 public final <V> Object compareAndExchangeReferenceRelease(Object o, long offset,
1636 Class<?> valueType,
1637 V expected,
1638 V x) {
1639 return compareAndExchangeReference(o, offset, valueType, expected, x);
1640 }
1641
1642 @ForceInline
1643 public final <V> Object compareAndExchangeValueRelease(Object o, long offset,
1644 Class<?> valueType,
1645 V expected,
1646 V x) {
1647 return compareAndExchangeValue(o, offset, valueType, expected, x);
1648 }
1649
1650 @IntrinsicCandidate
1651 public final boolean weakCompareAndSetReferencePlain(Object o, long offset,
1652 Object expected,
1653 Object x) {
1654 return compareAndSetReference(o, offset, expected, x);
1655 }
1656
1657 public final <V> boolean weakCompareAndSetReferencePlain(Object o, long offset,
1658 Class<?> valueType,
1659 V expected,
1660 V x) {
1661 if (valueType.isValue() || isValueObject(expected)) {
1662 return compareAndSetReference(o, offset, valueType, expected, x);
1663 } else {
1664 return weakCompareAndSetReferencePlain(o, offset, expected, x);
1665 }
1666 }
1667
1668 @ForceInline
1669 public final <V> boolean weakCompareAndSetValuePlain(Object o, long offset,
1670 Class<?> valueType,
1671 V expected,
1672 V x) {
1673 return compareAndSetValue(o, offset, valueType, expected, x);
1674 }
1675
1676 @IntrinsicCandidate
1677 public final boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
1678 Object expected,
1679 Object x) {
1680 return compareAndSetReference(o, offset, expected, x);
1681 }
1682
1683 public final <V> boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
1684 Class<?> valueType,
1685 V expected,
1686 V x) {
1687 if (valueType.isValue() || isValueObject(expected)) {
1688 return compareAndSetReference(o, offset, valueType, expected, x);
1689 } else {
1690 return weakCompareAndSetReferencePlain(o, offset, expected, x);
1691 }
1692 }
1693
1694 @ForceInline
1695 public final <V> boolean weakCompareAndSetValueAcquire(Object o, long offset,
1696 Class<?> valueType,
1697 V expected,
1698 V x) {
1699 return compareAndSetValue(o, offset, valueType, expected, x);
1700 }
1701
1702 @IntrinsicCandidate
1703 public final boolean weakCompareAndSetReferenceRelease(Object o, long offset,
1704 Object expected,
1705 Object x) {
1706 return compareAndSetReference(o, offset, expected, x);
1707 }
1708
1709 public final <V> boolean weakCompareAndSetReferenceRelease(Object o, long offset,
1710 Class<?> valueType,
1711 V expected,
1712 V x) {
1713 if (valueType.isValue() || isValueObject(expected)) {
1714 return compareAndSetReference(o, offset, valueType, expected, x);
1715 } else {
1716 return weakCompareAndSetReferencePlain(o, offset, expected, x);
1717 }
1718 }
1719
1720 @ForceInline
1721 public final <V> boolean weakCompareAndSetValueRelease(Object o, long offset,
1722 Class<?> valueType,
1723 V expected,
1724 V x) {
1725 return compareAndSetValue(o, offset, valueType, expected, x);
1726 }
1727
1728 @IntrinsicCandidate
1729 public final boolean weakCompareAndSetReference(Object o, long offset,
1730 Object expected,
1731 Object x) {
1732 return compareAndSetReference(o, offset, expected, x);
1733 }
1734
1735 public final <V> boolean weakCompareAndSetReference(Object o, long offset,
1736 Class<?> valueType,
1737 V expected,
1738 V x) {
1739 if (valueType.isValue() || isValueObject(expected)) {
1740 return compareAndSetReference(o, offset, valueType, expected, x);
1741 } else {
1742 return weakCompareAndSetReferencePlain(o, offset, expected, x);
1743 }
1744 }
1745
1746 @ForceInline
1747 public final <V> boolean weakCompareAndSetValue(Object o, long offset,
1748 Class<?> valueType,
1749 V expected,
1750 V x) {
1751 return compareAndSetValue(o, offset, valueType, expected, x);
1752 }
1753
1754 /**
1755 * Atomically updates Java variable to {@code x} if it is currently
1756 * holding {@code expected}.
1757 *
1758 * <p>This operation has memory semantics of a {@code volatile} read
1759 * and write. Corresponds to C11 atomic_compare_exchange_strong.
1760 *
1761 * @return {@code true} if successful
1762 */
1763 @IntrinsicCandidate
1764 public final native boolean compareAndSetInt(Object o, long offset,
1765 int expected,
1766 int x);
1767
1768 @IntrinsicCandidate
1769 public final native int compareAndExchangeInt(Object o, long offset,
1770 int expected,
1771 int x);
1772
1773 @IntrinsicCandidate
2349 public final boolean weakCompareAndSetLongRelease(Object o, long offset,
2350 long expected,
2351 long x) {
2352 return compareAndSetLong(o, offset, expected, x);
2353 }
2354
2355 @IntrinsicCandidate
2356 public final boolean weakCompareAndSetLong(Object o, long offset,
2357 long expected,
2358 long x) {
2359 return compareAndSetLong(o, offset, expected, x);
2360 }
2361
2362 /**
2363 * Fetches a reference value from a given Java variable, with volatile
2364 * load semantics. Otherwise identical to {@link #getReference(Object, long)}
2365 */
2366 @IntrinsicCandidate
2367 public native Object getReferenceVolatile(Object o, long offset);
2368
2369 /**
2370 * Global lock for atomic and volatile strength access to any value of
2371 * a value type. This is a temporary workaround until better localized
2372 * atomic access mechanisms are supported for value class and primitive class.
2373 */
2374 private static final Object valueLock = new Object();
2375
2376 public final <V> Object getValueVolatile(Object base, long offset, Class<?> valueType) {
2377 synchronized (valueLock) {
2378 return getValue(base, offset, valueType);
2379 }
2380 }
2381
2382 /**
2383 * Stores a reference value into a given Java variable, with
2384 * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
2385 */
2386 @IntrinsicCandidate
2387 public native void putReferenceVolatile(Object o, long offset, Object x);
2388
2389 public final <V> void putValueVolatile(Object o, long offset, Class<?> valueType, V x) {
2390 synchronized (valueLock) {
2391 putValue(o, offset, valueType, x);
2392 }
2393 }
2394
2395 /** Volatile version of {@link #getInt(Object, long)} */
2396 @IntrinsicCandidate
2397 public native int getIntVolatile(Object o, long offset);
2398
2399 /** Volatile version of {@link #putInt(Object, long, int)} */
2400 @IntrinsicCandidate
2401 public native void putIntVolatile(Object o, long offset, int x);
2402
2403 /** Volatile version of {@link #getBoolean(Object, long)} */
2404 @IntrinsicCandidate
2405 public native boolean getBooleanVolatile(Object o, long offset);
2406
2407 /** Volatile version of {@link #putBoolean(Object, long, boolean)} */
2408 @IntrinsicCandidate
2409 public native void putBooleanVolatile(Object o, long offset, boolean x);
2410
2411 /** Volatile version of {@link #getByte(Object, long)} */
2412 @IntrinsicCandidate
2413 public native byte getByteVolatile(Object o, long offset);
2414
2447 /** Volatile version of {@link #putFloat(Object, long, float)} */
2448 @IntrinsicCandidate
2449 public native void putFloatVolatile(Object o, long offset, float x);
2450
2451 /** Volatile version of {@link #getDouble(Object, long)} */
2452 @IntrinsicCandidate
2453 public native double getDoubleVolatile(Object o, long offset);
2454
2455 /** Volatile version of {@link #putDouble(Object, long, double)} */
2456 @IntrinsicCandidate
2457 public native void putDoubleVolatile(Object o, long offset, double x);
2458
2459
2460
2461 /** Acquire version of {@link #getReferenceVolatile(Object, long)} */
2462 @IntrinsicCandidate
2463 public final Object getReferenceAcquire(Object o, long offset) {
2464 return getReferenceVolatile(o, offset);
2465 }
2466
2467 public final <V> Object getValueAcquire(Object base, long offset, Class<?> valueType) {
2468 return getValueVolatile(base, offset, valueType);
2469 }
2470
2471 /** Acquire version of {@link #getBooleanVolatile(Object, long)} */
2472 @IntrinsicCandidate
2473 public final boolean getBooleanAcquire(Object o, long offset) {
2474 return getBooleanVolatile(o, offset);
2475 }
2476
2477 /** Acquire version of {@link #getByteVolatile(Object, long)} */
2478 @IntrinsicCandidate
2479 public final byte getByteAcquire(Object o, long offset) {
2480 return getByteVolatile(o, offset);
2481 }
2482
2483 /** Acquire version of {@link #getShortVolatile(Object, long)} */
2484 @IntrinsicCandidate
2485 public final short getShortAcquire(Object o, long offset) {
2486 return getShortVolatile(o, offset);
2487 }
2488
2489 /** Acquire version of {@link #getCharVolatile(Object, long)} */
2490 @IntrinsicCandidate
2515 public final double getDoubleAcquire(Object o, long offset) {
2516 return getDoubleVolatile(o, offset);
2517 }
2518
2519 /*
2520 * Versions of {@link #putReferenceVolatile(Object, long, Object)}
2521 * that do not guarantee immediate visibility of the store to
2522 * other threads. This method is generally only useful if the
2523 * underlying field is a Java volatile (or if an array cell, one
2524 * that is otherwise only accessed using volatile accesses).
2525 *
2526 * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
2527 */
2528
2529 /** Release version of {@link #putReferenceVolatile(Object, long, Object)} */
2530 @IntrinsicCandidate
2531 public final void putReferenceRelease(Object o, long offset, Object x) {
2532 putReferenceVolatile(o, offset, x);
2533 }
2534
2535 public final <V> void putValueRelease(Object o, long offset, Class<?> valueType, V x) {
2536 putValueVolatile(o, offset, valueType, x);
2537 }
2538
2539 /** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
2540 @IntrinsicCandidate
2541 public final void putBooleanRelease(Object o, long offset, boolean x) {
2542 putBooleanVolatile(o, offset, x);
2543 }
2544
2545 /** Release version of {@link #putByteVolatile(Object, long, byte)} */
2546 @IntrinsicCandidate
2547 public final void putByteRelease(Object o, long offset, byte x) {
2548 putByteVolatile(o, offset, x);
2549 }
2550
2551 /** Release version of {@link #putShortVolatile(Object, long, short)} */
2552 @IntrinsicCandidate
2553 public final void putShortRelease(Object o, long offset, short x) {
2554 putShortVolatile(o, offset, x);
2555 }
2556
2557 /** Release version of {@link #putCharVolatile(Object, long, char)} */
2558 @IntrinsicCandidate
2575 /** Release version of {@link #putLongVolatile(Object, long, long)} */
2576 @IntrinsicCandidate
2577 public final void putLongRelease(Object o, long offset, long x) {
2578 putLongVolatile(o, offset, x);
2579 }
2580
2581 /** Release version of {@link #putDoubleVolatile(Object, long, double)} */
2582 @IntrinsicCandidate
2583 public final void putDoubleRelease(Object o, long offset, double x) {
2584 putDoubleVolatile(o, offset, x);
2585 }
2586
2587 // ------------------------------ Opaque --------------------------------------
2588
2589 /** Opaque version of {@link #getReferenceVolatile(Object, long)} */
2590 @IntrinsicCandidate
2591 public final Object getReferenceOpaque(Object o, long offset) {
2592 return getReferenceVolatile(o, offset);
2593 }
2594
2595 public final <V> Object getValueOpaque(Object base, long offset, Class<?> valueType) {
2596 return getValueVolatile(base, offset, valueType);
2597 }
2598
2599 /** Opaque version of {@link #getBooleanVolatile(Object, long)} */
2600 @IntrinsicCandidate
2601 public final boolean getBooleanOpaque(Object o, long offset) {
2602 return getBooleanVolatile(o, offset);
2603 }
2604
2605 /** Opaque version of {@link #getByteVolatile(Object, long)} */
2606 @IntrinsicCandidate
2607 public final byte getByteOpaque(Object o, long offset) {
2608 return getByteVolatile(o, offset);
2609 }
2610
2611 /** Opaque version of {@link #getShortVolatile(Object, long)} */
2612 @IntrinsicCandidate
2613 public final short getShortOpaque(Object o, long offset) {
2614 return getShortVolatile(o, offset);
2615 }
2616
2617 /** Opaque version of {@link #getCharVolatile(Object, long)} */
2618 @IntrinsicCandidate
2633 }
2634
2635 /** Opaque version of {@link #getLongVolatile(Object, long)} */
2636 @IntrinsicCandidate
2637 public final long getLongOpaque(Object o, long offset) {
2638 return getLongVolatile(o, offset);
2639 }
2640
2641 /** Opaque version of {@link #getDoubleVolatile(Object, long)} */
2642 @IntrinsicCandidate
2643 public final double getDoubleOpaque(Object o, long offset) {
2644 return getDoubleVolatile(o, offset);
2645 }
2646
2647 /** Opaque version of {@link #putReferenceVolatile(Object, long, Object)} */
2648 @IntrinsicCandidate
2649 public final void putReferenceOpaque(Object o, long offset, Object x) {
2650 putReferenceVolatile(o, offset, x);
2651 }
2652
2653 public final <V> void putValueOpaque(Object o, long offset, Class<?> valueType, V x) {
2654 putValueVolatile(o, offset, valueType, x);
2655 }
2656
2657 /** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
2658 @IntrinsicCandidate
2659 public final void putBooleanOpaque(Object o, long offset, boolean x) {
2660 putBooleanVolatile(o, offset, x);
2661 }
2662
2663 /** Opaque version of {@link #putByteVolatile(Object, long, byte)} */
2664 @IntrinsicCandidate
2665 public final void putByteOpaque(Object o, long offset, byte x) {
2666 putByteVolatile(o, offset, x);
2667 }
2668
2669 /** Opaque version of {@link #putShortVolatile(Object, long, short)} */
2670 @IntrinsicCandidate
2671 public final void putShortOpaque(Object o, long offset, short x) {
2672 putShortVolatile(o, offset, x);
2673 }
2674
2675 /** Opaque version of {@link #putCharVolatile(Object, long, char)} */
2676 @IntrinsicCandidate
3071 /**
3072 * Atomically exchanges the given reference value with the current
3073 * reference value of a field or array element within the given
3074 * object {@code o} at the given {@code offset}.
3075 *
3076 * @param o object/array to update the field/element in
3077 * @param offset field/element offset
3078 * @param newValue new value
3079 * @return the previous value
3080 * @since 1.8
3081 */
3082 @IntrinsicCandidate
3083 public final Object getAndSetReference(Object o, long offset, Object newValue) {
3084 Object v;
3085 do {
3086 v = getReferenceVolatile(o, offset);
3087 } while (!weakCompareAndSetReference(o, offset, v, newValue));
3088 return v;
3089 }
3090
3091 @SuppressWarnings("unchecked")
3092 public final <V> Object getAndSetValue(Object o, long offset, Class<?> valueType, V newValue) {
3093 synchronized (valueLock) {
3094 Object oldValue = getValue(o, offset, valueType);
3095 putValue(o, offset, valueType, newValue);
3096 return oldValue;
3097 }
3098 }
3099
3100 @ForceInline
3101 public final Object getAndSetReferenceRelease(Object o, long offset, Object newValue) {
3102 Object v;
3103 do {
3104 v = getReference(o, offset);
3105 } while (!weakCompareAndSetReferenceRelease(o, offset, v, newValue));
3106 return v;
3107 }
3108
3109 @ForceInline
3110 public final <V> Object getAndSetValueRelease(Object o, long offset, Class<?> valueType, V newValue) {
3111 return getAndSetValue(o, offset, valueType, newValue);
3112 }
3113
3114 @ForceInline
3115 public final Object getAndSetReferenceAcquire(Object o, long offset, Object newValue) {
3116 Object v;
3117 do {
3118 v = getReferenceAcquire(o, offset);
3119 } while (!weakCompareAndSetReferenceAcquire(o, offset, v, newValue));
3120 return v;
3121 }
3122
3123 @ForceInline
3124 public final <V> Object getAndSetValueAcquire(Object o, long offset, Class<?> valueType, V newValue) {
3125 return getAndSetValue(o, offset, valueType, newValue);
3126 }
3127
3128 @IntrinsicCandidate
3129 public final byte getAndSetByte(Object o, long offset, byte newValue) {
3130 byte v;
3131 do {
3132 v = getByteVolatile(o, offset);
3133 } while (!weakCompareAndSetByte(o, offset, v, newValue));
3134 return v;
3135 }
3136
3137 @ForceInline
3138 public final byte getAndSetByteRelease(Object o, long offset, byte newValue) {
3139 byte v;
3140 do {
3141 v = getByte(o, offset);
3142 } while (!weakCompareAndSetByteRelease(o, offset, v, newValue));
3143 return v;
3144 }
3145
3146 @ForceInline
3147 public final byte getAndSetByteAcquire(Object o, long offset, byte newValue) {
4164 private static int convEndian(boolean big, int n) { return big == BIG_ENDIAN ? n : Integer.reverseBytes(n) ; }
4165 private static long convEndian(boolean big, long n) { return big == BIG_ENDIAN ? n : Long.reverseBytes(n) ; }
4166
4167
4168
4169 private native long allocateMemory0(long bytes);
4170 private native long reallocateMemory0(long address, long bytes);
4171 private native void freeMemory0(long address);
4172 private native void setMemory0(Object o, long offset, long bytes, byte value);
4173 @IntrinsicCandidate
4174 private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
4175 private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
4176 private native long objectFieldOffset0(Field f);
4177 private native long objectFieldOffset1(Class<?> c, String name);
4178 private native long staticFieldOffset0(Field f);
4179 private native Object staticFieldBase0(Field f);
4180 private native boolean shouldBeInitialized0(Class<?> c);
4181 private native void ensureClassInitialized0(Class<?> c);
4182 private native int arrayBaseOffset0(Class<?> arrayClass);
4183 private native int arrayIndexScale0(Class<?> arrayClass);
4184 private native long getObjectSize0(Object o);
4185 private native int getLoadAverage0(double[] loadavg, int nelems);
4186
4187
4188 /**
4189 * Invokes the given direct byte buffer's cleaner, if any.
4190 *
4191 * @param directBuffer a direct byte buffer
4192 * @throws NullPointerException if {@code directBuffer} is null
4193 * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
4194 * or is a {@link java.nio.Buffer#slice slice}, or is a
4195 * {@link java.nio.Buffer#duplicate duplicate}
4196 */
4197 public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
4198 if (!directBuffer.isDirect())
4199 throw new IllegalArgumentException("buffer is non-direct");
4200
4201 DirectBuffer db = (DirectBuffer) directBuffer;
4202 if (db.attachment() != null)
4203 throw new IllegalArgumentException("duplicate or slice");
4204
|