Add ipc module.
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
package io.izzel.taboolib.module.ipc;
|
||||
|
||||
import io.izzel.taboolib.util.UNSAFE;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class MemoryMappedFile {
|
||||
private static final Method mmap;
|
||||
private static final Method unmmap;
|
||||
private static final int BYTE_ARRAY_OFFSET;
|
||||
|
||||
private long addr, size;
|
||||
|
||||
static {
|
||||
try {
|
||||
mmap = getMethod(FileChannelImpl.class, "map0", int.class, long.class, long.class);
|
||||
unmmap = getMethod(FileChannelImpl.class, "unmap0", long.class, long.class);
|
||||
BYTE_ARRAY_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getMethod(Class<?> cls, String name, Class<?>... params) throws Exception {
|
||||
Method m = cls.getDeclaredMethod(name, params);
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
|
||||
protected MemoryMappedFile(FileChannel ch, long len) throws Exception {
|
||||
this.size = len;
|
||||
this.addr = (long) mmap.invoke(ch, 1, 0L, this.size);
|
||||
}
|
||||
|
||||
protected void unmap() throws Exception {
|
||||
unmmap.invoke(null, addr, this.size);
|
||||
}
|
||||
|
||||
public long getAddress() {
|
||||
return addr;
|
||||
}
|
||||
|
||||
public byte getByte(long pos) {
|
||||
return UNSAFE.getByte(pos + addr);
|
||||
}
|
||||
|
||||
protected byte getByteVolatile(long pos) {
|
||||
return UNSAFE.getByteVolatile(null, pos + addr);
|
||||
}
|
||||
|
||||
public int getInt(long pos) {
|
||||
return UNSAFE.getInt(pos + addr);
|
||||
}
|
||||
|
||||
protected int getIntVolatile(long pos) {
|
||||
return UNSAFE.getIntVolatile(null, pos + addr);
|
||||
}
|
||||
|
||||
public long getLong(long pos) {
|
||||
return UNSAFE.getLong(pos + addr);
|
||||
}
|
||||
|
||||
protected long getLongVolatile(long pos) {
|
||||
return UNSAFE.getLongVolatile(null, pos + addr);
|
||||
}
|
||||
|
||||
public void putByte(long pos, byte val) {
|
||||
UNSAFE.putByte(pos + addr, val);
|
||||
}
|
||||
|
||||
protected void putByteVolatile(long pos, byte val) {
|
||||
UNSAFE.putByteVolatile(null, pos + addr, val);
|
||||
}
|
||||
|
||||
public void putInt(long pos, int val) {
|
||||
UNSAFE.putInt(pos + addr, val);
|
||||
}
|
||||
|
||||
protected void putIntVolatile(long pos, int val) {
|
||||
UNSAFE.putIntVolatile(null, pos + addr, val);
|
||||
}
|
||||
|
||||
public void putLong(long pos, long val) {
|
||||
UNSAFE.putLong(pos + addr, val);
|
||||
}
|
||||
|
||||
protected void putLongVolatile(long pos, long val) {
|
||||
UNSAFE.putLongVolatile(null, pos + addr, val);
|
||||
}
|
||||
|
||||
public void getBytes(long pos, byte[] data, int offset, int length) {
|
||||
UNSAFE.copyMemory(null, pos + addr, data, BYTE_ARRAY_OFFSET + offset, length);
|
||||
}
|
||||
|
||||
public void setBytes(long pos, byte[] data, int offset, int length) {
|
||||
UNSAFE.copyMemory(data, BYTE_ARRAY_OFFSET + offset, null, pos + addr, length);
|
||||
}
|
||||
|
||||
protected boolean compareAndSwapInt(long pos, int expected, int value) {
|
||||
return UNSAFE.compareAndSwapInt(null, pos + addr, expected, value);
|
||||
}
|
||||
|
||||
protected boolean compareAndSwapLong(long pos, long expected, long value) {
|
||||
return UNSAFE.compareAndSwapLong(null, pos + addr, expected, value);
|
||||
}
|
||||
|
||||
protected int getAndAddInt(long pos, int delta) {
|
||||
return UNSAFE.getAndAddInt(null, pos + addr, delta);
|
||||
}
|
||||
|
||||
protected long getAndAddLong(long pos, long delta) {
|
||||
return UNSAFE.getAndAddLong(null, pos + addr, delta);
|
||||
}
|
||||
|
||||
protected int addAndGetInt(long pos, int delta) {
|
||||
return UNSAFE.getAndAddInt(null, pos + addr, delta) + delta;
|
||||
}
|
||||
|
||||
protected long addAndGetLong(long pos, long delta) {
|
||||
return UNSAFE.getAndAddLong(null, pos + addr, delta) + delta;
|
||||
}
|
||||
|
||||
protected long getAndSetInt(long pos, int val) {
|
||||
return UNSAFE.getAndSetInt(null, pos + addr, val);
|
||||
}
|
||||
|
||||
protected long getAndSetLong(long pos, long val) {
|
||||
return UNSAFE.getAndSetLong(null, pos + addr, val);
|
||||
}
|
||||
|
||||
protected void setMemory(long pos, long bytes, byte value) {
|
||||
UNSAFE.setMemory(pos + addr, bytes, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package io.izzel.taboolib.module.ipc;
|
||||
|
||||
public class MessageBlock {
|
||||
|
||||
private final MemoryMappedFile file;
|
||||
private final long baseOffset;
|
||||
private final long size;
|
||||
|
||||
public MessageBlock(MemoryMappedFile file, long baseOffset, long size) {
|
||||
this.file = file;
|
||||
this.baseOffset = baseOffset;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
int id = getId();
|
||||
file.setMemory(baseOffset, size, (byte) 0x00);
|
||||
putInt(0, id);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt(0);
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return getLong(4);
|
||||
}
|
||||
|
||||
public void updateTimestamp() {
|
||||
putLong(4, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public long getPayloadSize() {
|
||||
return size - 64;
|
||||
}
|
||||
|
||||
public long getAddress() {
|
||||
return file.getAddress() + baseOffset;
|
||||
}
|
||||
|
||||
public byte getByte(long pos) {
|
||||
return file.getByte(mapAddress(pos));
|
||||
}
|
||||
|
||||
public byte getByteVolatile(long pos) {
|
||||
return file.getByteVolatile(mapAddress(pos));
|
||||
}
|
||||
|
||||
public int getInt(long pos) {
|
||||
return file.getInt(mapAddress(pos));
|
||||
}
|
||||
|
||||
public int getIntVolatile(long pos) {
|
||||
return file.getIntVolatile(mapAddress(pos));
|
||||
}
|
||||
|
||||
public long getLong(long pos) {
|
||||
return file.getLong(mapAddress(pos));
|
||||
}
|
||||
|
||||
public long getLongVolatile(long pos) {
|
||||
return file.getLongVolatile(mapAddress(pos));
|
||||
}
|
||||
|
||||
public void putByte(long pos, byte val) {
|
||||
file.putByte(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public void putByteVolatile(long pos, byte val) {
|
||||
file.putByteVolatile(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public void putInt(long pos, int val) {
|
||||
file.putInt(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public void putIntVolatile(long pos, int val) {
|
||||
file.putIntVolatile(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public void putLong(long pos, long val) {
|
||||
file.putLong(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public void putLongVolatile(long pos, long val) {
|
||||
file.putLongVolatile(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public void getBytes(long pos, byte[] data, int offset, int length) {
|
||||
file.getBytes(mapAddress(pos), data, offset, length);
|
||||
}
|
||||
|
||||
public void setBytes(long pos, byte[] data, int offset, int length) {
|
||||
file.setBytes(mapAddress(pos), data, offset, length);
|
||||
}
|
||||
|
||||
public boolean compareAndSwapInt(long pos, int expected, int value) {
|
||||
return file.compareAndSwapInt(mapAddress(pos), expected, value);
|
||||
}
|
||||
|
||||
public boolean compareAndSwapLong(long pos, long expected, long value) {
|
||||
return file.compareAndSwapLong(mapAddress(pos), expected, value);
|
||||
}
|
||||
|
||||
public int getAndAddInt(long pos, int delta) {
|
||||
return file.getAndAddInt(mapAddress(pos), delta);
|
||||
}
|
||||
|
||||
public long getAndAddLong(long pos, long delta) {
|
||||
return file.getAndAddLong(mapAddress(pos), delta);
|
||||
}
|
||||
|
||||
public int addAndGetInt(long pos, int delta) {
|
||||
return file.addAndGetInt(mapAddress(pos), delta);
|
||||
}
|
||||
|
||||
public long addAndGetLong(long pos, long delta) {
|
||||
return file.addAndGetLong(mapAddress(pos), delta);
|
||||
}
|
||||
|
||||
public long getAndSetInt(long pos, int val) {
|
||||
return file.getAndSetInt(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
public long getAndSetLong(long pos, long val) {
|
||||
return file.getAndSetLong(mapAddress(pos), val);
|
||||
}
|
||||
|
||||
private long mapAddress(long pos) {
|
||||
if (pos < size) {
|
||||
return baseOffset + pos;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.izzel.taboolib.module.ipc;
|
||||
|
||||
public interface TabooIpcClient {
|
||||
|
||||
boolean connect(TabooIpcConfig config) throws Exception;
|
||||
|
||||
void disconnect() throws Exception;
|
||||
|
||||
boolean sendMessage(byte[] bytes, int index, int length, MessageBlock target);
|
||||
|
||||
default boolean sendMessage(byte[] bytes, MessageBlock target) {
|
||||
return sendMessage(bytes, 0, bytes.length, target);
|
||||
}
|
||||
|
||||
boolean readMessage(byte[] buf);
|
||||
|
||||
int getId();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.izzel.taboolib.module.ipc;
|
||||
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class TabooIpcClientImpl implements TabooIpcClient {
|
||||
|
||||
private volatile boolean available = false;
|
||||
private MemoryMappedFile file;
|
||||
private int id;
|
||||
private MessageBlock block;
|
||||
|
||||
@Override
|
||||
public synchronized boolean connect(TabooIpcConfig config) throws Exception {
|
||||
if (available) throw new IllegalStateException();
|
||||
long size = round(config.memorySize());
|
||||
long blockSize = round(config.blockSize());
|
||||
if (blockSize < 128 || size < (blockSize << 1) || size % blockSize != 0) return false;
|
||||
try (RandomAccessFile raf = new RandomAccessFile(config.fileLocation(), "rw")) {
|
||||
raf.setLength(size);
|
||||
try (FileChannel channel = raf.getChannel()) {
|
||||
this.file = new MemoryMappedFile(channel, size);
|
||||
this.id = file.getAndAddInt(0, 1);
|
||||
if (!login(size, blockSize, config.timeout())) {
|
||||
this.file.unmap();
|
||||
return available = false;
|
||||
}
|
||||
return available = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void disconnect() throws Exception {
|
||||
if (!available) throw new IllegalStateException();
|
||||
if (file != null) file.unmap();
|
||||
available = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendMessage(byte[] bytes, int index, int length, MessageBlock target) {
|
||||
if (!available) throw new IllegalStateException();
|
||||
if (bytes.length < length || target.getPayloadSize() < length)
|
||||
throw new IllegalArgumentException("message too long");
|
||||
if (target.compareAndSwapInt(16, 0, 1)) {
|
||||
target.setBytes(64, bytes, index, length);
|
||||
return target.compareAndSwapInt(16, 1, 2);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readMessage(byte[] buf) {
|
||||
if (!available) throw new IllegalStateException();
|
||||
if (this.block.getInt(16) == 2) {
|
||||
this.block.getBytes(64, buf, 0, (int) this.block.getPayloadSize());
|
||||
return this.block.compareAndSwapInt(16, 2, 0);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
if (!available) throw new IllegalStateException();
|
||||
return id;
|
||||
}
|
||||
|
||||
private boolean login(long size, long blockSize, long timeout) {
|
||||
long offset = blockSize;
|
||||
while (offset < size) {
|
||||
int prevId = file.getInt(offset);
|
||||
long cur = System.currentTimeMillis();
|
||||
long prev = file.getAndSetLong(offset + 4, cur);
|
||||
if (Math.abs(prev - cur) > timeout) {
|
||||
if (file.compareAndSwapInt(offset, prevId, id)) {
|
||||
this.block = new MessageBlock(file, offset, blockSize);
|
||||
this.block.reset();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
offset += blockSize;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static long round(long i) {
|
||||
return (i + 0xfffL) & ~0xfffL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.izzel.taboolib.module.ipc;
|
||||
|
||||
public interface TabooIpcConfig {
|
||||
|
||||
default long memorySize() {
|
||||
return 1 << 24;
|
||||
}
|
||||
|
||||
default long blockSize() {
|
||||
return 1 << 14;
|
||||
}
|
||||
|
||||
default long period() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
default long timeout() {
|
||||
return 60 * 1000;
|
||||
}
|
||||
|
||||
String fileLocation();
|
||||
}
|
||||
492
module-ipc/src/main/java/io/izzel/taboolib/util/UNSAFE.java
Normal file
492
module-ipc/src/main/java/io/izzel/taboolib/util/UNSAFE.java
Normal file
@@ -0,0 +1,492 @@
|
||||
package io.izzel.taboolib.util;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public class UNSAFE {
|
||||
|
||||
private static final Unsafe unsafe;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
unsafe = (Unsafe) theUnsafe.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(Object o, long offset) {
|
||||
return unsafe.getInt(o, offset);
|
||||
}
|
||||
|
||||
public static void putInt(Object o, long offset, int x) {
|
||||
unsafe.putInt(o, offset, x);
|
||||
}
|
||||
|
||||
public static Object getObject(Object o, long offset) {
|
||||
return unsafe.getObject(o, offset);
|
||||
}
|
||||
|
||||
public static void putObject(Object o, long offset, Object x) {
|
||||
unsafe.putObject(o, offset, x);
|
||||
}
|
||||
|
||||
public static boolean getBoolean(Object o, long offset) {
|
||||
return unsafe.getBoolean(o, offset);
|
||||
}
|
||||
|
||||
public static void putBoolean(Object o, long offset, boolean x) {
|
||||
unsafe.putBoolean(o, offset, x);
|
||||
}
|
||||
|
||||
public static byte getByte(Object o, long offset) {
|
||||
return unsafe.getByte(o, offset);
|
||||
}
|
||||
|
||||
public static void putByte(Object o, long offset, byte x) {
|
||||
unsafe.putByte(o, offset, x);
|
||||
}
|
||||
|
||||
public static short getShort(Object o, long offset) {
|
||||
return unsafe.getShort(o, offset);
|
||||
}
|
||||
|
||||
public static void putShort(Object o, long offset, short x) {
|
||||
unsafe.putShort(o, offset, x);
|
||||
}
|
||||
|
||||
public static char getChar(Object o, long offset) {
|
||||
return unsafe.getChar(o, offset);
|
||||
}
|
||||
|
||||
public static void putChar(Object o, long offset, char x) {
|
||||
unsafe.putChar(o, offset, x);
|
||||
}
|
||||
|
||||
public static long getLong(Object o, long offset) {
|
||||
return unsafe.getLong(o, offset);
|
||||
}
|
||||
|
||||
public static void putLong(Object o, long offset, long x) {
|
||||
unsafe.putLong(o, offset, x);
|
||||
}
|
||||
|
||||
public static float getFloat(Object o, long offset) {
|
||||
return unsafe.getFloat(o, offset);
|
||||
}
|
||||
|
||||
public static void putFloat(Object o, long offset, float x) {
|
||||
unsafe.putFloat(o, offset, x);
|
||||
}
|
||||
|
||||
public static double getDouble(Object o, long offset) {
|
||||
return unsafe.getDouble(o, offset);
|
||||
}
|
||||
|
||||
public static void putDouble(Object o, long offset, double x) {
|
||||
unsafe.putDouble(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int getInt(Object o, int offset) {
|
||||
return unsafe.getInt(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putInt(Object o, int offset, int x) {
|
||||
unsafe.putInt(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Object getObject(Object o, int offset) {
|
||||
return unsafe.getObject(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putObject(Object o, int offset, Object x) {
|
||||
unsafe.putObject(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean getBoolean(Object o, int offset) {
|
||||
return unsafe.getBoolean(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putBoolean(Object o, int offset, boolean x) {
|
||||
unsafe.putBoolean(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static byte getByte(Object o, int offset) {
|
||||
return unsafe.getByte(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putByte(Object o, int offset, byte x) {
|
||||
unsafe.putByte(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static short getShort(Object o, int offset) {
|
||||
return unsafe.getShort(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putShort(Object o, int offset, short x) {
|
||||
unsafe.putShort(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static char getChar(Object o, int offset) {
|
||||
return unsafe.getChar(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putChar(Object o, int offset, char x) {
|
||||
unsafe.putChar(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static long getLong(Object o, int offset) {
|
||||
return unsafe.getLong(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putLong(Object o, int offset, long x) {
|
||||
unsafe.putLong(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float getFloat(Object o, int offset) {
|
||||
return unsafe.getFloat(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putFloat(Object o, int offset, float x) {
|
||||
unsafe.putFloat(o, offset, x);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static double getDouble(Object o, int offset) {
|
||||
return unsafe.getDouble(o, offset);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putDouble(Object o, int offset, double x) {
|
||||
unsafe.putDouble(o, offset, x);
|
||||
}
|
||||
|
||||
public static byte getByte(long address) {
|
||||
return unsafe.getByte(address);
|
||||
}
|
||||
|
||||
public static void putByte(long address, byte x) {
|
||||
unsafe.putByte(address, x);
|
||||
}
|
||||
|
||||
public static short getShort(long address) {
|
||||
return unsafe.getShort(address);
|
||||
}
|
||||
|
||||
public static void putShort(long address, short x) {
|
||||
unsafe.putShort(address, x);
|
||||
}
|
||||
|
||||
public static char getChar(long address) {
|
||||
return unsafe.getChar(address);
|
||||
}
|
||||
|
||||
public static void putChar(long address, char x) {
|
||||
unsafe.putChar(address, x);
|
||||
}
|
||||
|
||||
public static int getInt(long address) {
|
||||
return unsafe.getInt(address);
|
||||
}
|
||||
|
||||
public static void putInt(long address, int x) {
|
||||
unsafe.putInt(address, x);
|
||||
}
|
||||
|
||||
public static long getLong(long address) {
|
||||
return unsafe.getLong(address);
|
||||
}
|
||||
|
||||
public static void putLong(long address, long x) {
|
||||
unsafe.putLong(address, x);
|
||||
}
|
||||
|
||||
public static float getFloat(long address) {
|
||||
return unsafe.getFloat(address);
|
||||
}
|
||||
|
||||
public static void putFloat(long address, float x) {
|
||||
unsafe.putFloat(address, x);
|
||||
}
|
||||
|
||||
public static double getDouble(long address) {
|
||||
return unsafe.getDouble(address);
|
||||
}
|
||||
|
||||
public static void putDouble(long address, double x) {
|
||||
unsafe.putDouble(address, x);
|
||||
}
|
||||
|
||||
public static long getAddress(long address) {
|
||||
return unsafe.getAddress(address);
|
||||
}
|
||||
|
||||
public static void putAddress(long address, long x) {
|
||||
unsafe.putAddress(address, x);
|
||||
}
|
||||
|
||||
public static long allocateMemory(long bytes) {
|
||||
return unsafe.allocateMemory(bytes);
|
||||
}
|
||||
|
||||
public static long reallocateMemory(long address, long bytes) {
|
||||
return unsafe.reallocateMemory(address, bytes);
|
||||
}
|
||||
|
||||
public static void setMemory(Object o, long offset, long bytes, byte value) {
|
||||
unsafe.setMemory(o, offset, bytes, value);
|
||||
}
|
||||
|
||||
public static void setMemory(long address, long bytes, byte value) {
|
||||
unsafe.setMemory(address, bytes, value);
|
||||
}
|
||||
|
||||
public static void copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes) {
|
||||
unsafe.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes);
|
||||
}
|
||||
|
||||
public static void copyMemory(long srcAddress, long destAddress, long bytes) {
|
||||
unsafe.copyMemory(srcAddress, destAddress, bytes);
|
||||
}
|
||||
|
||||
public static void freeMemory(long address) {
|
||||
unsafe.freeMemory(address);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int fieldOffset(Field f) {
|
||||
return unsafe.fieldOffset(f);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Object staticFieldBase(Class<?> c) {
|
||||
return unsafe.staticFieldBase(c);
|
||||
}
|
||||
|
||||
public static long staticFieldOffset(Field f) {
|
||||
return unsafe.staticFieldOffset(f);
|
||||
}
|
||||
|
||||
public static long objectFieldOffset(Field f) {
|
||||
return unsafe.objectFieldOffset(f);
|
||||
}
|
||||
|
||||
public static Object staticFieldBase(Field f) {
|
||||
return unsafe.staticFieldBase(f);
|
||||
}
|
||||
|
||||
public static boolean shouldBeInitialized(Class<?> c) {
|
||||
return unsafe.shouldBeInitialized(c);
|
||||
}
|
||||
|
||||
public static void ensureClassInitialized(Class<?> c) {
|
||||
unsafe.ensureClassInitialized(c);
|
||||
}
|
||||
|
||||
public static int arrayBaseOffset(Class<?> arrayClass) {
|
||||
return unsafe.arrayBaseOffset(arrayClass);
|
||||
}
|
||||
|
||||
public static int arrayIndexScale(Class<?> arrayClass) {
|
||||
return unsafe.arrayIndexScale(arrayClass);
|
||||
}
|
||||
|
||||
public static int addressSize() {
|
||||
return unsafe.addressSize();
|
||||
}
|
||||
|
||||
public static int pageSize() {
|
||||
return unsafe.pageSize();
|
||||
}
|
||||
|
||||
public static Class<?> defineClass(String name, byte[] b, int off, int len, ClassLoader loader, ProtectionDomain protectionDomain) {
|
||||
return unsafe.defineClass(name, b, off, len, loader, protectionDomain);
|
||||
}
|
||||
|
||||
public static Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
|
||||
return unsafe.defineAnonymousClass(hostClass, data, cpPatches);
|
||||
}
|
||||
|
||||
public static Object allocateInstance(Class<?> cls) throws InstantiationException {
|
||||
return unsafe.allocateInstance(cls);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void monitorEnter(Object o) {
|
||||
unsafe.monitorEnter(o);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void monitorExit(Object o) {
|
||||
unsafe.monitorExit(o);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean tryMonitorEnter(Object o) {
|
||||
return unsafe.tryMonitorEnter(o);
|
||||
}
|
||||
|
||||
public static void throwException(Throwable ee) {
|
||||
unsafe.throwException(ee);
|
||||
}
|
||||
|
||||
public static boolean compareAndSwapObject(Object o, long offset, Object expected, Object x) {
|
||||
return unsafe.compareAndSwapObject(o, offset, expected, x);
|
||||
}
|
||||
|
||||
public static boolean compareAndSwapInt(Object o, long offset, int expected, int x) {
|
||||
return unsafe.compareAndSwapInt(o, offset, expected, x);
|
||||
}
|
||||
|
||||
public static boolean compareAndSwapLong(Object o, long offset, long expected, long x) {
|
||||
return unsafe.compareAndSwapLong(o, offset, expected, x);
|
||||
}
|
||||
|
||||
public static Object getObjectVolatile(Object o, long offset) {
|
||||
return unsafe.getObjectVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putObjectVolatile(Object o, long offset, Object x) {
|
||||
unsafe.putObjectVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static int getIntVolatile(Object o, long offset) {
|
||||
return unsafe.getIntVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putIntVolatile(Object o, long offset, int x) {
|
||||
unsafe.putIntVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static boolean getBooleanVolatile(Object o, long offset) {
|
||||
return unsafe.getBooleanVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putBooleanVolatile(Object o, long offset, boolean x) {
|
||||
unsafe.putBooleanVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static byte getByteVolatile(Object o, long offset) {
|
||||
return unsafe.getByteVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putByteVolatile(Object o, long offset, byte x) {
|
||||
unsafe.putByteVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static short getShortVolatile(Object o, long offset) {
|
||||
return unsafe.getShortVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putShortVolatile(Object o, long offset, short x) {
|
||||
unsafe.putShortVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static char getCharVolatile(Object o, long offset) {
|
||||
return unsafe.getCharVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putCharVolatile(Object o, long offset, char x) {
|
||||
unsafe.putCharVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static long getLongVolatile(Object o, long offset) {
|
||||
return unsafe.getLongVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putLongVolatile(Object o, long offset, long x) {
|
||||
unsafe.putLongVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static float getFloatVolatile(Object o, long offset) {
|
||||
return unsafe.getFloatVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putFloatVolatile(Object o, long offset, float x) {
|
||||
unsafe.putFloatVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static double getDoubleVolatile(Object o, long offset) {
|
||||
return unsafe.getDoubleVolatile(o, offset);
|
||||
}
|
||||
|
||||
public static void putDoubleVolatile(Object o, long offset, double x) {
|
||||
unsafe.putDoubleVolatile(o, offset, x);
|
||||
}
|
||||
|
||||
public static void putOrderedObject(Object o, long offset, Object x) {
|
||||
unsafe.putOrderedObject(o, offset, x);
|
||||
}
|
||||
|
||||
public static void putOrderedInt(Object o, long offset, int x) {
|
||||
unsafe.putOrderedInt(o, offset, x);
|
||||
}
|
||||
|
||||
public static void putOrderedLong(Object o, long offset, long x) {
|
||||
unsafe.putOrderedLong(o, offset, x);
|
||||
}
|
||||
|
||||
public static void unpark(Object thread) {
|
||||
unsafe.unpark(thread);
|
||||
}
|
||||
|
||||
public static void park(boolean isAbsolute, long time) {
|
||||
unsafe.park(isAbsolute, time);
|
||||
}
|
||||
|
||||
public static int getLoadAverage(double[] loadavg, int nelems) {
|
||||
return unsafe.getLoadAverage(loadavg, nelems);
|
||||
}
|
||||
|
||||
public static int getAndAddInt(Object o, long offset, int delta) {
|
||||
return unsafe.getAndAddInt(o, offset, delta);
|
||||
}
|
||||
|
||||
public static long getAndAddLong(Object o, long offset, long delta) {
|
||||
return unsafe.getAndAddLong(o, offset, delta);
|
||||
}
|
||||
|
||||
public static int getAndSetInt(Object o, long offset, int newValue) {
|
||||
return unsafe.getAndSetInt(o, offset, newValue);
|
||||
}
|
||||
|
||||
public static long getAndSetLong(Object o, long offset, long newValue) {
|
||||
return unsafe.getAndSetLong(o, offset, newValue);
|
||||
}
|
||||
|
||||
public static Object getAndSetObject(Object o, long offset, Object newValue) {
|
||||
return unsafe.getAndSetObject(o, offset, newValue);
|
||||
}
|
||||
|
||||
public static void loadFence() {
|
||||
unsafe.loadFence();
|
||||
}
|
||||
|
||||
public static void storeFence() {
|
||||
unsafe.storeFence();
|
||||
}
|
||||
|
||||
public static void fullFence() {
|
||||
unsafe.fullFence();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user