Java Code Examples for sun.misc.Cleaner#clean()

The following examples show how to use sun.misc.Cleaner#clean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalStoreFile.java    From journalkeeper with Apache License 2.0 6 votes vote down vote up
private void unloadMappedBuffer() {
    try {
        final Buffer mapped = pageBuffer;
        pageBuffer = null;
        this.bufferType = NO_BUFFER;
        if (null != mapped) {
            Method getCleanerMethod;
            getCleanerMethod = mapped.getClass().getMethod("cleaner");
            getCleanerMethod.setAccessible(true);
            Cleaner cleaner = (Cleaner) getCleanerMethod.invoke(mapped, new Object[0]);
            cleaner.clean();
        }
        bufferPool.releaseMMap(this);
    } catch (Exception e) {
        logger.warn("Release direct buffer exception: ", e);
    }
}
 
Example 2
Source File: StoreFileImpl.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
private void unloadMappedBuffer() {
    try {
        final Buffer mapped = pageBuffer;
        pageBuffer = null;
        this.bufferType = NO_BUFFER;
        if (null != mapped) {
            Method getCleanerMethod;
            getCleanerMethod = mapped.getClass().getMethod("cleaner");
            getCleanerMethod.setAccessible(true);
            Cleaner cleaner = (Cleaner) getCleanerMethod.invoke(mapped, new Object[0]);
            cleaner.clean();
        }
        bufferPool.releaseMMap(this);
    } catch (Exception e) {
        logger.warn("Release direct buffer exception: ", e);
    }
}
 
Example 3
Source File: PreloadBufferPool.java    From journalkeeper with Apache License 2.0 5 votes vote down vote up
private void releaseIfDirect(ByteBuffer byteBuffer) {
    if (byteBuffer instanceof DirectBuffer) {
        try {
            Method getCleanerMethod;
            getCleanerMethod = byteBuffer.getClass().getMethod("cleaner");
            getCleanerMethod.setAccessible(true);
            Cleaner cleaner = (Cleaner) getCleanerMethod.invoke(byteBuffer, new Object[0]);
            cleaner.clean();
        } catch (Exception e) {
            logger.warn("Exception: ", e);
        }
    }
}
 
Example 4
Source File: ByteBufferUtil.java    From indexr with Apache License 2.0 5 votes vote down vote up
public static void free(ByteBuffer buffer) {
    if (buffer.isDirect()) {
        Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
        if (cleaner != null) {
            cleaner.clean();
        }
    }
}
 
Example 5
Source File: DirectBufCloser.java    From qmq with Apache License 2.0 5 votes vote down vote up
public static void close(ByteBuffer buffer) {
    if (buffer == null || !buffer.isDirect() || buffer.capacity() == 0) {
        return;
    }

    try {
        final Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
        cleaner.clean();
    } catch (Exception ignore) {

    }
}
 
Example 6
Source File: LogSegment.java    From qmq with Apache License 2.0 5 votes vote down vote up
private void clean(final ByteBuffer buffer) {
    if (buffer == null || !buffer.isDirect() || buffer.capacity() == 0) {
        return;
    }

    final Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
    cleaner.clean();
}
 
Example 7
Source File: PreloadBufferPool.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
private void releaseIfDirect(ByteBuffer byteBuffer) {
    if (byteBuffer instanceof DirectBuffer) {
        try {
            Method getCleanerMethod;
            getCleanerMethod = byteBuffer.getClass().getMethod("cleaner");
            getCleanerMethod.setAccessible(true);
            Cleaner cleaner = (Cleaner) getCleanerMethod.invoke(byteBuffer, new Object[0]);
            cleaner.clean();
        } catch (Exception e) {
            logger.warn("Exception: ", e);
        }
    }
}
 
Example 8
Source File: ReferenceQueue.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Enqueue the given reference onto this queue.
 * The caller is responsible for ensuring the lock is held on this queue,
 * and for calling notifyAll on this queue after the reference has been
 * enqueued. Returns true if the reference was enqueued successfully,
 * false if the reference had already been enqueued.
 * @GuardedBy("lock")
 */
private boolean enqueueLocked(Reference<? extends T> r) {
    // Verify the reference has not already been enqueued.
    if (r.queueNext != null) {
        return false;
    }

    if (r instanceof Cleaner) {
        // If this reference is a Cleaner, then simply invoke the clean method instead
        // of enqueueing it in the queue. Cleaners are associated with dummy queues that
        // are never polled and objects are never enqueued on them.
        Cleaner cl = (sun.misc.Cleaner) r;
        cl.clean();

        // Update queueNext to indicate that the reference has been
        // enqueued, but is now removed from the queue.
        r.queueNext = sQueueNextUnenqueued;
        return true;
    }

    if (tail == null) {
        head = r;
    } else {
        tail.queueNext = r;
    }
    tail = r;
    tail.queueNext = r;
    return true;
}
 
Example 9
Source File: FileChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 10
Source File: FileChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 11
Source File: FileChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 12
Source File: AbstractLogVisitor.java    From qmq with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    if (buffer == null) return;
    Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
    cleaner.clean();
}
 
Example 13
Source File: GeoWorldLoader.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
private static void destroyDirectByteBuffer(Buffer toBeDestroyed) {
	Cleaner cleaner = ((DirectBuffer) toBeDestroyed).cleaner();
	if (cleaner != null) {
		cleaner.clean();
	}
}
 
Example 14
Source File: FileChannelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 15
Source File: FileChannelImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 16
Source File: FileChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 17
Source File: FileChannelImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 18
Source File: FileChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 19
Source File: FileChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}
 
Example 20
Source File: FileChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void unmap(MappedByteBuffer bb) {
    Cleaner cl = ((DirectBuffer)bb).cleaner();
    if (cl != null)
        cl.clean();
}