< prev index next >
src/java.base/share/classes/sun/nio/fs/NativeBuffer.java
Print this page
*** 24,45 ****
*/
package sun.nio.fs;
import jdk.internal.misc.Unsafe;
! import jdk.internal.ref.Cleaner;
/**
* A light-weight buffer in native memory.
*/
class NativeBuffer {
private static final Unsafe unsafe = Unsafe.getUnsafe();
private final long address;
private final int size;
! private final Cleaner cleaner;
// optional "owner" to avoid copying
// (only safe for use by thread-local caches)
private Object owner;
--- 24,47 ----
*/
package sun.nio.fs;
import jdk.internal.misc.Unsafe;
! import jdk.internal.ref.CleanerFactory;
!
! import java.lang.ref.Cleaner;
/**
* A light-weight buffer in native memory.
*/
class NativeBuffer {
private static final Unsafe unsafe = Unsafe.getUnsafe();
private final long address;
private final int size;
! private final Cleaner.Cleanable cleanable;
// optional "owner" to avoid copying
// (only safe for use by thread-local caches)
private Object owner;
*** 54,64 ****
}
NativeBuffer(int size) {
this.address = unsafe.allocateMemory(size);
this.size = size;
! this.cleaner = Cleaner.create(this, new Deallocator(address));
}
void release() {
NativeBuffers.releaseNativeBuffer(this);
}
--- 56,66 ----
}
NativeBuffer(int size) {
this.address = unsafe.allocateMemory(size);
this.size = size;
! this.cleanable = CleanerFactory.cleaner().register(this, new Deallocator(address));
}
void release() {
NativeBuffers.releaseNativeBuffer(this);
}
*** 69,80 ****
int size() {
return size;
}
! Cleaner cleaner() {
! return cleaner;
}
// not synchronized; only safe for use by thread-local caches
void setOwner(Object owner) {
this.owner = owner;
--- 71,82 ----
int size() {
return size;
}
! void free() {
! cleanable.clean();
}
// not synchronized; only safe for use by thread-local caches
void setOwner(Object owner) {
this.owner = owner;
< prev index next >