< prev index next >

src/java.base/share/classes/java/nio/MappedMemoryUtils.java

Print this page
@@ -23,15 +23,15 @@
   * questions.
   */
  
  package java.nio;
  
- import jdk.internal.misc.Unsafe;
- 
  import java.io.FileDescriptor;
  import java.io.IOException;
  import java.io.UncheckedIOException;
+ import jdk.internal.misc.Blocker;
+ import jdk.internal.misc.Unsafe;
  
  /* package */ class MappedMemoryUtils {
  
      static boolean isLoaded(long address, boolean isSync, long size) {
          // a sync mapped buffer is always loaded

@@ -94,12 +94,18 @@
              // simply force writeback of associated cache lines
              Unsafe.getUnsafe().writebackMemory(address + index, length);
          } else {
              // force writeback via file descriptor
              long offset = mappingOffset(address, index);
+             long mappingAddress = mappingAddress(address, offset, index);
+             long mappingLength = mappingLength(offset, length);
              try {
-                 force0(fd, mappingAddress(address, offset, index), mappingLength(offset, length));
+                 if (Thread.currentThread().isVirtual()) {
+                     Blocker.managedBlock(() -> force0(fd, mappingAddress, mappingLength));
+                 } else {
+                     force0(fd, mappingAddress, mappingLength);
+                 }
              } catch (IOException cause) {
                  throw new UncheckedIOException(cause);
              }
          }
      }
< prev index next >