JDK-6283297 : JNI_CreateJavaVM spec clarification
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-06-09
  • Updated: 2021-09-02
  • Resolved: 2005-12-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 betaFixed
Related Reports
Relates :  
Description
After creating and destroing VM you can't create it once more. JNI spec unclear in this case. It states restriction in JDK version 1.1 only, and say nothing about other versions. "One process - one VM" is a good rule, but what is about successive creation/destroing of VM?

#include <jni.h>
#include <signal.h>
#include <stdio.h>

static JNIEnv *env;
static JavaVM *vm;

void initVM()
{
    vm = 0;
    env = 0;

    JavaVMInitArgs vm_args;
    JavaVMOption opt[2];

    opt[0].optionString = "-verbose:jni";
    opt[1].optionString = "-Xcheck:jni";
    vm_args.nOptions = 2;
    vm_args.version = JNI_VERSION_1_4;
    vm_args.ignoreUnrecognized = JNI_TRUE;
    vm_args.options = opt;

    jint result = JNI_CreateJavaVM( &vm, (void **) &env, &vm_args );

    if (result != 0) {
        printf("# ERROR: cannot create Java VM. %d\n", result);
        exit(result);
    }

    //(*vm)->AttachCurrentThread(vm, (void **) &env,  (void *) 0);
    printf("JVM started and attached\n");
    result = (*vm)->DestroyJavaVM(vm);

    if (result != 0) {
        printf("# ERROR: cannot destroy Java VM. %d\n", result);
        exit(result);
    }
}


int main(int argc, char **argv)
{
    int i;

    for (i = 0; i < 1000; ++i)
        initVM();

    return 0;
}

###@###.### 2005-06-09 17:12:50 GMT

Comments
EVALUATION JNI spec was updated to clean up the CreateJavaVM entry.
15-12-2005