Class GridUnsafe


  • public abstract class GridUnsafe
    extends Object

    Wrapper for Unsafe class.

    The following statements for memory access operations are true:

    • All putXxx(long addr, xxx val), getXxx(long addr), putXxx(byte[] arr, long off, xxx val), getXxx(byte[] arr, long off) and corresponding methods with LE suffix are alignment aware and can be safely used with unaligned pointers.
    • All putXxxField(Object obj, long fieldOff, xxx val) and getXxxField(Object obj, long fieldOff) methods are not alignment aware and can't be safely used with unaligned pointers. This methods can be safely used for object field values access because all object fields addresses are aligned.
    • All putXxxLE(...) and getXxxLE(...) methods assumes that byte order is fixed as little-endian while native byte order is big-endian. So it is client code responsibility to check native byte order before invoking of this methods.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ByteBuffer allocateBuffer​(int len)  
      static Object allocateInstance​(Class cls)
      Allocates instance of given class.
      static long allocateMemory​(long size)
      Allocates memory.
      static int arrayBaseOffset​(Class cls)
      Returns the offset of the first element in the storage allocation of a given array class.
      static int arrayIndexScale​(Class<?> cls)
      Returns the scale factor for addressing elements in the storage allocation of a given array class.
      static long bufferAddress​(ByteBuffer buf)
      Returns address of Buffer instance.
      static void cleanDirectBuffer​(ByteBuffer buf)
      Cleans direct java.nio.ByteBuffer
      static boolean compareAndSwapInt​(Object obj, long off, int exp, int upd)
      Integer CAS.
      static boolean compareAndSwapLong​(Object obj, long off, long exp, long upd)
      Long CAS.
      static void copyHeapOffheap​(Object srcBase, long srcOff, long dstAddr, long len)
      Copy memory from heap to offheap.
      static void copyMemory​(long src, long dst, long len)
      Copies memory.
      static void copyMemory​(Object srcBase, long srcOff, Object dstBase, long dstOff, long len)
      Sets all bytes in a given block of memory to a copy of another block.
      static void copyOffheapHeap​(long srcAddr, Object dstBase, long dstOff, long len)
      Copy memory from offheap to heap.
      static void copyOffheapOffheap​(long srcAddr, long dstAddr, long len)
      Copy memory between offheap locations.
      static int decrementAndGetInt​(long ptr)
      Atomically increments value stored in an integer pointed by ptr.
      static void freeBuffer​(ByteBuffer buf)  
      static void freeMemory​(long addr)
      Frees memory.
      static boolean getBoolean​(byte[] arr, long off)
      Gets boolean value from byte array.
      static boolean getBooleanField​(Object obj, long fieldOff)
      Gets boolean value from object field.
      static byte getByte​(byte[] arr, long off)
      Gets byte value from byte array.
      static byte getByte​(long addr)
      Gets byte value from given address.
      static byte getByteField​(Object obj, long fieldOff)
      Gets byte value from object field.
      static byte getByteVolatile​(Object obj, long off)
      Gets byte value with volatile semantic.
      static char getChar​(byte[] arr, long off)
      Gets char value from byte array.
      static char getChar​(long addr)
      Gets char value from given address.
      static char getCharField​(Object obj, long fieldOff)
      Gets char value from object field.
      static char getCharLE​(byte[] arr, long off)
      Gets char value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian.
      static char getCharLE​(long addr)
      Gets char value from given address assuming that value stored in little-endian byte order and native byte order is big-endian.
      static double getDouble​(byte[] arr, long off)
      Gets double value from byte array.
      static double getDouble​(long addr)
      Gets double value from given address.
      static double getDoubleField​(Object obj, long fieldOff)
      Gets double value from object field.
      static double getDoubleLE​(byte[] arr, long off)
      Gets double value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian.
      static double getDoubleLE​(long addr)
      Gets double value from given address assuming that value stored in little-endian byte order and native byte order is big-endian.
      static float getFloat​(byte[] arr, long off)
      Gets float value from byte array.
      static float getFloat​(long addr)
      Gets float value from given address.
      static float getFloatField​(Object obj, long fieldOff)
      Gets float value from object field.
      static float getFloatLE​(byte[] arr, long off)
      Gets float value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian.
      static float getFloatLE​(long addr)
      Gets float value from given address assuming that value stored in little-endian byte order and native byte order is big-endian.
      static int getInt​(byte[] arr, long off)
      Gets integer value from byte array.
      static int getInt​(long addr)
      Gets integer value from given address.
      static int getIntField​(Object obj, long fieldOff)
      Gets integer value from object field.
      static int getIntLE​(byte[] arr, long off)
      Gets integer value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian.
      static int getIntLE​(long addr)
      Gets integer value from given address assuming that value stored in little-endian byte order and native byte order is big-endian.
      static int getIntVolatile​(Object obj, long off)
      Gets integer value with volatile semantic.
      static long getLong​(byte[] arr, long off)
      Gets long value from byte array.
      static long getLong​(long addr)
      Gets long value from given address.
      static long getLongField​(Object obj, long fieldOff)
      Gets long value from object field.
      static long getLongLE​(byte[] arr, long off)
      Gets long value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian.
      static long getLongLE​(long addr)
      Gets long value from given address assuming that value stored in little-endian byte order and native byte order is big-endian.
      static long getLongVolatile​(Object obj, long off)
      Gets long value with volatile semantic.
      static Object getObjectField​(Object obj, long fieldOff)
      Gets reference from object field.
      static short getShort​(byte[] arr, long off)
      Gets short value from byte array.
      static short getShort​(long addr)
      Gets short value from given address.
      static short getShortField​(Object obj, long fieldOff)
      Gets short value from object field.
      static short getShortLE​(byte[] arr, long off)
      Gets short value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian.
      static short getShortLE​(long addr)
      Gets short value from given address assuming that value stored in little-endian byte order and native byte order is big-endian.
      static int incrementAndGetInt​(long ptr)
      Atomically increments value stored in an integer pointed by ptr.
      static Object invoke​(Method mtd, Object... args)
      Invokes some method on sun.misc.Unsafe instance.
      static long objectFieldOffset​(Field field)
      Returns object field offset.
      static int pageSize()
      Returns page size.
      static void putBoolean​(byte[] arr, long off, boolean val)
      Stores boolean value into byte array.
      static void putBooleanField​(Object obj, long fieldOff, boolean val)
      Stores boolean value into object field.
      static void putByte​(byte[] arr, long off, byte val)
      Stores byte value into byte array.
      static void putByte​(long addr, byte val)
      Stores given byte value.
      static void putByteField​(Object obj, long fieldOff, byte val)
      Stores byte value into object field.
      static void putByteVolatile​(Object obj, long off, byte val)
      Stores byte value with volatile semantic.
      static void putChar​(byte[] arr, long off, char val)
      Stores char value into byte array.
      static void putChar​(long addr, char val)
      Stores given char value.
      static void putCharField​(Object obj, long fieldOff, char val)
      Stores char value into object field.
      static void putCharLE​(byte[] arr, long off, char val)
      Stores char value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putCharLE​(long addr, char val)
      Stores given char value assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putDouble​(byte[] arr, long off, double val)
      Stores double value into byte array.
      static void putDouble​(long addr, double val)
      Stores given double value.
      static void putDoubleField​(Object obj, long fieldOff, double val)
      Stores double value into object field.
      static void putDoubleLE​(byte[] arr, long off, double val)
      Stores double value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putDoubleLE​(long addr, double val)
      Stores given double value assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putFloat​(byte[] arr, long off, float val)
      Stores float value into byte array.
      static void putFloat​(long addr, float val)
      Stores given float value.
      static void putFloatField​(Object obj, long fieldOff, float val)
      Stores float value into object field.
      static void putFloatLE​(byte[] arr, long off, float val)
      Stores float value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putFloatLE​(long addr, float val)
      Stores given float value assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putInt​(byte[] arr, long off, int val)
      Stores integer value into byte array.
      static void putInt​(long addr, int val)
      Stores given integer value.
      static void putIntField​(Object obj, long fieldOff, int val)
      Stores integer value into object field.
      static void putIntLE​(byte[] arr, long off, int val)
      Stores integer value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putIntLE​(long addr, int val)
      Stores given integer value assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putIntVolatile​(Object obj, long off, int val)
      Stores integer value with volatile semantic.
      static void putLong​(byte[] arr, long off, long val)
      Stores long value into byte array.
      static void putLong​(long addr, long val)
      Stores given integer value.
      static void putLongField​(Object obj, long fieldOff, long val)
      Stores long value into object field.
      static void putLongLE​(byte[] arr, long off, long val)
      Stores long value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putLongLE​(long addr, long val)
      Stores given integer value assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putLongVolatile​(Object obj, long off, long val)
      Stores long value with volatile semantic.
      static void putObjectField​(Object obj, long fieldOff, Object val)
      Stores reference value into object field.
      static void putObjectVolatile​(Object obj, long off, Object val)
      Stores reference value with volatile semantic.
      static void putShort​(byte[] arr, long off, short val)
      Stores short value into byte array.
      static void putShort​(long addr, short val)
      Stores given short value.
      static void putShortField​(Object obj, long fieldOff, short val)
      Stores short value into object field.
      static void putShortLE​(byte[] arr, long off, short val)
      Stores short value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static void putShortLE​(long addr, short val)
      Stores given short value assuming that value should be stored in little-endian byte order and native byte order is big-endian.
      static ByteBuffer reallocateBuffer​(ByteBuffer buf, int len)  
      static long reallocateMemory​(long addr, long len)
      Reallocates memory.
      static void setMemory​(long addr, long len, byte val)
      Fills memory with given value.
      static Object staticFieldBase​(Field field)
      Returns static field base.
      static long staticFieldOffset​(Field field)
      Returns static field offset.
      static ByteBuffer wrapPointer​(long ptr, int len)
      Wraps pointer to unmanaged memory into direct byte buffer.
      static void zeroMemory​(long addr, long len)
      Fills memory with zeroes.
    • Field Detail

      • NATIVE_BYTE_ORDER

        public static final ByteOrder NATIVE_BYTE_ORDER
      • BIG_ENDIAN

        public static final boolean BIG_ENDIAN
        Big endian.
      • ADDR_SIZE

        public static final int ADDR_SIZE
        Address size.
      • BYTE_ARR_OFF

        public static final long BYTE_ARR_OFF
      • BYTE_ARR_INT_OFF

        public static final int BYTE_ARR_INT_OFF
      • SHORT_ARR_OFF

        public static final long SHORT_ARR_OFF
      • INT_ARR_OFF

        public static final long INT_ARR_OFF
      • LONG_ARR_OFF

        public static final long LONG_ARR_OFF
      • FLOAT_ARR_OFF

        public static final long FLOAT_ARR_OFF
      • DOUBLE_ARR_OFF

        public static final long DOUBLE_ARR_OFF
      • CHAR_ARR_OFF

        public static final long CHAR_ARR_OFF
      • BOOLEAN_ARR_OFF

        public static final long BOOLEAN_ARR_OFF
    • Method Detail

      • wrapPointer

        public static ByteBuffer wrapPointer​(long ptr,
                                             int len)
        Wraps pointer to unmanaged memory into direct byte buffer.
        Parameters:
        ptr - Pointer to wrap.
        len - Memory location length.
        Returns:
        Byte buffer wrapping the given memory.
      • allocateBuffer

        public static ByteBuffer allocateBuffer​(int len)
        Parameters:
        len - Length.
        Returns:
        Allocated direct buffer.
      • reallocateBuffer

        public static ByteBuffer reallocateBuffer​(ByteBuffer buf,
                                                  int len)
        Parameters:
        buf - Buffer.
        len - New length.
        Returns:
        Reallocated direct buffer.
      • getBooleanField

        public static boolean getBooleanField​(Object obj,
                                              long fieldOff)
        Gets boolean value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Boolean value from object field.
      • putBooleanField

        public static void putBooleanField​(Object obj,
                                           long fieldOff,
                                           boolean val)
        Stores boolean value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getByteField

        public static byte getByteField​(Object obj,
                                        long fieldOff)
        Gets byte value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Byte value from object field.
      • putByteField

        public static void putByteField​(Object obj,
                                        long fieldOff,
                                        byte val)
        Stores byte value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getShortField

        public static short getShortField​(Object obj,
                                          long fieldOff)
        Gets short value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Short value from object field.
      • putShortField

        public static void putShortField​(Object obj,
                                         long fieldOff,
                                         short val)
        Stores short value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getCharField

        public static char getCharField​(Object obj,
                                        long fieldOff)
        Gets char value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Char value from object field.
      • putCharField

        public static void putCharField​(Object obj,
                                        long fieldOff,
                                        char val)
        Stores char value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getIntField

        public static int getIntField​(Object obj,
                                      long fieldOff)
        Gets integer value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Integer value from object field.
      • putIntField

        public static void putIntField​(Object obj,
                                       long fieldOff,
                                       int val)
        Stores integer value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getLongField

        public static long getLongField​(Object obj,
                                        long fieldOff)
        Gets long value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Long value from object field.
      • putLongField

        public static void putLongField​(Object obj,
                                        long fieldOff,
                                        long val)
        Stores long value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getFloatField

        public static float getFloatField​(Object obj,
                                          long fieldOff)
        Gets float value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Float value from object field.
      • putFloatField

        public static void putFloatField​(Object obj,
                                         long fieldOff,
                                         float val)
        Stores float value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getDoubleField

        public static double getDoubleField​(Object obj,
                                            long fieldOff)
        Gets double value from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Double value from object field.
      • putDoubleField

        public static void putDoubleField​(Object obj,
                                          long fieldOff,
                                          double val)
        Stores double value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getObjectField

        public static Object getObjectField​(Object obj,
                                            long fieldOff)
        Gets reference from object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        Returns:
        Reference from object field.
      • putObjectField

        public static void putObjectField​(Object obj,
                                          long fieldOff,
                                          Object val)
        Stores reference value into object field.
        Parameters:
        obj - Object.
        fieldOff - Field offset.
        val - Value.
      • getBoolean

        public static boolean getBoolean​(byte[] arr,
                                         long off)
        Gets boolean value from byte array.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Boolean value from byte array.
      • putBoolean

        public static void putBoolean​(byte[] arr,
                                      long off,
                                      boolean val)
        Stores boolean value into byte array.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getByte

        public static byte getByte​(byte[] arr,
                                   long off)
        Gets byte value from byte array.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Byte value from byte array.
      • putByte

        public static void putByte​(byte[] arr,
                                   long off,
                                   byte val)
        Stores byte value into byte array.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getShort

        public static short getShort​(byte[] arr,
                                     long off)
        Gets short value from byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Short value from byte array.
      • putShort

        public static void putShort​(byte[] arr,
                                    long off,
                                    short val)
        Stores short value into byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getChar

        public static char getChar​(byte[] arr,
                                   long off)
        Gets char value from byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Char value from byte array.
      • putChar

        public static void putChar​(byte[] arr,
                                   long off,
                                   char val)
        Stores char value into byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getInt

        public static int getInt​(byte[] arr,
                                 long off)
        Gets integer value from byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Integer value from byte array.
      • putInt

        public static void putInt​(byte[] arr,
                                  long off,
                                  int val)
        Stores integer value into byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getLong

        public static long getLong​(byte[] arr,
                                   long off)
        Gets long value from byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Long value from byte array.
      • putLong

        public static void putLong​(byte[] arr,
                                   long off,
                                   long val)
        Stores long value into byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getFloat

        public static float getFloat​(byte[] arr,
                                     long off)
        Gets float value from byte array. Alignment aware.
        Parameters:
        arr - Object.
        off - Offset.
        Returns:
        Float value from byte array.
      • putFloat

        public static void putFloat​(byte[] arr,
                                    long off,
                                    float val)
        Stores float value into byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getDouble

        public static double getDouble​(byte[] arr,
                                       long off)
        Gets double value from byte array. Alignment aware.
        Parameters:
        arr - byte array.
        off - Offset.
        Returns:
        Double value from byte array. Alignment aware.
      • putDouble

        public static void putDouble​(byte[] arr,
                                     long off,
                                     double val)
        Stores double value into byte array. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getShortLE

        public static short getShortLE​(byte[] arr,
                                       long off)
        Gets short value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Short value from byte array.
      • putShortLE

        public static void putShortLE​(byte[] arr,
                                      long off,
                                      short val)
        Stores short value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getCharLE

        public static char getCharLE​(byte[] arr,
                                     long off)
        Gets char value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Char value from byte array.
      • putCharLE

        public static void putCharLE​(byte[] arr,
                                     long off,
                                     char val)
        Stores char value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getIntLE

        public static int getIntLE​(byte[] arr,
                                   long off)
        Gets integer value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Integer value from byte array.
      • putIntLE

        public static void putIntLE​(byte[] arr,
                                    long off,
                                    int val)
        Stores integer value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getLongLE

        public static long getLongLE​(byte[] arr,
                                     long off)
        Gets long value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Long value from byte array.
      • putLongLE

        public static void putLongLE​(byte[] arr,
                                     long off,
                                     long val)
        Stores long value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getFloatLE

        public static float getFloatLE​(byte[] arr,
                                       long off)
        Gets float value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Float value from byte array.
      • putFloatLE

        public static void putFloatLE​(byte[] arr,
                                      long off,
                                      float val)
        Stores float value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getDoubleLE

        public static double getDoubleLE​(byte[] arr,
                                         long off)
        Gets double value from byte array assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        Returns:
        Double value from byte array.
      • putDoubleLE

        public static void putDoubleLE​(byte[] arr,
                                       long off,
                                       double val)
        Stores double value into byte array assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        arr - Byte array.
        off - Offset.
        val - Value.
      • getByte

        public static byte getByte​(long addr)
        Gets byte value from given address.
        Parameters:
        addr - Address.
        Returns:
        Byte value from given address.
      • putByte

        public static void putByte​(long addr,
                                   byte val)
        Stores given byte value.
        Parameters:
        addr - Address.
        val - Value.
      • getShort

        public static short getShort​(long addr)
        Gets short value from given address. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Short value from given address.
      • putShort

        public static void putShort​(long addr,
                                    short val)
        Stores given short value. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getChar

        public static char getChar​(long addr)
        Gets char value from given address. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Char value from given address.
      • putChar

        public static void putChar​(long addr,
                                   char val)
        Stores given char value. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getInt

        public static int getInt​(long addr)
        Gets integer value from given address. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Integer value from given address.
      • putInt

        public static void putInt​(long addr,
                                  int val)
        Stores given integer value. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getLong

        public static long getLong​(long addr)
        Gets long value from given address. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Long value from given address.
      • putLong

        public static void putLong​(long addr,
                                   long val)
        Stores given integer value. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getFloat

        public static float getFloat​(long addr)
        Gets float value from given address. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Float value from given address.
      • putFloat

        public static void putFloat​(long addr,
                                    float val)
        Stores given float value. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getDouble

        public static double getDouble​(long addr)
        Gets double value from given address. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Double value from given address.
      • putDouble

        public static void putDouble​(long addr,
                                     double val)
        Stores given double value. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getShortLE

        public static short getShortLE​(long addr)
        Gets short value from given address assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Short value from given address.
      • putShortLE

        public static void putShortLE​(long addr,
                                      short val)
        Stores given short value assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getCharLE

        public static char getCharLE​(long addr)
        Gets char value from given address assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Char value from given address.
      • putCharLE

        public static void putCharLE​(long addr,
                                     char val)
        Stores given char value assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getIntLE

        public static int getIntLE​(long addr)
        Gets integer value from given address assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Integer value from given address.
      • putIntLE

        public static void putIntLE​(long addr,
                                    int val)
        Stores given integer value assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getLongLE

        public static long getLongLE​(long addr)
        Gets long value from given address assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Long value from given address.
      • putLongLE

        public static void putLongLE​(long addr,
                                     long val)
        Stores given integer value assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getFloatLE

        public static float getFloatLE​(long addr)
        Gets float value from given address assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Float value from given address.
      • putFloatLE

        public static void putFloatLE​(long addr,
                                      float val)
        Stores given float value assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • getDoubleLE

        public static double getDoubleLE​(long addr)
        Gets double value from given address assuming that value stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        Returns:
        Double value from given address.
      • putDoubleLE

        public static void putDoubleLE​(long addr,
                                       double val)
        Stores given double value assuming that value should be stored in little-endian byte order and native byte order is big-endian. Alignment aware.
        Parameters:
        addr - Address.
        val - Value.
      • staticFieldOffset

        public static long staticFieldOffset​(Field field)
        Returns static field offset.
        Parameters:
        field - Field.
        Returns:
        Static field offset.
      • objectFieldOffset

        public static long objectFieldOffset​(Field field)
        Returns object field offset.
        Parameters:
        field - Field.
        Returns:
        Object field offset.
      • staticFieldBase

        public static Object staticFieldBase​(Field field)
        Returns static field base.
        Parameters:
        field - Field.
        Returns:
        Static field base.
      • allocateMemory

        public static long allocateMemory​(long size)
        Allocates memory.
        Parameters:
        size - Size.
        Returns:
        address.
      • reallocateMemory

        public static long reallocateMemory​(long addr,
                                            long len)
        Reallocates memory.
        Parameters:
        addr - Address.
        len - Length.
        Returns:
        address.
      • setMemory

        public static void setMemory​(long addr,
                                     long len,
                                     byte val)
        Fills memory with given value.
        Parameters:
        addr - Address.
        len - Length.
        val - Value.
      • zeroMemory

        public static void zeroMemory​(long addr,
                                      long len)
        Fills memory with zeroes.
        Parameters:
        addr - Address.
        len - Length.
      • copyOffheapOffheap

        public static void copyOffheapOffheap​(long srcAddr,
                                              long dstAddr,
                                              long len)
        Copy memory between offheap locations.
        Parameters:
        srcAddr - Source address.
        dstAddr - Destination address.
        len - Length.
      • copyOffheapHeap

        public static void copyOffheapHeap​(long srcAddr,
                                           Object dstBase,
                                           long dstOff,
                                           long len)
        Copy memory from offheap to heap.
        Parameters:
        srcAddr - Source address.
        dstBase - Destination base.
        dstOff - Destination offset.
        len - Length.
      • copyHeapOffheap

        public static void copyHeapOffheap​(Object srcBase,
                                           long srcOff,
                                           long dstAddr,
                                           long len)
        Copy memory from heap to offheap.
        Parameters:
        srcBase - Source base.
        srcOff - Source offset.
        dstAddr - Destination address.
        len - Length.
      • copyMemory

        public static void copyMemory​(long src,
                                      long dst,
                                      long len)
        Copies memory.
        Parameters:
        src - Source.
        dst - Dst.
        len - Length.
      • copyMemory

        public static void copyMemory​(Object srcBase,
                                      long srcOff,
                                      Object dstBase,
                                      long dstOff,
                                      long len)
        Sets all bytes in a given block of memory to a copy of another block.
        Parameters:
        srcBase - Source base.
        srcOff - Source offset.
        dstBase - Dst base.
        dstOff - Dst offset.
        len - Length.
      • freeMemory

        public static void freeMemory​(long addr)
        Frees memory.
        Parameters:
        addr - Address.
      • arrayBaseOffset

        public static int arrayBaseOffset​(Class cls)
        Returns the offset of the first element in the storage allocation of a given array class.
        Parameters:
        cls - Class.
        Returns:
        the offset of the first element in the storage allocation of a given array class.
      • arrayIndexScale

        public static int arrayIndexScale​(Class<?> cls)
        Returns the scale factor for addressing elements in the storage allocation of a given array class.
        Parameters:
        cls - Class.
        Returns:
        the scale factor for addressing elements in the storage allocation of a given array class.
      • compareAndSwapInt

        public static boolean compareAndSwapInt​(Object obj,
                                                long off,
                                                int exp,
                                                int upd)
        Integer CAS.
        Parameters:
        obj - Object.
        off - Offset.
        exp - Expected.
        upd - Upd.
        Returns:
        True if operation completed successfully, false - otherwise.
      • compareAndSwapLong

        public static boolean compareAndSwapLong​(Object obj,
                                                 long off,
                                                 long exp,
                                                 long upd)
        Long CAS.
        Parameters:
        obj - Object.
        off - Offset.
        exp - Expected.
        upd - Upd.
        Returns:
        True if operation completed successfully, false - otherwise.
      • incrementAndGetInt

        public static int incrementAndGetInt​(long ptr)
        Atomically increments value stored in an integer pointed by ptr.
        Parameters:
        ptr - Pointer to an integer.
        Returns:
        Updated value.
      • decrementAndGetInt

        public static int decrementAndGetInt​(long ptr)
        Atomically increments value stored in an integer pointed by ptr.
        Parameters:
        ptr - Pointer to an integer.
        Returns:
        Updated value.
      • getByteVolatile

        public static byte getByteVolatile​(Object obj,
                                           long off)
        Gets byte value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        Returns:
        Byte value.
      • putByteVolatile

        public static void putByteVolatile​(Object obj,
                                           long off,
                                           byte val)
        Stores byte value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        val - Value.
      • getIntVolatile

        public static int getIntVolatile​(Object obj,
                                         long off)
        Gets integer value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        Returns:
        Integer value.
      • putIntVolatile

        public static void putIntVolatile​(Object obj,
                                          long off,
                                          int val)
        Stores integer value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        val - Value.
      • getLongVolatile

        public static long getLongVolatile​(Object obj,
                                           long off)
        Gets long value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        Returns:
        Long value.
      • putLongVolatile

        public static void putLongVolatile​(Object obj,
                                           long off,
                                           long val)
        Stores long value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        val - Value.
      • putObjectVolatile

        public static void putObjectVolatile​(Object obj,
                                             long off,
                                             Object val)
        Stores reference value with volatile semantic.
        Parameters:
        obj - Object.
        off - Offset.
        val - Value.
      • pageSize

        public static int pageSize()
        Returns page size.
        Returns:
        Page size.
      • bufferAddress

        public static long bufferAddress​(ByteBuffer buf)
        Returns address of Buffer instance.
        Parameters:
        buf - Buffer.
        Returns:
        Buffer memory address.
      • invoke

        public static Object invoke​(Method mtd,
                                    Object... args)
        Invokes some method on sun.misc.Unsafe instance.
        Parameters:
        mtd - Method.
        args - Arguments.
      • cleanDirectBuffer

        public static void cleanDirectBuffer​(ByteBuffer buf)
        Cleans direct java.nio.ByteBuffer
        Parameters:
        buf - Direct buffer.