use of sun.misc.Unsafe in project ignite by apache.
the class GridUnsafe method unsafe.
/**
* @return Instance of Unsafe class.
*/
private static Unsafe unsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException ignored) {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Unsafe>() {
@Override
public Unsafe run() throws Exception {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
}
});
} catch (PrivilegedActionException e) {
throw new RuntimeException("Could not initialize intrinsics.", e.getCause());
}
}
}
use of sun.misc.Unsafe in project lwjgl by LWJGL.
the class MappedObjectUnsafe method getUnsafeInstance.
private static Unsafe getUnsafeInstance() {
final Field[] fields = Unsafe.class.getDeclaredFields();
/*
Different runtimes use different names for the Unsafe singleton,
so we cannot use .getDeclaredField and we scan instead. For example:
Oracle: theUnsafe
PERC : m_unsafe_instance
Android: THE_ONE
*/
for (Field field : fields) {
if (!field.getType().equals(Unsafe.class))
continue;
final int modifiers = field.getModifiers();
if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)))
continue;
field.setAccessible(true);
try {
return (Unsafe) field.get(null);
} catch (IllegalAccessException e) {
// ignore
}
break;
}
throw new UnsupportedOperationException();
}
use of sun.misc.Unsafe in project powermock by powermock.
the class WhiteboxImpl method getUnsafe.
private static Unsafe getUnsafe() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
Field field1 = Unsafe.class.getDeclaredField("theUnsafe");
field1.setAccessible(true);
Unsafe unsafe = (Unsafe) field1.get(null);
return unsafe;
}
use of sun.misc.Unsafe in project j2objc by google.
the class MappedByteBuffer method load.
/**
* Loads this buffer's content into physical memory.
*
* <p> This method makes a best effort to ensure that, when it returns,
* this buffer's content is resident in physical memory. Invoking this
* method may cause some number of page faults and I/O operations to
* occur. </p>
*
* @return This buffer
*/
public final MappedByteBuffer load() {
checkMapped();
if ((address == 0) || (capacity() == 0))
return this;
long offset = mappingOffset();
long length = mappingLength(offset);
load0(mappingAddress(offset), length);
// Read a byte from each page to bring it into memory. A checksum
// is computed as we go along to prevent the compiler from otherwise
// considering the loop as dead code.
Unsafe unsafe = Unsafe.getUnsafe();
int ps = Bits.pageSize();
int count = Bits.pageCount(length);
long a = mappingAddress(offset);
byte x = 0;
for (int i = 0; i < count; i++) {
x ^= unsafe.getByte(a);
a += ps;
}
if (unused != 0)
unused = x;
return this;
}
use of sun.misc.Unsafe in project hazelcast by hazelcast.
the class UnsafeUtil method findUnsafe.
private static Unsafe findUnsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException se) {
return AccessController.doPrivileged(new PrivilegedAction<Unsafe>() {
@Override
public Unsafe run() {
try {
Class<Unsafe> type = Unsafe.class;
try {
Field field = type.getDeclaredField("theUnsafe");
field.setAccessible(true);
return type.cast(field.get(type));
} catch (Exception e) {
for (Field field : type.getDeclaredFields()) {
if (type.isAssignableFrom(field.getType())) {
field.setAccessible(true);
return type.cast(field.get(type));
}
}
}
} catch (Throwable t) {
throw rethrow(t);
}
throw new RuntimeException("Unsafe unavailable");
}
});
}
}
Aggregations