2014-04-21 02:14:48 +00:00
|
|
|
/* Copyright (c) 2008-2014, Avian Contributors
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2012-03-13 14:28:33 +00:00
|
|
|
package sun.misc;
|
|
|
|
|
2013-02-20 17:22:40 +00:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
2012-03-13 14:28:33 +00:00
|
|
|
public final class Unsafe {
|
|
|
|
private void Unsafe() { }
|
|
|
|
|
2013-12-06 21:56:02 +00:00
|
|
|
private static final Unsafe theUnsafe = new Unsafe();
|
2012-03-13 14:28:33 +00:00
|
|
|
|
|
|
|
public static Unsafe getUnsafe() {
|
2013-12-06 21:56:02 +00:00
|
|
|
return theUnsafe;
|
2012-03-13 14:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public native long allocateMemory(long bytes);
|
|
|
|
|
2012-03-14 17:54:03 +00:00
|
|
|
public native void setMemory
|
|
|
|
(Object base, long offset, long count, byte value);
|
2012-03-13 14:28:33 +00:00
|
|
|
|
|
|
|
public native void freeMemory(long address);
|
|
|
|
|
|
|
|
public native byte getByte(long address);
|
|
|
|
|
|
|
|
public native void putByte(long address, byte x);
|
|
|
|
|
|
|
|
public native short getShort(long address);
|
|
|
|
|
|
|
|
public native void putShort(long address, short x);
|
|
|
|
|
|
|
|
public native char getChar(long address);
|
|
|
|
|
|
|
|
public native void putChar(long address, char x);
|
|
|
|
|
|
|
|
public native int getInt(long address);
|
|
|
|
|
|
|
|
public native void putInt(long address, int x);
|
|
|
|
|
|
|
|
public native long getLong(long address);
|
|
|
|
|
|
|
|
public native void putLong(long address, long x);
|
|
|
|
|
|
|
|
public native float getFloat(long address);
|
|
|
|
|
|
|
|
public native void putFloat(long address, float x);
|
|
|
|
|
|
|
|
public native double getDouble(long address);
|
|
|
|
|
|
|
|
public native void putDouble(long address, double x);
|
|
|
|
|
2014-03-31 21:23:42 +00:00
|
|
|
public native boolean getBooleanVolatile(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putBooleanVolatile(Object o, long offset, boolean x);
|
|
|
|
|
|
|
|
public native byte getByteVolatile(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putByteVolatile(Object o, long offset, byte x);
|
|
|
|
|
|
|
|
public native short getShortVolatile(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putShortVolatile(Object o, long offset, short x);
|
|
|
|
|
|
|
|
public native char getCharVolatile(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putCharVolatile(Object o, long offset, char x);
|
|
|
|
|
2014-03-03 21:51:43 +00:00
|
|
|
public native int getIntVolatile(Object o, long offset);
|
|
|
|
|
2013-04-23 19:47:15 +00:00
|
|
|
public native void putIntVolatile(Object o, long offset, int x);
|
|
|
|
|
2014-03-31 21:23:42 +00:00
|
|
|
public native float getFloatVolatile(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putFloatVolatile(Object o, long offset, float x);
|
|
|
|
|
|
|
|
public native double getDoubleVolatile(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putDoubleVolatile(Object o, long offset, double x);
|
|
|
|
|
2013-12-18 18:06:15 +00:00
|
|
|
public native long getLongVolatile(Object o, long offset);
|
|
|
|
|
2014-03-31 21:23:42 +00:00
|
|
|
public native void putLongVolatile(Object o, long offset, long x);
|
2014-01-03 00:49:56 +00:00
|
|
|
|
2014-08-21 19:09:42 +00:00
|
|
|
public long getLong(Object o, long offset) {
|
|
|
|
return getLongVolatile(o, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void putLong(Object o, long offset, long x) {
|
|
|
|
putLongVolatile(o, offset, x);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:23:42 +00:00
|
|
|
public native void putOrderedLong(Object o, long offset, long x);
|
2014-01-03 00:49:56 +00:00
|
|
|
|
2013-04-23 19:47:15 +00:00
|
|
|
public native void putOrderedInt(Object o, long offset, int x);
|
|
|
|
|
|
|
|
public native Object getObject(Object o, long offset);
|
|
|
|
|
|
|
|
public native void putObject(Object o, long offset, Object x);
|
|
|
|
|
2014-01-03 01:00:53 +00:00
|
|
|
public native void putObjectVolatile(Object o, long offset, Object x);
|
|
|
|
|
|
|
|
public native void putOrderedObject(Object o, long offset, Object x);
|
|
|
|
|
2014-03-03 21:51:43 +00:00
|
|
|
public native Object getObjectVolatile(Object o, long offset);
|
|
|
|
|
2012-03-13 14:28:33 +00:00
|
|
|
public native long getAddress(long address);
|
|
|
|
|
|
|
|
public native void putAddress(long address, long x);
|
2012-08-11 12:56:19 +00:00
|
|
|
|
|
|
|
public native int arrayBaseOffset(Class arrayClass);
|
|
|
|
|
2014-03-07 16:08:19 +00:00
|
|
|
public native int arrayIndexScale(Class arrayClass);
|
|
|
|
|
2013-02-20 17:22:40 +00:00
|
|
|
public native long objectFieldOffset(Field field);
|
|
|
|
|
2013-04-23 19:47:15 +00:00
|
|
|
public native void park(boolean absolute, long time);
|
|
|
|
|
|
|
|
public native void unpark(Object target);
|
|
|
|
|
2012-08-11 12:56:19 +00:00
|
|
|
public native void copyMemory(Object srcBase, long srcOffset,
|
|
|
|
Object destBase, long destOffset,
|
|
|
|
long count);
|
|
|
|
|
2013-02-20 17:22:40 +00:00
|
|
|
public native boolean compareAndSwapInt(Object o, long offset, int old,
|
|
|
|
int new_);
|
|
|
|
|
2013-12-12 18:12:38 +00:00
|
|
|
public native boolean compareAndSwapLong(Object o, long offset,
|
|
|
|
long old, long new_);
|
|
|
|
|
2013-04-23 19:47:15 +00:00
|
|
|
public native boolean compareAndSwapObject(Object o, long offset, Object old,
|
|
|
|
Object new_);
|
|
|
|
|
2012-08-11 12:56:19 +00:00
|
|
|
public void copyMemory(long src, long dst, long count) {
|
|
|
|
copyMemory(null, src, null, dst, count);
|
|
|
|
}
|
2013-12-06 03:28:08 +00:00
|
|
|
|
|
|
|
public native void throwException(Throwable t);
|
2012-03-13 14:28:33 +00:00
|
|
|
}
|