JDK-4361067 : hotspot VM crashes when bringing up thru JNI when signal handler is installed
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2000-08-09
  • Updated: 2020-11-03
  • Resolved: 2000-08-28
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  

Name: stC104175			Date: 08/09/2000

$ java -version
java version "1.3.0beta_refresh"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta_refresh-b09)
Java HotSpot(TM) Client VM (build 1.3.0beta-b07, mixed mode)

run the following code:
#include <stdio.h>
#include <signal.h>
#include <assert.h>
#include <jni.h>

void signalHandler(int sig, siginfo_t* info, void *vp) { }

int main(int argc, char **argv)
  JNIEnv *env = NULL;
  JavaVM *JVP_jvm;
  jint res;
  JavaVMInitArgs vm_args;
  JavaVMOption options[1];
  struct sigaction sigAct;
  int ret;

  /* install a signal handler for SEGV */
  sigAct.sa_handler = SIG_DFL;
  sigAct.sa_sigaction = signalHandler;
  sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
  ret = sigaction(SIGSEGV,&sigAct,NULL);
  assert(ret == 0);

  options[0].optionString = "" ;
  // this resolves the problem, but does not install JVM's signal handlers:
  // options[0].optionString = "-XX:+AllowUserSignalHandlers" ;

  vm_args.version = JNI_VERSION_1_2 ;
  vm_args.options = options;
  vm_args.nOptions = 1;
  vm_args.ignoreUnrecognized = 1;

  res = JNI_CreateJavaVM(&JVP_jvm, (void **) &env, &vm_args);
  printf("JVM %screated.\n", res < 0 ? "not ":"" );


compiled with:
cc -I/usr/java/include -I/usr/java/include/linux hotsig.c
-L/usr/java/jre/lib/i386 -ljava

$ ldd a.out
        libjava.so => /usr/java/jre/lib/i386/libjava.so (0x4001e000)
        libc.so.6 => /lib/libc.so.6 (0x40042000)
        libjvm.so => /usr/java/jre/lib/i386/hotspot/libjvm.so (0x4013d000)
        libverify.so => /usr/java/jre/lib/i386/libverify.so (0x40541000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x40555000)
        libdl.so.2 => /lib/libdl.so.2 (0x4056b000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x4056e000)
        libstdc++-libc6.1-1.so.2 => /usr/lib/libstdc++-libc6.1-1.so.2
        libm.so.6 => /lib/libm.so.6 (0x405c8000)

$ a.out
# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
# Error ID: 4F533F4C494E55580E4350500549
# Problematic Thread: Segmentation fault

Is there a way to let the hotspot JVM install its own signal handlers
if there are already signal handlers installed before VM is brought up
thru JNI ?
(Review ID: 107898) 

WORK AROUND Name: stC104175 Date: 08/09/2000 use -XX:+AllowUserSignalHandlers option this does not install JVM signal handlers ======================================================================

PUBLIC COMMENTS > Is there a way to let the hotspot JVM install its own signal handlers > if there are already signal handlers installed before VM is brought up > thru JNI ? One way to have handled application signal handlers would have been to use signal handler chaining on the JVM side, i.e. when creating the VM have the JVM install its own handlers and remember the previous (if any) handlers. Then, if the signal wasn't for the VM to have passed it onto the original handler to handle. Instead, if an application uses its own handlers, and the -XX:+AllowUserSignalHandlers flag is used, the VM will not install its own handlers. In this case it is the responsibility of the application handlers to pass the signals that aren't for it onto Java via the following routine :- extern "C" int JVM_handle_linux_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized) The following clarifies how to use the function :- This routine may be used by user applications as a "hook" to catch signals. The user-defined signal handler must pass unrecognized signals to this routine, and if it returns true (non-zero), then the signal handler must return immediately. If the flag "abort_if_unrecognized" is true, then this routine will never retun false (zero), but instead will execute a VM panic routine kill the process. If this routine returns false, it is OK to call it again. This allows the user-defined signal handler to perform checks either before or after the VM performs its own checks. Naturally, the user code would be making a serious error if it tried to handle an exception (such as a null check or breakpoint) that the VM was generating for its own correct operation. This routine may recognize any of the following kinds of signals: SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGUSR1. It should be consulted by handlers for any of those signals. The caller of this routine must pass in the three arguments supplied to the function referred to in the "sa_sigaction" (not the "sa_handler") field of the structure passed to sigaction(). This routine assumes that the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. In order for stack overflow checking to operate correctly, the handler for SIGSEGV should also have to specify the SA_ONSTACK bit. Note that the VM will print warnings if it detects conflicting signal handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".

EVALUATION This is working as designed. See the public summary for a description of how user signal handlers should be used with the JVM. robert.lougher@Eng 2000-08-28