// Path: src/main/java/com/yahoo/memory4/UnsafeUtil.java
// public static final Unsafe unsafe;


import static com.yahoo.memory4.UnsafeUtil.unsafe;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
import sun.misc.Cleaner;
import sun.nio.ch.FileChannelImpl;
    final long fileOffset = state.getFileOffset();
    final long capacity = state.getCapacity();
    checkOffsetAndCapacity(fileOffset, capacity);

    final File file = state.getFile();
    if (isFileReadOnly(file)) {
      throw new ReadOnlyMemoryException("File is read-only.");
    }

    final String mode = "rw";
    final RandomAccessFile raf = new RandomAccessFile(file, mode);
    final FileChannel fc = raf.getChannel();
    final long nativeBaseOffset = map(fc, fileOffset, capacity);
    state.putNativeBaseOffset(nativeBaseOffset);

    // len can be more than the file.length
    raf.setLength(capacity);
    final MappedByteBuffer mbb = createDummyMbbInstance(nativeBaseOffset);
    return new AllocateDirectWritableMap(state, raf, mbb);
  }

  @Override
  public WritableMemory get() {
    return this;
  }

  @Override
  public void load() {
    madvise();
    // Read a byte from each page to bring it into memory.
// Path: src/main/java/com/yahoo/memory4/UnsafeUtil.java
// public static final Unsafe unsafe;


// Path: src/main/java/com/yahoo/memory4/AllocateDirectWritableMap.java
import static com.yahoo.memory4.UnsafeUtil.unsafe;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
import sun.misc.Cleaner;
import sun.nio.ch.FileChannelImpl;

    final long fileOffset = state.getFileOffset();
    final long capacity = state.getCapacity();
    checkOffsetAndCapacity(fileOffset, capacity);

    final File file = state.getFile();
    if (isFileReadOnly(file)) {
      throw new ReadOnlyMemoryException("File is read-only.");
    }

    final String mode = "rw";
    final RandomAccessFile raf = new RandomAccessFile(file, mode);
    final FileChannel fc = raf.getChannel();
    final long nativeBaseOffset = map(fc, fileOffset, capacity);
    state.putNativeBaseOffset(nativeBaseOffset);

    // len can be more than the file.length
    raf.setLength(capacity);
    final MappedByteBuffer mbb = createDummyMbbInstance(nativeBaseOffset);
    return new AllocateDirectWritableMap(state, raf, mbb);
  }

  @Override
  public WritableMemory get() {
    return this;
  }

  @Override
  public void load() {
    madvise();
    // Read a byte from each page to bring it into memory.
    final int ps = unsafe.pageSize();