Esempio n. 1
0
 public static void cleanDirectBuffer(Buffer mappedFile) {
   if (mappedFile instanceof DirectBuffer) {
     Cleaner cleaner = ((DirectBuffer) mappedFile).cleaner();
     if (cleaner != null) {
       cleaner.clean();
     }
   }
 }
Esempio n. 2
0
 /**
  * Force to unmap direct buffer if the buffer is no longer used. It is unsafe operation and
  * currently a walk-around to avoid huge memory occupation caused by memory map.
  *
  * @param buffer the byte buffer to be unmapped
  */
 public static void cleanDirectBuffer(ByteBuffer buffer) {
   if (buffer == null) {
     return;
   }
   if (buffer.isDirect()) {
     Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
     cleaner.clean();
   }
 }
Esempio n. 3
0
  public MappedStore(
      File file, FileChannel.MapMode mode, long size, ObjectSerializer objectSerializer)
      throws IOException {
    if (size < 0 || size > 128L << 40) {
      throw new IllegalArgumentException("invalid size: " + size);
    }

    this.file = file;
    this.size = size;
    this.objectSerializer = objectSerializer;

    try {
      RandomAccessFile raf = new RandomAccessFile(file, accesModeFor(mode));
      if (raf.length() != this.size && !file.getAbsolutePath().startsWith("/dev/")) {
        if (mode != FileChannel.MapMode.READ_WRITE) {
          throw new IOException("Cannot resize file to " + size + " as mode is not READ_WRITE");
        }

        raf.setLength(this.size);
      }

      this.fileChannel = raf.getChannel();
      this.address = map0(fileChannel, imodeFor(mode), 0L, size);
      this.cleaner = Cleaner.create(this, new Unmapper(address, size, fileChannel));
    } catch (Exception e) {
      throw wrap(e);
    }
  }
 public NativeBytesStore(
     long address, long maximumLimit, @Nullable Runnable deallocator, boolean elastic) {
   setAddress(address);
   this.maximumLimit = maximumLimit;
   cleaner = deallocator == null ? null : Cleaner.create(this, deallocator);
   underlyingObject = null;
   this.elastic = elastic;
 }
  private void performRelease() {
    if (refCount.get() > 0) {
      LOGGER.info("NativeBytesStore discarded without releasing ", createdHere);
    }

    memory = null;
    if (cleaner != null) cleaner.clean();
  }
Esempio n. 6
0
  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);
  }
Esempio n. 7
0
 public void free() {
   cleaner.clean();
 }
Esempio n. 8
0
 private void clean(MappedByteBuffer mapping) {
   if (mapping == null) return;
   Cleaner cleaner = ((DirectBuffer) mapping).cleaner();
   if (cleaner != null) cleaner.clean();
 }
Esempio n. 9
0
 @Override
 public void free() {
   cleaner.clean();
 }
Esempio n. 10
0
 private SelectorWrapper(Selector sel) {
   this.sel = sel;
   Cleaner.create(this, new Closer(sel));
 }