classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FAQ, 4.1 OutOfMemoryException


From: Andrew Haley
Subject: Re: FAQ, 4.1 OutOfMemoryException
Date: Fri, 14 Jan 2005 10:43:06 +0000

Artur Biesiadowski writes:
 > Sascha Brawer wrote:
 > 
 > > I was just re-reading the FAQ [1] -- what would speak against 
 > > pre-allocating thread-specific OutOfMemoryException objects when 
 > > creating a thread? (Probably more a VM-specific thing, but since it's 
 > > mentioned in the Classpath FAQ...)
 > 
 > You have basically two choices with implementing OOME. You can go
 > stacktrace-less route (only throw it, do not provide entire stack
 > trace with it) - then you can get away with single instance per
 > entire jvm, as it has no state. Or you can try to fit stack in
 > there - but place for it has to be preallocated. Memory usage can
 > start to sum up if you will preallocate it for every thread out
 > there. This looks like optimizing for very rare case for me and
 > making more garbage in the heap that it is needed for all normal
 > jvm runs.

Right.  In practice, handling OutOfMemoryException in a sane way is
extremely difficult.  I suspect the only real way to do it reliably is
reserve memory so that there is space for the exception to throw, but
then you need to stop other threads running during that time.

 > I'm not sure if danger of many threads throwing OOME at the same
 > time is really so big. Every sane jvm will trigger full gc before
 > throwing OOME - and to have full gc going, there has to be some
 > kind of synchronization on memory allocation between all threads. I
 > suppose it should be possible to lock heap/gc for as long as it is
 > needed to unwind stack to point where OOME is catched (if ever),
 > perform another gc and only then unblock heap monitor.

Indeed.  The problem is that anything you do when catching an
OutOfMemoryException risks running out of memory!  There's not much
any java program can do other than logging the failure and exiting.

Andrew.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]