Some sun.misc internal APIs are deprectaed in JDK 9 and will be encapsulated or removed in a future release.
private Cleaner createCleaner(Entry<T> entry) { return Cleaner.create(entry, new Runnable() { @Override public void run() { closeFromCleaner(); } }); }
public ReferenceCountingResourceHolder(final T object, final Closeable closer) { this.object = object; this.closer = closer; this.cleaner = Cleaner.create(this, new CloserRunnable(object, closer, refCount)); }
private CountingHolder(final MemcachedClientIF clientIF) { this.clientIF = clientIF; cleaner = Cleaner.create(this, new ClientLeakNotifier(count, clientIF)); } }
protected void init(String file, long length, boolean clearFile) throws Exception { File f = new File(file); if ( f.exists() && clearFile ) { f.delete(); } this.file = f; if ( f.exists() ) { length = f.length(); } RandomAccessFile raf = new RandomAccessFile(f, "rw"); raf.setLength(length); // FIXME: see stackoverflow. does not work always FileChannel fileChannel = raf.getChannel(); this.fileChannel = raf.getChannel(); this.baseAdress = map0(fileChannel, imodeFor(FileChannel.MapMode.READ_WRITE), 0L, length); this.length = length; this.cleaner = Cleaner.create(this, new Unmapper(baseAdress, length, fileChannel)); }
private ObjectResourceHolder makeObjectWithHandler() { T object = generator.get(); ObjectId objectId = new ObjectId(); ObjectLeakNotifier notifier = new ObjectLeakNotifier(this); // Using objectId as referent for Cleaner, because if the object itself (e. g. ByteBuffer) is leaked after taken // from the pool, and the ResourceHolder is not closed, Cleaner won't notify about the leak. return new ObjectResourceHolder(object, objectId, Cleaner.create(objectId, notifier), notifier); }
protected void init(String file, long length, boolean clearFile) throws Exception { File f = new File(file); if ( f.exists() && clearFile ) { f.delete(); } this.file = f; if ( f.exists() ) { length = f.length(); } RandomAccessFile raf = new RandomAccessFile(f, "rw"); raf.setLength(length); // FIXME: see stackoverflow. does not work always FileChannel fileChannel = raf.getChannel(); this.fileChannel = raf.getChannel(); this.baseAdress = map0(fileChannel, imodeFor(FileChannel.MapMode.READ_WRITE), 0L, length); this.length = length; this.cleaner = Cleaner.create(this, new Unmapper(baseAdress, length, fileChannel)); }
Cleaner cleaner = Cleaner.create(cache, cacheDisposer); MapDbCacheDisposerAndCleaner disposerAndCleaner = new MapDbCacheDisposerAndCleaner( cacheDisposer,
private Cleaner createCleaner(Entry<T> entry) { return Cleaner.create(entry, new Runnable() { @Override public void run() { closeFromCleaner(); } }); }
public static void main(String[] args) throws InterruptedException { new RandomAccess() { public void finalize() { new Throwable(Thread.currentThread().getName()).printStackTrace(); } }; Cleaner.create(new Integer(1), () -> new Throwable(Thread.currentThread().getName()).printStackTrace()); System.gc(); Thread.sleep(1000); } }
private CountingHolder(final MemcachedClientIF clientIF) { this.clientIF = clientIF; cleaner = Cleaner.create(this, new ClientLeakNotifier(count, clientIF)); } }
public ReferenceCountingResourceHolder(final T object, final Closeable closer) { this.object = object; this.closer = closer; this.cleaner = Cleaner.create(this, new CloserRunnable(object, closer, refCount)); }
private CountingHolder(final MemcachedClientIF clientIF) { this.clientIF = clientIF; cleaner = Cleaner.create(this, new ClientLeakNotifier(count, clientIF)); } }
MappedArenaStore(long offset, long size) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { this.offset = offset; this.size = size; this.end = offset + size; if (randomAccessFile.length() < end) { if (mode != FileChannel.MapMode.READ_WRITE) { throw new IOException("Cannot resize file to " + end + " as mode is not READ_WRITE"); } randomAccessFile.setLength(end); } this.address = map0(fileChannel, imodeFor(mode), offset, size); this.cleaner = Cleaner.create(this, new Unmapper(address, size, fileChannel)); }
public AbstractOffheapArray(long capacity) { if (capacity < 0) { throw new IllegalArgumentException("Cannot allocate with capacity=" + capacity); } address = UNSAFE.allocateMemory(capacity); boxedAddress = new AtomicLong(address); Deallocator deallocator = new Deallocator(boxedAddress); cleaner = Cleaner.create(this, deallocator); UNSAFE.setMemory(address, capacity, (byte) 0); this.capacity = capacity; }
private ObjectResourceHolder makeObjectWithHandler() { T object = generator.get(); ObjectId objectId = new ObjectId(); ObjectLeakNotifier notifier = new ObjectLeakNotifier(this); // Using objectId as referent for Cleaner, because if the object itself (e. g. ByteBuffer) is leaked after taken // from the pool, and the ResourceHolder is not closed, Cleaner won't notify about the leak. return new ObjectResourceHolder(object, objectId, Cleaner.create(objectId, notifier), notifier); }
public static ByteBuffer getByteBuffer(long address, int length, boolean autoFree) { ByteBuffer instance = getHollowDirectByteBuffer(); if (autoFree) { Cleaner cleaner = Cleaner.create(instance, new Deallocator(address)); setByteBuffer(instance, address, length, cleaner); } else { setByteBuffer(instance, address, length, null); } instance.order(ByteOrder.nativeOrder()); return instance; }
AllocateDirectMap(final File file, final long fileOffsetBytes, final long capacityBytes, final boolean localReadOnly) { this.capacityBytes = capacityBytes; resourceReadOnly = isFileReadOnly(file); final long fileLength = file.length(); if ((localReadOnly || resourceReadOnly) && ((fileOffsetBytes + capacityBytes) > fileLength)) { throw new IllegalArgumentException( "Read-only mode and requested map length is greater than current file length: " + "Requested Length = " + (fileOffsetBytes + capacityBytes) + ", Current File Length = " + fileLength); } raf = mapper(file, fileOffsetBytes, capacityBytes, resourceReadOnly); nativeBaseOffset = map(raf.getChannel(), resourceReadOnly, fileOffsetBytes, capacityBytes); deallocator = new Deallocator(nativeBaseOffset, capacityBytes, raf); cleaner = Cleaner.create(this, deallocator); }
public DirectStore(ObjectSerializer objectSerializer, long size, boolean zeroOut) { this.objectSerializer = objectSerializer; address = NativeBytes.UNSAFE.allocateMemory(size); // System.out.println("old value " + Integer.toHexString(NativeBytes.UNSAFE.getInt(null, address))); if (zeroOut) { NativeBytes.UNSAFE.setMemory(address, size, (byte) 0); NativeBytes.UNSAFE.putLongVolatile(null, address, 0L); } this.size = size; deallocator = new Deallocator(address); cleaner = Cleaner.create(this, deallocator); }
public DirectStore(ObjectSerializer objectSerializer, long size, boolean zeroOut) { this.objectSerializer = objectSerializer; address = NativeBytes.UNSAFE.allocateMemory(size); // System.out.println("old value " + Integer.toHexString(NativeBytes.UNSAFE.getInt(null, address))); if (zeroOut) { NativeBytes.UNSAFE.setMemory(address, size, (byte) 0); NativeBytes.UNSAFE.putLongVolatile(null, address, 0L); } this.size = size; deallocator = new Deallocator(address); cleaner = Cleaner.create(this, deallocator); }
AbstractMappedStore(MmapInfoHolder mmapInfoHolder, File file, FileChannel.MapMode mode, long startInFile, long size, ObjectSerializer objectSerializer) throws IOException { validateSize(size); this.file = file; this.mmapInfoHolder = mmapInfoHolder; this.mmapInfoHolder.setSize(size); this.objectSerializer = objectSerializer; this.mode = mode; try { this.raf = new RandomAccessFile(file, accesModeFor(mode)); resizeIfNeeded(startInFile, size); map(startInFile); this.cleaner = Cleaner.create(this, new Unmapper(mmapInfoHolder, raf)); } catch (Exception e) { throw wrap(e); } }