tags:

views:

60

answers:

1

I'm trying to get the default jvm args of the available JVM but I'm getty a strange output. Anyone can point me to what's wrong?

Output:

65542
�p����Y����k�.L�R���g���J����sk��,��*�Jk��xk��

Code:

#include "jni.h"
#include <iostream>
#include <dlfcn.h>
#include <cstdlib>

using namespace std;

void * JNI_FindCreateJavaVM(char *vmlibpath) {
    void *libVM = dlopen(vmlibpath, RTLD_LAZY);

    if (libVM == NULL) {
        return NULL;
    }
    return dlsym(libVM, "JNI_GetDefaultJavaVMInitArgs");
}

int main() {
    JavaVMOption vm_options;
    JavaVMInitArgs vm_args;

    vm_args.version = JNI_VERSION_1_6;
    vm_args.ignoreUnrecognized = JNI_FALSE;
    vm_args.options = &vm_options;

    void* (*lib_func)(void *) = 0;

    lib_func = (void*(*)(void*)) JNI_FindCreateJavaVM(
            "/usr/lib/jvm/java-6-sun/jre/lib/i386/client/libjvm.so");

    lib_func(&vm_args);

    cout << vm_args.version << endl;
    cout << vm_args.options[0].optionString << endl;

    return 0;
}
+1  A: 

The prototype for JNI_GetCreatedJavaVMs is:

jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs);

You call the function with a *JavaVMInitArgs parameter and I am not sure why you expect your code to print anything reasonable.

jarnbjo
I eddited but now I'm getting the following output:65542�p����Y����k�.L�R���g���J����sk��,��*�Jk��xk��
Marcos Roriz