Class Unsafe

java.lang.Object
pcap.common.internal.Unsafe

@Inclubating
public class Unsafe
extends Object
Author:
Ardika Rommy Sanjaya
  • Field Details

    • HAS_UNSAFE

      public static final boolean HAS_UNSAFE
  • Constructor Details

  • Method Details

    • arrayBaseOffset

      public int arrayBaseOffset​(Class<?> arrayClass)
    • allocateMemory

      public long allocateMemory​(long bytes)
    • reallocateMemory

      public long reallocateMemory​(long address, long bytes)
      Resizes a new block of native memory, to the given size in bytes. The contents of the new block past the size of the old block are uninitialized; they will generally be garbage. The resulting native pointer will be zero if and only if the requested size is zero. The resulting native pointer will be aligned for all value types. Dispose of this memory by calling freeMemory(long), or resize it with reallocateMemory(long, long). The address passed to this method may be null, in which case an allocation will be performed.

      Note: It is the resposibility of the caller to make sure arguments are checked before the methods are called. While some rudimentary checks are performed on the input, the checks are best effort and when performance is an overriding priority, as when methods of this class are optimized by the runtime compiler, some or all checks (if any) may be elided. Hence, the caller must not rely on the checks and corresponding exceptions!

      Parameters:
      address - memory address.
      bytes - size of new memory block.
      Returns:
      returns memory address.
      Throws:
      RuntimeException - if the size is negative or too large for the native size_t type
      OutOfMemoryError - if the allocation is refused by the system
      See Also:
      allocateMemory(long)
    • freeMemory

      public void freeMemory​(long address)
      Disposes of a block of native memory, as obtained from allocateMemory(long) or reallocateMemory(long, long). The address passed to this method may be null, in which case no action is taken.

      Note: It is the resposibility of the caller to make sure arguments are checked before the methods are called. While some rudimentary checks are performed on the input, the checks are best effort and when performance is an overriding priority, as when methods of this class are optimized by the runtime compiler, some or all checks (if any) may be elided. Hence, the caller must not rely on the checks and corresponding exceptions!

      Parameters:
      address - memory address.
      Throws:
      RuntimeException - if any of the arguments is invalid
      See Also:
      allocateMemory(long)
    • copyMemory

      public void copyMemory​(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes)
      Sets all bytes in a given block of memory to a copy of another block.
      Parameters:
      srcBase - src base.
      srcOffset - src offset.
      destBase - dst base.
      destOffset - dst offset.
      bytes - size.
    • getByte

      public byte getByte​(long address)
      Fetches a value from a given memory address. If the address is zero, or does not point into a block obtained from allocateMemory(long), the results are undefined.
      Parameters:
      address - memory address.
      See Also:
      allocateMemory(long)
    • putByte

      public void putByte​(long address, byte x)
      Stores a value into a given memory address. If the address is zero, or does not point into a block obtained from allocateMemory(long), the results are undefined.
      Parameters:
      address - memory address.
      x - value.
      See Also:
      getByte(long)
    • getShort

      public short getShort​(long address)
      Parameters:
      address - memory address.
      See Also:
      getByte(long)
    • putShort

      public void putShort​(long address, short x)
      Parameters:
      address - memory address.
      x - value.
      See Also:
      putByte(long, byte)
    • getChar

      public char getChar​(long address)
      Parameters:
      address - memory address.
      See Also:
      getByte(long)
    • putChar

      public void putChar​(long address, char x)
      Parameters:
      address - memory address.
      x - value.
      See Also:
      putByte(long, byte)
    • getInt

      public int getInt​(long address)
      Parameters:
      address - memory address.
      See Also:
      getByte(long)
    • putInt

      public void putInt​(long address, int x)
      Parameters:
      address - memory address.
      x - value.
      See Also:
      putByte(long, byte)
    • getLong

      public long getLong​(long address)
      Parameters:
      address - memory address.
      See Also:
      getByte(long)
    • putLong

      public void putLong​(long address, long x)
      Parameters:
      address - memory address.
      x - value.
      See Also:
      putByte(long, byte)
    • getFloat

      public float getFloat​(long address)
      Parameters:
      address - memory address.
      See Also:
      getByte(long)
    • putFloat

      public void putFloat​(long address, float x)
      Parameters:
      address - memory address.
      x - value.
      See Also:
      putByte(long, byte)
    • getDouble

      public double getDouble​(long address)
      Parameters:
      address - memory address.
      See Also:
      getByte(long)
    • putDouble

      public void putDouble​(long address, double x)
      Parameters:
      address - memory address.
      x - value.
      See Also:
      putByte(long, byte)
    • bufferCleaner

      public Method bufferCleaner()
      Get direct ByteBuffer cleaner.
      Returns:
      cleaner method.