use of sun.misc.Unsafe in project hbase by apache.
the class UnsafeUtil method getUnsafe.
/**
* Gets the {@code sun.misc.Unsafe} instance, or {@code null} if not available on this platform.
*/
private static sun.misc.Unsafe getUnsafe() {
sun.misc.Unsafe unsafe = null;
try {
unsafe = AccessController.doPrivileged(new PrivilegedExceptionAction<Unsafe>() {
@Override
public sun.misc.Unsafe run() throws Exception {
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
for (Field f : k.getDeclaredFields()) {
f.setAccessible(true);
Object x = f.get(null);
if (k.isInstance(x)) {
return k.cast(x);
}
}
// The sun.misc.Unsafe field does not exist.
return null;
}
});
} catch (Throwable e) {
// Catching Throwable here due to the fact that Google AppEngine raises NoClassDefFoundError
// for Unsafe.
}
return unsafe;
}
use of sun.misc.Unsafe in project groovy by apache.
the class FastStringUtils method loadUnsafe.
private static Unsafe loadUnsafe() {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
return (Unsafe) unsafeField.get(null);
} catch (Exception e) {
return null;
}
}
use of sun.misc.Unsafe in project hadoop by apache.
the class ShortCircuitShm method safetyDance.
private static Unsafe safetyDance() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
} catch (Throwable e) {
LOG.error("failed to load misc.Unsafe", e);
}
return null;
}
use of sun.misc.Unsafe in project neo4j by neo4j.
the class UnsafeUtil method getUnsafe.
private static Unsafe getUnsafe() {
try {
PrivilegedExceptionAction<Unsafe> getUnsafe = () -> {
try {
return Unsafe.getUnsafe();
} catch (Exception e) {
Class<Unsafe> type = Unsafe.class;
Field[] fields = type.getDeclaredFields();
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers()) && type.isAssignableFrom(field.getType())) {
field.setAccessible(true);
return type.cast(field.get(null));
}
}
LinkageError error = new LinkageError("No static field of type sun.misc.Unsafe");
error.addSuppressed(e);
throw error;
}
};
return AccessController.doPrivileged(getUnsafe);
} catch (Exception e) {
throw new LinkageError("Cannot access sun.misc.Unsafe", e);
}
}
use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class VMAnonymousClass method getUnsafe.
private static synchronized Unsafe getUnsafe() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("Unable to get Unsafe instance.", e);
}
}
Aggregations