本文整理了Java中sun.misc.Unsafe
类的一些代码示例,展示了Unsafe
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe
类的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
[英]The package name notwithstanding, this class is the quasi-standard way for Java code to gain access to and use functionality which, when unsupervised, would allow one to break the pointer/type safety of Java.
[中]尽管有包名,但这个类是Java代码访问和使用功能的准标准方式,在无监督的情况下,它将允许人们破坏Java的指针/类型安全性。
代码示例来源:origin: google/guava
@Override
public long getLongLittleEndian(byte[] array, int offset) {
return theUnsafe.getLong(array, (long) offset + BYTE_ARRAY_BASE_OFFSET);
}
代码示例来源:origin: netty/netty
static int getInt(Object object, long fieldOffset) {
return UNSAFE.getInt(object, fieldOffset);
}
代码示例来源:origin: netty/netty
static void putInt(byte[] data, int index, int value) {
UNSAFE.putInt(data, BYTE_ARRAY_BASE_OFFSET + index, value);
}
代码示例来源:origin: prestodb/presto
public void clear(int offset, int length)
{
while (length >= SIZE_OF_LONG) {
unsafe.putLong(base, address + offset, 0);
offset += SIZE_OF_LONG;
length -= SIZE_OF_LONG;
}
while (length > 0) {
unsafe.putByte(base, address + offset, (byte) 0);
offset++;
length--;
}
}
代码示例来源:origin: redisson/redisson
static String unsafeCreateString(char[] chars) {
String mutable = new String();
UNSAFE.putObject(mutable, STRING_VALUE_FIELD_OFFSET, chars);
if (STRING_COUNT_FIELD_OFFSET != -1) {
UNSAFE.putInt(mutable, STRING_COUNT_FIELD_OFFSET, chars.length);
}
return mutable;
}
代码示例来源:origin: prestodb/presto
private static int computeOffset(Field field) {
if (Modifier.isStatic(field.getModifiers())) {
return (int) VMSupport.U.staticFieldOffset(field);
} else {
return (int) VMSupport.U.objectFieldOffset(field);
}
}
代码示例来源:origin: com.koloboke/koloboke-impl-jdk8
@Override
public void setValue(short value) {
if (curKey != free) {
if (expectedModCount == modCount()) {
U.putShort(tab, INT_BASE + SHORT_VALUE_OFFSET + (((long) (index)) << INT_SCALE_SHIFT), value);
} else {
throw new java.util.ConcurrentModificationException();
}
} else {
throw new java.lang.IllegalStateException();
}
}
代码示例来源:origin: com.koloboke/koloboke-impl-jdk8
@Override
public void setValue(float value) {
if (curKey != free) {
if (expectedModCount == modCount()) {
U.putInt(tab, LONG_BASE + FLOAT_VALUE_OFFSET + (((long) (index)) << LONG_SCALE_SHIFT), Float.floatToIntBits(value));
} else {
throw new java.util.ConcurrentModificationException();
}
} else {
throw new java.lang.IllegalStateException();
}
}
代码示例来源:origin: com.koloboke/koloboke-impl-jdk8
@Override
public void setValue(byte value) {
if (curKey != free) {
if (expectedModCount == modCount()) {
U.putByte(tab, CHAR_BASE + BYTE_VALUE_OFFSET + (((long) (index)) << CHAR_SCALE_SHIFT), value);
} else {
throw new java.util.ConcurrentModificationException();
}
} else {
throw new java.lang.IllegalStateException();
}
}
代码示例来源:origin: google/guava
@Override
public void putLongLittleEndian(byte[] array, int offset, long value) {
theUnsafe.putLong(array, (long) offset + BYTE_ARRAY_BASE_OFFSET, value);
}
},
代码示例来源:origin: netty/netty
static byte getByte(byte[] data, int index) {
return UNSAFE.getByte(data, BYTE_ARRAY_BASE_OFFSET + index);
}
代码示例来源:origin: netty/netty
static void putByte(byte[] data, int index, byte value) {
UNSAFE.putByte(data, BYTE_ARRAY_BASE_OFFSET + index, value);
}
代码示例来源:origin: netty/netty
static void putShort(byte[] data, int index, short value) {
UNSAFE.putShort(data, BYTE_ARRAY_BASE_OFFSET + index, value);
}
代码示例来源:origin: netty/netty
static short getShort(long address) {
return UNSAFE.getShort(address);
}
代码示例来源:origin: google/guava
@Override
void putNext(Waiter waiter, Waiter newValue) {
UNSAFE.putObject(waiter, WAITER_NEXT_OFFSET, newValue);
}
代码示例来源:origin: netty/netty
static long objectFieldOffset(Field field) {
return UNSAFE.objectFieldOffset(field);
}
代码示例来源:origin: com.koloboke/koloboke-impl-jdk8
@Override
public void setValue(short value) {
if (curKey != free) {
if (expectedModCount == modCount()) {
U.putShort(tab, INT_BASE + SHORT_VALUE_OFFSET + (((long) (index)) << INT_SCALE_SHIFT), value);
} else {
throw new java.util.ConcurrentModificationException();
}
} else {
throw new java.lang.IllegalStateException();
}
}
代码示例来源:origin: com.koloboke/koloboke-impl-jdk8
@Override
public void setValue(int value) {
if (curKey != FREE_BITS) {
if (expectedModCount == modCount()) {
U.putInt(tab, LONG_BASE + INT_VALUE_OFFSET + (((long) (index)) << LONG_SCALE_SHIFT), value);
} else {
throw new java.util.ConcurrentModificationException();
}
} else {
throw new java.lang.IllegalStateException();
}
}
代码示例来源:origin: netty/netty
static void putLong(byte[] data, int index, long value) {
UNSAFE.putLong(data, BYTE_ARRAY_BASE_OFFSET + index, value);
}
代码示例来源:origin: netty/netty
static byte getByte(long address) {
return UNSAFE.getByte(address);
}
内容来源于网络,如有侵权,请联系作者删除!