mmanders    01/06/19 15:57:25

  Modified:    src/native/jk Tag: tomcat_32 jk_jni_worker.c
  Log:
  Even though Apache is documented as only calling the module initializer function 
(jk_init) once, it actually calls it multiple times, at least on Windows.  A couple of 
times it is called on the same process which causes open_jvm to fail on the second 
pass because the jvm was alread instantiated on the first pass.  In open_jvm2, we can 
catch this and try to get the instatiated jvm and attach to it, preventing a hard 
failure (a call to jk_error_exit()) which also shuts down the webserver.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.3   +28 -7     jakarta-tomcat/src/native/jk/Attic/jk_jni_worker.c
  
  Index: jk_jni_worker.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/native/jk/Attic/jk_jni_worker.c,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- jk_jni_worker.c   2000/09/13 23:06:25     1.7.2.2
  +++ jk_jni_worker.c   2001/06/19 22:57:23     1.7.2.3
  @@ -57,7 +57,7 @@
    * Description: In process JNI worker                                      *
    * Author:      Gal Shachor <[EMAIL PROTECTED]>                           *
    * Based on:                                                               *
  - * Version:     $Revision: 1.7.2.2 $                                           *
  + * Version:     $Revision: 1.7.2.3 $                                           *
    ***************************************************************************/
   
   #if !defined(WIN32) && !defined(NETWARE)
  @@ -89,6 +89,7 @@
   
   jint (JNICALL *jni_get_default_java_vm_init_args)(void *) = NULL;
   jint (JNICALL *jni_create_java_vm)(JavaVM **, JNIEnv **, void *) = NULL;
  +jint (JNICALL *jni_get_created_java_vms)(JavaVM **, int, int *) = NULL;
   
   #define JAVA_BRIDGE_CLASS_NAME ("org/apache/tomcat/service/JNIEndpoint")
    
  @@ -688,10 +689,13 @@
           (FARPROC)jni_create_java_vm = 
               GetProcAddress(hInst, "JNI_CreateJavaVM");
   
  +        (FARPROC)jni_get_created_java_vms = 
  +            GetProcAddress(hInst, "JNI_GetCreatedJavaVMs");
  +
           (FARPROC)jni_get_default_java_vm_init_args = 
               GetProcAddress(hInst, "JNI_GetDefaultJavaVMInitArgs");
   
  -        if(jni_create_java_vm && jni_get_default_java_vm_init_args) {
  +        if(jni_create_java_vm && jni_get_default_java_vm_init_args && 
jni_get_created_java_vms) {
               return JK_TRUE;
           }
   
  @@ -711,9 +715,10 @@
       }
       if (0 != javaNlmHandle) {
           jni_create_java_vm = ImportSymbol(GetNLMHandle(), "JNI_CreateJavaVM");
  +        jni_get_created_java_vms = ImportSymbol(GetNLMHandle(), 
"JNI_GetCreatedJavaVMs");
           jni_get_default_java_vm_init_args = ImportSymbol(GetNLMHandle(), 
"JNI_GetDefaultJavaVMInitArgs");
       }
  -    if(jni_create_java_vm && jni_get_default_java_vm_init_args) {
  +    if(jni_create_java_vm && jni_get_default_java_vm_init_args && 
jni_get_created_java_vms) {
           return JK_TRUE;
       }
   #else 
  @@ -729,9 +734,10 @@
                  dlerror());
       } else {
           jni_create_java_vm = dlsym(handle, "JNI_CreateJavaVM");
  +        jni_get_created_java_vms = dlsym(handle, "JNI_GetCreatedJavaVMs");
           jni_get_default_java_vm_init_args = dlsym(handle, 
"JNI_GetDefaultJavaVMInitArgs");
   
  -        if(jni_create_java_vm && jni_get_default_java_vm_init_args) {
  +        if(jni_create_java_vm && jni_get_default_java_vm_init_args && 
jni_get_created_java_vms) {
            jk_log(l, JK_LOG_DEBUG, 
                      "In load_jvm_dll, symbols resolved, done\n");
               return JK_TRUE;
  @@ -909,7 +915,7 @@
       int optn = 0, err;
       char* tmp;
   
  -    *env = NULL;
  +    *env = penv = NULL;
   
       jk_log(l, JK_LOG_DEBUG, 
              "Into open_jvm2\n");
  @@ -970,10 +976,25 @@
       }
   
       jk_log(l, JK_LOG_DEBUG, "In open_jvm2, about to create JVM...\n");
  +
  +    err=jni_create_java_vm(&(p->jvm), &penv, &vm_args);
  +
  +    if (JNI_EEXIST == err)
  +    {
  +        int vmCount;
  +     jk_log(l, JK_LOG_DEBUG, "JVM alread instantiated.  Trying to attach 
instead.\n"); 
  +
  +        jni_get_created_java_vms(&(p->jvm), 1, &vmCount);
  +        if (NULL != p->jvm)
  +            penv = attach_to_jvm(p, l);
   
  -    if((err=jni_create_java_vm(&(p->jvm), &penv, &vm_args)) != 0) {
  +        if (NULL != penv)
  +            err = 0;
  +    }
  +
  +    if(err != 0) {
        jk_log(l, JK_LOG_EMERG, "Fail-> could not create JVM, code: %d \n", err); 
  -        return JK_FALSE;
  +            return JK_FALSE;
       }
       jk_log(l, JK_LOG_DEBUG, "In open_jvm2, JVM created, done\n");
   
  
  
  

Reply via email to