public Boolean run() { Boolean success = Boolean.FALSE; try { // java 9 if (UNMAP_SUPPORTED) CLEANER.freeBuffer(buffer.toString(), buffer); // java 8 and lower else { Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class<?>[]) null); getCleanerMethod.setAccessible(true); Object cleaner = getCleanerMethod.invoke(buffer, (Object[]) null); Method clean = cleaner.getClass().getMethod("clean", (Class<?>[]) null); clean.invoke(cleaner, (Object[]) null); } success = Boolean.TRUE; } catch (Exception e) { // This really is a show stopper on windows Logger logger = LoggerFactory.getLogger(ByteBufferRandomAccessSource.class); logger.debug(e.getMessage()); } return success; } });
public Boolean run() { Boolean success = Boolean.FALSE; try { // java 9 if (UNMAP_SUPPORTED) CLEANER.freeBuffer(buffer.toString(), buffer); // java 8 and lower else { Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class<?>[]) null); getCleanerMethod.setAccessible(true); Object cleaner = getCleanerMethod.invoke(buffer, (Object[]) null); Method clean = cleaner.getClass().getMethod("clean", (Class<?>[]) null); clean.invoke(cleaner, (Object[]) null); } success = Boolean.TRUE; } catch (Exception e) { // This really is a show stopper on windows Logger logger = LoggerFactory.getLogger(ByteBufferRandomAccessSource.class); logger.debug(e.getMessage()); } return success; } });
private static Object unmapHackImpl() { final Lookup lookup = lookup(); try { // *** sun.misc.Unsafe unmapping (Java 9+) *** final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe"); // first check if Unsafe has the right method, otherwise we can give up // without doing any security critical stuff: final MethodHandle unmapper = lookup.findVirtual(unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class)); // fetch the unsafe instance and bind it to the virtual MH: final Field f = unsafeClass.getDeclaredField("theUnsafe"); f.setAccessible(true); final Object theUnsafe = f.get(null); return new BufferCleaner(ByteBuffer.class, unmapper.bindTo(theUnsafe)); } catch (Exception e) { return e.getMessage(); } } }
private static Object unmapHackImpl() { final Lookup lookup = lookup(); try { // *** sun.misc.Unsafe unmapping (Java 9+) *** final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe"); // first check if Unsafe has the right method, otherwise we can give up // without doing any security critical stuff: final MethodHandle unmapper = lookup.findVirtual(unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class)); // fetch the unsafe instance and bind it to the virtual MH: final Field f = unsafeClass.getDeclaredField("theUnsafe"); f.setAccessible(true); final Object theUnsafe = f.get(null); return new BufferCleaner(ByteBuffer.class, unmapper.bindTo(theUnsafe)); } catch (Exception e) { return e.getMessage(); } } }