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

SIGQUIT and jcmd attaching mechanism does not work with signal chaining library

    XMLWordPrintable

Details

    • b15

    Backports

      Description

        After JDK-8279124, sending SIGQUIT to get thread dumps and using jcmd to attach a running Java process stopped working if signal chaining library (libjsig.so) is enabled. See https://docs.oracle.com/en/java/javase/17/troubleshoot/handle-signals-and-exceptions.html#GUID-CB49A2A7-2A9F-4C18-948F-6D4A96FF688D for more about signal chaining.

        According to test/hotspot/jtreg/runtime/signal/README, SIGQUIT does not support chaining. After JDK-8279124, the JVM calls sigaction() twice to set two different handlers for SIGQUIT. The first time it sets the handler within the window bounded by libjsig's JVM_begin_signal_setting() and JVM_end_signal_setting(), but the window is intended for signals that support chaining. When the second time it calls os::signal() => sigaction(), the overridden sigaction() in jsig.c runs the following branch:
          if (jvm_signal_installed && sigused) {
            /* jvm has installed its signal handler for this signal. */
            /* Save the handler. Don't really install it. */
            if (oact != NULL) {
              *oact = sact[sig];
            }
            if (act != NULL) {
              sact[sig] = *act;
            }
            signal_unlock();
            return 0;
          }

        As a result, the second time does not really install the UserHandler for SIGQUIT.

        Context: Our Java applications almost always enable signal chaining. We have a customized launcher with logic to override sigaction() similarly to what libjsig.so does.

        Reproducible steps:
        $ LD_PRELOAD=<jdk_path>lib/server/libjsig.so <jdk_path>/bin/java -jar <application_jar>
        $ kill -SIGQUIT <application_pid>
        Expected: Thread dump is printed on stdout.
        Actual: Nothing is printed.

        Also "$ jcmd <application_pid>" gives an error:
        2006627:
        java.io.IOException: No such process
        at jdk.attach/sun.tools.attach.VirtualMachineImpl.sendQuitTo(Native Method)
        at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:83)
        at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
        at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
        at jdk.jcmd/sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:113)
        at jdk.jcmd/sun.tools.jcmd.JCmd.main(JCmd.java:97)

        Attachments

          Issue Links

            Activity

              People

                manc Man Cao
                manc Man Cao
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: