Hi,
I am using a JVM as a companion aof a big C program . Thus I start the JVM myself, using JNI_CreateJavaVM.
It is a GUI Win2K app, using some JDK1.3 or mosre recent, from SUN or IBM.
I would like to able to restart the JVM without restarting my app (for instance, to run it in debug mode, thus changing the starting parameters, or to run a different VM).
But the second call to JNI_CreateJavaVM stops my app.
Here is a small program that isolate the behavior :
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
JavaVM *jvm,*vmBuf[1024];
JNIEnv *env;
static char * params[]=
{
"-Djava.compiler=NONE",
NULL
};
JavaVMInitArgs args;
long rc=0,nVMs;
JavaVMOption *cp,*curcp;
int _i,nbPar;
main()
{
for(nbPar=0;params[nbPar]!=NULL;nbPar++);
cp=malloc(sizeof(*cp)*(nbPar+2));
curcp=cp;
for(_i=0;_i<nbPar;_i++)
{
char *par=params[_i];
// we make a copy because cp[].optionString is not declared as const...
curcp->optionString=malloc(strlen(par)+1);
strcpy(curcp->optionString,par);
curcp++;
}
args.version = JNI_VERSION_1_2;
args.nOptions = curcp-cp;
args.options = cp;
args.ignoreUnrecognized = JNI_FALSE;
rc=JNI_CreateJavaVM(&jvm, (void**)&env,&args);
if(rc != 0)
{
printf( "JNI_CreateJavaVM failure");
return(1);
}
rc=(*jvm)->DetachCurrentThread(jvm);
if(rc != 0)
{
printf( "DetachCurrentThread failure");
return(1);
}
rc=(*jvm)->DestroyJavaVM(jvm);
if(rc != 0)
{
printf( "DestroyJavaVM failure");
return(1);
}
nVMs= -1;
rc=JNI_GetCreatedJavaVMs(vmBuf, 1024,&nVMs);
if(rc != 0)
{
printf( "JNI_GetCreatedJavaVMs failure");
return(1);
}
printf("JNI_GetCreatedJavaVMs = %d\n",nVMs);
rc=JNI_CreateJavaVM(&jvm, (void**)&env,&args);
if(rc != 0)
{
printf( "Second JNI_CreateJavaVM failure");
return(1);
}
}
for example, running withy sun JDK1.3.01 server dll, it ouputs :
JNI_GetCreatedJavaVMs = 0
#
# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Error ID: 455843455054494F4E530E43505000D8
#
# Problematic Thread: prio=8865624 tid=0x874758 nid=0x14a3e70b allocated
#
Is there any workaround ?
Thanks for your help
C.Dore
PS: the bug is submitted, but a wide and clever audience opinion is also accurate.