开发者

How to get Default JVM INITIAL ARGS In JNI

开发者 https://www.devze.com 2022-12-17 06:35 出处:网络
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?

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(vmlib开发者_JS百科path, 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;
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号