online.0227
online.0227

Reputation: 648

Re-calling JNI_CreateJavaVM returns -1 after calling DestroyJavaVM

I am trying to recall JNI_CreateJavaVM after calling DestroyJavaVM.

I call them in following order: InitJVM -> ReleaseJVM -> InitJVM

First time when initialing, JNI_CreateJavaVM returns 0 and works fine. second time when initialing after destroying, JNI_CreateJavaVM return -1 and does not work.

What would be the problem?

Here is a function that create JVM:

#elif __linux
HRESULT PWNJava::InitJVM(void) {

    if(m_bRunning) {
        Log("Error : JVM is already Running! (PWNJava::Init)");
        return PWN_FAIL;
    }

    const int kNumOptions = 3;
    JavaVMOption options[kNumOptions] = {
        { const_cast<char*> ("-Xmx128m"), NULL},
        { const_cast<char*> ("-verbose:gc"), NULL},
        { const_cast<char*> ("-Djava.class.path=../../Class"), NULL}
    };

    JavaVMInitArgs vm_args;
    vm_args.version = JNI_VERSION_1_6;
    vm_args.options = options;
    vm_args.nOptions = sizeof (options) / sizeof (JavaVMOption);
    assert(vm_args.nOptions == kNumOptions);

    int res = JNI_CreateJavaVM(&jvm, reinterpret_cast<void**> (&env), &vm_args);
    if (res != JNI_OK) {
        Log("Error : createJavaVM(&jvm, &env, &vm_args)");
        return PWN_FAIL;
    }

    m_bRunning = true;

    Log("Success : PWNJava::Init");

    return PWN_OK;
}

#endif

Here is a function deleting JVM:

void PWNJava::ReleaseJVM(void) {

    if (jvm)
        jvm->DestroyJavaVM();

    jvm = NULL;
    delete jvm;

    env = NULL;
    delete env;

    m_bRunning = false;

    Log("Success : PWNJava::ReleaseJVM");

}

Upvotes: 2

Views: 2091

Answers (1)

user207421
user207421

Reputation: 310980

Last time I looked at JNI_DestroyJVM(), it said "The JDK/JRE still does not support VM unloading, however." Just don't call it, and don't re-initialize it either.

Upvotes: 2

Related Questions