use of sun.misc.Unsafe in project caffeine by ben-manes.
the class UnsafeAccess method load.
static Unsafe load(String openJdk, String android) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Field field;
try {
// try OpenJDK field name
field = Unsafe.class.getDeclaredField(openJdk);
} catch (NoSuchFieldException e) {
try {
// try Android field name
field = Unsafe.class.getDeclaredField(android);
} catch (NoSuchFieldException e2) {
// try to create a new instance
Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor();
unsafeConstructor.setAccessible(true);
return unsafeConstructor.newInstance();
}
}
field.setAccessible(true);
return (Unsafe) field.get(null);
}
use of sun.misc.Unsafe in project es6draft by anba.
the class UnsafeHolder method initializeUnsafe.
private static Unsafe initializeUnsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException e) {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
});
} catch (PrivilegedActionException e2) {
throw new ExceptionInInitializerError(e2.getException());
}
}
}
use of sun.misc.Unsafe in project es6draft by anba.
the class UnsafeHolder method initializeUnsafe.
private static Unsafe initializeUnsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException e) {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
});
} catch (PrivilegedActionException e2) {
throw new ExceptionInInitializerError(e2.getException());
}
}
}
use of sun.misc.Unsafe in project hadoop by apache.
the class NativeIO method getOperatingSystemPageSize.
/**
* @return the operating system's page size.
*/
static long getOperatingSystemPageSize() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
Unsafe unsafe = (Unsafe) f.get(null);
return unsafe.pageSize();
} catch (Throwable e) {
LOG.warn("Unable to get operating system page size. Guessing 4096.", e);
return 4096;
}
}
use of sun.misc.Unsafe in project wildfly by wildfly.
the class FastConcurrentDirectDeque method getUnsafe0.
private static Unsafe getUnsafe0() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (Throwable t) {
throw new RuntimeException("JDK did not allow accessing unsafe", t);
}
}
Aggregations