Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8217884

File system iniitialization deadlock

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      There appears to be a classic lock-order deadlock when two threads call System.loadLibrary and FileSystems.getDefault to invoke class initialization.

      ---
      import java.util.concurrent.ExecutorService;
      import java.util.concurrent.Executors;
      import java.util.concurrent.Future;
      import static java.util.concurrent.TimeUnit.SECONDS;

      public class Repro {

          static sun.security.ec.SunEC newSunEC() {
              return new sun.security.ec.SunEC();
          }

          static void getDefaultFileSystem() {
              java.nio.file.FileSystems.getDefault();
          }

          public static void main(String[] args) throws Throwable {
              ExecutorService ex1 = Executors.newSingleThreadExecutor();
              ExecutorService ex2 = Executors.newSingleThreadExecutor();

              Future<?> future1 = ex1.submit(Repro::newSunEC);
              Future<?> future2 = ex2.submit(Repro::getDefaultFileSystem);

              future1.get();
              future2.get();

              ex1.shutdown();
              ex2.shutdown();

              ex1.awaitTermination(Long.MAX_VALUE, SECONDS);
              ex2.awaitTermination(Long.MAX_VALUE, SECONDS);
          }
      }
      ---

      When I run this program repeatedly with jdk8, I (eventually) see this deadlock:


      "pool-2-thread-1" #10 prio=5 os_prio=0 tid=0x00007f55c81c0000 nid=0x47e waiting for monitor entry [0x00007f55b3319000]
         java.lang.Thread.State: BLOCKED (on object monitor)
      at java.lang.Runtime.loadLibrary0(Runtime.java:862)
      - waiting to lock <0x000000076cf9a060> (a java.lang.Runtime)
      at java.lang.System.loadLibrary(System.java:1122)
      at sun.nio.fs.UnixNativeDispatcher$1.run(UnixNativeDispatcher.java:573)
      at sun.nio.fs.UnixNativeDispatcher$1.run(UnixNativeDispatcher.java:571)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.nio.fs.UnixNativeDispatcher.<clinit>(UnixNativeDispatcher.java:571)
      at sun.nio.fs.UnixFileSystem.<init>(UnixFileSystem.java:67)
      at sun.nio.fs.LinuxFileSystem.<init>(LinuxFileSystem.java:39)
      at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:46)
      at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:39)
      at sun.nio.fs.UnixFileSystemProvider.<init>(UnixFileSystemProvider.java:56)
      at sun.nio.fs.LinuxFileSystemProvider.<init>(LinuxFileSystemProvider.java:41)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at java.lang.Class.newInstance(Class.java:442)
      at sun.nio.fs.DefaultFileSystemProvider.createProvider(DefaultFileSystemProvider.java:48)
      at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:63)
      at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
      at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89)
      at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
      at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
      at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
      at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
      at Repro.getDefaultFileSystem(Repro.java:13)
      at Repro$$Lambda$2/1023892928.run(Unknown Source)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)

      "pool-1-thread-1" #9 prio=5 os_prio=0 tid=0x00007f55c81be000 nid=0x47d in Object.wait() [0x00007f55b341c000]
         java.lang.Thread.State: RUNNABLE
      at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
      at java.nio.file.Paths.get(Paths.java:138)
      at sun.misc.Launcher$ExtClassLoader.findLibrary(Launcher.java:235)
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1830)
      at java.lang.Runtime.loadLibrary0(Runtime.java:870)
      - locked <0x000000076cf9a060> (a java.lang.Runtime)
      at java.lang.System.loadLibrary(System.java:1122)
      at sun.security.ec.SunEC$1.run(SunEC.java:60)
      at sun.security.ec.SunEC$1.run(SunEC.java:58)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.security.ec.SunEC.<clinit>(SunEC.java:58)
      at Repro.newSunEC(Repro.java:9)
      at Repro$$Lambda$1/2003749087.call(Unknown Source)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)

      "main" #1 prio=5 os_prio=0 tid=0x00007f55c800a800 nid=0x46e waiting on condition [0x00007f55d168d000]
         java.lang.Thread.State: WAITING (parking)
      at sun.misc.Unsafe.park(Native Method)
      - parking to wait for <0x000000076d33c320> (a java.util.concurrent.FutureTask)
      at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
      at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:429)
      at java.util.concurrent.FutureTask.get(FutureTask.java:191)
      at Repro.main(Repro.java:23)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              martin Martin Buchholz
              Reporter:
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: