OutOfMemoryError (on GCOverheadLimit)
Florian Binder
java at java4.info
Thu Jul 12 09:40:29 PDT 2012
Hi Everyone,
I have seen an OutOfMemoryError can be thrown even if there would be
enough space for the allocation (if it takes more than 98% of time or
something like this).
But the javadoc of OutOfMemoryError says:
"Thrown when the Java Virtual Machine cannot allocate an object because
it is out of memory, and no more memory could be made available by the
garbage collector."
Therefore I thought an OutOfMemoryError can only be thrown if memory is
allocated.
For the serial and parallel gc this is no problem, because the gc is
only triggered on object allocations. But what is with the CMS or G1?
When do they throw the OOME if the OverheadLimit is reached? On the next
object allocation or immidiately (interrupting the thread[s] at any
position)? And which Thread is getting the OOME? Only one, or all?
The reason for these questions is that I would like to know if OOME can
be thrown only on object allocation or anytime.
Is it possible that the following method throws an OOME?:
public int sumAll(int[] data) {
int sum = 0;
for(int i = 0; i < data.length; i++) {
sum += data[i];
}
return sum;
}
Thanks,
Flo
More information about the hotspot-gc-use
mailing list