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;
}