Java: Error occurred during initialization of VM

Java: Error occurred during initialization of VM

por Sayee Krishnan -
Número de respuestas: 3

we got the  error like this while executing Java program. we used Java method for this program.

Source code is:

int sumSquares(int[] data) {
    int total = 0;
    for (int i = 0; i < data.length; i++) {
        total += data[i] * data[i];
    }
    return total;
}

Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes

Any idea as to what should be modified.



Thank you.


Sayee Krishnan.S


En respuesta a Sayee Krishnan

Re: Java: Error occurred during initialization of VM

por Richard Lobb -

It seems from a quick web search that your Jobe server must be using Oracle Java rather than the usual open-jdk. There's apparently a bug in Oracle Java if you try to run it when there's a memory limit imposed by ulimit (see http://bugs.java.com/view_bug.do?bug_id=8043516).

Probably the easiest fix is to turn off the use of ulimit by setting the memory limit for the job to 0. That should be safe, because the Java VM manages memory itself.

To set the memory limit to 0, log in as an administrator and edit your three Java question prototypes, which are in the CR_PROTOTYPES category. Open the Advanced customisation section, and set the Memory Limit field to 0.

Please post back advising whether or not that solves the problem. If it does, I'll think about whether to set the memory limit to 0 for all Java questions in the distribution.

Richard

En respuesta a Richard Lobb

Re: Java: Error occurred during initialization of VM

por Richard Lobb -

Oops. Looking at the code, I see that my "fix" won't work, because Jobe ignores the memorylimit parameter in the case of Java (which asks for silly amounts of virtual memory when it starts, but doesn't use most of it).

Assuming you have access to Jobe as a sysadmin, you could try the following fix instead. Around line 17 of <jobehome>/application/libraries/java_task.php you'll find a line like:

$params['memorylimit'] = 2500; // 2.5GB - JVM is greedy!

Change that to 

$params['memorylimit'] = 0;   // Disregard memory limit - let JVM manage memory

As I said in the previous posting, this doesn't mean student submissions can gobble unlimited memory, as memory limits are set by the JVM (and can be configured by a question author using java command parameters like -Xss and -Xmx)

I'll be pushing this change (and quite a few others) to github within the next 24 hours, so if it's not urgent you could hold off until then.

Richard