< prev index next >

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

Print this page




   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 jdk.internal.misc;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;

  29 import jdk.internal.vm.annotation.ForceInline;

  30 
  31 import java.lang.reflect.Field;
  32 import java.security.ProtectionDomain;
  33 
  34 
  35 /**
  36  * A collection of methods for performing low-level, unsafe operations.
  37  * Although the class and all methods are public, use of this class is
  38  * limited because only trusted code can obtain instances of it.
  39  *
  40  * <em>Note:</em> It is the resposibility of the caller to make sure
  41  * arguments are checked before methods of this class are
  42  * called. While some rudimentary checks are performed on the input,
  43  * the checks are best effort and when performance is an overriding
  44  * priority, as when methods of this class are optimized by the
  45  * runtime compiler, some or all checks (if any) may be elided. Hence,
  46  * the caller must not rely on the checks and corresponding
  47  * exceptions!
  48  *
  49  * @author John R. Rose


3701     private native void freeMemory0(long address);
3702     private native void setMemory0(Object o, long offset, long bytes, byte value);
3703     @HotSpotIntrinsicCandidate
3704     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
3705     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
3706     private native long objectFieldOffset0(Field f);
3707     private native long objectFieldOffset1(Class<?> c, String name);
3708     private native long staticFieldOffset0(Field f);
3709     private native Object staticFieldBase0(Field f);
3710     private native boolean shouldBeInitialized0(Class<?> c);
3711     private native void ensureClassInitialized0(Class<?> c);
3712     private native int arrayBaseOffset0(Class<?> arrayClass);
3713     private native int arrayIndexScale0(Class<?> arrayClass);
3714     private native int addressSize0();
3715     private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
3716     private native int getLoadAverage0(double[] loadavg, int nelems);
3717     private native boolean unalignedAccess0();
3718     private native boolean isBigEndian0();
3719 
3720 























3721     // The following deprecated methods are used by JSR 166.
3722 
3723     @Deprecated(since="12", forRemoval=true)
3724     public final Object getObject(Object o, long offset) {
3725         return getReference(o, offset);
3726     }
3727     @Deprecated(since="12", forRemoval=true)
3728     public final Object getObjectVolatile(Object o, long offset) {
3729         return getReferenceVolatile(o, offset);
3730     }
3731     @Deprecated(since="12", forRemoval=true)
3732     public final Object getObjectAcquire(Object o, long offset) {
3733         return getReferenceAcquire(o, offset);
3734     }
3735     @Deprecated(since="12", forRemoval=true)
3736     public final Object getObjectOpaque(Object o, long offset) {
3737         return getReferenceOpaque(o, offset);
3738     }
3739 
3740 




   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 jdk.internal.misc;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.ref.Cleaner;
  30 import jdk.internal.vm.annotation.ForceInline;
  31 import sun.nio.ch.DirectBuffer;
  32 
  33 import java.lang.reflect.Field;
  34 import java.security.ProtectionDomain;
  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 resposibility 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


3703     private native void freeMemory0(long address);
3704     private native void setMemory0(Object o, long offset, long bytes, byte value);
3705     @HotSpotIntrinsicCandidate
3706     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
3707     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
3708     private native long objectFieldOffset0(Field f);
3709     private native long objectFieldOffset1(Class<?> c, String name);
3710     private native long staticFieldOffset0(Field f);
3711     private native Object staticFieldBase0(Field f);
3712     private native boolean shouldBeInitialized0(Class<?> c);
3713     private native void ensureClassInitialized0(Class<?> c);
3714     private native int arrayBaseOffset0(Class<?> arrayClass);
3715     private native int arrayIndexScale0(Class<?> arrayClass);
3716     private native int addressSize0();
3717     private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
3718     private native int getLoadAverage0(double[] loadavg, int nelems);
3719     private native boolean unalignedAccess0();
3720     private native boolean isBigEndian0();
3721 
3722 
3723     /**
3724      * Invokes the given direct byte buffer's cleaner, if any.
3725      *
3726      * @param directBuffer a direct byte buffer
3727      * @throws NullPointerException     if {@code directBuffer} is null
3728      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
3729      *                                  or is a {@link java.nio.Buffer#slice slice}, or is a
3730      *                                  {@link java.nio.Buffer#duplicate duplicate}
3731      */
3732     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
3733         if (!directBuffer.isDirect())
3734             throw new IllegalArgumentException("buffer is non-direct");
3735 
3736         DirectBuffer db = (DirectBuffer) directBuffer;
3737         if (db.attachment() != null)
3738             throw new IllegalArgumentException("duplicate or slice");
3739 
3740         Cleaner cleaner = db.cleaner();
3741         if (cleaner != null) {
3742             cleaner.clean();
3743         }
3744     }
3745 
3746     // The following deprecated methods are used by JSR 166.
3747 
3748     @Deprecated(since="12", forRemoval=true)
3749     public final Object getObject(Object o, long offset) {
3750         return getReference(o, offset);
3751     }
3752     @Deprecated(since="12", forRemoval=true)
3753     public final Object getObjectVolatile(Object o, long offset) {
3754         return getReferenceVolatile(o, offset);
3755     }
3756     @Deprecated(since="12", forRemoval=true)
3757     public final Object getObjectAcquire(Object o, long offset) {
3758         return getReferenceAcquire(o, offset);
3759     }
3760     @Deprecated(since="12", forRemoval=true)
3761     public final Object getObjectOpaque(Object o, long offset) {
3762         return getReferenceOpaque(o, offset);
3763     }
3764 
3765 


< prev index next >