Question Authors' Forum

Java: Error occurred during initialization of VM

 
Picture of Sayee Krishnan
Java: Error occurred during initialization of VM
by Sayee Krishnan - Wednesday, 11 January 2017, 11:53 PM
 

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


Picture of Richard Lobb
Re: Java: Error occurred during initialization of VM
by Richard Lobb - Thursday, 12 January 2017, 8:31 AM
 

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

Picture of Richard Lobb
Re: Java: Error occurred during initialization of VM
by Richard Lobb - Thursday, 12 January 2017, 5:15 PM
 

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

Picture of clint welbar
Re: Java: Error occurred during initialization of VM
by clint welbar - Tuesday, 18 April 2017, 6:36 PM
 
Starting a JVM like below will start it with 256MB of memory, and will allow the process to use up to 2048MB of memory:

  java -Xmx2048m -Xms256m

More about...memory management

Clint