diff options
Diffstat (limited to 'lang/src/main/java/net/openhft/lang/io/VanillaMappedBytes.java')
-rw-r--r-- | lang/src/main/java/net/openhft/lang/io/VanillaMappedBytes.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lang/src/main/java/net/openhft/lang/io/VanillaMappedBytes.java b/lang/src/main/java/net/openhft/lang/io/VanillaMappedBytes.java index 6f8191f..812a16d 100644 --- a/lang/src/main/java/net/openhft/lang/io/VanillaMappedBytes.java +++ b/lang/src/main/java/net/openhft/lang/io/VanillaMappedBytes.java @@ -15,7 +15,6 @@ */ package net.openhft.lang.io; -import sun.misc.Cleaner; import sun.nio.ch.DirectBuffer; import java.io.File; @@ -23,6 +22,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import java.lang.reflect.Method; public class VanillaMappedBytes extends NativeBytes { private final File path; @@ -31,6 +31,18 @@ public class VanillaMappedBytes extends NativeBytes { private final FileLifecycleListener fileLifecycleListener; private final long index; private boolean unmapped; + private static final Method invokeCleaner; + + static { + Method tmpCleaner; + try { + tmpCleaner = UNSAFE.getClass().getDeclaredMethod("invokeCleaner", ByteBuffer.class); + tmpCleaner.setAccessible(true); + } catch (Throwable t) { + tmpCleaner = null; + } + invokeCleaner = tmpCleaner; + } public VanillaMappedBytes(final File path, final MappedByteBuffer buffer) { this(path, buffer, -1, null, FileLifecycleListener.FileLifecycleListeners.IGNORE); @@ -92,10 +104,13 @@ public class VanillaMappedBytes extends NativeBytes { @Override protected synchronized void cleanup() { if(!this.unmapped) { - Cleaner cl = ((DirectBuffer)this.buffer).cleaner(); - if (cl != null) { + if (invokeCleaner != null) { long start = System.nanoTime(); - cl.clean(); + try { + invokeCleaner.invoke(UNSAFE, this.buffer); + } catch (Throwable e) { + + } fileLifecycleListener.onEvent( FileLifecycleListener.EventType.UNMAP, |