< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java

Print this page
*** 23,10 ***
--- 23,11 ---
   * questions.
   */
  
  package sun.nio.fs;
  
+ import jdk.internal.misc.Blocker;
  import jdk.internal.misc.Unsafe;
  
  import static sun.nio.fs.WindowsConstants.*;
  
  /**

*** 64,20 ***
                             long lpSecurityAttributes,
                             int dwCreationDisposition,
                             int dwFlagsAndAttributes)
          throws WindowsException
      {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             return CreateFile0(buffer.address(),
!                                dwDesiredAccess,
!                                dwShareMode,
!                                lpSecurityAttributes,
!                                dwCreationDisposition,
!                                dwFlagsAndAttributes);
!         } finally {
!             buffer.release();
          }
      }
      static long CreateFile(String path,
                             int dwDesiredAccess,
                             int dwShareMode,
--- 65,27 ---
                             long lpSecurityAttributes,
                             int dwCreationDisposition,
                             int dwFlagsAndAttributes)
          throws WindowsException
      {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() ->
!                         CreateFile0(buffer.address(),
!                                     dwDesiredAccess,
!                                     dwShareMode,
!                                     lpSecurityAttributes,
!                                     dwCreationDisposition,
!                                     dwFlagsAndAttributes));
!             } else {
+                 return CreateFile0(buffer.address(),
+                                    dwDesiredAccess,
+                                    dwShareMode,
+                                    lpSecurityAttributes,
+                                    dwCreationDisposition,
+                                    dwFlagsAndAttributes);
+             }
          }
      }
      static long CreateFile(String path,
                             int dwDesiredAccess,
                             int dwShareMode,

*** 107,15 ***
       * DeleteFile(
       *   LPCTSTR lpFileName
       * )
       */
      static void DeleteFile(String path) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             DeleteFile0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native void DeleteFile0(long lpFileName)
          throws WindowsException;
  
--- 115,16 ---
       * DeleteFile(
       *   LPCTSTR lpFileName
       * )
       */
      static void DeleteFile(String path) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> DeleteFile0(buffer.address()));
!             } else {
!                 DeleteFile0(buffer.address());
+             }
          }
      }
      private static native void DeleteFile0(long lpFileName)
          throws WindowsException;
  

*** 124,15 ***
       *   LPCTSTR lpPathName,
       *   LPSECURITY_ATTRIBUTES lpSecurityAttributes
       * )
       */
      static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             CreateDirectory0(buffer.address(), lpSecurityAttributes);
!         } finally {
!             buffer.release();
          }
      }
      private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes)
          throws WindowsException;
  
--- 133,16 ---
       *   LPCTSTR lpPathName,
       *   LPSECURITY_ATTRIBUTES lpSecurityAttributes
       * )
       */
      static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> CreateDirectory0(buffer.address(), lpSecurityAttributes));
!             } else {
!                 CreateDirectory0(buffer.address(), lpSecurityAttributes);
+             }
          }
      }
      private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes)
          throws WindowsException;
  

*** 140,15 ***
       * RemoveDirectory(
       *   LPCTSTR lpPathName
       * )
       */
      static void RemoveDirectory(String path) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             RemoveDirectory0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native void RemoveDirectory0(long lpFileName)
          throws WindowsException;
  
--- 150,16 ---
       * RemoveDirectory(
       *   LPCTSTR lpPathName
       * )
       */
      static void RemoveDirectory(String path) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> RemoveDirectory0(buffer.address()));
!             } else {
!                 RemoveDirectory0(buffer.address());
+             }
          }
      }
      private static native void RemoveDirectory0(long lpFileName)
          throws WindowsException;
  

*** 187,17 ***
       *   LPCTSTR lpFileName,
       *   LPWIN32_FIND_DATA lpFindFileData
       * )
       */
      static FirstFile FindFirstFile(String path) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
-         try {
              FirstFile data = new FirstFile();
!             FindFirstFile0(buffer.address(), data);
              return data;
-         } finally {
-             buffer.release();
          }
      }
      static class FirstFile {
          private long handle;
          private String name;
--- 198,18 ---
       *   LPCTSTR lpFileName,
       *   LPWIN32_FIND_DATA lpFindFileData
       * )
       */
      static FirstFile FindFirstFile(String path) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
              FirstFile data = new FirstFile();
!             if (Thread.currentThread().isVirtual()) {
+                 Blocker.managedBlock(() -> FindFirstFile0(buffer.address(), data));
+             } else {
+                 FindFirstFile0(buffer.address(), data);
+             }
              return data;
          }
      }
      static class FirstFile {
          private long handle;
          private String name;

*** 216,15 ***
       *   LPCTSTR lpFileName,
       *   LPWIN32_FIND_DATA lpFindFileData
       * )
       */
      static long FindFirstFile(String path, long address) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             return FindFirstFile1(buffer.address(), address);
!         } finally {
!             buffer.release();
          }
      }
      private static native long FindFirstFile1(long lpFileName, long address)
          throws WindowsException;
  
--- 228,16 ---
       *   LPCTSTR lpFileName,
       *   LPWIN32_FIND_DATA lpFindFileData
       * )
       */
      static long FindFirstFile(String path, long address) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> FindFirstFile1(buffer.address(), address));
!             } else {
!                 return FindFirstFile1(buffer.address(), address);
+             }
          }
      }
      private static native long FindFirstFile1(long lpFileName, long address)
          throws WindowsException;
  

*** 234,11 ***
       *   LPWIN32_FIND_DATA lpFindFileData
       * )
       *
       * @return  lpFindFileData->cFileName or null
       */
!     static native String FindNextFile(long handle, long address)
          throws WindowsException;
  
      /**
       * HANDLE FindFirstStreamW(
       *   LPCWSTR lpFileName,
--- 247,18 ---
       *   LPWIN32_FIND_DATA lpFindFileData
       * )
       *
       * @return  lpFindFileData->cFileName or null
       */
!     static String FindNextFile(long handle, long address) throws WindowsException {
+         if (Thread.currentThread().isVirtual()) {
+             return Blocker.managedBlock(() -> FindNextFile0(handle, address));
+         } else {
+             return FindNextFile0(handle, address);
+         }
+     }
+     private static native String FindNextFile0(long handle, long address)
          throws WindowsException;
  
      /**
       * HANDLE FindFirstStreamW(
       *   LPCWSTR lpFileName,

*** 246,19 ***
       *   LPVOID lpFindStreamData,
       *   DWORD dwFlags
       * )
       */
      static FirstStream FindFirstStream(String path) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
-         try {
              FirstStream data = new FirstStream();
!             FindFirstStream0(buffer.address(), data);
              if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE)
                  return null;
              return data;
-         } finally {
-             buffer.release();
          }
      }
      static class FirstStream {
          private long handle;
          private String name;
--- 266,20 ---
       *   LPVOID lpFindStreamData,
       *   DWORD dwFlags
       * )
       */
      static FirstStream FindFirstStream(String path) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
              FirstStream data = new FirstStream();
!             if (Thread.currentThread().isVirtual()) {
+                 Blocker.managedBlock(() -> FindFirstStream0(buffer.address(), data));
+             } else {
+                 FindFirstStream0(buffer.address(), data);
+             }
              if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE)
                  return null;
              return data;
          }
      }
      static class FirstStream {
          private long handle;
          private String name;

*** 274,11 ***
       * FindNextStreamW(
       *   HANDLE hFindStream,
       *   LPVOID lpFindStreamData
       * )
       */
!     static native String FindNextStream(long handle) throws WindowsException;
  
      /**
       * FindClose(
       *   HANDLE hFindFile
       * )
--- 295,18 ---
       * FindNextStreamW(
       *   HANDLE hFindStream,
       *   LPVOID lpFindStreamData
       * )
       */
!     static String FindNextStream(long handle) throws WindowsException {
+         if (Thread.currentThread().isVirtual()) {
+             return Blocker.managedBlock(() -> FindNextStream0(handle));
+         } else {
+             return FindNextStream0(handle);
+         }
+     }
+     private static native String FindNextStream0(long handle) throws WindowsException;
  
      /**
       * FindClose(
       *   HANDLE hFindFile
       * )

*** 289,11 ***
       * GetFileInformationByHandle(
       *   HANDLE hFile,
       *   LPBY_HANDLE_FILE_INFORMATION lpFileInformation
       * )
       */
!     static native void GetFileInformationByHandle(long handle, long address)
          throws WindowsException;
  
      /**
       * CopyFileEx(
       *   LPCWSTR lpExistingFileName
--- 317,20 ---
       * GetFileInformationByHandle(
       *   HANDLE hFile,
       *   LPBY_HANDLE_FILE_INFORMATION lpFileInformation
       * )
       */
!     static void GetFileInformationByHandle(long handle, long address)
+         throws WindowsException
+     {
+         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> GetFileInformationByHandle0(handle, address));
+         } else {
+             GetFileInformationByHandle0(handle, address);
+         }
+     }
+     private static native void GetFileInformationByHandle0(long handle, long address)
          throws WindowsException;
  
      /**
       * CopyFileEx(
       *   LPCWSTR lpExistingFileName

*** 306,18 ***
       */
      static void CopyFileEx(String source, String target, int flags,
                             long addressToPollForCancel)
          throws WindowsException
      {
!         NativeBuffer sourceBuffer = asNativeBuffer(source);
!         NativeBuffer targetBuffer = asNativeBuffer(target);
!         try {
!             CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
!                         addressToPollForCancel);
!         } finally {
!             targetBuffer.release();
!             sourceBuffer.release();
          }
      }
      private static native void CopyFileEx0(long existingAddress, long newAddress,
          int flags, long addressToPollForCancel) throws WindowsException;
  
--- 343,20 ---
       */
      static void CopyFileEx(String source, String target, int flags,
                             long addressToPollForCancel)
          throws WindowsException
      {
!         try (NativeBuffer sourceBuffer = asNativeBuffer(source);
!              NativeBuffer targetBuffer = asNativeBuffer(target)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() ->
!                     CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
!                                 addressToPollForCancel));
!             } else {
!                 CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
+                             addressToPollForCancel);
+             }
          }
      }
      private static native void CopyFileEx0(long existingAddress, long newAddress,
          int flags, long addressToPollForCancel) throws WindowsException;
  

*** 329,17 ***
       * )
       */
      static void MoveFileEx(String source, String target, int flags)
          throws WindowsException
      {
!         NativeBuffer sourceBuffer = asNativeBuffer(source);
!         NativeBuffer targetBuffer = asNativeBuffer(target);
!         try {
!             MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
!         } finally {
!             targetBuffer.release();
!             sourceBuffer.release();
          }
      }
      private static native void MoveFileEx0(long existingAddress, long newAddress,
          int flags) throws WindowsException;
  
--- 368,18 ---
       * )
       */
      static void MoveFileEx(String source, String target, int flags)
          throws WindowsException
      {
!         try (NativeBuffer sourceBuffer = asNativeBuffer(source);
!              NativeBuffer targetBuffer = asNativeBuffer(target)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() ->
!                     MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags));
!             } else {
!                 MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
+             }
          }
      }
      private static native void MoveFileEx0(long existingAddress, long newAddress,
          int flags) throws WindowsException;
  

*** 347,15 ***
       * DWORD GetFileAttributes(
       *   LPCTSTR lpFileName
       * )
       */
      static int GetFileAttributes(String path) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             return GetFileAttributes0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native int GetFileAttributes0(long lpFileName)
          throws WindowsException;
  
--- 387,16 ---
       * DWORD GetFileAttributes(
       *   LPCTSTR lpFileName
       * )
       */
      static int GetFileAttributes(String path) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> GetFileAttributes0(buffer.address()));
!             } else {
!                 return GetFileAttributes0(buffer.address());
+             }
          }
      }
      private static native int GetFileAttributes0(long lpFileName)
          throws WindowsException;
  

*** 365,15 ***
       *   DWORD dwFileAttributes
       */
      static void SetFileAttributes(String path, int dwFileAttributes)
          throws WindowsException
      {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             SetFileAttributes0(buffer.address(), dwFileAttributes);
!         } finally {
!             buffer.release();
          }
      }
      private static native void SetFileAttributes0(long lpFileName,
          int dwFileAttributes) throws WindowsException;
  
--- 406,16 ---
       *   DWORD dwFileAttributes
       */
      static void SetFileAttributes(String path, int dwFileAttributes)
          throws WindowsException
      {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> SetFileAttributes0(buffer.address(), dwFileAttributes));
!             } else {
!                 SetFileAttributes0(buffer.address(), dwFileAttributes);
+             }
          }
      }
      private static native void SetFileAttributes0(long lpFileName,
          int dwFileAttributes) throws WindowsException;
  

*** 383,31 ***
       *   GET_FILEEX_INFO_LEVELS fInfoLevelId,
       *   LPVOID lpFileInformation
       * );
       */
      static void GetFileAttributesEx(String path, long address) throws WindowsException {
!         NativeBuffer buffer = asNativeBuffer(path);
!         try {
!             GetFileAttributesEx0(buffer.address(), address);
!         } finally {
!             buffer.release();
          }
      }
      private static native void GetFileAttributesEx0(long lpFileName, long address)
          throws WindowsException;
      /**
       * SetFileTime(
       *   HANDLE hFile,
       *   CONST FILETIME *lpCreationTime,
       *   CONST FILETIME *lpLastAccessTime,
       *   CONST FILETIME *lpLastWriteTime
       * )
       */
!     static native void SetFileTime(long handle,
!                                    long createTime,
!                                    long lastAccessTime,
!                                    long lastWriteTime)
          throws WindowsException;
  
      /**
       * SetEndOfFile(
       *   HANDLE hFile
--- 425,42 ---
       *   GET_FILEEX_INFO_LEVELS fInfoLevelId,
       *   LPVOID lpFileInformation
       * );
       */
      static void GetFileAttributesEx(String path, long address) throws WindowsException {
!         try (NativeBuffer buffer = asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> GetFileAttributesEx0(buffer.address(), address));
!             } else {
!                 GetFileAttributesEx0(buffer.address(), address);
+             }
          }
      }
      private static native void GetFileAttributesEx0(long lpFileName, long address)
          throws WindowsException;
+ 
      /**
       * SetFileTime(
       *   HANDLE hFile,
       *   CONST FILETIME *lpCreationTime,
       *   CONST FILETIME *lpLastAccessTime,
       *   CONST FILETIME *lpLastWriteTime
       * )
       */
!     static void SetFileTime(long handle, long createTime, long lastAccessTime, long lastWriteTime)
!         throws WindowsException
!     {
!         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> SetFileTime0(handle, createTime, lastAccessTime, lastWriteTime));
+         } else {
+             SetFileTime0(handle, createTime, lastAccessTime, lastWriteTime);
+         }
+     }
+     private static native void SetFileTime0(long handle,
+                                             long createTime,
+                                             long lastAccessTime,
+                                             long lastWriteTime)
          throws WindowsException;
  
      /**
       * SetEndOfFile(
       *   HANDLE hFile

*** 618,12 ***
                                  long pSecurityDescriptor)
          throws WindowsException
      {
          NativeBuffer buffer = asNativeBuffer(path);
          try {
!             SetFileSecurity0(buffer.address(), securityInformation,
!                 pSecurityDescriptor);
          } finally {
              buffer.release();
          }
      }
      static native void SetFileSecurity0(long lpFileName, int securityInformation,
--- 671,12 ---
                                  long pSecurityDescriptor)
          throws WindowsException
      {
          NativeBuffer buffer = asNativeBuffer(path);
          try {
!             // may be called with elevated privileges so always run on current thread
!             SetFileSecurity0(buffer.address(), securityInformation, pSecurityDescriptor);
          } finally {
              buffer.release();
          }
      }
      static native void SetFileSecurity0(long lpFileName, int securityInformation,
< prev index next >