开发者

Creating a JVM per JNI_CreateJavaVM, receiving a OutOfMemoryError

I'm creating a JVM out of a C++-program per JNI, and the creation itself works fine. The communication with the JVM works also fine; I am able to find classes, create objects, call methods and so on. But one of my methods needs quite a lot of memory, and the JVM throws a OutOfMemoryError when calling it. Which I don't understand, as there is more than one GB of free RAM available. The whole process uses about 200MB and it seems that it doesn't even try to allocate more; it sticks at 200MB and then the exceptions is thrown.

I tried to pass the -Xmx-option to the JVM, but it won't work when the JVM is created through JNI. As far as I understood, a JVM created through JNI should be able to access all the memory available, making the -Xmx-options unnecessary - but obviously th开发者_如何学运维is assumption is wrong.

So the question is, how can I say the JVM that it just should use as much as memory as it needs?

System: MacOS 10.6

Creation of the JVM:

JNIEnv *env;
JavaVMInitArgs vm_args;

JavaVMOption options;
//Path to the java source code
options.optionString = jvm_options; // setting the classpath
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;

int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);
if(ret < 0)
  printf("\nUnable to Launch JVM\n");


Seems like I got something wrong with the -Xmx-option - tried it again and it works now.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜