mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 12:04:39 +02:00
8164900: Add support for O_DIRECT
Add support for Direct I/O in FileChannel Co-authored-by: Volker Simonis <volker.simonis@gmail.com> Reviewed-by: alanb, bpb, alanbur, coffeys, aph, clanger, plevart, mli, psandoz, simonis
This commit is contained in:
parent
97db013bd3
commit
ec1c3bce45
30 changed files with 1523 additions and 45 deletions
|
@ -30,6 +30,8 @@ import java.io.IOException;
|
|||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.JavaIOFileDescriptorAccess;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import java.io.File;
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
class FileDispatcherImpl extends FileDispatcher {
|
||||
|
||||
|
@ -123,6 +125,21 @@ class FileDispatcherImpl extends FileDispatcher {
|
|||
return true;
|
||||
}
|
||||
|
||||
int setDirectIO(FileDescriptor fd, String path)
|
||||
{
|
||||
int result = -1;
|
||||
String filePath = path.substring(0, path.lastIndexOf(File.separator));
|
||||
CharBuffer buffer = CharBuffer.allocate(filePath.length());
|
||||
buffer.put(filePath);
|
||||
try {
|
||||
result = setDirect0(fd, buffer);
|
||||
} catch (IOException e) {
|
||||
throw new UnsupportedOperationException
|
||||
("Error setting up DirectIO", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean isFastFileTransferRequested() {
|
||||
String fileTransferProp = GetPropertyAction
|
||||
.privilegedGetProperty("jdk.nio.enableFastFileTransfer");
|
||||
|
@ -177,4 +194,6 @@ class FileDispatcherImpl extends FileDispatcher {
|
|||
static native void close0(FileDescriptor fd) throws IOException;
|
||||
|
||||
static native long duplicateHandle(long fd) throws IOException;
|
||||
|
||||
static native int setDirect0(FileDescriptor fd, CharBuffer buffer) throws IOException;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -74,6 +74,7 @@ class WindowsChannelFactory {
|
|||
boolean overlapped;
|
||||
boolean sync;
|
||||
boolean dsync;
|
||||
boolean direct;
|
||||
|
||||
// non-standard
|
||||
boolean shareRead = true;
|
||||
|
@ -121,6 +122,10 @@ class WindowsChannelFactory {
|
|||
flags.shareDelete = false;
|
||||
continue;
|
||||
}
|
||||
if (ExtendedOptions.DIRECT.matches(option)) {
|
||||
flags.direct = true;
|
||||
continue;
|
||||
}
|
||||
if (option == null)
|
||||
throw new NullPointerException();
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -161,7 +166,8 @@ class WindowsChannelFactory {
|
|||
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
|
||||
|
||||
FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor);
|
||||
return FileChannelImpl.open(fdObj, pathForWindows, flags.read, flags.write, null);
|
||||
return FileChannelImpl.open(fdObj, pathForWindows, flags.read,
|
||||
flags.write, flags.direct, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -125,7 +125,7 @@ class WindowsFileStore
|
|||
}
|
||||
|
||||
// read the free space info
|
||||
private DiskFreeSpace readDiskFreeSpace() throws IOException {
|
||||
private DiskFreeSpace readDiskFreeSpaceEx() throws IOException {
|
||||
try {
|
||||
return GetDiskFreeSpaceEx(root);
|
||||
} catch (WindowsException x) {
|
||||
|
@ -134,19 +134,32 @@ class WindowsFileStore
|
|||
}
|
||||
}
|
||||
|
||||
private DiskFreeSpace readDiskFreeSpace() throws IOException {
|
||||
try {
|
||||
return GetDiskFreeSpace(root);
|
||||
} catch (WindowsException x) {
|
||||
x.rethrowAsIOException(root);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotalSpace() throws IOException {
|
||||
return readDiskFreeSpace().totalNumberOfBytes();
|
||||
return readDiskFreeSpaceEx().totalNumberOfBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUsableSpace() throws IOException {
|
||||
return readDiskFreeSpace().freeBytesAvailable();
|
||||
return readDiskFreeSpaceEx().freeBytesAvailable();
|
||||
}
|
||||
|
||||
public long getBlockSize() throws IOException {
|
||||
return readDiskFreeSpace().bytesPerSector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnallocatedSpace() throws IOException {
|
||||
return readDiskFreeSpace().freeBytesAvailable();
|
||||
return readDiskFreeSpaceEx().freeBytesAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,6 +178,8 @@ class WindowsFileStore
|
|||
return getUsableSpace();
|
||||
if (attribute.equals("unallocatedSpace"))
|
||||
return getUnallocatedSpace();
|
||||
if (attribute.equals("bytesPerSector"))
|
||||
return getBlockSize();
|
||||
// windows specific for testing purposes
|
||||
if (attribute.equals("volume:vsn"))
|
||||
return volInfo.volumeSerialNumber();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -485,21 +485,50 @@ class WindowsNativeDispatcher {
|
|||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GetDiskFreeSpace(
|
||||
* LPCTSTR lpRootPathName,
|
||||
* LPDWORD lpSectorsPerCluster,
|
||||
* LPDWORD lpBytesPerSector,
|
||||
* LPDWORD lpNumberOfFreeClusters,
|
||||
* LPDWORD lpTotalNumberOfClusters
|
||||
* )
|
||||
*/
|
||||
static DiskFreeSpace GetDiskFreeSpace(String path)
|
||||
throws WindowsException
|
||||
{
|
||||
NativeBuffer buffer = asNativeBuffer(path);
|
||||
try {
|
||||
DiskFreeSpace space = new DiskFreeSpace();
|
||||
GetDiskFreeSpace0(buffer.address(), space);
|
||||
return space;
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
static class DiskFreeSpace {
|
||||
private long freeBytesAvailable;
|
||||
private long totalNumberOfBytes;
|
||||
private long totalNumberOfFreeBytes;
|
||||
private long bytesPerSector;
|
||||
private DiskFreeSpace() { }
|
||||
|
||||
public long freeBytesAvailable() { return freeBytesAvailable; }
|
||||
public long totalNumberOfBytes() { return totalNumberOfBytes; }
|
||||
public long totalNumberOfFreeBytes() { return totalNumberOfFreeBytes; }
|
||||
public long bytesPerSector() { return bytesPerSector; }
|
||||
}
|
||||
private static native void GetDiskFreeSpaceEx0(long lpDirectoryName,
|
||||
DiskFreeSpace obj)
|
||||
throws WindowsException;
|
||||
|
||||
|
||||
private static native void GetDiskFreeSpace0(long lpRootPathName,
|
||||
DiskFreeSpace obj)
|
||||
throws WindowsException;
|
||||
|
||||
/**
|
||||
* GetVolumePathName(
|
||||
* LPCTSTR lpszFileName,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue