Requested array size exceeds VM limit...

A

aa

Hello,

I create a Java virtual machine in a C++ application with
following settings:
....
string classPath = // any class path

JavaVMOption options[4];
options[0].optionString = const_cast<char*>(classPath.c_str());
options[1].optionString = const_cast<char*>("-Xmx512m");
options[2].optionString = const_cast<char*>("-Xss1m");
options[3].optionString = const_cast<char*>("-Xoss1m");

JavaVMInitArgs args;
args.version = JNI_VERSION_1_4;
args.nOptions = 4;
args.options = options;
args.ignoreUnrecognized = JNI_TRUE;
....

This part runs correctly and I get a valid virtual machine.
The problem is in the code below:
....
jClass = mEnv->FindClass("java/lang/String");
jConstructor = mEnv->GetMethodID(jClass, "<init>", "([B)V");
jInputObject = mEnv->NewObject(jClass, jConstructor);
....
and also here:
....
// 'len' is 7
jbyteArray jByteField = mEnv->NewByteArray(static_cast<jsize>(len));
....

In both of above cases an exception has been thrown
with this message:
Requested array size exceeds VM limit

I changed the maximum heap size (until 1 megabytes)
but without any result. What is wrong in my code? Must I
change any virtual machine settings?

Any idea?

Thanks in advance,
Anahita
 
A

Andrew Thompson

I create a Java virtual machine in a C++ application with
following settings:

I have no experience with that exact area, but..
// 'len' is 7
jbyteArray jByteField = mEnv->NewByteArray(static_cast<jsize>(len));

...what makes you so sure the value of len is '7'?
Did you log it or print it just before the line?
If not, I suggest you do confirm the value is 7.

Andrew T.
 
A

aa

Hello,

I had followed it with debugger and was sure
that the 'len' is 7 just before the last line. However I
adjusted the code temporarily and set the required
array size to 1. It doesn't work even for one byte!

....
jsize jLen = 1;
jbyteArray jByteField = mEnv->NewByteArray(jLen);
....

Thanks,
Anahita
 
A

Andrew Thompson

(e-mail address removed) wrote:
.....
I had followed it with debugger and was sure
that the 'len' is 7 just before the last line. However I
adjusted the code temporarily and set the required
array size to 1. It doesn't work even for one byte!

...
jsize jLen = 1;
jbyteArray jByteField = mEnv->NewByteArray(jLen);
...

That is bizarre! Unfortunately, I am really not
experienced enough with this area to comment
further, so I am bowing out of this thread in hope
that some of the gurus will happen by very soon,
to clarify the meaning of that, and advise further.

I'll sure keep tuned..

Andrew T.
 
G

Gordon Beaton

The problem is in the code below:
...
jClass = mEnv->FindClass("java/lang/String");
jConstructor = mEnv->GetMethodID(jClass, "<init>", "([B)V");
jInputObject = mEnv->NewObject(jClass, jConstructor);

You didn't supply the argument needed by the constructor. I'd expect
erratic or undefined behaviour from this point on.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top