## Question Authors' Forum

### Java: Error occurred during initialization of VM

Java: Error occurred during initialization of VM

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];
}
}

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

Re: Java: Error occurred during initialization of VM

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

Re: Java: Error occurred during initialization of VM

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).

$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

Re: Java: Error occurred during initialization of VM

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