1 /*
   2  * Copyright (c) 2000, 2024, 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
  23  * questions.
  24  */
  25 
  26 package sun.misc;
  27 
  28 import jdk.internal.vm.annotation.ForceInline;
  29 import jdk.internal.misc.VM;
  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.Reflection;
  32 
  33 import java.lang.reflect.Field;
  34 import java.util.Set;
  35 
  36 
  37 /**
  38  * A collection of methods for performing low-level, unsafe operations.
  39  * Although the class and all methods are public, use of this class is
  40  * limited because only trusted code can obtain instances of it.
  41  *
  42  * <em>Note:</em> It is the responsibility of the caller to make sure
  43  * arguments are checked before methods of this class are
  44  * called. While some rudimentary checks are performed on the input,
  45  * the checks are best effort and when performance is an overriding
  46  * priority, as when methods of this class are optimized by the
  47  * runtime compiler, some or all checks (if any) may be elided. Hence,
  48  * the caller must not rely on the checks and corresponding
  49  * exceptions!
  50  *
  51  * @author John R. Rose
  52  * @see #getUnsafe
  53  */
  54 
  55 public final class Unsafe {
  56 
  57     static {
  58         Reflection.registerMethodsToFilter(Unsafe.class, Set.of("getUnsafe"));
  59     }
  60 
  61     private Unsafe() {}
  62 
  63     private static final Unsafe theUnsafe = new Unsafe();
  64     private static final jdk.internal.misc.Unsafe theInternalUnsafe = jdk.internal.misc.Unsafe.getUnsafe();
  65 
  66     /**
  67      * Provides the caller with the capability of performing unsafe
  68      * operations.
  69      *
  70      * <p>The returned {@code Unsafe} object should be carefully guarded
  71      * by the caller, since it can be used to read and write data at arbitrary
  72      * memory addresses.  It must never be passed to untrusted code.
  73      *
  74      * <p>Most methods in this class are very low-level, and correspond to a
  75      * small number of hardware instructions (on typical machines).  Compilers
  76      * are encouraged to optimize these methods accordingly.
  77      *
  78      * <p>Here is a suggested idiom for using unsafe operations:
  79      *
  80      * <pre> {@code
  81      * class MyTrustedClass {
  82      *   private static final Unsafe unsafe = Unsafe.getUnsafe();
  83      *   ...
  84      *   private long myCountAddress = ...;
  85      *   public int getCount() { return unsafe.getByte(myCountAddress); }
  86      * }}</pre>
  87      *
  88      * (It may assist compilers to make the local variable {@code final}.)
  89      *
  90      * @throws  SecurityException if the class loader of the caller
  91      *          class is not in the system domain in which all permissions
  92      *          are granted.
  93      */
  94     @CallerSensitive
  95     public static Unsafe getUnsafe() {
  96         Class<?> caller = Reflection.getCallerClass();
  97         if (!VM.isSystemDomainLoader(caller.getClassLoader()))
  98             throw new SecurityException("Unsafe");
  99         return theUnsafe;
 100     }
 101 
 102     /// peek and poke operations
 103     /// (compilers should optimize these to memory ops)
 104 
 105     // These work on object fields in the Java heap.
 106     // They will not work on elements of packed arrays.
 107 
 108     /**
 109      * Fetches a value from a given Java variable.
 110      * More specifically, fetches a field or array element within the given
 111      * object {@code o} at the given offset, or (if {@code o} is null)
 112      * from the memory address whose numerical value is the given offset.
 113      * <p>
 114      * The results are undefined unless one of the following cases is true:
 115      * <ul>
 116      * <li>The offset was obtained from {@link #objectFieldOffset} on
 117      * the {@link java.lang.reflect.Field} of some Java field and the object
 118      * referred to by {@code o} is of a class compatible with that
 119      * field's class.
 120      *
 121      * <li>The offset and object reference {@code o} (either null or
 122      * non-null) were both obtained via {@link #staticFieldOffset}
 123      * and {@link #staticFieldBase} (respectively) from the
 124      * reflective {@link Field} representation of some Java field.
 125      *
 126      * <li>The object referred to by {@code o} is an array, and the offset
 127      * is an integer of the form {@code B+N*S}, where {@code N} is
 128      * a valid index into the array, and {@code B} and {@code S} are
 129      * the values obtained by {@link #arrayBaseOffset} and {@link
 130      * #arrayIndexScale} (respectively) from the array's class.  The value
 131      * referred to is the {@code N}<em>th</em> element of the array.
 132      *
 133      * </ul>
 134      * <p>
 135      * If one of the above cases is true, the call references a specific Java
 136      * variable (field or array element).  However, the results are undefined
 137      * if that variable is not in fact of the type returned by this method.
 138      * <p>
 139      * This method refers to a variable by means of two parameters, and so
 140      * it provides (in effect) a <em>double-register</em> addressing mode
 141      * for Java variables.  When the object reference is null, this method
 142      * uses its offset as an absolute address.  This is similar in operation
 143      * to methods such as {@link #getInt(long)}, which provide (in effect) a
 144      * <em>single-register</em> addressing mode for non-Java variables.
 145      * However, because Java variables may have a different layout in memory
 146      * from non-Java variables, programmers should not assume that these
 147      * two addressing modes are ever equivalent.  Also, programmers should
 148      * remember that offsets from the double-register addressing mode cannot
 149      * be portably confused with longs used in the single-register addressing
 150      * mode.
 151      *
 152      * @param o Java heap object in which the variable resides, if any, else
 153      *        null
 154      * @param offset indication of where the variable resides in a Java heap
 155      *        object, if any, else a memory address locating the variable
 156      *        statically
 157      * @return the value fetched from the indicated Java variable
 158      * @throws RuntimeException No defined exceptions are thrown, not even
 159      *         {@link NullPointerException}
 160      */
 161     @ForceInline
 162     public int getInt(Object o, long offset) {
 163         return theInternalUnsafe.getInt(o, offset);
 164     }
 165 
 166     /**
 167      * Stores a value into a given Java variable.
 168      * <p>
 169      * The first two parameters are interpreted exactly as with
 170      * {@link #getInt(Object, long)} to refer to a specific
 171      * Java variable (field or array element).  The given value
 172      * is stored into that variable.
 173      * <p>
 174      * The variable must be of the same type as the method
 175      * parameter {@code x}.
 176      *
 177      * @param o Java heap object in which the variable resides, if any, else
 178      *        null
 179      * @param offset indication of where the variable resides in a Java heap
 180      *        object, if any, else a memory address locating the variable
 181      *        statically
 182      * @param x the value to store into the indicated Java variable
 183      * @throws RuntimeException No defined exceptions are thrown, not even
 184      *         {@link NullPointerException}
 185      */
 186     @ForceInline
 187     public void putInt(Object o, long offset, int x) {
 188         theInternalUnsafe.putInt(o, offset, x);
 189     }
 190 
 191     /**
 192      * Fetches a reference value from a given Java variable.
 193      * @see #getInt(Object, long)
 194      */
 195     @ForceInline
 196     public Object getObject(Object o, long offset) {
 197         return theInternalUnsafe.getReference(o, offset);
 198     }
 199 
 200     /**
 201      * Stores a reference value into a given Java variable.
 202      * <p>
 203      * Unless the reference {@code x} being stored is either null
 204      * or matches the field type, the results are undefined.
 205      * If the reference {@code o} is non-null, card marks or
 206      * other store barriers for that object (if the VM requires them)
 207      * are updated.
 208      * @see #putInt(Object, long, int)
 209      */
 210     @ForceInline
 211     public void putObject(Object o, long offset, Object x) {
 212         theInternalUnsafe.putReference(o, offset, x);
 213     }
 214 
 215     /** @see #getInt(Object, long) */
 216     @ForceInline
 217     public boolean getBoolean(Object o, long offset) {
 218         return theInternalUnsafe.getBoolean(o, offset);
 219     }
 220 
 221     /** @see #putInt(Object, long, int) */
 222     @ForceInline
 223     public void putBoolean(Object o, long offset, boolean x) {
 224         theInternalUnsafe.putBoolean(o, offset, x);
 225     }
 226 
 227     /** @see #getInt(Object, long) */
 228     @ForceInline
 229     public byte getByte(Object o, long offset) {
 230         return theInternalUnsafe.getByte(o, offset);
 231     }
 232 
 233     /** @see #putInt(Object, long, int) */
 234     @ForceInline
 235     public void putByte(Object o, long offset, byte x) {
 236         theInternalUnsafe.putByte(o, offset, x);
 237     }
 238 
 239     /** @see #getInt(Object, long) */
 240     @ForceInline
 241     public short getShort(Object o, long offset) {
 242         return theInternalUnsafe.getShort(o, offset);
 243     }
 244 
 245     /** @see #putInt(Object, long, int) */
 246     @ForceInline
 247     public void putShort(Object o, long offset, short x) {
 248         theInternalUnsafe.putShort(o, offset, x);
 249     }
 250 
 251     /** @see #getInt(Object, long) */
 252     @ForceInline
 253     public char getChar(Object o, long offset) {
 254         return theInternalUnsafe.getChar(o, offset);
 255     }
 256 
 257     /** @see #putInt(Object, long, int) */
 258     @ForceInline
 259     public void putChar(Object o, long offset, char x) {
 260         theInternalUnsafe.putChar(o, offset, x);
 261     }
 262 
 263     /** @see #getInt(Object, long) */
 264     @ForceInline
 265     public long getLong(Object o, long offset) {
 266         return theInternalUnsafe.getLong(o, offset);
 267     }
 268 
 269     /** @see #putInt(Object, long, int) */
 270     @ForceInline
 271     public void putLong(Object o, long offset, long x) {
 272         theInternalUnsafe.putLong(o, offset, x);
 273     }
 274 
 275     /** @see #getInt(Object, long) */
 276     @ForceInline
 277     public float getFloat(Object o, long offset) {
 278         return theInternalUnsafe.getFloat(o, offset);
 279     }
 280 
 281     /** @see #putInt(Object, long, int) */
 282     @ForceInline
 283     public void putFloat(Object o, long offset, float x) {
 284         theInternalUnsafe.putFloat(o, offset, x);
 285     }
 286 
 287     /** @see #getInt(Object, long) */
 288     @ForceInline
 289     public double getDouble(Object o, long offset) {
 290         return theInternalUnsafe.getDouble(o, offset);
 291     }
 292 
 293     /** @see #putInt(Object, long, int) */
 294     @ForceInline
 295     public void putDouble(Object o, long offset, double x) {
 296         theInternalUnsafe.putDouble(o, offset, x);
 297     }
 298 
 299     // These work on values in the C heap.
 300 
 301     /**
 302      * Fetches a value from a given memory address.  If the address is zero, or
 303      * does not point into a block obtained from {@link #allocateMemory}, the
 304      * results are undefined.
 305      *
 306      * @see #allocateMemory
 307      */
 308     @ForceInline
 309     public byte getByte(long address) {
 310         return theInternalUnsafe.getByte(address);
 311     }
 312 
 313     /**
 314      * Stores a value into a given memory address.  If the address is zero, or
 315      * does not point into a block obtained from {@link #allocateMemory}, the
 316      * results are undefined.
 317      *
 318      * @see #getByte(long)
 319      */
 320     @ForceInline
 321     public void putByte(long address, byte x) {
 322         theInternalUnsafe.putByte(address, x);
 323     }
 324 
 325     /** @see #getByte(long) */
 326     @ForceInline
 327     public short getShort(long address) {
 328         return theInternalUnsafe.getShort(address);
 329     }
 330 
 331     /** @see #putByte(long, byte) */
 332     @ForceInline
 333     public void putShort(long address, short x) {
 334         theInternalUnsafe.putShort(address, x);
 335     }
 336 
 337     /** @see #getByte(long) */
 338     @ForceInline
 339     public char getChar(long address) {
 340         return theInternalUnsafe.getChar(address);
 341     }
 342 
 343     /** @see #putByte(long, byte) */
 344     @ForceInline
 345     public void putChar(long address, char x) {
 346         theInternalUnsafe.putChar(address, x);
 347     }
 348 
 349     /** @see #getByte(long) */
 350     @ForceInline
 351     public int getInt(long address) {
 352         return theInternalUnsafe.getInt(address);
 353     }
 354 
 355     /** @see #putByte(long, byte) */
 356     @ForceInline
 357     public void putInt(long address, int x) {
 358         theInternalUnsafe.putInt(address, x);
 359     }
 360 
 361     /** @see #getByte(long) */
 362     @ForceInline
 363     public long getLong(long address) {
 364         return theInternalUnsafe.getLong(address);
 365     }
 366 
 367     /** @see #putByte(long, byte) */
 368     @ForceInline
 369     public void putLong(long address, long x) {
 370         theInternalUnsafe.putLong(address, x);
 371     }
 372 
 373     /** @see #getByte(long) */
 374     @ForceInline
 375     public float getFloat(long address) {
 376         return theInternalUnsafe.getFloat(address);
 377     }
 378 
 379     /** @see #putByte(long, byte) */
 380     @ForceInline
 381     public void putFloat(long address, float x) {
 382         theInternalUnsafe.putFloat(address, x);
 383     }
 384 
 385     /** @see #getByte(long) */
 386     @ForceInline
 387     public double getDouble(long address) {
 388         return theInternalUnsafe.getDouble(address);
 389     }
 390 
 391     /** @see #putByte(long, byte) */
 392     @ForceInline
 393     public void putDouble(long address, double x) {
 394         theInternalUnsafe.putDouble(address, x);
 395     }
 396 
 397 
 398     /**
 399      * Fetches a native pointer from a given memory address.  If the address is
 400      * zero, or does not point into a block obtained from {@link
 401      * #allocateMemory}, the results are undefined.
 402      *
 403      * <p>If the native pointer is less than 64 bits wide, it is extended as
 404      * an unsigned number to a Java long.  The pointer may be indexed by any
 405      * given byte offset, simply by adding that offset (as a simple integer) to
 406      * the long representing the pointer.  The number of bytes actually read
 407      * from the target address may be determined by consulting {@link
 408      * #addressSize}.
 409      *
 410      * @see #allocateMemory
 411      */
 412     @ForceInline
 413     public long getAddress(long address) {
 414         return theInternalUnsafe.getAddress(address);
 415     }
 416 
 417     /**
 418      * Stores a native pointer into a given memory address.  If the address is
 419      * zero, or does not point into a block obtained from {@link
 420      * #allocateMemory}, the results are undefined.
 421      *
 422      * <p>The number of bytes actually written at the target address may be
 423      * determined by consulting {@link #addressSize}.
 424      *
 425      * @see #getAddress(long)
 426      */
 427     @ForceInline
 428     public void putAddress(long address, long x) {
 429         theInternalUnsafe.putAddress(address, x);
 430     }
 431 
 432 
 433     /// wrappers for malloc, realloc, free:
 434 
 435     /**
 436      * Allocates a new block of native memory, of the given size in bytes.  The
 437      * contents of the memory are uninitialized; they will generally be
 438      * garbage.  The resulting native pointer will be zero if and only if the
 439      * requested size is zero.  The resulting native pointer will be aligned for
 440      * all value types.   Dispose of this memory by calling {@link #freeMemory}
 441      * or resize it with {@link #reallocateMemory}.
 442      *
 443      * <em>Note:</em> It is the responsibility of the caller to make
 444      * sure arguments are checked before the methods are called. While
 445      * some rudimentary checks are performed on the input, the checks
 446      * are best effort and when performance is an overriding priority,
 447      * as when methods of this class are optimized by the runtime
 448      * compiler, some or all checks (if any) may be elided. Hence, the
 449      * caller must not rely on the checks and corresponding
 450      * exceptions!
 451      *
 452      * @throws RuntimeException if the size is negative or too large
 453      *         for the native size_t type
 454      *
 455      * @throws OutOfMemoryError if the allocation is refused by the system
 456      *
 457      * @see #getByte(long)
 458      * @see #putByte(long, byte)
 459      */
 460     @ForceInline
 461     public long allocateMemory(long bytes) {
 462         return theInternalUnsafe.allocateMemory(bytes);
 463     }
 464 
 465     /**
 466      * Resizes a new block of native memory, to the given size in bytes.  The
 467      * contents of the new block past the size of the old block are
 468      * uninitialized; they will generally be garbage.  The resulting native
 469      * pointer will be zero if and only if the requested size is zero.  The
 470      * resulting native pointer will be aligned for all value types.  Dispose
 471      * of this memory by calling {@link #freeMemory}, or resize it with {@link
 472      * #reallocateMemory}.  The address passed to this method may be null, in
 473      * which case an allocation will be performed.
 474      *
 475      * <em>Note:</em> It is the responsibility of the caller to make
 476      * sure arguments are checked before the methods are called. While
 477      * some rudimentary checks are performed on the input, the checks
 478      * are best effort and when performance is an overriding priority,
 479      * as when methods of this class are optimized by the runtime
 480      * compiler, some or all checks (if any) may be elided. Hence, the
 481      * caller must not rely on the checks and corresponding
 482      * exceptions!
 483      *
 484      * @throws RuntimeException if the size is negative or too large
 485      *         for the native size_t type
 486      *
 487      * @throws OutOfMemoryError if the allocation is refused by the system
 488      *
 489      * @see #allocateMemory
 490      */
 491     @ForceInline
 492     public long reallocateMemory(long address, long bytes) {
 493         return theInternalUnsafe.reallocateMemory(address, bytes);
 494     }
 495 
 496     /**
 497      * Sets all bytes in a given block of memory to a fixed value
 498      * (usually zero).
 499      *
 500      * <p>This method determines a block's base address by means of two parameters,
 501      * and so it provides (in effect) a <em>double-register</em> addressing mode,
 502      * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
 503      * the offset supplies an absolute base address.
 504      *
 505      * <p>The stores are in coherent (atomic) units of a size determined
 506      * by the address and length parameters.  If the effective address and
 507      * length are all even modulo 8, the stores take place in 'long' units.
 508      * If the effective address and length are (resp.) even modulo 4 or 2,
 509      * the stores take place in units of 'int' or 'short'.
 510      *
 511      * <em>Note:</em> It is the responsibility of the caller to make
 512      * sure arguments are checked before the methods are called. While
 513      * some rudimentary checks are performed on the input, the checks
 514      * are best effort and when performance is an overriding priority,
 515      * as when methods of this class are optimized by the runtime
 516      * compiler, some or all checks (if any) may be elided. Hence, the
 517      * caller must not rely on the checks and corresponding
 518      * exceptions!
 519      *
 520      * @throws RuntimeException if any of the arguments is invalid
 521      *
 522      * @since 1.7
 523      */
 524     @ForceInline
 525     public void setMemory(Object o, long offset, long bytes, byte value) {
 526         theInternalUnsafe.setMemory(o, offset, bytes, value);
 527     }
 528 
 529     /**
 530      * Sets all bytes in a given block of memory to a fixed value
 531      * (usually zero).  This provides a <em>single-register</em> addressing mode,
 532      * as discussed in {@link #getInt(Object,long)}.
 533      *
 534      * <p>Equivalent to {@code setMemory(null, address, bytes, value)}.
 535      */
 536     @ForceInline
 537     public void setMemory(long address, long bytes, byte value) {
 538         theInternalUnsafe.setMemory(address, bytes, value);
 539     }
 540 
 541     /**
 542      * Sets all bytes in a given block of memory to a copy of another
 543      * block.
 544      *
 545      * <p>This method determines each block's base address by means of two parameters,
 546      * and so it provides (in effect) a <em>double-register</em> addressing mode,
 547      * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
 548      * the offset supplies an absolute base address.
 549      *
 550      * <p>The transfers are in coherent (atomic) units of a size determined
 551      * by the address and length parameters.  If the effective addresses and
 552      * length are all even modulo 8, the transfer takes place in 'long' units.
 553      * If the effective addresses and length are (resp.) even modulo 4 or 2,
 554      * the transfer takes place in units of 'int' or 'short'.
 555      *
 556      * <em>Note:</em> It is the responsibility of the caller to make
 557      * sure arguments are checked before the methods are called. While
 558      * some rudimentary checks are performed on the input, the checks
 559      * are best effort and when performance is an overriding priority,
 560      * as when methods of this class are optimized by the runtime
 561      * compiler, some or all checks (if any) may be elided. Hence, the
 562      * caller must not rely on the checks and corresponding
 563      * exceptions!
 564      *
 565      * @throws RuntimeException if any of the arguments is invalid
 566      *
 567      * @since 1.7
 568      */
 569     @ForceInline
 570     public void copyMemory(Object srcBase, long srcOffset,
 571                            Object destBase, long destOffset,
 572                            long bytes) {
 573         theInternalUnsafe.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes);
 574     }
 575 
 576     /**
 577      * Sets all bytes in a given block of memory to a copy of another
 578      * block.  This provides a <em>single-register</em> addressing mode,
 579      * as discussed in {@link #getInt(Object,long)}.
 580      *
 581      * Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.
 582      */
 583     @ForceInline
 584     public void copyMemory(long srcAddress, long destAddress, long bytes) {
 585         theInternalUnsafe.copyMemory(srcAddress, destAddress, bytes);
 586     }
 587 
 588     /**
 589      * Disposes of a block of native memory, as obtained from {@link
 590      * #allocateMemory} or {@link #reallocateMemory}.  The address passed to
 591      * this method may be null, in which case no action is taken.
 592      *
 593      * <em>Note:</em> It is the responsibility of the caller to make
 594      * sure arguments are checked before the methods are called. While
 595      * some rudimentary checks are performed on the input, the checks
 596      * are best effort and when performance is an overriding priority,
 597      * as when methods of this class are optimized by the runtime
 598      * compiler, some or all checks (if any) may be elided. Hence, the
 599      * caller must not rely on the checks and corresponding
 600      * exceptions!
 601      *
 602      * @throws RuntimeException if any of the arguments is invalid
 603      *
 604      * @see #allocateMemory
 605      */
 606     @ForceInline
 607     public void freeMemory(long address) {
 608         theInternalUnsafe.freeMemory(address);
 609     }
 610 
 611     /// random queries
 612 
 613     /**
 614      * This constant differs from all results that will ever be returned from
 615      * {@link #staticFieldOffset}, {@link #objectFieldOffset},
 616      * or {@link #arrayBaseOffset}.
 617      */
 618     public static final int INVALID_FIELD_OFFSET = jdk.internal.misc.Unsafe.INVALID_FIELD_OFFSET;
 619 
 620     /**
 621      * Reports the location of a given field in the storage allocation of its
 622      * class.  Do not expect to perform any sort of arithmetic on this offset;
 623      * it is just a cookie which is passed to the unsafe heap memory accessors.
 624      *
 625      * <p>Any given field will always have the same offset and base, and no
 626      * two distinct fields of the same class will ever have the same offset
 627      * and base.
 628      *
 629      * <p>As of 1.4.1, offsets for fields are represented as long values,
 630      * although the Sun JVM does not use the most significant 32 bits.
 631      * However, JVM implementations which store static fields at absolute
 632      * addresses can use long offsets and null base pointers to express
 633      * the field locations in a form usable by {@link #getInt(Object,long)}.
 634      * Therefore, code which will be ported to such JVMs on 64-bit platforms
 635      * must preserve all bits of static field offsets.
 636      *
 637      * @deprecated The guarantee that a field will always have the same offset
 638      * and base may not be true in a future release. The ability to provide an
 639      * offset and object reference to a heap memory accessor will be removed
 640      * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
 641      *
 642      * @see #getInt(Object, long)
 643      */
 644     @Deprecated(since="18")
 645     @ForceInline
 646     @SuppressWarnings("preview")
 647     public long objectFieldOffset(Field f) {
 648         if (f == null) {
 649             throw new NullPointerException();
 650         }
 651         Class<?> declaringClass = f.getDeclaringClass();
 652         if (declaringClass.isHidden()) {
 653             throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
 654         }
 655         if (declaringClass.isRecord()) {
 656             throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
 657         }
 658         if (declaringClass.isValue()) {
 659             throw new UnsupportedOperationException("can't get field offset on a value class: " + f);
 660         }
 661         return theInternalUnsafe.objectFieldOffset(f);
 662     }
 663 
 664     /**
 665      * Reports the location of a given static field, in conjunction with {@link
 666      * #staticFieldBase}.
 667      * <p>Do not expect to perform any sort of arithmetic on this offset;
 668      * it is just a cookie which is passed to the unsafe heap memory accessors.
 669      *
 670      * <p>Any given field will always have the same offset, and no two distinct
 671      * fields of the same class will ever have the same offset.
 672      *
 673      * <p>As of 1.4.1, offsets for fields are represented as long values,
 674      * although the Sun JVM does not use the most significant 32 bits.
 675      * It is hard to imagine a JVM technology which needs more than
 676      * a few bits to encode an offset within a non-array object,
 677      * However, for consistency with other methods in this class,
 678      * this method reports its result as a long value.
 679      *
 680      * @deprecated The guarantee that a field will always have the same offset
 681      * and base may not be true in a future release. The ability to provide an
 682      * offset and object reference to a heap memory accessor will be removed
 683      * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
 684      *
 685      * @see #getInt(Object, long)
 686      */
 687     @Deprecated(since="18")
 688     @ForceInline
 689     @SuppressWarnings("preview")
 690     public long staticFieldOffset(Field f) {
 691         if (f == null) {
 692             throw new NullPointerException();
 693         }
 694         Class<?> declaringClass = f.getDeclaringClass();
 695         if (declaringClass.isHidden()) {
 696             throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
 697         }
 698         if (declaringClass.isRecord()) {
 699             throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
 700         }
 701         if (declaringClass.isValue()) {
 702             throw new UnsupportedOperationException("can't get field offset on a value class: " + f);
 703         }
 704         return theInternalUnsafe.staticFieldOffset(f);
 705     }
 706 
 707     /**
 708      * Reports the location of a given static field, in conjunction with {@link
 709      * #staticFieldOffset}.
 710      * <p>Fetch the base "Object", if any, with which static fields of the
 711      * given class can be accessed via methods like {@link #getInt(Object,
 712      * long)}.  This value may be null.  This value may refer to an object
 713      * which is a "cookie", not guaranteed to be a real Object, and it should
 714      * not be used in any way except as argument to the get and put routines in
 715      * this class.
 716      *
 717      * @deprecated The guarantee that a field will always have the same offset
 718      * and base may not be true in a future release. The ability to provide an
 719      * offset and object reference to a heap memory accessor will be removed
 720      * in a future release. Use {@link java.lang.invoke.VarHandle} instead.
 721      */
 722     @Deprecated(since="18")
 723     @ForceInline
 724     @SuppressWarnings("preview")
 725     public Object staticFieldBase(Field f) {
 726         if (f == null) {
 727             throw new NullPointerException();
 728         }
 729         Class<?> declaringClass = f.getDeclaringClass();
 730         if (declaringClass.isHidden()) {
 731             throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
 732         }
 733         if (declaringClass.isRecord()) {
 734             throw new UnsupportedOperationException("can't get base address on a record class: " + f);
 735         }
 736         if (declaringClass.isValue()) {
 737             throw new UnsupportedOperationException("can't get field offset on a value class: " + f);
 738         }
 739         return theInternalUnsafe.staticFieldBase(f);
 740     }
 741 
 742     /**
 743      * Reports the offset of the first element in the storage allocation of a
 744      * given array class.  If {@link #arrayIndexScale} returns a non-zero value
 745      * for the same class, you may use that scale factor, together with this
 746      * base offset, to form new offsets to access elements of arrays of the
 747      * given class.
 748      *
 749      * @see #getInt(Object, long)
 750      * @see #putInt(Object, long, int)
 751      */
 752     @ForceInline
 753     public int arrayBaseOffset(Class<?> arrayClass) {
 754         return theInternalUnsafe.arrayBaseOffset(arrayClass);
 755     }
 756 
 757     /** The value of {@code arrayBaseOffset(boolean[].class)} */
 758     public static final int ARRAY_BOOLEAN_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;
 759 
 760     /** The value of {@code arrayBaseOffset(byte[].class)} */
 761     public static final int ARRAY_BYTE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;
 762 
 763     /** The value of {@code arrayBaseOffset(short[].class)} */
 764     public static final int ARRAY_SHORT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_SHORT_BASE_OFFSET;
 765 
 766     /** The value of {@code arrayBaseOffset(char[].class)} */
 767     public static final int ARRAY_CHAR_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_CHAR_BASE_OFFSET;
 768 
 769     /** The value of {@code arrayBaseOffset(int[].class)} */
 770     public static final int ARRAY_INT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_INT_BASE_OFFSET;
 771 
 772     /** The value of {@code arrayBaseOffset(long[].class)} */
 773     public static final int ARRAY_LONG_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_LONG_BASE_OFFSET;
 774 
 775     /** The value of {@code arrayBaseOffset(float[].class)} */
 776     public static final int ARRAY_FLOAT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_FLOAT_BASE_OFFSET;
 777 
 778     /** The value of {@code arrayBaseOffset(double[].class)} */
 779     public static final int ARRAY_DOUBLE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
 780 
 781     /** The value of {@code arrayBaseOffset(Object[].class)} */
 782     public static final int ARRAY_OBJECT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_OBJECT_BASE_OFFSET;
 783 
 784     /**
 785      * Reports the scale factor for addressing elements in the storage
 786      * allocation of a given array class.  However, arrays of "narrow" types
 787      * will generally not work properly with accessors like {@link
 788      * #getByte(Object, long)}, so the scale factor for such classes is reported
 789      * as zero.
 790      *
 791      * @see #arrayBaseOffset
 792      * @see #getInt(Object, long)
 793      * @see #putInt(Object, long, int)
 794      */
 795     @ForceInline
 796     public int arrayIndexScale(Class<?> arrayClass) {
 797         return theInternalUnsafe.arrayIndexScale(arrayClass);
 798     }
 799 
 800     /** The value of {@code arrayIndexScale(boolean[].class)} */
 801     public static final int ARRAY_BOOLEAN_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_INDEX_SCALE;
 802 
 803     /** The value of {@code arrayIndexScale(byte[].class)} */
 804     public static final int ARRAY_BYTE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BYTE_INDEX_SCALE;
 805 
 806     /** The value of {@code arrayIndexScale(short[].class)} */
 807     public static final int ARRAY_SHORT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_SHORT_INDEX_SCALE;
 808 
 809     /** The value of {@code arrayIndexScale(char[].class)} */
 810     public static final int ARRAY_CHAR_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_CHAR_INDEX_SCALE;
 811 
 812     /** The value of {@code arrayIndexScale(int[].class)} */
 813     public static final int ARRAY_INT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_INT_INDEX_SCALE;
 814 
 815     /** The value of {@code arrayIndexScale(long[].class)} */
 816     public static final int ARRAY_LONG_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_LONG_INDEX_SCALE;
 817 
 818     /** The value of {@code arrayIndexScale(float[].class)} */
 819     public static final int ARRAY_FLOAT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_FLOAT_INDEX_SCALE;
 820 
 821     /** The value of {@code arrayIndexScale(double[].class)} */
 822     public static final int ARRAY_DOUBLE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_INDEX_SCALE;
 823 
 824     /** The value of {@code arrayIndexScale(Object[].class)} */
 825     public static final int ARRAY_OBJECT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE;
 826 
 827     /**
 828      * Reports the size in bytes of a native pointer, as stored via {@link
 829      * #putAddress}.  This value will be either 4 or 8.  Note that the sizes of
 830      * other primitive types (as stored in native memory blocks) is determined
 831      * fully by their information content.
 832      */
 833     @ForceInline
 834     public int addressSize() {
 835         return theInternalUnsafe.addressSize();
 836     }
 837 
 838     /** The value of {@code addressSize()} */
 839     public static final int ADDRESS_SIZE = theInternalUnsafe.addressSize();
 840 
 841     /**
 842      * Reports the size in bytes of a native memory page (whatever that is).
 843      * This value will always be a power of two.
 844      */
 845     @ForceInline
 846     public int pageSize() {
 847         return theInternalUnsafe.pageSize();
 848     }
 849 
 850 
 851     /// random trusted operations from JNI:
 852 
 853     /**
 854      * Allocates an instance but does not run any constructor.
 855      * Initializes the class if it has not yet been.
 856      */
 857     @ForceInline
 858     public Object allocateInstance(Class<?> cls)
 859         throws InstantiationException {
 860         return theInternalUnsafe.allocateInstance(cls);
 861     }
 862 
 863     /** Throws the exception without telling the verifier. */
 864     @ForceInline
 865     public void throwException(Throwable ee) {
 866         theInternalUnsafe.throwException(ee);
 867     }
 868 
 869     /**
 870      * Atomically updates Java variable to {@code x} if it is currently
 871      * holding {@code expected}.
 872      *
 873      * <p>This operation has memory semantics of a {@code volatile} read
 874      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
 875      *
 876      * @return {@code true} if successful
 877      */
 878     @ForceInline
 879     public final boolean compareAndSwapObject(Object o, long offset,
 880                                               Object expected,
 881                                               Object x) {
 882         return theInternalUnsafe.compareAndSetReference(o, offset, expected, x);
 883     }
 884 
 885     /**
 886      * Atomically updates Java variable to {@code x} if it is currently
 887      * holding {@code expected}.
 888      *
 889      * <p>This operation has memory semantics of a {@code volatile} read
 890      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
 891      *
 892      * @return {@code true} if successful
 893      */
 894     @ForceInline
 895     public final boolean compareAndSwapInt(Object o, long offset,
 896                                            int expected,
 897                                            int x) {
 898         return theInternalUnsafe.compareAndSetInt(o, offset, expected, x);
 899     }
 900 
 901     /**
 902      * Atomically updates Java variable to {@code x} if it is currently
 903      * holding {@code expected}.
 904      *
 905      * <p>This operation has memory semantics of a {@code volatile} read
 906      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
 907      *
 908      * @return {@code true} if successful
 909      */
 910     @ForceInline
 911     public final boolean compareAndSwapLong(Object o, long offset,
 912                                             long expected,
 913                                             long x) {
 914         return theInternalUnsafe.compareAndSetLong(o, offset, expected, x);
 915     }
 916 
 917     /**
 918      * Fetches a reference value from a given Java variable, with volatile
 919      * load semantics. Otherwise identical to {@link #getObject(Object, long)}
 920      */
 921     @ForceInline
 922     public Object getObjectVolatile(Object o, long offset) {
 923         return theInternalUnsafe.getReferenceVolatile(o, offset);
 924     }
 925 
 926     /**
 927      * Stores a reference value into a given Java variable, with
 928      * volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)}
 929      */
 930     @ForceInline
 931     public void putObjectVolatile(Object o, long offset, Object x) {
 932         theInternalUnsafe.putReferenceVolatile(o, offset, x);
 933     }
 934 
 935     /** Volatile version of {@link #getInt(Object, long)}  */
 936     @ForceInline
 937     public int getIntVolatile(Object o, long offset) {
 938         return theInternalUnsafe.getIntVolatile(o, offset);
 939     }
 940 
 941     /** Volatile version of {@link #putInt(Object, long, int)}  */
 942     @ForceInline
 943     public void putIntVolatile(Object o, long offset, int x) {
 944         theInternalUnsafe.putIntVolatile(o, offset, x);
 945     }
 946 
 947     /** Volatile version of {@link #getBoolean(Object, long)}  */
 948     @ForceInline
 949     public boolean getBooleanVolatile(Object o, long offset) {
 950         return theInternalUnsafe.getBooleanVolatile(o, offset);
 951     }
 952 
 953     /** Volatile version of {@link #putBoolean(Object, long, boolean)}  */
 954     @ForceInline
 955     public void putBooleanVolatile(Object o, long offset, boolean x) {
 956         theInternalUnsafe.putBooleanVolatile(o, offset, x);
 957     }
 958 
 959     /** Volatile version of {@link #getByte(Object, long)}  */
 960     @ForceInline
 961     public byte getByteVolatile(Object o, long offset) {
 962         return theInternalUnsafe.getByteVolatile(o, offset);
 963     }
 964 
 965     /** Volatile version of {@link #putByte(Object, long, byte)}  */
 966     @ForceInline
 967     public void putByteVolatile(Object o, long offset, byte x) {
 968         theInternalUnsafe.putByteVolatile(o, offset, x);
 969     }
 970 
 971     /** Volatile version of {@link #getShort(Object, long)}  */
 972     @ForceInline
 973     public short getShortVolatile(Object o, long offset) {
 974         return theInternalUnsafe.getShortVolatile(o, offset);
 975     }
 976 
 977     /** Volatile version of {@link #putShort(Object, long, short)}  */
 978     @ForceInline
 979     public void putShortVolatile(Object o, long offset, short x) {
 980         theInternalUnsafe.putShortVolatile(o, offset, x);
 981     }
 982 
 983     /** Volatile version of {@link #getChar(Object, long)}  */
 984     @ForceInline
 985     public char getCharVolatile(Object o, long offset) {
 986         return theInternalUnsafe.getCharVolatile(o, offset);
 987     }
 988 
 989     /** Volatile version of {@link #putChar(Object, long, char)}  */
 990     @ForceInline
 991     public void putCharVolatile(Object o, long offset, char x) {
 992         theInternalUnsafe.putCharVolatile(o, offset, x);
 993     }
 994 
 995     /** Volatile version of {@link #getLong(Object, long)}  */
 996     @ForceInline
 997     public long getLongVolatile(Object o, long offset) {
 998         return theInternalUnsafe.getLongVolatile(o, offset);
 999     }
1000 
1001     /** Volatile version of {@link #putLong(Object, long, long)}  */
1002     @ForceInline
1003     public void putLongVolatile(Object o, long offset, long x) {
1004         theInternalUnsafe.putLongVolatile(o, offset, x);
1005     }
1006 
1007     /** Volatile version of {@link #getFloat(Object, long)}  */
1008     @ForceInline
1009     public float getFloatVolatile(Object o, long offset) {
1010         return theInternalUnsafe.getFloatVolatile(o, offset);
1011     }
1012 
1013     /** Volatile version of {@link #putFloat(Object, long, float)}  */
1014     @ForceInline
1015     public void putFloatVolatile(Object o, long offset, float x) {
1016         theInternalUnsafe.putFloatVolatile(o, offset, x);
1017     }
1018 
1019     /** Volatile version of {@link #getDouble(Object, long)}  */
1020     @ForceInline
1021     public double getDoubleVolatile(Object o, long offset) {
1022         return theInternalUnsafe.getDoubleVolatile(o, offset);
1023     }
1024 
1025     /** Volatile version of {@link #putDouble(Object, long, double)}  */
1026     @ForceInline
1027     public void putDoubleVolatile(Object o, long offset, double x) {
1028         theInternalUnsafe.putDoubleVolatile(o, offset, x);
1029     }
1030 
1031     /**
1032      * Version of {@link #putObjectVolatile(Object, long, Object)}
1033      * that does not guarantee immediate visibility of the store to
1034      * other threads. This method is generally only useful if the
1035      * underlying field is a Java volatile (or if an array cell, one
1036      * that is otherwise only accessed using volatile accesses).
1037      *
1038      * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
1039      */
1040     @ForceInline
1041     public void putOrderedObject(Object o, long offset, Object x) {
1042         theInternalUnsafe.putReferenceRelease(o, offset, x);
1043     }
1044 
1045     /** Ordered/Lazy version of {@link #putIntVolatile(Object, long, int)}  */
1046     @ForceInline
1047     public void putOrderedInt(Object o, long offset, int x) {
1048         theInternalUnsafe.putIntRelease(o, offset, x);
1049     }
1050 
1051     /** Ordered/Lazy version of {@link #putLongVolatile(Object, long, long)} */
1052     @ForceInline
1053     public void putOrderedLong(Object o, long offset, long x) {
1054         theInternalUnsafe.putLongRelease(o, offset, x);
1055     }
1056 
1057     /**
1058      * Unblocks the given thread blocked on {@code park}, or, if it is
1059      * not blocked, causes the subsequent call to {@code park} not to
1060      * block.  Note: this operation is "unsafe" solely because the
1061      * caller must somehow ensure that the thread has not been
1062      * destroyed. Nothing special is usually required to ensure this
1063      * when called from Java (in which there will ordinarily be a live
1064      * reference to the thread) but this is not nearly-automatically
1065      * so when calling from native code.
1066      *
1067      * @param thread the thread to unpark.
1068      *
1069      * @deprecated Use {@link java.util.concurrent.locks.LockSupport#unpark(Thread)} instead.
1070      */
1071     @Deprecated(since="22", forRemoval=true)
1072     @ForceInline
1073     public void unpark(Object thread) {
1074         theInternalUnsafe.unpark(thread);
1075     }
1076 
1077     /**
1078      * Blocks current thread, returning when a balancing
1079      * {@code unpark} occurs, or a balancing {@code unpark} has
1080      * already occurred, or the thread is interrupted, or, if not
1081      * absolute and time is not zero, the given time nanoseconds have
1082      * elapsed, or if absolute, the given deadline in milliseconds
1083      * since Epoch has passed, or spuriously (i.e., returning for no
1084      * "reason"). Note: This operation is in the Unsafe class only
1085      * because {@code unpark} is, so it would be strange to place it
1086      * elsewhere.
1087      *
1088      * @deprecated Use {@link java.util.concurrent.locks.LockSupport#parkNanos(long)} or
1089      * {@link java.util.concurrent.locks.LockSupport#parkUntil(long)} instead.
1090      */
1091     @Deprecated(since="22", forRemoval=true)
1092     @ForceInline
1093     public void park(boolean isAbsolute, long time) {
1094         theInternalUnsafe.park(isAbsolute, time);
1095     }
1096 
1097     /**
1098      * Gets the load average in the system run queue assigned
1099      * to the available processors averaged over various periods of time.
1100      * This method retrieves the given {@code nelem} samples and
1101      * assigns to the elements of the given {@code loadavg} array.
1102      * The system imposes a maximum of 3 samples, representing
1103      * averages over the last 1,  5,  and  15 minutes, respectively.
1104      *
1105      * @param loadavg an array of double of size nelems
1106      * @param nelems the number of samples to be retrieved and
1107      *        must be 1 to 3.
1108      *
1109      * @return the number of samples actually retrieved; or -1
1110      *         if the load average is unobtainable.
1111      *
1112      * @deprecated Use {@link java.lang.management.OperatingSystemMXBean#getSystemLoadAverage()}
1113      * instead.
1114      */
1115     @Deprecated(since="22", forRemoval=true)
1116     @ForceInline
1117     public int getLoadAverage(double[] loadavg, int nelems) {
1118         return theInternalUnsafe.getLoadAverage(loadavg, nelems);
1119     }
1120 
1121     // The following contain CAS-based Java implementations used on
1122     // platforms not supporting native instructions
1123 
1124     /**
1125      * Atomically adds the given value to the current value of a field
1126      * or array element within the given object {@code o}
1127      * at the given {@code offset}.
1128      *
1129      * @param o object/array to update the field/element in
1130      * @param offset field/element offset
1131      * @param delta the value to add
1132      * @return the previous value
1133      * @since 1.8
1134      */
1135     @ForceInline
1136     public final int getAndAddInt(Object o, long offset, int delta) {
1137         return theInternalUnsafe.getAndAddInt(o, offset, delta);
1138     }
1139 
1140     /**
1141      * Atomically adds the given value to the current value of a field
1142      * or array element within the given object {@code o}
1143      * at the given {@code offset}.
1144      *
1145      * @param o object/array to update the field/element in
1146      * @param offset field/element offset
1147      * @param delta the value to add
1148      * @return the previous value
1149      * @since 1.8
1150      */
1151     @ForceInline
1152     public final long getAndAddLong(Object o, long offset, long delta) {
1153         return theInternalUnsafe.getAndAddLong(o, offset, delta);
1154     }
1155 
1156     /**
1157      * Atomically exchanges the given value with the current value of
1158      * a field or array element within the given object {@code o}
1159      * at the given {@code offset}.
1160      *
1161      * @param o object/array to update the field/element in
1162      * @param offset field/element offset
1163      * @param newValue new value
1164      * @return the previous value
1165      * @since 1.8
1166      */
1167     @ForceInline
1168     public final int getAndSetInt(Object o, long offset, int newValue) {
1169         return theInternalUnsafe.getAndSetInt(o, offset, newValue);
1170     }
1171 
1172     /**
1173      * Atomically exchanges the given value with the current value of
1174      * a field or array element within the given object {@code o}
1175      * at the given {@code offset}.
1176      *
1177      * @param o object/array to update the field/element in
1178      * @param offset field/element offset
1179      * @param newValue new value
1180      * @return the previous value
1181      * @since 1.8
1182      */
1183     @ForceInline
1184     public final long getAndSetLong(Object o, long offset, long newValue) {
1185         return theInternalUnsafe.getAndSetLong(o, offset, newValue);
1186     }
1187 
1188     /**
1189      * Atomically exchanges the given reference value with the current
1190      * reference value of a field or array element within the given
1191      * object {@code o} at the given {@code offset}.
1192      *
1193      * @param o object/array to update the field/element in
1194      * @param offset field/element offset
1195      * @param newValue new value
1196      * @return the previous value
1197      * @since 1.8
1198      */
1199     @ForceInline
1200     public final Object getAndSetObject(Object o, long offset, Object newValue) {
1201         return theInternalUnsafe.getAndSetReference(o, offset, newValue);
1202     }
1203 
1204     /**
1205      * Ensures that loads before the fence will not be reordered with loads and
1206      * stores after the fence; a "LoadLoad plus LoadStore barrier".
1207      *
1208      * Corresponds to C11 atomic_thread_fence(memory_order_acquire)
1209      * (an "acquire fence").
1210      *
1211      * A pure LoadLoad fence is not provided, since the addition of LoadStore
1212      * is almost always desired, and most current hardware instructions that
1213      * provide a LoadLoad barrier also provide a LoadStore barrier for free.
1214      *
1215      * @deprecated Use {@link java.lang.invoke.VarHandle#acquireFence()} instead.
1216      * @since 1.8
1217      */
1218     @Deprecated(since="22", forRemoval=true)
1219     @ForceInline
1220     public void loadFence() {
1221         theInternalUnsafe.loadFence();
1222     }
1223 
1224     /**
1225      * Ensures that loads and stores before the fence will not be reordered with
1226      * stores after the fence; a "StoreStore plus LoadStore barrier".
1227      *
1228      * Corresponds to C11 atomic_thread_fence(memory_order_release)
1229      * (a "release fence").
1230      *
1231      * A pure StoreStore fence is not provided, since the addition of LoadStore
1232      * is almost always desired, and most current hardware instructions that
1233      * provide a StoreStore barrier also provide a LoadStore barrier for free.
1234      *
1235      * @deprecated Use {@link java.lang.invoke.VarHandle#releaseFence()} instead.
1236      * @since 1.8
1237      */
1238     @Deprecated(since="22", forRemoval=true)
1239     @ForceInline
1240     public void storeFence() {
1241         theInternalUnsafe.storeFence();
1242     }
1243 
1244     /**
1245      * Ensures that loads and stores before the fence will not be reordered
1246      * with loads and stores after the fence.  Implies the effects of both
1247      * loadFence() and storeFence(), and in addition, the effect of a StoreLoad
1248      * barrier.
1249      *
1250      * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
1251      *
1252      * @deprecated Use {@link java.lang.invoke.VarHandle#fullFence()} instead.
1253      * @since 1.8
1254      */
1255     @Deprecated(since="22", forRemoval=true)
1256     @ForceInline
1257     public void fullFence() {
1258         theInternalUnsafe.fullFence();
1259     }
1260 
1261     /**
1262      * Invokes the given direct byte buffer's cleaner, if any.
1263      *
1264      * @param directBuffer a direct byte buffer
1265      * @throws NullPointerException if {@code directBuffer} is null
1266      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
1267      * or is a {@link java.nio.Buffer#slice slice}, or is a
1268      * {@link java.nio.Buffer#duplicate duplicate}
1269      * @since 9
1270      */
1271     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
1272         if (!directBuffer.isDirect())
1273             throw new IllegalArgumentException("buffer is non-direct");
1274 
1275         theInternalUnsafe.invokeCleaner(directBuffer);
1276     }
1277 }