Requested array size exceeds VM limit...

Discussion in 'Java' started by aa@dsa-ac.de, Nov 27, 2006.

  1. Guest

    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
     
    , Nov 27, 2006
    #1
    1. Advertising

  2. wrote:
    ....
    > 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.
     
    Andrew Thompson, Nov 28, 2006
    #2
    1. Advertising

  3. Guest

    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
     
    , Nov 28, 2006
    #3
  4. 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.
     
    Andrew Thompson, Nov 28, 2006
    #4
  5. On 27 Nov 2006 11:04:19 -0800, wrote:
    > 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

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Nov 28, 2006
    #5
  6. Guest

    Hello,

    you are right! Thank you for hint, it works now...

    Anahita
     
    , Nov 28, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z2xlbm4=?=
    Replies:
    0
    Views:
    348
    =?Utf-8?B?Z2xlbm4=?=
    Jun 22, 2006
  2. Replies:
    14
    Views:
    935
    Mark McIntyre
    Jan 28, 2006
  3. Replies:
    1
    Views:
    1,132
    Victor Bazarov
    Jun 28, 2005
  4. Ben
    Replies:
    7
    Views:
    449
    Dave Anderson
    May 17, 2006
  5. Replies:
    2
    Views:
    403
    Eric Sosman
    Dec 17, 2013
Loading...

Share This Page