Skip to content

Commit

Permalink
GH-555 use FileChannel.MapMode.PRIVATE on macOS aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
thurka committed Feb 9, 2024
1 parent c77fde6 commit f04e47a
Showing 1 changed file with 19 additions and 1 deletion.
Expand Up @@ -205,6 +205,18 @@ private static boolean isLinux() {
return osName.endsWith("Linux"); // NOI18N
}

private static boolean isMacOS() {
String osName = System.getProperty("os.name"); // NOI18N

return "Mac OS X".equals(osName); // NOI18N
}

private static boolean isAarch64() {
String osArch = System.getProperty("os.arch"); // NOI18N

return "aarch64".equals(osArch); // NOI18N
}

abstract Entry createEntry(long index);

abstract Entry createEntry(long index,long value);
Expand Down Expand Up @@ -379,7 +391,7 @@ public void force() throws IOException {

private static class MemoryMappedData extends AbstractData {

private static final FileChannel.MapMode MAP_MODE = isLinux() ? FileChannel.MapMode.PRIVATE : FileChannel.MapMode.READ_WRITE;
private static final FileChannel.MapMode MAP_MODE = computeMapMode();

//~ Instance fields ------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -439,6 +451,12 @@ private static MappedByteBuffer createBuffer(RandomAccessFile file, long length)
return channel.map(MAP_MODE, 0, length);
}
}

private static FileChannel.MapMode computeMapMode() {
if (isLinux()) return FileChannel.MapMode.PRIVATE;
if (isMacOS() && isAarch64()) return FileChannel.MapMode.PRIVATE;
return FileChannel.MapMode.READ_WRITE;
}
}

private static class LongMemoryMappedData extends AbstractData {
Expand Down

0 comments on commit f04e47a

Please sign in to comment.