Java9Cleaner() { // code replace // AtomicFieldUpdater.getUnsafe().invokeCleaner(buffer); // in JDK9 the "official" dispose method is sun.misc.Unsafe#invokeCleaner // since we have to target both jdk 8 and 9 we have to use reflection myUnsafe = AtomicFieldUpdater.getUnsafe(); try { myInvokeCleanerMethod = myUnsafe.getClass().getMethod("invokeCleaner", ByteBuffer.class); myInvokeCleanerMethod.setAccessible(true); } catch (Exception e) { // something serious, needs to be logged LOGGER.error(e); throw new RuntimeException(e); } }
@SuppressWarnings("UnusedDeclaration") public PromiseManager(@NotNull AtomicFieldUpdater<HOST, Promise<VALUE>> fieldUpdater) { this.fieldUpdater = fieldUpdater; }
public PromiseManager(@NotNull Class<HOST> ownerClass) { //noinspection unchecked fieldUpdater = ((AtomicFieldUpdater)AtomicFieldUpdater.forFieldOfType(ownerClass, Promise.class)); }
@SuppressWarnings("UnusedDeclaration") public AsyncValueLoaderManager(@NotNull AtomicFieldUpdater<HOST, AsyncResult<VALUE>> fieldUpdater) { this.fieldUpdater = fieldUpdater; }
public AsyncValueLoaderManager(@NotNull Class<HOST> ownerClass) { //noinspection unchecked fieldUpdater = ((AtomicFieldUpdater)AtomicFieldUpdater.forFieldOfType(ownerClass, AsyncResult.class)); }
private static Object[] getBacktrace(@Nonnull Throwable throwable) { // the JVM blocks access to Throwable.backtrace via reflection Object backtrace = BACKTRACE_FIELD_OFFSET == -1 ? null : AtomicFieldUpdater.getUnsafe().getObject(throwable, BACKTRACE_FIELD_OFFSET); // obsolete jdk return backtrace instanceof Object[] && ((Object[])backtrace).length == 5 ? (Object[])backtrace : null; }
/** * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. * Replace with a simple call to Unsafe.getUnsafe when integrating * into a jdk. * * @return a sun.misc.Unsafe */ private static Unsafe getUnsafe() { return AtomicFieldUpdater.getUnsafe(); }