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

Preloading libjsig.dylib causes deadlock when signal() is called

    Details

    • Subcomponent:
    • Resolved In Build:
      b74

      Backports

        Description

        According to Oracle's document:
            http://www.oracle.com/technetwork/java/javase/signals-139944.html#gbzcj

        Applications need to preload libjsig library to enable signal chaining. However, after libjsig.dylib is preloaded, any call from native code to signal() causes a deadlock.

          Issue Links

            Activity

            Hide
            dbuck David Buck added a comment - - edited
            Deadlock happens because OS X c runtime implements signal() by calling sigaction() (instead of an internal name like __sigaction()). So the sigaction() resolves back to libjsig, and we deadlock, because we are clearly not reentrant.

            Example hang:

                User stack:
                __psynch_mutexwait (in libsystem_kernel.dylib) + 10 (0x7fff86b8b166)
                  signal_lock (in libjsig.dylib) + 19 (0x1072fb5e3)
                    sigaction (in libjsig.dylib) + 24 (0x1072fba08)
                      signal__ (in libsystem_c.dylib) + 77 (0x7fff8b70319b)
                        call_os_signal (in libjsig.dylib) + 180 (0x1072fb6f4)
                          set_signal (in libjsig.dylib) + 279 (0x1072fb8a7)
                            signal (in libjsig.dylib) + 39 (0x1072fb8f7)
                              0x00000001071f3c7f (in cp) + 643 (0x1071f3c7f)
                                start (in libdyld.dylib) + 1 (0x7fff858a25c9)
                                  0x00000004 (in cp) (0x4)

            In other words, this single thread is "deadlocking" with itself. It has already taken the lock in signal() and then is trying to recursively retake the lock in sigaction(). As it is not a recursive lock (nor should it be), we deadlock.

            Can be reproduced easily with any executable that calls signal():

            ===
            DYLD_FORCE_FLAT_NAMESPACE=0 DYLD_INSERT_LIBRARIES="/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libjsig.dylib" cp -f testfile testfile
            ===
            Show
            dbuck David Buck added a comment - - edited Deadlock happens because OS X c runtime implements signal() by calling sigaction() (instead of an internal name like __sigaction()). So the sigaction() resolves back to libjsig, and we deadlock, because we are clearly not reentrant. Example hang:     User stack:     __psynch_mutexwait (in libsystem_kernel.dylib) + 10 (0x7fff86b8b166)       signal_lock (in libjsig.dylib) + 19 (0x1072fb5e3)         sigaction (in libjsig.dylib) + 24 (0x1072fba08)           signal__ (in libsystem_c.dylib) + 77 (0x7fff8b70319b)             call_os_signal (in libjsig.dylib) + 180 (0x1072fb6f4)               set_signal (in libjsig.dylib) + 279 (0x1072fb8a7)                 signal (in libjsig.dylib) + 39 (0x1072fb8f7)                   0x00000001071f3c7f (in cp) + 643 (0x1071f3c7f)                     start (in libdyld.dylib) + 1 (0x7fff858a25c9)                       0x00000004 (in cp) (0x4) In other words, this single thread is "deadlocking" with itself. It has already taken the lock in signal() and then is trying to recursively retake the lock in sigaction(). As it is not a recursive lock (nor should it be), we deadlock. Can be reproduced easily with any executable that calls signal(): === DYLD_FORCE_FLAT_NAMESPACE=0 DYLD_INSERT_LIBRARIES="/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libjsig.dylib" cp -f testfile testfile ===
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/hs-rt/hotspot/rev/660fa1b69f63
            User: dbuck
            Date: 2015-07-01 03:18:51 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/hs-rt/hotspot/rev/660fa1b69f63 User: dbuck Date: 2015-07-01 03:18:51 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/660fa1b69f63
            User: lana
            Date: 2015-07-22 21:33:30 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/660fa1b69f63 User: lana Date: 2015-07-22 21:33:30 +0000
            Hide
            mcastegr Mattis Castegren (Inactive) added a comment -
            Suggested note:
            Applications need to preload the libjsig library to enable signal chaining. Previously, on OS X, after libjsig.dylib was preloaded, any call from native code to signal() caused a deadlock. This has been fixed
            Show
            mcastegr Mattis Castegren (Inactive) added a comment - Suggested note: Applications need to preload the libjsig library to enable signal chaining. Previously, on OS X, after libjsig.dylib was preloaded, any call from native code to signal() caused a deadlock. This has been fixed

              People

              • Assignee:
                dbuck David Buck
                Reporter:
                shadowbug Shadow Bug
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: