Skip to content

Commit

Permalink
Employ sun misc Cleaner for unmap - java8 only
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Jun 22, 2023
1 parent 5fabbd3 commit 013ca0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.channels.FileChannel;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import sun.nio.ch.DirectBuffer;

/**
* <p>A stitching of {@link MappedByteBuffer}s to operate on large memory mapped blobs. {@code MappedByteBuffer} is
Expand Down Expand Up @@ -305,7 +306,15 @@ public void unmapBlob() {
LOG.warning("SNAP: unmapBlob called on BlobByteBuffer after its already been unmapped previously. " +
"spine.length= " + spine.length + ", i= " + i);
}
try {
sun.misc.Cleaner cleaner = ((DirectBuffer) spine[i]).cleaner();
cleaner.clean();
} catch (Exception e) {
LOG.warning("SNAP: sun.misc.Cleaner support not available in app");
}

spine[i] = null;

// SNAP: TODO: instead of calling it too frequently, let app decide when to call it
// System.gc(); // just a hint, but does seem to keep the size of mapped file region lower- both virtual and physical sizes as reported by vmmap on mac
// note that this also adds 2s to delta refresh that's 10s without it
Expand Down
Binary file not shown.

0 comments on commit 013ca0f

Please sign in to comment.